Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

(Instruction formats) Write a sequence of instructions that will compute the value

of y = x2 + 2x + 3 for a given x using

a. three-address instructions
b. two-address instructions
c. one-address instructions

a)

1. LOAD R1, x ; Load x into register R1


2. MUL R2, R1, R1 ; Compute x^2 and store in R2
3. ADD R3, R2, 2 ; Compute x^2 + 2x and store in R3
4. ADD R4, R3, 3 ; Compute x^2 + 2x + 3 and store in R4
5. STORE R4, y ; Store the result in variable y
b)
1. LOAD R1, x ; Load x into register R1
2. MUL R1, R1 ; Compute x^2 and store in R1
3. ADD R1, 2 ; Compute x^2 + 2x and store in R1
4. ADD R1, 3 ; Compute x^2 + 2x + 3 and store in R1
5. STORE R1, y ; Store the result in variable y
c)
1. LOAD x ; Load x into the accumulator register
2. MUL x ; Compute x^2 in the accumulator register
3. ADD 2 ; Compute x^2 + 2x in the accumulator register
4. ADD 3 ; Compute x^2 + 2x + 3 in the accumulator register
5. STORE y ; Store the result in variable y
Problems: 11.1 Given the following memory values and a one-address machine
with an accumulator:
Word 20 contains 40
Word 30 contains 50
Word 40 contains 60
Word 50 contains 70
What values do the following instructions load into the accumulator?
a. Load IMMEDIATE 20
b. Load DIRECT 20
c. Load INDIRECT 20
d. Load IMMEDIATE 30
e. Load DIRECT 30
f. Load INDIRECT 30
Load IMMEDIATE 20:
- Loads the immediate value 20 into the accumulator.
- Value loaded: 20
Load DIRECT 20:
- Loads the contents of the memory location specified by the direct address
20 into the accumulator.
- Memory location 20 contains 40.
- Value loaded: 40
Load INDIRECT 20:
- Loads the contents of the memory location whose address is stored in the
memory location specified by the direct address 20 into the accumulator.
- Memory location 20 contains 40, and the contents of memory location 40 is
60.
- Value loaded: 60
Load IMMEDIATE 30:
- Loads the immediate value 30 into the accumulator.
- Value loaded: 30
Load DIRECT 30:
- Loads the contents of the memory location specified by the direct address 30
into the accumulator.
- Memory location 30 contains 50.
- Value loaded: 50
Load INDIRECT 30:
- Loads the contents of the memory location whose address is stored in the
memory location specified by the direct address 30 into the accumulator.
- Memory location 30 contains 50, and the contents of memory location 50 is
70.
- Value loaded: 70
In summary:
a. Load IMMEDIATE 20 → 20
b. Load DIRECT 20 → 40
c. Load INDIRECT 20 → 60
d. Load IMMEDIATE 30 → 30
e. Load DIRECT 30 → 50
f. Load INDIRECT 30 → 70
11.3 An address field in an instruction contains decimal value 14. Where is the
corresponding operand located for:
a) immediate addressing?
b) direct addressing?
c) indirect addressing?
d) register addressing?
e) register indirect addressing?

a. Immediate Addressing → Operand: 14

b. Direct Addressing → Operand: At memory address 14

c. Indirect Addressing → Operand: At the memory address stored in memory location 14

d. Register Addressing → Operand: In register labeled with the number 14

e. Register Indirect Addressing → Operand: At the memory address stored in the register labeled
with the number 14

a) 14 (The address field).

b) Memory location 14.

c) The memory location whose address is in memory location 14.

d) Register 14.

e) The memory location whose address is in register 14.

You might also like