{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs313-2006-t2-problemset1-solution

# cs313-2006-t2-problemset1-solution - CPSC 313 06W Term 2...

This preview shows pages 1–2. Sign up to view the full content.

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. I’m not going to include the output, because if you can run objdump you can do it yourself. The differences in the swap procedure are: (a) The instructions now have actual addresses.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

cs313-2006-t2-problemset1-solution - CPSC 313 06W Term 2...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online