Assembler
Well THis is the Assembler Section
Where you come to learn a bit of ASM
OK..well you want to Know some assembler
you came right place.
I Cant promise youll be some ASM guru when you leave, but
If you paid attention and under stodd you will know some assebler..
First Lets talk about the basics
Assembler is a low level language meaning
its hard to learn, High level languages (easier) are like Basic
Now in assembler, when you use numbers, they wont be base 10,
there base 16, in hexadecimal
the Hex Number systemis as follows:
base 10 (numbers u used to)
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
base 16 (hex)
1h
2h
3h
4h
5h
6h
7h
8h
9h
ah
Bh
ch
dh
eh
fh
10h
11h
12h
13h
14h
15h
16h
17h
18h
19h
1ah
1bh
1ch
See?
thats how that works..
Now you must know that a CPU is made up of registers, a register is a place
to store values, these will hold all of your variables (called offsets)
the registers are
AX (made up of ah and al)
BX (bh and bl)
CX (ch and cl)
DX (dh and dl)
ES
DS
CS
SS
SP
Ok, the last 5 regiosters
ES is the extra segment registers, where extra data is kept
ahh wahst this word? segment, in ASM a segment is 64k bytes ofdata in length
no larger.
DS is the data segment, the segment where all the program data is kept in a program
CS is code segment, where all the program code is kept
SS is stack segment, all Programs have a stack, usually 1k, where values can be stored
SP is the stack Pointer
OK, with that off lets get coding.
first We Will talk about Push/pop
PUSH
Syntax:
push
Ok, lets say we PUSH AX in a program
What ever value AX hlds wil be stored on the stack, imagine the stack as a shelf to keep
something on until u need to use it...
Also if you push multiple values, the last one you push will be on the stack 1st
example
lets say i do this in a program:
PUSH ax
PUSH 4
PUSH 7
7 will be first on the stack.. so when i want to POP it off, the first pop ill use 7, the next 4, the next
ax
POP
Syntax:
POP
nOW, LATER IN THE PROgram lets say you want to go the "shelf"
Stack and retrieve a value, BUT THE VALUE U MUST BE FIRST ON STACK TO USE IT
example lts say u:
push 7
push 9
and want to put 7 in ax
and u do this
pop ax
It wont be 7! because the 9 is on the stack before the 7 so it will be popped first
got that down?
Good
Next is the MOV instruction it Movs a value into a register:
Syntax:
mov
Example of its use
mov ax,5
after this, ax will hold the value of 5
this can be done wiith most of the registers, but a few of the segment registers cant be manipulated this way
Next improtant aprt, routine labeling
yes you must label routines in your program, so they can be refrenced
Lets say u have code to make a farty noise come out the speaker (lurance, dont get any ideas)
you might have it like this:
SpeakerFart:
this is so you can reference this routine throughout the program, whioch brings me to my next section
JMP
(jump)
these are used to hop around in your program, lets say u wanna go to the fartysound routine from another
section of the program, u could add this line in when u wanna jump
JMP FartyNoise
that will jump and begin execution at routine labeled FartyNoise
Now a lesson In memory addressing...
in a PC comapitble system memory is adddressed in Segment:offset form
ie:
0009:FFFF
that says that the data at hand is 9h spot on segment and is at FFFFH in that segment
Segments are 64k in length or 65,535 bytes
FFFFh in hexadecimal
when offset # is at ffffh and u add more to it, you up segment number
when adding 1, it goes:
0009:ffffh
000a:0000h
000a:0001h
and on.
see?
Which brings me to my next assembler command.
LEA
Load effective address
this Loads the address of that offset into the register in question.
and is used like this
lea dx,[fart+5]
this will load fart+5 into dx
what are those brackets u ask?
they tell the processor to combine everything in the brackets to one offset