# // Sample assembly language program for CSE 413 # # // Output from your compiler on similar source code will # // probably be somewhat different, but the basic code # // should be roughly the same and should have the same effect. # # int main() { .text .globl _d$main _d$main: # BEGINNING OF FUNCTION # int answer; # int m; int n; # # m = get(); # Function Prolog - 3 instructions pushl %ebp # save ebp and set up frame pointer movl %esp, %ebp # set frame ptr to pt. to top of stack subl $12, %esp # allocate local vars call _get addl $0, %esp # pop params off stack movl %eax, -8(%ebp) # Storing m # n = get(); call _get addl $0, %esp # pop params off stack movl %eax, -4(%ebp) # Storing n # answer = doubleSum(m,n); movl -8(%ebp), %eax # Using m pushl %eax # Push a parameter movl -4(%ebp), %eax # Using n pushl %eax # Push a parameter call doubleSum addl $8, %esp # pop params off stack movl %eax, -12(%ebp) # Storing answer # answer = put(answer); movl -12(%ebp), %eax # Using answer pushl %eax # Push a parameter call _put addl $4, %esp # pop params off stack movl %eax, -12(%ebp) # Storing answer # return 0-1; movl $0, %eax # Using 0 pushl %eax # push previous value onto stack movl $1, %eax # Using 1 popl %ecx # pop left operand from stack subl %eax, %ecx # subtract, final result in ecx movl %ecx, %eax # move result to eax # Function Eplilog - 3 instructions movl %ebp, %esp # free local vars popl %ebp # restore frame pointer (ebp) ret # return to caller # } # # int doubleSum(int a, int b) { doubleSum: # BEGINNING OF FUNCTION # int x; int y; # int total ; # # x = a * 2; # Function Prolog - 3 instructions pushl %ebp # save ebp and set up frame pointer movl %esp, %ebp # set frame ptr to pt. to top of stack subl $12, %esp # allocate local vars movl 12(%ebp), %eax # Using a pushl %eax # push previous value onto stack movl $2, %eax # Using 2 popl %ecx # pop left operand from stack imull %ecx, %eax # multiply, final product in eax movl %eax, -12(%ebp) # Storing x # y = b; movl 8(%ebp), %eax # Using b movl %eax, -8(%ebp) # Storing y # total = x + y; movl -12(%ebp), %eax # Using x pushl %eax # push previous value onto stack movl -8(%ebp), %eax # Using y popl %ecx # pop left operand from stack addl %ecx, %eax # add, final result in eax movl %eax, -4(%ebp) # Storing total # return total; movl -4(%ebp), %eax # Using total # Function Eplilog - 3 instructions movl %ebp, %esp # free local vars popl %ebp # restore frame pointer (ebp) ret # return to caller # }