This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CPSC 313 06W Term 2 Problem Set #1 Solution 1. I edited the output slightly to make it shorter. .bss _counter: .space 4 # allocate space for global counter .text _swap: pushl %ebp # save ebp movl %esp, %ebp # set up ebp for this function subl $8, %esp # allocate space for saved regs movl %ebx, (%esp) # save ebx movl 8(%ebp), %edx # load a into edx movl 16(%ebp), %ebx # load j into ebx movl %esi, 4(%esp) # save esi movl 12(%ebp), %ecx # load i into ecx movl (%edx,%ebx,4), %eax # load a[i] into t (eax) movl (%edx,%ecx,4), %esi # load a[j] into a temp (esi) movl %eax, (%edx,%ecx,4) # store t into a[j] movl %esi, (%edx,%ebx,4) # store temp into a[i] movl _counter, %eax # load counter to increment it movl (%esp), %ebx # restore saved ebx movl 4(%esp), %esi # restore saved esi incl %eax # increment counter movl %eax, _counter # write it back movl %ebp, %esp # set up for popping ebp popl %ebp # restore saved ebp ret # return 2. Im not going to include the output, because if you can run objdump you can do it yourself.2....
View Full Document
This note was uploaded on 10/09/2011 for the course CPSC 344 taught by Professor Karen during the Fall '10 term at The University of British Columbia.
- Fall '10