Skip to main content

Address-format code for Y=A+(B*C)+D

Short answer

Y = A+(B*C)+D requires three three-address, six two-address, five one-address, and eight zero-address instructions. The one-address code needs no temporaries because the accumulator can hold all intermediate results.

Write down the following equation in three addresses, two addresses, one address and zero address instruction. If necessary, use temporary location T to store intermediate result. Y = A + (B*C) + D.

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. Left-to-right evaluation gives (A + (B×C)) + D.

Fully bracketed: Y = (A+(B*C))+D. Postfix (reverse Polish) form: A B C * + D +.

Three-address instructions (OP dest, src1, src2)

MUL R1, B, C   ; R1 = B * C
ADD R2, A, R1  ; R2 = A + R1
ADD Y, R2, D   ; Y = R2 + D

Number of instructions: 3. Shortest program, but each instruction is long (three addresses).

Two-address instructions (OP dest, src; dest = dest OP src)

MOV R1, A   ; R1 = A
MOV R2, B   ; R2 = B
MUL R2, C   ; R2 = R2 * C
ADD R1, R2  ; R1 = R1 + R2
ADD R1, D   ; R1 = R1 + D
MOV Y, R1   ; Y = R1

Number of instructions: 6. A MOV is needed first because the destination operand is overwritten.

One-address instructions (accumulator AC is the implied operand)

LOAD B   ; AC = B
MUL C    ; AC = AC * C
ADD A    ; AC = AC + A
ADD D    ; AC = AC + D
STORE Y  ; Y = AC

Number of instructions: 5. No temporary location T is needed here, because every intermediate result can stay in AC (addition is commutative, so B×C is computed first and A is added to it).

Zero-address instructions (stack machine)

PUSH A  ; push A
PUSH B  ; push B
PUSH C  ; push C
MUL     ; pop two, compute, push result
ADD     ; pop two, compute, push result
PUSH D  ; push D
ADD     ; pop two, compute, push result
POP Y   ; Y = top of stack

Number of instructions: 8. 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 = 3, 2-address = 6, 1-address = 5, 0-address = 8 instructions. Fewer addresses per instruction usually means shorter instructions but more of them.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Organization and Architecture chapter 2 questions →