13.2 x86 and ARM Addressing Modes
COS2621 - Computer Organisation · 13. Instruction Sets: Addressing Modes and Formats
x86 and ARM Addressing Modes
Introduction to Addressing Modes
Addressing modes define how the operand of an instruction is accessed. In x86 and ARM architectures, different addressing modes offer flexibility in how data is accessed and manipulated. Understanding these modes is crucial for efficient programming.
x86 Addressing Modes
x86 architecture supports several addressing modes:
- Immediate Addressing: The operand is specified directly in the instruction. For example,
MOV AX, 10moves the value 10 directly into the AX register. - Direct Addressing: The address of the operand is given explicitly. For example,
MOV AX, [1234h]moves the value at memory address 1234h into AX. - Indirect Addressing: The address of the operand is stored in a register. For example,
MOV AX, [BX]moves the value at the address contained in BX into AX. - Indexed Addressing: Combines a base address with an offset. For example,
MOV AX, [BX + SI]moves the value at the address calculated by adding the contents of BX and SI into AX.
ARM Addressing Modes
ARM architecture also features multiple addressing modes:
- Immediate Addressing: Similar to x86, where the operand is specified directly. Example:
MOV R0, #10loads the immediate value 10 into R0. - Register Indirect Addressing: The address is specified in a register. Example:
LDR R1, [R2]loads the value from the address in R2 into R1. - Base Plus Offset Addressing: Combines a base address in a register with an immediate offset. Example:
LDR R1, [R2, #4]loads the value from the address in R2 plus 4 into R1. - Pre-indexed Addressing: Accesses memory before executing the instruction. Example:
LDR R1, [R2, #4]!loads the value from the address in R2 plus 4 into R1 and updates R2.
Examples of Addressing Modes
x86 Example
Consider the following x86 code snippet:
MOV AX, 10 ; Immediate addressing
MOV BX, [1234h] ; Direct addressing
MOV CX, [BX] ; Indirect addressing
MOV DX, [BX + SI] ; Indexed addressingARM Example
For ARM, an example would be:
MOV R0, #5 ; Immediate addressing
LDR R1, [R2] ; Register indirect addressing
LDR R2, [R3, #8] ; Base plus offset addressing
LDR R4, [R5, #12]! ; Pre-indexed addressingWatch out: Confusing immediate values with memory addresses can lead to errors. Always check whether you need to reference a value directly or access it from memory.
Memory Storage Example
Consider the following assembly language program fragment:
org 0x100
label1: dw 0x76EF
nop
mov ax, ax
nopThis code stores the value 76h in position 100h and EFh in position 101h. Therefore, the correct statement is that 76h is stored in position 100h and EFh is stored in position 101h.
Conclusion
Addressing modes are essential for accessing data in assembly language programming. Understanding the differences between x86 and ARM addressing modes can greatly enhance your ability to write efficient assembly code.
Check your understanding
- What is the difference between immediate addressing and direct addressing?
- Provide an example of indexed addressing in x86.
- How does base plus offset addressing work in ARM?
- What are the potential pitfalls when using indirect addressing?
Test yourself
5 quick questions on this lesson. Pick an answer to see if you're right.
1. Which of the following is an example of immediate addressing in x86 architecture?
2. Which of the following x86 instructions demonstrates indexed addressing?
3. Consider the following pseudo-ops (use NASM): org 0x100 db 'Q' dw 213h db 15 In which relative memory location will (i) 51h and (ii) (15) 10 respectively be stored?
4. In ARM architecture, which addressing mode uses a base address in a register combined with an immediate offset?
5. What is the primary difference between immediate addressing and direct addressing?