Write a code for Y=A*(B+D/C)+(G*E) using three addresses, two address, one address and zero address instruction format.

This answer is restricted. Please login to view the answer of this question.

Login Now

Given

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

Zero Address Instruction

PUSH A   TOS ← A
PUSH B   TOS ← B
PUSH D   TOS ← D
PUSH C   TOS ← C
DIV      TOS ← D / C
ADD      TOS ← B + D / C
PUSH G   TOS ← G
PUSH E   TOS ← E
MUL      TOS ← G * E
ADD      TOS ← G + D / C) + (G * C)
MUL      TOS ← A * (B + D / C) + (G * C)
POP Y

One Address Instruction

LOAD G    AC ← M[G]
MUL E     AC ← AC * E
STORE T   M[T] ← AC

LOAD D    AC ← M[D]
DIV C     AC ← AC / C
ADD B     AC ← AC + B
MUL A     AC ← AC * A

ADD T       AC ← AC + T
STORE Y     M[Y] ← AC

Two Address Format

MOV R1, A   R1 ← M[A]

MOV R2, D   R2 ← M[D]
DIV R2, C   R2 ← R2 / C
ADD R2, B   R2 ← R2 + B

MOV R3, G   R3 ← M[G]
MUL R3, E   R3 ← R3 * E

MUL R1, R2  R1 ← R1 * R2
ADD R1, R3  R1 ← R1 + R3

MOV Y, R1   M[Y] ← R1

Three Address Instruction

DIV R1, D, C    R1 ← M[D] / M[C]
ADD R1, R1, B   R1 ← R1 + M[B]

MUL R2, G, E    R2 ← M[G] * M[E]

MUL R1, R1, A   R1 ← R1 * M[A]
ADD Y, R1, R2   M[Y] ← R1 * R2
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .