Computer Science AS OCR
-
1-1-structure-and-function-of-the-processor as5 主题
-
1-2-types-of-processor as3 主题
-
1-3-input-output-and-storage as2 主题
-
2-1-systems-software as8 主题
-
2-3-software-development as5 主题
-
2-4-types-of-programming-language as4 主题
-
3-1-compression-encryption-and-hashing as3 主题
-
3-2-databases as3 主题
-
3-3-networks as8 主题
-
3-4-web-technologies as13 主题
-
html as
-
css as
-
css-styling as
-
javascript as
-
variables-and-constants-in-javascript as
-
outputs-in-javascript as
-
selection-in-javascript- as
-
for-loops-in-javascript- as
-
while-loops-in-javascript- as
-
strings-in-javascript- as
-
operators-in-javascript- as
-
nested-statements-in-javascript as
-
functions-and-procedures-in-javascript as
-
html as
-
4-1-data-types as8 主题
-
4-2-data-structures as4 主题
-
4-3-boolean-algebra as1 主题
-
5-1-computing-related-legislation as4 主题
-
5-2-moral-and-ethical-issues as9 主题
-
6-1-thinking-abstractly as3 主题
-
6-2-thinking-ahead as1 主题
-
6-3-thinking-procedurally as3 主题
-
6-4-thinking-logically as2 主题
-
6-5-thinking-concurrently as2 主题
-
7-1-programming-techniques as9 主题
-
8-1-standard-algorithms-and-big-o-notation as8 主题
modes-of-addressing as
Exam code:H046
Modes of Addressing
What is an addressing mode?
-
Addressing modes are ways in which an instruction in assembly language or machine code can access data stored in memory.
-
There are four main types of addressing modes:
-
Immediate
-
Direct
-
Indirect
-
Indexed
-
Immediate addressing
-
Operand is part of the instruction itself
MOV AX, 1234h // Moves the immediate hex value 1234h to the AX register
Direct addressing
-
The memory address of the operand is directly specified
MOV AX, [1234h] // Take the value stored in memory location 1234h and move to the AX register
Indirect addressing
-
A register contains the memory address of the operand
-
If
BXcontains the value2000h:
MOV AX, [BX] // Moves the value from memory location 2000h to the AX register
-
This does not mean “Move the value 2000h into AX”
-
Instead, it means, “Look in the memory address 2000h (the value currently stored in the BX register) and move whatever value you find into the AX register.”
-
When brackets
[ ]are around a register in assembly language (like[BX]), it’s an instruction to treat the value inside that register as a memory address and to use the data at that memory address for the operation
Indexed addressing
-
Combines a base address with an index to compute the effective address
-
If
BXcontains0050handSIhas a base address1000h:
MOV AX, [BX + SI] // Move the value at memory location 1050h to AX
-
Fetches data from the effective address (because
1000h + 0050his1050h) and moves it into the AX register
Worked Example
Consider a basic computer system with the following assembly language instructions and a memory layout starting at address 1000.
1000: MOV AX, 8
1002: ADD AX, [BX]
1004: MOV [0008], AX
1006: MOV CX, [BX+DI]
1008: HLT
Assume the registers have the following values before execution:
AX = 0000
BX = 0003
DI = 0002
CX = 0010
Memory contains:
0000: 0
0001: 0
0002: 0
0003: 5
0004: 0
0005: 7
0006: 7
0007: 9
0008: 0
a) For the instruction at 1002, identify the addressing mode used and explain what it does in the context of this instruction.
[2]
b) After the instruction at 1004 has executed, what will the value at memory address 0008 be? Justify your answer.
[2]
c) What value will be moved into the CX register after the instruction at 1006 executes? Explain the addressing mode used.
[2]
Answer:
Answer that gets full marks:
a) The instruction at 1002 uses Indirect Addressing. The instruction ADD AX, [BX] adds the value at the memory address contained in the BX register to the AX register. In this case, since BX is 3, it will add the value at memory address 3 to AX.
b) The value at memory address 0008 will be 13. Before the instruction, AX contains the value 8. After adding 5 (from memory address 3 due to the instruction at 1002), AX will have the value 13. The instruction at 1004 then moves this value to memory address 0008.
c) The value moved into the CX register will be 7. The instruction at 1006 uses Indexed Addressing. It accesses memory by combining the address in BX with the offset in DI. Given BX is 3 and DI is 2, the effective address is 3 + 2 = 5, so it fetches the value 7 from address 0005 into CX.
Acceptable responses:
a) Any answer identifying Indirect Addressing and explaining its use in the context of fetching a value from memory for the instruction should be awarded marks.
b) Any answer stating that the value at address 0008 will be 13 due to adding 8 and 5 should be awarded marks.
c) Any response indicating the use of Indexed Addressing and explaining the value fetch from address 5 should be awarded marks.
Responses