- Asked 16/22
- 2075 Chaitra · 8 marks
Address-format code for Y=(A+B)/C+D/(E*F)
Short answer
Y = (A+B)/C + D/(E*F) takes five three-address, nine two-address, eleven one-address, and twelve zero-address instructions. The one-address program stores partial results in memory temporaries.
Write codes using 3, 2, 1 and 0 address instruction formats to perform the operation Y = (A+B)/C + D/(E*F).
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.
Fully bracketed: Y = ((A+B)/C)+(D/(E*F)). Postfix (reverse Polish) form: A B + C / D E F * / +.
Three-address instructions (OP dest, src1, src2)
ADD R1, A, B ; R1 = A + B
DIV R2, R1, C ; R2 = R1 / C
MUL R3, E, F ; R3 = E * F
DIV R4, D, R3 ; R4 = D / R3
ADD Y, R2, R4 ; Y = R2 + R4
Number of instructions: 5. Shortest program, but each instruction is long (three addresses).
Two-address instructions (OP dest, src; dest = dest OP src)
MOV R1, A ; R1 = A
ADD R1, B ; R1 = R1 + B
DIV R1, C ; R1 = R1 / C
MOV R2, D ; R2 = D
MOV R3, E ; R3 = E
MUL R3, F ; R3 = R3 * F
DIV R2, R3 ; R2 = R2 / R3
ADD R1, R2 ; R1 = R1 + R2
MOV Y, R1 ; Y = R1
Number of instructions: 9. A MOV is needed first because the destination operand is overwritten.
One-address instructions (accumulator AC is the implied operand)
LOAD A ; AC = A
ADD B ; AC = AC + B
DIV C ; AC = AC / C
STORE T1 ; T1 = AC
LOAD E ; AC = E
MUL F ; AC = AC * F
STORE T2 ; T2 = AC
LOAD D ; AC = D
DIV T2 ; AC = AC / T2
ADD T1 ; AC = AC + T1
STORE Y ; Y = AC
Number of instructions: 11. 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
ADD ; pop two, compute, push result
PUSH C ; push C
DIV ; pop two, compute, push result
PUSH D ; push D
PUSH E ; push E
PUSH F ; push F
MUL ; pop two, compute, push result
DIV ; pop two, compute, push result
ADD ; pop two, compute, push result
POP Y ; Y = top of stack
Number of instructions: 12. 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 = 5, 2-address = 9, 1-address = 11, 0-address = 12 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=A/B+(C×D)+F(H/G) · 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=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 →