loading...

CS501 Assignment 1 Solution Spring 2017

Question:

Consider the following equation;

z= 8(a-b) + 19(c-29)

You have to solve this equation using the following;

  • 3-Address instruction

Solution:

SUB z, a, b                  # z ← a-b

MUL z, 8                     # z←8(a-b)

SUB T, c, 29                # T←(c-29)

MUL T, T, 19               #T←19(c-29)

ADD z, z, T                   #z←(z+T)

  • 2-Address instruction

Solution:

MOV z, a               #z←a

SUB z, b                 #z←(z-b)

MUL z, 8                #z←8(z)

MOV T, c                #T←c

SUB T, 29               #T←T-29

MUL T, 19              #T←19(T)

ADD z, T                  #z←z+T

  • 1-Address Instruction

Solution :

LOAD c                              #AC←c

SUB 29                              #AC←AC-29

MUL 19                             #AC←AC*19

STOR z                               # z←AC

LOAD a                              #AC←a

SUB b                                 #AC←AC-b

MUL 8                                #AC←AC*8

STOR z                               # z←AC

  • 0-Address Instruction

Solution :

PUSH a

PUSH b

SUB

MUL

PUSH c

PUSH 29

SUB

MUL

ADD

POP z
DOWNLOAD SOLUTION HERE
loading...