Convert the following C code into MIPS assembly. Pleasecomment MIPS code, thanks
ID: 3608825 • Letter: C
Question
Convert the following C code into MIPS assembly. Pleasecomment MIPS code, thanks!i. int fib_inter(int a, int b, int n ){ if(n==0)
return b; else return fib_inter(a+b,a, n-1);
}
ii. int compare(int a, int b){ if(sub(a,b) >=0)
return 1;
else
return 0;
}
iii. int sub(int a, int b){ return a-b;
}
i. int fib_inter(int a, int b, int n ){ if(n==0)
return b; else return fib_inter(a+b,a, n-1);
}
ii. int compare(int a, int b){ if(sub(a,b) >=0)
return 1;
else
return 0;
}
iii. int sub(int a, int b){ return a-b;
}
Explanation / Answer
i) First we put variables in registers MOV ax, a MOV bx, b MOV cx, n L2: CMP cx, 0 JNZ L1 RET bx L1: MOV dx, ax dx=ax ADD ax, bx ax=ax+bx MOV ax, bx MOV ax, dx SUB cx,1 JMP L2 ii) MOV ax a MOV bx b SUB ax, bx BGE L1 ret 1 L1: ret 0 iii) MOV ax, a MOV bx, b SUB ax, bx I hopw this will helpu.....Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.