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

Given the following C code: long rfun (int x) if ( x-0 ) return 0; int nx-x >> 2

ID: 3752973 • Letter: G

Question

Given the following C code: long rfun (int x) if ( x-0 ) return 0; int nx-x >> 2 return x - rv; Fill in the blanks by dragging the appropriate entries below rfun: movl $0,%eax testl %edi, %edi je.L6 %rbs %edi, pushq movl %ebx movs1q call movs1a shrl $2, 6edi %edi, rfun %ebx, %rdi %rbx movq %rbx, %rax popq %rbs .L6: rep ret unsigned int ulq 96rdi, 96r ubq 9brax, 96r ddq 96rbx, 96ra mulq 96rbx, 96r estl 96edi, 96ec mpq $100, 96rdi | testq %rdi, 96rdi leaq (9%rdi,96rdi), rdi shrl $2, 9%edi sarl $2, 9%edi sarq $2, 96rdi sarq $3, 96rdi ja .L6 shrq $2,%rdi je.L6 js .L6

Explanation / Answer

shrl = Logical shift right  
The bits that slide off the end disappear (except for the last, which goes into the carry flag),
and the spaces are always filled with zeros. Logical shifts are best used with unsigned numbers.

But if number are signed then we need :
sarl = Arithmetic shift right
Arithmetic shift (also referred to as signed shift), like a logical shift,
The bits that slide off the end disappear (except for the last, which goes into the carry flag).
But in an arithmetic shift, the spaces are filled in such a way to preserve the sign of the number being slide.

hence use ( sarl $2,%edi ) instead of ( shrl $2,%edi )

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