The GNU Assembler

The macro engine of the GNU Assembler is quite similar to that of Microsoft's MASM, yet there are a few syntactic differences (not taking into account the overall syntax difference) that we have to pay attention to. Let us take the output_message procedure from the Linux test program in Chapter 2, Setting Up a Development
Environment
, and replace the call to printf() with a simple macro for demonstration purposes.

.macro print message       ; .macro macro_name parameter
pushl message ; Put the parameter on stack
; parameters are prefixed with ''
call printf ; Call printf() library function
add $4, %esp ; Restore stack after cdecl function call
.endm

output_message:
pushl %ebp
movl %esp, %ebp
print 8(%ebp) ; This line would expand to the above macro
movl $0, %eax
leave
ret $4
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset