-
Notifications
You must be signed in to change notification settings - Fork 122
/
ram.asm
92 lines (52 loc) · 1.61 KB
/
ram.asm
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
; Examples of how to access RAM in NASM.
%include "lib/common_nasm.inc"
section .bss
resd0 resd 1
resd1 resd 1
ENTRY
; Square brackets `[]` are needed to access the *data*,
; otherwise the address of the label is understood:
; Data:
mov dword [resd0], 1
ASSERT_EQ [resd0], 1, dword
; Address:
mov dword eax, resd1
sub eax, resd0
ASSERT_EQ eax, 4
; # Memory size
; TODO examples.
; When operations involve registers it is not necessary to specify
; the number of bytes to move around since that can be deduced from the
; register form: `eax` = 4 bytes, `ax` == 2 bytes, etc.
; But when moving or comparing literals to RAM
; it is mandatory to specify the number of bytes to move.
; Error: size not specified.
;mov [resd0], 1
; NASM knows it is 4 bytes because we are using eax:
mov eax, 1
mov [resd0], eax
; List of all size keywords:
; http://stackoverflow.com/questions/12063840/what-are-the-sizes-of-tword-oword-and-yword-operands
; # byte
; 1
; # word
; 2
; # dword
; 4
; Double word.
; # qword
; 8
; Quadruple word.
; Only possible in 64-bit.
; # tword
; 10
; Ten.
; Used for x87 floating point formats. TODO example
; # oword
; 16
; TODO example
; # yword
; 32
; # zword
; 64
EXIT