Computer architecture · A level · OCR H446 1.2.4, AQA 7517 4.7.3.3, Eduqas A500QS 2.1 · about 20 min
Opcodes, operands and instruction formats; immediate, direct, indirect and indexed addressing.
[1 mark]Address 30 holds 45 and address 45 holds 8. The operand is 30. What value does indirect addressing use?
[1 mark]Which addressing mode is best suited to stepping through an array in a loop?
[1 mark]In immediate addressing, the operand is...
[1 mark]An instruction is 16 bits: 5 bits of opcode and 11 bits of operand. What is the largest address direct addressing can reach?
[1 mark]Why will a program compiled for an x86 processor not run on an ARM processor?
[1 mark]An 8-bit instruction has a 4-bit opcode then a 4-bit operand. What does this print?
instruction = 0b10110110 print(instruction >> 4, instruction & 0b1111)
11 6
The top four bits 1011 are 11 and the bottom four bits 0110 are 6.
Memory is the list memory (addresses 0 to 9) and the index register ix holds 2. Write operand_value(mode, operand):
- mode is one of the strings "immediate", "direct", "indirect" or "indexed";
- operand is a whole number from 0 to 9;
- it returns the value an instruction would use in that mode, as defined in the table above.
For each operand in [2, 5], and for each mode in the order immediate, direct, indirect, indexed, print a line in the form direct 2 -> 1: the mode, the operand, ->, then the value. That is eight lines. The robot does not move.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
memory = [4, 7, 1, 9, 5, 3, 8, 0, 6, 2]
ix = 2
def operand_value(mode, operand):
return operandThe hint students can ask for: For each mode, ask how many times memory is looked up and with which address. Immediate needs no look-up, direct one, indirect uses the result of one look-up as the address for another, and indexed adjusts the address using the index register before looking up.
from bugbot import *
connect()
memory = [4, 7, 1, 9, 5, 3, 8, 0, 6, 2]
ix = 2
def operand_value(mode, operand):
if mode == "immediate":
return operand
if mode == "direct":
return memory[operand]
if mode == "indirect":
return memory[memory[operand]]
if mode == "indexed":
return memory[operand + ix]
for operand in [2, 5]:
for mode in ["immediate", "direct", "indirect", "indexed"]:
print(mode, operand, "->", operand_value(mode, operand))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.