Author Topic: Can you tell the assembler a certain gpr is the base address for a symbol?  (Read 10760 times)

Offline JoeCoder

  • Jr. Member
  • *
  • Posts: 72
  • Country: by
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.
« Last Edit: July 06, 2011, 11:24:37 AM by JoeCoder »
If you can't code it in assembly, it can't be coded!

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Can you
« Reply #1 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...

Offline JoeCoder

  • Jr. Member
  • *
  • Posts: 72
  • Country: by
Re: Can you
« Reply #2 on: July 06, 2011, 11:21:55 AM »
Thanks, I'll look into those. Sorry for the subject title, I fixed it now.

If you can't code it in assembly, it can't be coded!