# # File: func1_mod.s # Author: William T Krieger, Oct 2003 # # My modification of the func1 test case. # It demonstrates a simple function call. # There are also global variables: initialized and not. # data section: global vars .data x: .long 0 # x = 0 y: .long 0 # y = 0 .bss z: .long # global var z .text # start text sections: code and constants # # Function: _main() # void _main() # Demonstrates good, old reliable "Hello world". Shows how to call printf(). .globl _main _main: pushl %ebp # enter _main() movl %esp, %ebp movl $5,x # x = 5 movl x,%eax # call plus10( x) pushl %eax call plus10 addl $4,%esp movl %eax,y # y = return value movl %ebp, %esp # exit _main() pop %ebp ret # # Function: plus10 # int plus10( int p1) # The return value is p1+10. .globl plus10 plus10: pushl %ebp # enter plus10() movl %esp, %ebp movl 8(%ebp),%edx # %edx = first parameter addl $10,%edx # %edx = %edx + 10 movl %edx,%eax # %eax = %edx, set return value movl %ebp, %esp # exit plus10() pop %ebp ret