The Registers (Continued)

As before I've mentioned about the AX registers, now we'll continue about the other registers. Take note guys!.

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:DI] 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 THELABEL

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:DI] 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.

So, that's all for now and I'll come back with some example of the stack and the WRONG and RIGHT doing in the stack. Have fun y'all!

No comments: