NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: JoeCoder on July 06, 2011, 08:03:37 AM

Title: Can you tell the assembler a certain gpr is the base address for a symbol?
Post by: JoeCoder on July 06, 2011, 08:03:37 AM
Hi guys. I understood from one of Frank's examples the way to use structs is something like

Code: [Select]
struc mystruc
  fielda resd 1
  fieldb resd 1
endstruc

and then

Code: [Select]
mov eax,mystruc
mov dword [eax+fielda],fieldc

In the assembler I use for work, we have a way to tell the assembler that a certain gpr should be used as a base address for a structure. It's actually more flexible and complicated than that, but what I want to know is if there is a way to accomplish that feature in NASM.

Edit: I guess the above example is invalid in x86 since you can't "mov" storage to storage, but I don't know how to give a more obvious example and I hope you get the general idea.

I would like to be able to let the assembler know that eax is the base register for mystruc so that I could refer to fields directly and do something like

Code: [Select]
mov eax,mystruc
; tell the assembler eax is the base address for mystruc
mov dword fielda,fieldc

Is this possible?

Thanks.
Title: Re: Can you
Post by: Rob Neff on July 06, 2011, 10:51:19 AM
If I understand you correctly you are asking if the assembler "assumes" certain registers such that they do not have to be specified within the line of code.  While x86 does have certain registers that are used implicitly with opcodes you must always specify the base and offsets when accessing your structures.  However you are free to write macros that emulate that behavior.  That's pretty much how the var() and argv() macros are designed in NASMX which use ebp as the base register.  Different purpose but same concept...
Title: Re: Can you
Post by: JoeCoder on July 06, 2011, 11:21:55 AM
Thanks, I'll look into those. Sorry for the subject title, I fixed it now.