Qbasicnews.com

Full Version: NASM with QB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Before I ask my questions, I would like to tell you that I have absolutely no experience writing ASM and I don't know what I'm doing. Wink

I'm using NASM (the Netwide Assembler) to make a QB lib. Just for starters, I wrote a little mouse routine:

Code:
uppercase
use16
segment code

align 4
global MouseShow
MouseShow:
push bp
mov bp,sp
mov ax,1
int 33h
pop bp
retf

This works just fine. But now, I want to put the value that I'm going to store into ax in a memory variable thingy. I try this:
Code:
uppercase
use16

segment data
TestVar dw 1
segment code

align 4
global MouseShow
MouseShow:
push bp
mov bp,sp
mov ax,TestVar
int 33h
pop bp
retf
This doesn't work. I also tried putting brackets around TestVar in the mov (mov ax,[TestVar]), but that didn't help. Do I need to do something special because TestVar is in a different segment from the mouse routine? Any help would be appreciated.
Haven't used NASM but QB expects these values in functions:

Byte: Al
Integer: Ax
LongIntegers : Dx:ax
I'm pretty sure that in NASM, "mov ax,TestVar" moves the address of TestVar into ax. You need to use square brackets any time you want to read/write TestVar's value.

Maybe your library and Qb aren't using the same segment for data. Try it with some code to check if the segment address of TestVar equals DS.
Ah, I figured it out. I used mov ax,[ds:TestVar] and it worked just fine. Smile But now I have more questions... how do I get arguments from QB? I've tried this (it should be a function that returns the 2-byte int passed to it back again, i.e. func(5) should return 5)
Code:
global func
func:
push bp
mov bp,sp
mov ax,[bp+6]
pop bp
retf 2
I define it in QB as DECLARE FUNCTION func%(n%) and call it like PRINT func%(5).
But this doesn't work... I get something like 3523 or something every single time... do I need to do something with segments here too? I tried putting [ss:bp+6] but that didn't seem to help... is my ss the same as QB's ss when my function gets called? And do I need to allocate stack space in a stack segment (in MASM/TASM, this seems to be done with .STACK 100h or similar)...?
QB is passing the address of n% because you don't have a BYVAL before the n%.
Use DECLARE FUNCTION func%(BYVAL n%) or

mov bx,[bp+6]
mov ax,[bx]

(not both...)
Man, I'm stupid... I knew that. Smile Too much VB.NET goes to the head.

Yet another question:
Are floating-point values returned from functions in DX:AX or ST0 or somewhere else?
Also, is it always safe to assume that any scalar data (i.e. Integer, Long, Single, Double) is stored in DS, or is it possible for QB to use a different segment?
When passing byref (or whatever the default is called), it's always in DS, I guess because QB copies it there. The only time it ever isn't in DS is when it's BYVAL on the stack or passed with SEG.