Question

Write a program equivalent to the C language assignment statement z = a + (b *...

Write a program equivalent to the C language assignment statement
z = a + (b * c) + (d * e) - (f / g) - (h * i);
Use only:
(a) Three-address instructions
(b) Two-address instructions

Please explain the process as clearly as possible. I would like to LEARN how this is done in so little address instructions. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

z = a + (b * c) + (d * e) - (f / g) - (h * i)

(a) Three-address instructions

It is assumed that the computer has two processor registers, R1 and R2. The symbol M [A] denotes the operand at memory address A.

Every instruction has 2 source operands and a destination register/memory address

Instruction format : Operation destination operand, source operand1, source operand2.

destination operand = source operand1 Operation source operand2.

MUL R1, b, c -------- R1 <- M[b] * M[c] R1 = b * c

MUL R2, d, e -------- R2 <- M[d] * M[e] R2 = d * e

ADD R1, R1, R2 ---- R1 <- R1 + R2 R1 = (b * c) + (d * e)

DIV R2, f, g ---------- R2 <- M[f] / M[g] R2 = f / g

SUB R1, R1, R2 ---- R1 <- R1 - R2 R1 = (b * c) + (d * e) - (f / g)

MUL R2, h, i --------- R2 <- M[h] * M[i] R2 = h * i

SUB R1, R1, R2 ---- R1 <- R1 - R2 R1 = (b * c) + (d * e) - (f / g) - (h * i)

ADD z, R1, R2 ------ z <- R1 + R2   z = a + (b * c) + (d * e) - (f / g) - (h * i)

(b) Two-address instructions

Every instruction has 2 source operands and the first source operand acts as the destination register/memory address

Instruction format : Operation destination operand, source operand

destination operand = destination operand Operation source operand.

MOV R1, b ------ R1 <- M[b] R1 = b

MUL R1, c ------ R1 <- R1 * c R1 = b*c

MOV R2, d ----- R2 <- M[d] R2 = d

MUL R2, e ------ R2 <- R2 * e R2 = d*e

ADD R1, R2 ---- R1 <- R1 + R2 R1 = (b * c) + (d * e)

MOV R2, f ------ R2 <- M[f] R2 = f

DIV R2, g ------- R2 <- R2 / g R2 = f/g

SUB R1, R2 ---- R1 <- R1 - R2 R1 = (b * c) + (d * e) - (f / g)

MOV R2, h ----- R2 <- M[h] R2 = f

MUL R2, i ------ R2 <- R2 * i R2 = h*i

SUB R1, R1, R2 ----- R1 <- R1 - R2 R1 = (b * c) + (d * e) - (f / g) - (h * i)

ADD R1, a -------- R1 <- R1 + a R1 = a + (b * c) + (d * e) - (f / g) - (h * i)

MOV z, R1 ------- z <- R1 z = a + (b * c) + (d * e) - (f / g) - (h * i)

Add a comment
Know the answer?
Add Answer to:
Write a program equivalent to the C language assignment statement z = a + (b *...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT