Question

1) Write the assembly code to implement expression A = B + C * ((D -...

1) Write the assembly code to implement expression A = B + C * ((D - E) * F) on 3-, 2-, 1-, and 0- address machines. Do not rearrange the expression. In accordance with "good programming", computing the expression should not change the values of its operands. Feel free to use a temporary variable, perhaps called T, if you feel you need one.

2) For the four code implementations of (1), compute the total size of the program, assuming: · Op-codes are 4 bits, · Addresses occupy 12 bit

Homework Answers

Answer #1

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

3 - address machine

SUB R1, D, E

MUL R1, R1, F

MUL R1, R1, C

ADD A, R1, B

Number of instruction - 4

Size of one instruction - 16 bits => 2B

Size of the program = 4*2B = 8B

2 - address machine

MOV T1, B

MOV T2, C

MOV T3, D

SUB T3, E

MPY T3, F

MPY T2, T3

ADD T1, T2

MOV A, T1

Number of instruction - 8

Size of one instruction - 16 bits => 2B

Size of the program = 8*2B = 16B

1 - address machine

LOAD B

LOAD C

LOAD D

SUB E

MPY F

MPY C

ADD B

STORE A

Number of instruction - 8

Size of one instruction - 16 bits => 2B

Size of the program = 8*2B = 16B

0 - address machine

PUSH B

PUSH C

PUSH D

PUSH E

SUB

PUSH F

MPY

MPY

ADD

POP A

Number of instruction - 10

Size of one instruction - 16 bits => 2B

Size of the program = 10*2B = 20B

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions