# # File: template.s # Author: William T Krieger, Oct 2003 # # This is a template that can be used as a starting point for # writing assembly code functions, not just main(). # data section: global vars .data x: .long 7 # x = 7 y: .long 23 # y = 23 # bss section: un-initialized global vars .bss z: .long # global var z # text section: code .text format: .ascii "Hello world\0" # # Function: _main() # void _main() # This function is a shell demonstrating how to setup the entry, # body and exit parts of a function. .globl _main # required by linker to find _main() _main: pushl %ebp # enter _main(), save caller's FP movl %esp, %ebp # set our FP pushl %ebx # save regs we change in this function pushl %edi pushl %esi # # your code goes here! # pop %esi # restore regs that we saved at the top pop %edi pop %ebx movl %ebp, %esp # exit _main(), restore caller's SP pop %ebp # restore caller's FP ret