Advanced macros and %include

%include

%include pastes another file into the source at assembly time. Put shared constants and macros in one file and include it wherever they are needed:

%include "consts.inc" %include "macros.inc"

%define

%define names a constant or a simple macro. Case matters: %define and %idefine differ, and %xdefine re-expands at definition time. Use it for syscall numbers and struct offsets:

%define SYS_EXIT 60 %define PTR_SIZE 8 %define BUF_END buf + BUF_LEN

%if and friends

The preprocessor has conditionals: %if, %ifdef, %elif, %else, %endif. They test assembly-time values, so one source can build with or without debug code:

%ifdef DEBUG mov rdi, debug_msg call print_string %endif

Next: Linking object files

Article author: Arthur Isaev