-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathasm_tutorial_01.html
executable file
·172 lines (127 loc) · 6.05 KB
/
asm_tutorial_01.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
160
161
162
163
164
165
166
167
168
169
170
171
172
<HTML>
<HEAD>
<TITLE>8086 assembler tutorial for beginners (part 1)</TITLE>
<META name="description" content="what is assembly language? startup tutorial for beginners.">
</HEAD>
<BODY>
<FONT FACE="Verdana" SIZE=3>
<FONT SIZE=+1>
<B>8086 assembler tutorial for beginners (part 1)</B>
</FONT>
<BR><BR>
<BR>
This tutorial is intended for those who are not familiar with assembler at all,
or have a very distant idea about it. Of course if you have knowledge of some high level
programming language (java, basic, c/c++, pascal...) that may help you a lot.
<br>
But even if you are familiar with assembler, it is still a good idea to look
through this document in order to study emu8086 syntax.
<br><br>
It is assumed that you have some knowledge about number representation (hex/bin),
if not it is highly recommended to study
<a href="numbering_systems_tutorial.html"><b>numbering systems tutorial</b></a>
before you proceed.
<BR><BR><BR>
<FONT SIZE=+2><B>what is assembly language?</B></FONT>
<BR><BR>
Assembly language is a low level programming language.
You need to get some knowledge about computer structure
in order to understand anything.
The simple computer model as I see it:<br>
<IMG SRC="img/model.gif" WIDTH=382 HEIGHT=241>
<BR> The <B>system bus</B> (shown in yellow) connects the various components
of a computer.<BR>
The <B>CPU</B> is the heart of the computer, most of computations occur inside the <B>CPU</B>.<BR>
<B>RAM</B> is a place to where the programs are loaded in order to be executed.
<BR><BR><BR>
<FONT SIZE=+2><B>inside the CPU</B></FONT>
<BR><BR>
<IMG SRC="img/cpu.gif" WIDTH=540 HEIGHT=284><BR><BR>
<B>general purpose registers</B><BR><BR>
8086 CPU has 8 general purpose registers, each register has its own name:
<BR>
<UL>
<LI> <B>AX</B> - the accumulator register (divided into <B>AH / AL</B>).</LI>
<LI> <B>BX</B> - the base address register (divided into <B>BH / BL</B>).</LI>
<LI> <B>CX</B> - the count register (divided into <B>CH / CL</B>).</LI>
<LI> <B>DX</B> - the data register (divided into <B>DH / DL</B>).</LI>
<LI> <B>SI</B> - source index register.</LI>
<LI> <B>DI</B> - destination index register.</LI>
<LI> <B>BP</B> - base pointer.</LI>
<LI> <B>SP</B> - stack pointer.</LI>
</UL>
<BR>
Despite the name of a register, it's the programmer who determines
the usage for each general purpose register. The main purpose of a register is to
keep a number (variable). The size of the above registers is 16 bit, it's something
like: <b>0011000000111001b</b> (in binary form), or <b>12345</b> in decimal (human) form.
<BR><BR>
4 general purpose registers (AX, BX, CX, DX) are made of two separate 8 bit
registers, for example if AX=
<B><FONT COLOR=RED>00110000</FONT><FONT COLOR=BLUE>00111001</FONT>b</B>,
then AH=<B><FONT COLOR=RED>00110000</FONT>b</B>
and AL=<B><FONT COLOR=BLUE>00111001</FONT>b</B>. Therefore, when you modify any of the 8 bit
registers 16 bit register is also updated, and vice-versa. The same is for other 3 registers,
"H" is for high and "L" is for low part.
<BR><BR>
Because registers are located inside the CPU,
they are much faster than memory. Accessing a memory location
requires the use of a system bus, so it takes much longer.
Accessing data in a register usually takes no time.
Therefore, you should try to keep variables in the registers.
Register sets are very small and most registers have special
Purposes which limit their use as variables, but they
are still an excellent place to store temporary data of
calculations.
<BR><BR>
<B>segment registers</B><BR><BR>
<UL>
<LI> <B>CS</B> - points at the segment containing the current program.</LI>
<LI> <B>DS</B> - generally points at segment where variables are defined.</LI>
<LI> <B>ES</B> - extra segment register, it's up to a coder to define its usage.</LI>
<LI> <B>SS</B> - points at the segment containing the stack.</LI>
</UL>
Although it is possible to store any data in the
segment registers, this is never a good idea.
The segment registers have a very special purpose
- pointing at accessible blocks of memory.
<BR><BR>
Segment registers work together with general purpose register to access
any memory value. For example if we would like to access memory at the physical
address <B>12345h</B> (hexadecimal), we should set the <B>DS = 1230h</B> and
<B>SI = 0045h</B>. This is good, since this way we can
access much more memory than with a single register that is limited to 16 bit values.<BR>
CPU makes a calculation of physical address by multiplying the segment register by 10h
and adding general purpose register to it <NOBR>(1230h * 10h + 45h = 12345h):</NOBR><BR>
<IMG SRC="img/effective_address.gif" WIDTH=63 HEIGHT=75>
<BR>
The address formed with 2 registers is called an <B>effective address</B>.
<BR>
By default <B>BX, SI</B> and <B>DI</B> registers work with <B>DS</B> segment register;<BR>
<B>BP</B> and <B>SP</B> work with <B>SS</B> segment register.<BR>
Other general purpose registers cannot form an effective address!
<BR>
also, although <B>BX</B> can form an effective address, <B>BH</B> and <B>BL</B> cannot.
<BR><BR>
<B>special purpose registers</B><BR><BR>
<UL>
<LI> <B>IP</B> - the instruction pointer.</LI>
<LI> <B>flags register</B> - determines the current state of the microprocessor.</LI>
</UL>
<BR>
<B>IP</B> register always works together with <B>CS</B> segment register and it points
to currently executing instruction.<BR>
<B>Flags register</B> is modified automatically by CPU after mathematical operations,
this allows to determine the type of the result, and to determine conditions
to transfer control to other parts of the program.<BR>
Generally you cannot access these registers directly, the way you can access AX and other general registers, but it is possible to change values of system registers using some tricks that you will learn a little bit later.
<BR><BR><BR>
<HR>
<CENTER>
<A HREF="asm_tutorial_02.html"><B> >>> Next Part >>> </B></A>
</CENTER>
<HR>
<BR>
</FONT>
</BODY>
</HTML>