Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 (While Loop) (20 points) Consider the following assembly code for a fu

ID: 3601077 • Letter: P

Question

Problem 1 (While Loop) (20 points) Consider the following assembly code for a function with a while loop Prob1: jmp .L2 .L5: dil is the lower 8 bits of %rdi testb $1, %dil je .L3 leal 7 (% rdi, %rdi, 8) , addl $6, %esi %eax mp.L2 ·L3 : 1(,%rsi, $3, %esi $2, %edi 2), %eax leal addl sh11 .L2: cmpl %edi, %esi jb .L5 ret Based on the assembly code above, fill in the blanks below in its corresponding C source code You may only use the source-level C variable names such as n, m and result. Don't use register names! unsigned prob2 (unsigned n, unsigned m) unsigned result; while( if ( result = else( result return result;

Explanation / Answer

.file "q1.c" .text .globl main .type main, @function main: pushl %ebp # stack frame setup; no corresponding C code movl %esp, %ebp subl $32, %esp movl $7, -8(%ebp) # a = 7; movl $100, -12(%ebp) # b = 100; movl $1, -4(%ebp) # c = 1; jmp .L2 # This jumps to code that evaluates a condition and # may jump back to the label L7 right below this; # that indicates that this is a translation of a C # WHILE loop, and the test to continue the loop is # in the code at label L2. .L7: movl -8(%ebp), %eax # eax = a imull -4(%ebp), %eax # multiply by c; eax = a*c cmpl -12(%ebp), %eax # compare a*c to b jb .L3 # jump forward to L3 if a*c
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote