NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: waltje on December 24, 2020, 08:16:31 PM
-
Hi all,
Just finished porting several projects from Fasm to Nasm, for several reasons.
These are realmode (BIOS and DOS) projects, so all is 16bit here.
Only thing left to do is fixing the structure accessing.
Case:
We have a struct, defined as
struc foo
.bar db ?
.bla db 20 dup(?)
.erm dw ?
endstruc
Now, we get called from another task, and they pass us a
pointer to 'foo' in es:bx.
The code then wants to do
mov al, es:[bx].bar
but it chokes, as it doesnt know what to do with the '.bar' tag.
What is the proper syntax to "cast" the es:bx pointer to be of
type 'foo' ? I also tried
mov al, es:[bx]foo.bar
but still nada...
Thankyou,
Fred
-
Hi Fred.
Welcome to the forum.
Nasm likes everything inside the square brackets...
mov al, [es: bx + foo.bar]
... should work.
Best,
Frank
P. S. Nasm doesn't do "dup". "times 20 0"
-
P. S. Nasm doesn't do "dup". "times 20 0"
Or using res? like:
struc foo
.bar: resb 1
.bla: resb 20
.erm: resw 1
endstruc
-
Yeah that would be better. But not "dup".
Best,
Frank
-
> Yeah that would be better. But not "dup".
From the manual (and my code ;-) :
"Since NASM 2.15, the MASM syntax of using ? and DUP in the Dx directives is also supported. Thus, the above example could also be written:"
At any rate.... learned that the displacement has to come BEFRORE the pointer,
as in:
mov al, es:foo.bar[bx]
and that indeed works. Yay!
That said, it would be more syntax-consistent to have:
mov al, foo ptr es:[bx].bar
akin to using 'word ptr' and the like, which pretty much
tell the assemble about the 'type' of the operand ?
Fred
-
I stand corrected.
Best,
Frank