Using MIPS Assembly Language You are tasked to calculate a s
Using MIPS Assembly Language
You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for the expression:
f = (A^4 - 4B^3 + 3C^2 - 2D)
g = (A * B^2 + C^2 * D^3)
Without using any intrinsic multiplication instructions, subroutines, and function calls. More formally,write MIPS assembly code that accepts four positive integers A, B, C, and D as input parameters. Thecode shall execute in MARS to prompt the user to enter four positive integers represented in decimal,each separated by the Enter key. The program will then output f and g in decimal and binary, using syscall routines for each output.
NOT ALLOWED TO USE { mul, mul.d, mul.s, mulo, mulou, mult, multu, mulu, div, divu, rem,sll, sllv, sra, srav, srl, srlv }
Solution
LC0:
.string \"Enter values of A , B, C ,D \"
.LC1:
.string \"%d%d%d%d\"
.LC2:
.string \"The value of f is %d :\"
.LC3:
.string \"The value of g is %d:\"
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rsi, [rbp-24]
lea rcx, [rbp-20]
lea rdx, [rbp-16]
lea rax, [rbp-12]
mov r8, rsi
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-12]
xor eax, 4
mov ecx, eax
mov eax, DWORD PTR [rbp-16]
xor eax, 3
lea esi, [0+rax*4]
mov eax, DWORD PTR [rbp-20]
xor eax, 2
mov edx, eax
mov eax, edx
add eax, eax
add edx, eax
mov eax, DWORD PTR [rbp-24]
add eax, eax
sub edx, eax
mov eax, edx
add eax, esi
sub ecx, eax
mov eax, ecx
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov eax, DWORD PTR [rbp-24]
lea edx, [rax+rax]
mov eax, DWORD PTR [rbp-20]
xor eax, edx
xor eax, 3
lea edx, [rax+2]
mov eax, DWORD PTR [rbp-16]
xor edx, eax
mov eax, DWORD PTR [rbp-12]
imul eax, edx
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov eax, 0
leave
ret

