# # File: while1.s # Author: William T Krieger, Oct 2003 # # My modification of the while1 test case demonstrating a simple while loop. .text FMT0: .ascii "x = %d\12\0" FMT1: .ascii "Done.\0" .align 4 # # Function: _main() # void _main() # Deomonstrates a simple while loop. .globl _main _main: pushl %ebp # enter _main() movl %esp, %ebp subl $4, %esp # adjust stack for 1 local var # x = -4(%ebp) movl $7,-4(%ebp) # x = 7 LOOP_START: cmpl $0,-4(%ebp) # compare( 0, x) jg LOOP1_BODY # if > jump to LOOP1_BODY jmp LOOP1_END # else jump to LOOP_END1 LOOP1_BODY: movl -4(%ebp),%eax # call printf( fmt, x) pushl %eax pushl $FMT0 call _printf addl $8,%esp decl -4(%ebp) # x-- jmp LOOP_START # jump to top of loop LOOP1_END: pushl $FMT1 # call printf( fmt1) call _printf addl $4,%esp movl %ebp, %esp # exit _main() pop %ebp ret