THE REGISTERS:
I've mentioned AX, AL, and AH before, and you're probably wondering what
exactly they are. Well, I'm gonna go through one by one and explain
what each register is and what it's most common uses are. Here goes:
AX (AH/AL):
AX is a 16 bit register which, as metioned before, is merely two bytes
attached together. Well, for AX, BX, CX, & DX you can independantly
access each part of the 16 bit register through the 8bit (or byte sized)
registers. For AX, they are AL and AH, which are the Low and High parts
of AX, respectivly. It should be noted that any change to AL or AH,
will change AX. Similairly any changes to AX may or may not change AL and
AH. For instance:
Let's suppose that AX = 00000h (AH and AL both = 0, too)
mov AX,0
mov AL,0
mov AH,0
Now we set AL = 0FFh.
mov AL,0FFh
:AX => 000FFh ;I'm just showing ya what's in the registers
:AL => 0FFh
:AH => 000h
Now we increase AX by one:
INC AX
:AX => 00100h (= 256.. 255+1= 256)
:AL => 000h (Notice that the change to AX changed AL and AH)
:AH => 001h
Now we set AH = 0ABh (=171)
mov AH,0ABh
:AX => 0AB00h
:AL => 000h
:AH => 0ABh
Notice that the first example was just redundant...
We could've set AX = 0 by just doing
mov ax,0
:AX => 00000h
:AL => 000h
:AH => 000h
I think ya got the idea...
SPECIAL USES OF AX:
Used as the destination of an IN (in port)
ex: IN AL,DX
IN AX,DX
Source for the output for an OUT
ex: OUT DX,AL
OUT DX,AX
Destination for LODS (grabs byte/word from [DS:SI] and INCreses SI)
ex: lodsb (same as: mov al,[ds:si] ; inc si )
lodsw (same as: mov ax,[ds:si] ; inc si ; inc si )
Source for STOS (puts AX/AL into [ES

I] and INCreses DI)
ex: stosb (same as: mov [es:di],al ; inc di )
stosw (same as: mov [es:di],ax ; inc di ; inc di )
Used for MUL, IMUL, DIV, IDIV
BX (BH/BL): same as AX (BH/BL)
SPECIAL USES:
As mentioned before, BX can be used as an OFFSET register.
ex: mov ax,[ds:bx] (grabs the WORD at the address created by
DS and BX)
CX (CH/CL): Same as AX
SPECIAL USES:
Used in REP prefix to repeat an instruction CX number of times
ex: mov cx,10
mov ax,0
rep stosb ;this would write 10 zeros to [ES

I] and increase
;DI by 10.
Used in LOOP
ex: mov cx,100
THELABEL:
;do something that would print out 'HI'
loop THELABEL ;this would print out 'HI' 100 times
;the loop is the same as: dec cx
jne THELABAL
DX (DH/DL): Same as above
SPECIAL USES:
USED in word sized MUL, DIV, IMUL, IDIV as DEST for high word
or remainder
ex: mov bx,10
mov ax,5
mul bx ;this multiplies BX by AX and puts the result
;in DX:AX
ex: (continue from above)
div bx ;this divides DX:AX by BX and put the result in AX and
;the remainder (in this case zero) in DX
Used as address holder for IN's, and OUT's (see ax's examples)
INDEX REGISTERS:
DI: Used as destination address holder for stos, movs (see ax's examples)
Also can be used as an OFFSET register
SI: Used as source address holder for lods, movs (see ax's examples)
Also can be used as OFFSET register
Example of MOVS:
movsb ;moves whats at [DS:SI] into [ES

I] and increases
movsw ; DI and SI by one for movsb and 2 for movsw
NOTE: Up to here we have assumed that the DIRECTION flag was cleared.
If the direction flag was set, the DI & SI would be DECREASED
instead of INCREASED.
ex: cld ;clears direction flag
std ;sets direction flag
STACK RELATED INDEX REGISTERS:
BP: Base Pointer. Can be used to access the stack. Default segment is
SS. Can be used to access data in other segments throught the use
of a SEGMENT OVERRIDE.
ex: mov al,[ES:BP] ;moves a byte from segment ES, offset BP
Segment overrides are used to specify WHICH of the 4 (or 6 on the
386) segment registers to use.
SP: Stack Pointer. Does just that. Segment overrides don't work on this
guy. Points to the current position in the stack. Don't alter unless
you REALLY know what you are doing.
SEGMENT REGISTERS:
DS: Data segment- all data read are from the segment pointed to be this
segment register unless a segment overide is used.
Used as source segment for movs, lods
This segment also can be thought of as the "Default Segment" because
if no segment override is present, DS is assumed to be the segmnet
you want to grab the data from.
ES: Extra Segment- this segment is used as the destination segment
for movs, stos
Can be used as just another segment... You need to specify [ES:°°]
to use this segment.
FS: (386+) No particular reason for it's name... I mean, we have CS, DS,
and ES, why not make the next one FS?

Just another segment..
GS: (386+) Same as FS
OTHERS THAT YOU SHOULDN'T OR CAN'T CHANGE:
CS: Segment that points to the next instruction- can't change directly
IP: Offset pointer to the next instruction- can't even access
The only was to change CS or IP would be through a JMP, CALL, or RET
SS: Stack segment- don't mess with it unless you know what you're
doing. Changing this will probably crash the computer. This is the
segment that the STACK resides in.
Heck, as long as I've mentioned it, lets look at the STACK:
The STACK is an area of memory that has the properties of a STACK of
plates- the last one you put on is the first one take off. The only
difference is that the stack of plates is on the roof. (Ok, so that
can't really happen... unless gravity was shut down...) Meaning that
as you put another plate (or piece of data) on the stack, the STACK grows
DOWNWARD. Meaning that the stack pointer is DECREASED after each PUSH,
and INCREASED after each POP.
_____ Top of the allocated memory in the stack segment (SS)
þ
þ
þ
þ ® SP (the stack pointer points to the most recently pushed byte)
Truthfully, you don't need to know much more than a stack is Last In,
First Out (LIFO).
WRONG ex: push cx ;this swaps the contents of CX and AX
push ax ;of course, if you wanted to do this quicker, you'd
...
pop cx ;just say XCHG cx,ax
pop ax ; but thats not my point.
RIGHT ex: push cx ;this correctly restores AX & CX
push ax
...
pop ax
pop cx