-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathaddressing.asm
More file actions
48 lines (37 loc) · 1.53 KB
/
addressing.asm
File metadata and controls
48 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;; NOTE that this is not a program meant to be run. It is just a way to demonstrate
;; that the instructions and addressing modes to assemble without error.
section .text
global start
start:
;; register addressing mode
mov rax, rbx
; direct (or immediate) addressing mode
; you cannot store to a constant, so only the source may be a constant
mov rax, 10 ; source operand is a constant
; indirect addressing mode
; one of the operands is the address of the memory location in a register
mov rax, [rbx]
mov [rbx], rax
; invalid!
; mov [rax], [rbx]
; indirect with displacement
; address = base + displacement
;
; typical use is to access structure elements (the displacement is the offset
; to the structure member)
mov rax, [24+rbx] ; base is rbx, displacement is 24
mov [24+rbx], rax
; indirect with displacement and scaled index
mov rax, [array + rbx * 4]
mov [array + rbx * 4], rax
; indirect with displacement in a second register
mov rax, [rbx + rcx]
mov [rbx + rcx], rax
; indirect with displacement in a second register scaled
mov rax, [rbx + rcx *4]
mov [rbx + rcx *4], rax
; indirect with displacement and another displacement in a second register scaled
mov rax, [24 + rbx + rcx *4]
mov [24 + rbx + rcx *4], rax
section .bss
array: resb 8192