For Loop and Array: Because the compiler has optimized some of the accesses to t
ID: 3600846 • Letter: F
Question
For Loop and Array:
Because the compiler has optimized some of the accesses to the array, the registers don’t all correspond exactly to variables in the source code. (And the statements and instructions don’t line up exactly one-toone either, so don’t put too much significance in the way we’ve spaced the lines.) For each of the following registers, as it is used in a particular range of instructions (shown by their assembly code line number), write a C expression that corresponds to the value in the register. Your expressions should be written using the C variables mat, r, and c, together with C operators and constants; don’t use register names.
#define SIZE 10 prob3: pushl movl pushl pushl pushl subl movl movl leal movl addl movl movl %ebp %esp, %ebp %edi %esi %ebx $4,%esp 8 (%ebp), $1, (%eax) 40 (%eax), %ebx $ void prob3 (int mat [SIZE] [SIZE]) 2 int r, ci %eax mat [0] [0] 1; = 10 12 13 14 15 16 1, 40(%eax) $80,%eax %eax,-16(%ebp) $1, %edi for (r = 1; rExplanation / Answer
init: irmovl Stack, %esp //Set up stack pointer irmovl Stack, %ebp //Set up base pointer call main //call main program halt //Terminate program bubble: pushl %ebp //setup rrmovl %esp, %ebp pushl %edx //declaring *data mrmovl 8(%ebp), %edx pushl %ecx //declaring count mrmovl 12(%ebp), %ecx pushl %ebx //declaring i pushl %esi //declaring last pushl %edi pushl %eax irmovl $1, %edi //%edi = 1 rrmovl %ecx,%esi //last=count subl %edi,%esi //last-- L1: irmovl $0, %edi //%edi = 0 subl %edi,%esi //last -= 0 jle L9 //ends loop if last = last mrmovl (%edx,%ebx,4),%eax //%eax = data[i] irmovl $1, %edi //%edi = 1 mrmovl 4(%edx,%ebx,4),%edi //%edi = data[i++] subl %eax,%edi //%edi = data[i++]-data[i] jge L7 //cancel if statement if data[i++]>=data[i] mrmovl 4(%edx,%ebx,4),%edi //%edi = data[i++] rmmovl %edi, (%edx,%ebx,4) //data[i] = data[i++] rmmovl %eax, 4(%edx,%ebx,4) //data[i++] = data[i] L7: irmovl $1, %edi //%edi = 1 addl %edi,%ebx //i++ jmp L2 //go to beginning of loop L8: irmovl $1, %edi //%edi = 1 subl %edi,%esi //last-- jmp L1 L9: popl %ebx //finish popl %esi popl %edi popl %eax popl %ebp ret main: pushl %ebp //setup rrmovl %esp, %ebp pushl %ebx //declaring *data mrmovl data, %ebx pushl %esi //declaring count mrmovl count, %esi rmmovl %ebx, (%esp) //move data to be used by bubble rmmovl %esi, 4(%esp) //move count to be used by bubble call bubble popl %ebx //finish popl %esi popl %ebp ret .comm data,20,4 //data = memory location .align 4 count: .long 5 //count = memory location data: .long 2 //data array assignment .long 1 .long 3 .long 5 .long 4 .pos 0x200 Stack: .long 0Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.