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

Y = A/B + C/D * (E – F) a) on a general register CPU with 3-address instructions

ID: 3731621 • Letter: Y

Question

Y = A/B + C/D * (E – F)

a) on a general register CPU with 3-address instructions

b) on a general register CPU with 2-address instructions

c) on an accumulator-based CPU with 1-address instructions

d) on a stack-based CPU with 0-address instructions (note: in a stackbased machine, PUSH and POP are one-address instructions) Assume that each CPU has ADD, SUB, MUL and DIV instructions in addition to LOAD, STORE, MOVE, POP and PUSH instructions as appropriate in its instruction set. Also assume that operand A is in memory location MA, operand B is in memory location MB, and so on.

Explanation / Answer

a) 3 ADDRESS INSTRUCTIONS :

SUB R1 ME MF # R1 <- E - F

DIV R2 MC MD # R2 <- C/D

MUL R1 R1 R2 # R1<- R1*R2

DIV R2 MA MB # R2<- A/B

ADD Y R1 R2 # Y<- R1+R2

b) 2 ADDRESS INSTRUCTIONS:

MOVE R1 ME # R1<- E

SUB R1 MF # R1<- R1 - F

MOVE R2 MC # R2<- C

DIV R2 MD # R2<- R2/D

MUL R1 R2 # R1<- R1*R2

MOVE R2 MA # R2<- A

DIV R2 MB # R2<- R2/B

ADD R1 R2 # R1<- R1+R2

STORE Y R1 # Y<- R1

c) 1 ADDRESS INSTRUCTION:

LOAD ME # ACC<- E

SUB MF # ACC<-ACC - F

STORE MX # MX<-ACC

LOAD MC # ACC<- C

DIV MD # ACC<-ACC/D

MUL MX # ACC<-ACC*MX

STORE MX # MX<-ACC

LOAD MA # ACC<-A

DIV MB # ACC<-ACC/B

ADD MX # ACC<-ACC + MX

STORE Y # Y<-ACC

d) 0 ADDRESS INSTRUCTION:

NOTE: DURING ARITHMETIC OPERATION FIRST POPPED ELEMENT WILL BE THE SECOND OPERAND AND SECOND POPPED ELEMENT WILL BE THE FIRST OPERAND.

PUSH ME

PUSH MF

SUB

PUSH MC

PUSH MD

DIV

MUL

PUSH MA

PUSH MB

DIV

ADD

POP Y