NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: Dumah on August 22, 2011, 07:09:59 PM

Title: Using macros to put struc on stack
Post by: Dumah 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.
Title: Re: Using macros to put struc on stack
Post by: Rob Neff 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 (http://forum.nasm.us/index.php?topic=1226.0).  There is a bunch of information available at the NASMX Project forum (http://www.asmcommunity.net/board/index.php?board=77.0).

May help you, or may not...

Title: Re: Using macros to put struc on stack
Post by: Dumah 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)?
Title: Re: Using macros to put struc on stack
Post by: Rob Neff 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.
Title: Re: Using macros to put struc on stack
Post by: Dumah 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