Skip to main content

Instruction fields and address formats for X=(E+F)*(G+H)

Short answer

Common instruction fields are opcode (operation), address field(s) (operand locations), and mode field (addressing mode). For X = (E+F)*(G+H), postfix is E F + G H + *. Three-address uses 3 instructions (ADD, ADD, MUL). Two-address needs 6 with MOV overhead. One-address accumulator requires 7 with temporary T1. Zero-address stack uses 8 instructions (PUSH, ADD, PUSH, ADD, MUL, POP). Fewer addresses yield shorter instructions but longer programs.

What are the most common fields in an instruction? How can you perform X=(E+F)*(G+H) operation by using zero, one, two and three address instruction format. Assume that E, F, G, H and X are memory addresses.

Common fields of an instruction

  1. Operation code (opcode): specifies the operation to be performed (add, load, jump).
  2. Address field(s): give the location of the operands or result: a memory address or a register number. The number of address fields depends on the instruction format.
  3. Mode field: specifies how the address field is used to find the operand (direct, indirect, immediate, indexed, ...).

X = (E+F)*(G+H)

Assumptions: the operands are memory locations, R1, R2, ... are CPU registers, T1, T2, ... are temporary memory locations, and X receives the result. Multiplication and division are done before addition and subtraction, and equal-priority operators go left to right. All of E, F, G, H and X are memory addresses.

Fully bracketed: X = (E+F)*(G+H). Postfix (reverse Polish) form: E F + G H + *.

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

ADD R1, E, F   ; R1 = E + F
ADD R2, G, H   ; R2 = G + H
MUL X, R1, R2  ; X = R1 * R2

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, E   ; R1 = E
ADD R1, F   ; R1 = R1 + F
MOV R2, G   ; R2 = G
ADD R2, H   ; R2 = R2 + H
MUL R1, R2  ; R1 = R1 * R2
MOV X, R1   ; X = 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 E    ; AC = E
ADD F     ; AC = AC + F
STORE T1  ; T1 = AC
LOAD G    ; AC = G
ADD H     ; AC = AC + H
MUL T1    ; AC = AC * T1
STORE X   ; X = AC

Number of instructions: 7. Intermediate results that cannot stay in AC are saved in memory temporaries.

Zero-address instructions (stack machine)

PUSH E  ; push E
PUSH F  ; push F
ADD     ; pop two, compute, push result
PUSH G  ; push G
PUSH H  ; push H
ADD     ; pop two, compute, push result
MUL     ; pop two, compute, push result
POP X   ; X = 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 = 7, 0-address = 8 instructions. Fewer addresses per instruction means shorter instructions but more of them.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Organization and Architecture chapter 2 questions →