Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN MIPS ONLY 1. (30 points) Translate the high-level language code below into as

ID: 3749648 • Letter: I

Question

IN MIPS ONLY

1. (30 points) Translate the high-level language code below into assembly instructions. The variables A, B, C, D, E and F are located in the memory and can be accessed by their label (e.g., LOAD RI, A will load A from the memory into R1)Minimize the number of instructions in the assembly code that you write. F (A+B)*C(E-D) a) Write the code for an accumulator architecture b) Write the code for a stack architecture. Assume that the division (subtraction) operation divides (subtracts) the topmost value in the stack by the second topmost value. c) Write the code for a register-memory architecture d) Write the code for a load-store architecture

Explanation / Answer

Question 1 Accumulator architecture

clear     //Clear accumulator

add E //Acc=E

sub D   //Acc=E-D

st F //F=E-D

clear //Clear accumulator

add A //Acc=A

add B //Acc=A+B

mul C //Acc=(A+B)*C

div F //Acc=(A+B)*C-(E+D)

st F //F=(A+B)*C-(E+D)

--------------------------------------------

Question 2 Stack architecture

push D \Stack=D

push D   \Stack=E

                          D

sub         \E-D

push A \A

               E-D

push B \B

               A

               E-D

add \A+B

          E-D

push C   \C

                 A+B

                  E-D

mul      \(A+B)*C

             E-D

div       \(A+B)*C/(E-D)

----------------------------------------------------

Question 3 Register memory

add r1,A,B   1=A+B

mult r1,r1,C 1=(A+B)*C

sub r2,E,D   2=E-D

div r1,r1,r2   1=(A+B)*C/(E-D)

-------------------------------------------------------

Question 4 Load/Store

ld r1,A   1=A

ld r2,B 2=B

add r1,r1,r2 1=A+B

ld r2,C    2=C

mult r1,r1,r2 1=(A+B)*C

ld $r2,D     2=D

ld $r3,E    3=E

sub $r2,$r3,$r2 \E-D

div $r1,$r1,$r2   1=(A+B)*C/(E-D)

st $r1,F     \F=(A+B)*C/(E-D)