You have a MIPS Procedure called/labeled “NumCrunch” that takes in two integer p
ID: 3682559 • Letter: Y
Question
You have a MIPS Procedure called/labeled “NumCrunch” that takes in two integer parameters and "crunches" on those numbers. You need to write a Procedure called/labeled “DoubleCrunch” that takes in two integer parameter and returns "doubles" the "crunched" numbers. Write the “DoubleCrunch” Procedure. Do not write the “NumCrunch” Procedure. Just call it. (Hint: you already know how to double a number in MIPS without using a multiplication command...
Example in C: int doubleCrunch(int x, int y)
{
int ret = NumCrunch(x, y); // DO NOT WRITE THE NumCrunch PROCEDURE!
ret = ret * 2; return ret;
}
Explanation / Answer
doubleCrunch(int, int):
pushq %rbp
movq %rsp, %rbp
subq $24, %rsp
movl %edi, -20(%rbp)
movl %esi, -24(%rbp)
movl -24(%rbp), %edx
movl -20(%rbp), %eax
movl %edx, %esi
movl %eax, %edi
call NumCrunch(int, int)
movl %eax, -4(%rbp)
sall -4(%rbp)
movl -4(%rbp), %eax
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.