1 %macro print 2 ; Declare a macro to print a string, with two arguments
2 mov eax,4 ; Put magic # for system call sys_write into rax
3 mov edi,1 ; Prepare arg 1 of sys_write, 1 - file descriptor of stdo
4 mov esi,%1 ; Prepare arg 2, a string reference
5 mov edx,%2 ; Prepare arg 3, string length, no deref. b/c constant
6 int 80h ; Call the kernel
10 hello: db 'Hello, world.',10 ; declare initialized string with linefeed char
11 helloLen: equ $-hello ; declare and init. constant
15 global _start ; Declare program entry point
18 push ebp ; Prologue, save stack pointer
19 mov ebp,esp ; Get base pointer (start of arguments)
20 mov ebx,[ebp+8] ; Get first argument (offset from base by the return address)
21 print ebx,helloLen ; Macro, replaced inline
22 leave ; Epilogue, equivalent to mov esp,ebp; pop ebp
23 ret ; Return control to caller
26 cmp byte [done],1 ; Compare byte padded value of done with 1
27 jg exit ; Jump if greater than to exit
29 mov byte [done], 1 ; Put 1 in done
31 push hello ; Push the last argument of _print onto the stack
32 call _print ; Call the function _print
35 mov eax,1 ; The system call for exit (sys_exit)
36 mov edi,0 ; Exit with return code of 0 (no error)