views:

271

answers:

2

Can somebody please explain how to use macros in x86 assembly coding

+4  A: 

It depends on what complier you are using.

Typically an assembler macro will take the following form;

begin MyMacro %1, %2
   mov eax, %1
   add eax, %2
end

This would exist in the header section of your source code and does not output any code unless it is referenced. You would inline this with the other assembler.

mov ecx, 88
MyMacro ecx, 12
asr ecx, 3

The "parameters" %1 and %2 in this case would be replaced with ecx and 12 generating the following output

mov ecx, 88
mov eax, ecx
add eax, 12
asr ecx, 3
Dead account
thank u for the solution :)
no problem, please mark as answer
Dead account
Great Ian. Even a bad asked question deserves a good answer :)
jyzuz
A: 

That's a really broad question. There are a zillion ways to use Macros. Some assembly language developers use them tons, some hate them.

One of the most common ways is to use macros for function prologues and epilogues. Another is to use them for fetching saving parameters on the stack.

Foredecker