You are tasked to calculate a specific algebraic expansion. i.e. compute the val
ID: 663226 • Letter: Y
Question
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 = (AB^2+C^2D^3) without using any intrinsic multiplication instructions. More formally, write MIPS assembly code that accepts four positive integers a, b, c, and d as input parameters. The code shall execute in MARS to prompt the user to enter four positive integers represented in decimal, each separated by the Enter key. The program shall calculate f= (A^4-4B^3+3C^2-2D) and g = (AB^2+C^2D^3) using your own self-written multiplication routine. The program will then output f in decimal and binary, using syscall routines for each output.Explanation / Answer
lw $t0, a #load x from memory
lw $t1, b #load y from memory
lw $t2, c #load x from memory
lw $t3, d #load y from memory
mul $t6,$t0,$t0 #a*a
mul $t7,$t0,$t0 #a*a
mul $t6,$t6,$t7 #a*a*a*a and store in $t6
mul $t8,$t1,$t1 #b*b and store in $t8
mul $t9,$t8,$t1 #$t8*b and store in $t9
mul $t9,4,$t9 #4*b*b*b
mul $t10,$t2,$t2 #c*c
mul $t10,3,$t10 #3*c*c
mul $t11,2,$t3 #2*d
sub $t12,$t6,$t9 #a*a*a*a-4*b*b*b
add $t12,$t12,$t10 #a*a*a*a-4*b*b*b+3*c*c
sub $t12,$t12,$t11 # f =a*a*a*a-4*b*b*b+3*c*c-2*d
mul $13,$t0,$t8 #a*b*b
mul $s14,$t2,$t2 #c*c
mul $15,$t3,$t3 #d*d
mul $15,$15,$t3 #d*d*d
mul $15,$14,$15 #c*c*d*d*d
add $15,$13 # g value contains in $15 ie g=c*c*d*d*d
complie the program and u will get output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.