-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMemory References.html
159 lines (155 loc) · 7.68 KB
/
Memory References.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<title>Memory Referencing</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>Memory Referencing</h1>
<h2>Overview</h2>
<p>With memory references, there are several ways to define the address.
To calculate addresses, it can mean adding registers like si, bp,di, bx and an offset together.
</p>
<h2>Assembling Memory References</h2>
<ul>
<li>This explanation is mainly for people
interested in making an assembler or people editing the instruction set files.</li>
<li>Currently, there is a #mode directive to use in instruction set files.
If you use it for an instruction, the memory mode will be defined in the 2 bits just
after the opcode's machine code and before the machine code for operands.
There is another part of the memory reference.
All memory references use a 3-bit portion to define how the registers are set up.
Look at the supported expressions list.
That is mode 2 with those 8 different values for those 3 bits.
There are also modes 0,1, and 3.
Modes 0 and 1 use the same registers as mode 2 but with smaller offsets.
Mode 0 uses no offset so the r/m machine code is just 3 bits.
Mode 1 uses 8-bit offsets so the machine code is 3+8 or 11 bits long.
Mode 3 uses the basic 16-bit registers(ax,cx,dx,bx...) and no offset so it is also just 3-bits long.</li>
</ul>
<h2>Supported expressions</h2>
(currently, only assembles to(shown in bold font) mode 2 and
mode 0:reg 6 but disassembles all memory references)
<table class="bordered-cells">
<tr><td>
<h4 class="mode">MODE 0</h4>
<ul>
<li>0: <span class="register-name">BX+SI</span></li>
<li>1: <span class="register-name">BX+DI</span></li>
<li>2: <span class="register-name">BP+SI</span></li>
<li>3: <span class="register-name">BP+DI</span></li>
<li>4: <span class="register-name">SI</span></li>
<li>5: <span class="register-name">DI</span></li>
<li><b>6: Offset16</b></li>
<li>7: <span class="register-name">BX</span></li>
</ul>
</td><td>
<h4 class="mode">MODE 1</h4>
<ul>
<li>0: <span class="register-name">BX+SI</span>+offset8</li>
<li>1: <span class="register-name">BX+DI</span>+offset8</li>
<li>2: <span class="register-name">BP+SI</span>+offset8</li>
<li>3: <span class="register-name">BP+DI</span>+offset8</li>
<li>4: <span class="register-name">SI</span>+offset8</li>
<li>5: <span class="register-name">DI</span>+offset8</li>
<li>6: <span class="register-name">BP</span>+offset8</li>
<li>7: <span class="register-name">BX</span>+offset8</li>
</ul>
</td><td>
<h4 class="mode">MODE 2</h4>
<ul>
<li><b>0: <span class="register-name">BX+SI</span>+offset16</b></li>
<li><b>1: <span class="register-name">BX+DI</span>+offset16</b></li>
<li><b>2: <span class="register-name">BP+SI</span>+offset16</b></li>
<li><b>3: <span class="register-name">BP+DI</span>+offset16</b></li>
<li><b>4: <span class="register-name">SI</span>+offset16</b></li>
<li><b>5: <span class="register-name">DI</span>+offset16</b></li>
<li><b>6: <span class="register-name">BP</span>+offset16</b></li>
<li><b>7: <span class="register-name">BX</span>+offset16</b></li>
</ul>
</td></tr>
</table>
<h2>Segment overrides</h2>
<p>You can set the segment register by placing it in the left part of the brackets, left of a :.</p>
<strong>Examples</strong>
<table><tr><td>
<ul>
<li><b>mov</b> <span class="register-name">al</span>, [<span class="segment-register">es</span>:<span class="register-name">si</span>+<span class="variable-name-reference">message</span>]</li>
<li><b>mov</b> <span class="register-name">al</span>,
<span class="variable-name-reference">message</span>[<span class="segment-register">ss</span>:<span class="register-name">si</span>]</li>
<li><b>mov</b> <span class="register-name">al</span>,
<span class="segment-register">cs</span>:[<span class="register-name">si</span>+<span class="variable-name-reference">message</span>+<span class="number-literal">3</span>]</li>
<li><b>mov</b> <span class="register-name">al</span>,
<span class="variable-name-reference">message</span>[<span class="segment-register">gs</span>:<span class="register-name">si</span>+<span class="number-literal">3</span>]</li>
</ul>
<br>
<span class="assembly-label">message</span>: <b>db</b> <span class="string-literal">'Hello World'</span>, <span class="number-literal">0</span>
</td></tr></table>
<br><br><br>
<h2>Using them</h2>
<p>Put the expression for the memory address in square brackets. If you use a label before the brackets, that address is added to the offset. Labels can also be added inside the brackets.</p>
<h2>Examples</h2>
<table><tr><td>
<ul>
<li><b>mov</b> <span class="register-name">al</span>,
[<span class="register-name">si</span>+<span class="variable-name-reference">message</span>]</li>
<li><b>mov</b> <span class="register-name">al</span>,
<span class="variable-name-reference">message</span>[<span class="register-name">si</span>]
<span class="comment">; this is the same as the previous statement.</span></li>
<li><b>mov</b> <span class="register-name">al</span>,
[<span class="register-name">si</span>+<span class="variable-name-reference">message</span>+<span class="number-literal">3</span>]</li>
<li><b>mov</b> <span class="register-name">al</span>,
[<span class="register-name">si</span>+<span class="variable-name-reference">message</span>+<span class="number-literal">2</span>+<span class="number-literal">1</span>]
<span class="comment">; this is the same as the previous statement.</span></li>
<li><b>mov</b> <span class="register-name">al</span>, <span class="variable-name-reference">message</span>[<span class="register-name">si</span>+<span class="number-literal">1</span>+<span class="number-literal">2</span>]
<span class="comment">; this is the same as the previous 2 statements.</span>
</li>
</ul>
<span class="assembly-label">message</span>: <b>db</b> <span class="string-literal">'Hello World'</span>, <span class="number-literal">0</span>
</td></tr></table>
<h2>Operand Sizes</h2>
<p>You can specify the size of the data being referred to using a few different symbols.
All of these work for memory references but some don't have data defintions that work yet.</p>
<table class="bordered-cells">
<tr>
<td><strong>Symbol</strong></td>
<td><strong>Size</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><strong>BYTE</strong></td>
<td>8 bits</td>
<td>used in integer instructions, for data definitions use db</td>
</tr>
<tr>
<td><strong>WORD</strong></td>
<td>16 bits</td>
<td>used in integer and floating point instructions, for data definitions use dw</td>
</tr>
<tr>
<td><strong>DWORD</strong></td>
<td>32 bits</td>
<td>Double word, used in floating point instructions, for data definitions use
dd(not working completely yet)</td>
</tr>
<tr>
<td><strong>QWORD</strong></td>
<td>64 bits</td>
<td>Quad word, used in floating point instructions, for data definitions use
dq(not supported at all yet in data definitions)</td>
</tr>
<tr>
<td><strong>PWORD</strong></td>
<td>80 bits</td>
<td>Penta word, used as extended precision floating point in floating point instructions,
for data definitions use dp(not supported yet at all in data definitions)</td>
</tr>
<tr>
<td><strong>OWORD</strong></td>
<td>128 bits</td>
<td>Octal word, used as single precision floating point in SSE instructions,
for data definitions use do(not supported yet at all in data definitions)</td>
</tr>
</table>
</body>
</html>