Assembly Code Pep8 Question Write a Pep8 subroutine that is
Assembly Code Pep/8 Question
Write a Pep/8 subroutine that is equivalent to the following C function int Q2 (int A, int B) {int M, C = 0; M = (A + B)/2; while (M > 0) {C += 3; M--;} return C;}Solution
Answer:
MIPS Assembly Language Code :
L0:
 push rbp
 mov rbp, rsp
 mov DWORD PTR [rbp-20], edi
 mov DWORD PTR [rbp-24], esi
 mov DWORD PTR [rbp-8], 0
 mov edx, DWORD PTR [rbp-20]
 mov eax, DWORD PTR [rbp-24]
 add eax, edx
 mov edx, eax
 shr edx, 31
 add eax, edx
 sar eax
 mov DWORD PTR [rbp-4], eax
 .L3:
 cmp DWORD PTR [rbp-4], 0
 jle .L2
 add DWORD PTR [rbp-8], 3
 sub DWORD PTR [rbp-4], 1
 jmp .L3
 .L2:
 mov eax, DWORD PTR [rbp-8]
 pop rbp
 ret

