Why NASM macros don't generate code?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Why NASM macros don't generate code?

Post by ~ »

Whether I use NASM or YASM I'm having a problem in which macros don't seem to generate anything for some reason.

I have tried putting them before the rest of the code but they keep. Even YASM reports them as undefined symbols if I try to use them in some code like this (because of the local label named .__1):

Code: Select all

   .__1:
   ___MACRO_push_rsp
   ___MACRO_pop_rsp

   mov eax,ebp
   cmp dword[eax+1_],2
   je .__1
They aren't reported as undefined if I use a global label (without a dot at the beginning of if).


My macros are something like this:

Code: Select all

%macro ___MACRO_push_rsp 0
 push esp


%endmacro



%macro ___MACRO_pop_rsp 0
 pop esp


%endmacro


But they don't generate code for some reason. It's as if they weren't included in the source files and if they are called more than once it's like defining a label and is reported as a redefinition.

It doesn't happen if I put the macros in a source file with macros only (no other definitions or db, dw, dd variables, etc.) and also if I put them before anything else in the program includes. Maybe it's like C with some definitions which need to be defined before first use?


Does anybody know what could be done or some further information I coud provide to solve this?
Last edited by ~ on Mon Jan 04, 2010 8:38 am, edited 1 time in total.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Why NASM macros don't generate code?

Post by thepowersgang »

Did you remember to actually call the macros?
Just defining a macro does nothing to the final output, it needs to be invoked.

Example:

Code: Select all

%macro FRAME_INIT 0
push ebp
mov ebp, esp
%endmacro
%macro FRAME_CLOSE
pop ebp
%endmacro

function:
    FRAME_INIT
    ... do stuff
    FRAME_CLOSE
    ret
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Why NASM macros don't generate code?

Post by qw »

I don't find anything wrong. You are defining the macro's before using them, arent't you? Maybe you'd better post the complete code.
Post Reply