- Asked 16/22
- 2070 Chaitra · 8 marks
Address-format code for Y=A/B+(C×D)+F(H/G)
Short answer
For Y = A/B+(C×D)+F(H/G), the postfix form is A B / C D * + F H G / * +. Three-address code uses 6 instructions (DIV, MUL, ADD, DIV, MUL, ADD). Two-address requires 11 instructions with MOV overhead. One-address (accumulator) needs 12 instructions using temporaries T1, T2. Zero-address (stack) uses 14 instructions following postfix directly with PUSH/POP. Fewer addresses per instruction means shorter instructions but more total instructions.
Write codes using 3, 2, 1 and 0 address instruction formats to perform the operation Y = A/B+(C×D)+F(H/G).
Assumptions: the operands are memory locations, R1, R2, ... are CPU registers, T1, T2, ... are temporary memory locations, and Y receives the result. Multiplication and division are done before addition and subtraction, and equal-priority operators go left to right. Adjacent letters with no operator, or a letter before a bracket, are read as multiplication. So F(H/G) is F × (H/G).
Fully bracketed: Y = ((A/B)+(CD))+(F(H/G)). Postfix (reverse Polish) form: A B / C D * + F H G / * +.
Three-address instructions (OP dest, src1, src2)
DIV R1, A, B ; R1 = A / B
MUL R2, C, D ; R2 = C * D
ADD R3, R1, R2 ; R3 = R1 + R2
DIV R4, H, G ; R4 = H / G
MUL R5, F, R4 ; R5 = F * R4
ADD Y, R3, R5 ; Y = R3 + R5
Number of instructions: 6. Shortest program, but each instruction is long (three addresses).
Two-address instructions (OP dest, src; dest = dest OP src)
MOV R1, A ; R1 = A
DIV R1, B ; R1 = R1 / B
MOV R2, C ; R2 = C
MUL R2, D ; R2 = R2 * D
ADD R1, R2 ; R1 = R1 + R2
MOV R2, F ; R2 = F
MOV R3, H ; R3 = H
DIV R3, G ; R3 = R3 / G
MUL R2, R3 ; R2 = R2 * R3
ADD R1, R2 ; R1 = R1 + R2
MOV Y, R1 ; Y = R1
Number of instructions: 11. A MOV is needed first because the destination operand is overwritten.
One-address instructions (accumulator AC is the implied operand)
LOAD A ; AC = A
DIV B ; AC = AC / B
STORE T1 ; T1 = AC
LOAD C ; AC = C
MUL D ; AC = AC * D
ADD T1 ; AC = AC + T1
STORE T2 ; T2 = AC
LOAD H ; AC = H
DIV G ; AC = AC / G
MUL F ; AC = AC * F
ADD T2 ; AC = AC + T2
STORE Y ; Y = AC
Number of instructions: 12. Intermediate results that cannot stay in AC are saved in memory temporaries.
Zero-address instructions (stack machine)
PUSH A ; push A
PUSH B ; push B
DIV ; pop two, compute, push result
PUSH C ; push C
PUSH D ; push D
MUL ; pop two, compute, push result
ADD ; pop two, compute, push result
PUSH F ; push F
PUSH H ; push H
PUSH G ; push G
DIV ; pop two, compute, push result
MUL ; pop two, compute, push result
ADD ; pop two, compute, push result
POP Y ; Y = top of stack
Number of instructions: 14. Only PUSH and POP carry an address; ADD, SUB, MUL, DIV work on the top two stack items, so the program follows the postfix form directly.
Summary: 3-address = 6, 2-address = 11, 1-address = 12, 0-address = 14 instructions. Fewer addresses per instruction means shorter instructions but more of them.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Address-format code for Y=(A+B)*(C+D) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for X=(A*B/C)-(D+E/F) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for X=(P+Q)×(R+S) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=A*(B+D/C)+(G*E)/F · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=A/(B+C)+(D+E)*F · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(A+B)*(C+D)+G/E*F · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for X=(A-B*F)*C+D/E · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=AB+(C/D)+E(F/G) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(A-B+C)*(E+F/G) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(A-B/C)×(D+E×G)/F · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(A-B/C)*[D+(E*G)] · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(W+X)*(Y-Z) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=(A+B)/C+D/(E*F) · Computer Organization and Architecture, chapter 2 · asked 16×
- Address-format code for Y=AB+(F/G)+CD · Computer Organization and Architecture, chapter 2 · asked 16×
- Instruction fields and address formats for X=(E+F)*(G+H) · Computer Organization and Architecture, chapter 2
- Instruction and data format, addressing modes · Microprocessor, chapter 2 · asked 2×
- Datapath operation and instruction cycles · Embedded System, chapter 2
- Convolutional vs block codes; (7,4) cyclic code for 1011 · Communication Systems, chapter 8 · asked 2×
All Computer Organization and Architecture chapter 2 questions →