Question

Write the code to implement the expression A (((B C)/D) *(E F) *G) on 3-, 2-, 1-, and 0- address machines. Do not rearrange t

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

CODING :

The given expression is

{\color{Red} A = (B - (C + D)) * (E + F)}

Assume R1, R2 are registers. M[ ] is any memory location.

The instructions ADD, SUB, MUL are used for addition, subtraction and multiplication respectively.

An n-address machine will specify n operand addresses in the instruction. So, a 3-address machine has instructions like ADD R1,A,B where R1 = M[A] + M[B]. The instruction adds the content at memory location A and B and places the result in the register R1.

3-address instruction for given expression:

ADD R1, C, D # R1 = M[C] + M[D]

SUB R1, B, R1 # R1 = M[B] - R1

ADD R2, E, F # R2 = M[E] + M[F]

MUL A, R1, R2 # M[A] = R1 * R2

2-address instruction for given expression:

Here, two addresses are specified in the instructions and MOV instruction is used for data movement.

MOV R1, C # R1 = M[C]

ADD R1, D # R1 = R1 + M[D]

MOV R2, B # R2 = M[B]

SUB R2, R1 # R2 = R2 - R1

MOV R1, E # R1 = M[E]

ADD R1, F # R1 = R1 + M[F]

MUL R1, R2 # R1 = R1 * R2

MOV A, R1 # M[A] = R1

1-address instruction for given expression:

1-address machine uses an accumulator AC to hold one operand. One operand is in accumulator and other is in the register or memory location. There is no need to explicitly specify the accumulator as CPU already knows it.

LOAD and STORE instructions are used for data movement.

LOAD C # AC = M[C]

ADD D # AC = AC + M[D]

STORE T # M[T] = AC

LOAD B # AC = M[B]

SUB T # AC = AC - M[T]

STORE T # M[T] = AC

LOAD E # AC = M[E]

ADD F # AC = AC + M[F]

MUL T # AC = AC * M[T]

STORE A # M[A] = AC

0-address instruction for given expression:

0- address machine uses a stack to store both source operands and destination operands. PUSH and POP instructions are used for data movement. The expression is converted to reverse Polish notation.

TOP means the top of the stack.

Reverse Polish Notation - B C D + - E F + *

PUSH B # TOP = B

PUSH C # TOP = C

PUSH D # TOP = D

ADD # TOP = C + D

SUB # TOP = B - (C + D)

PUSH E # TOP = E

PUSH F # TOP = F

ADD # TOP = E + F

MUL # TOP = (B - (C + D)) * (E + F)

POP A # M[A] = TOP

Add a comment
Know the answer?
Add Answer to:
Write the code to implement the expression A (((B C)/D) *(E F) *G) on 3-, 2-, 1-, and 0- address ...
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