Author Topic: Using macros to put struc on stack  (Read 7057 times)

Offline Dumah

  • Jr. Member
  • *
  • Posts: 4
Using macros to put struc on stack
« on: August 22, 2011, 07:09:59 PM »
Hi.

I'm trying to get used to the preprocessor on NASM and trying to understand the stack managing macros (4.8 of http://www.nasm.us/doc/nasmdoc4.html).

I understand how the %local directive works, but was wondering if I could use it with data sizes other than word, dword etc.

If I defined a data structure with 'struc', could I use it here? I have tried to do so but have come up with errors.

Any suggestions would be welcome.

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Using macros to put struc on stack
« Reply #1 on: August 22, 2011, 07:56:44 PM »

Nasm support of structures is currently sparse. You may wish to think of structures as just an array of bytes with a specific size and field offsets within that array.

You might also be interested in the NASMX package.  You can read the announcement here.  There is a bunch of information available at the NASMX Project forum.

May help you, or may not...


Offline Dumah

  • Jr. Member
  • *
  • Posts: 4
Re: Using macros to put struc on stack
« Reply #2 on: August 22, 2011, 07:59:39 PM »
Thanks, I'll give it a look.

With regard to the %local directive, do you know how I would declare a lump of memory (say 20 bytes)?

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Using macros to put struc on stack
« Reply #3 on: August 22, 2011, 08:22:26 PM »
That's just one area where NASMX will help you.

A quick example ( I just now wrote it, thus untested )

Code: [Select]
proc myfunc
locals
    local varA, dword   ; reserve one dword - 4 bytes
    local varB, byte    ; reserve one byte
    local varC, byte, 255    ; reserve an array of bytes
endlocals
    ;
    ; your code here
    ;
endproc

hope that helps.

Offline Dumah

  • Jr. Member
  • *
  • Posts: 4
Re: Using macros to put struc on stack
« Reply #4 on: August 22, 2011, 08:24:15 PM »
Ah...that looks like what I need. I'd better get downloading and reading the manuals...

Many thanks