# Execution begins at address 0 .pos 0 init: irmovl Stack, %esp # Set up Stack pointer irmovl Stack, %ebp # Set up base pointer jmp Main # Execute main program # Array of 4 elements .align 4 array: .long 0xd .long 0xc0 .long 0xb00 .long 0xa000 Main: irmovl $4,%eax pushl %eax # Push 4 irmovl array,%edx pushl %edx # Push array call RSum # Sum(array, 4) halt /* $begin sum-ys 0 */ /* Recursive sum (used to test leave) */ # int RSum(int *Start, int Count) RSum: pushl %ebp rrmovl %esp,%ebp pushl %ebx # save %ebx mrmovl 8(%ebp),%ecx # ecx = Start mrmovl 12(%ebp),%edx # edx = Count irmovl $0, %eax # sum = 0 andl %edx,%edx # any remaining elements ? je End # no - we are done # make recursive call irmovl -1,%ebx addl %edx,%ebx # count-1 pushl %ebx irmovl $4,%ebx addl %ecx,%ebx # start+4 pushl %ebx call RSum # compute sum (start+1,count-1) # clean up the stack popl %ebx popl %ebx mrmovl 8(%ebp),%ecx mrmovl (%ecx),%ebx # get *Start addl %ebx,%eax # add to sum End: popl %ebx leave ret /* $end sum-ys 0 */ .pos 0x100 Stack: # The stack goes here