Академический Документы
Профессиональный Документы
Культура Документы
CS – code segment SI
DS – data segment DI
ES – extra segment
SS – stack segment
71
16-bit General Purpose Registers
There are eight general purpose registers: AX, BX, CX, DX, SP, BP, SI, and DI. These can be used as
the left or right operand in any of the ALU operations and can be loaded from a memory cell and
stored back into a memory cell. They can also be loaded with a chosen number.
Most of the calculations in a program are done using the general purpose registers.
Note: SP, BP, SI, and DI have other special purposes and normally should not be used as general
purpose registers.
There are eight 8-bit general purpose register names: AH, AL, BH, BH, CH, CL, DH, and DL. Note
that these are NOT extra registers but only sub-divisions of the 16-bit registers.
AX = (AH) + (AL) where AH is the high byte and AL is the lower byte of the 2-byte register AX
BX = (BH) + (BL) where BH is the high byte and BL is the lower byte of the 2-byte register BX
CX = (CH) + (CL) where CH is the high byte and CL is the lower byte of the 2-byte register CX
DX = (DH) + (DL) where DH is the high byte and DL is the lower byte of the 2-byte register DX
Segment Registers
There are four segment registers: CS, DS, SS, and ES. They are specifically designed to store the
starting addresses for the segments that make up your program and its data. There are special machine
language instructions designed to use these registers and therefore you cannot use these registers in
most general instructions.
Index Registers
There are four index registers: BX, BP, SI, and DI. They can be used to help select a memory cell for
loading, storing, or calculations. When used as index registers, they simulate the action of a pointer
variable in C++.
Additionally, your instructions can add to the contents of these registers so that the register’s contents
does not change, but you do access a different memory cell; much like array indexing command in
C++, array[2], where “array” is your pointer variable and 2 is a calculation added to the pointer
variable to access a memory cell which is some number of bytes away from “array”.
Base Registers
There are two base registers: BX, and BP. The contents of these registers can be added to the contents
of the SI and DI registers to form the “base-plus-index addressing mode”. This mode is similar to the
C++ array indexing command, array[x], where a variable is used for array indexing rather than a hard-
coded literal like array[2].
72
AX (Accumulator Register) General Purpose (efficient register)
The most often used general purpose register. There are special instructions versions of some general
instructions which are coded differently, to be more efficient, when this register is used. This register
is automatically affected when doing multiplication and division and for certain adjustment
instructions. This register is also used by many programming languages to hold the return value from
a function. You may use all 16 bits of this register at once, or may independently use one or both of
the two bytes that make up this register. Note that if an operation uses the AL register, the results of
the operation will NOT affect the AH register and vice versa.
73
SP (Stack Pointer Register) Special Purpose
Can be used as a general purpose register but SHOULD NOT be! This register is used to keep track of
how much memory has been used in a portion of memory called the stack. The stack is used to keep
track procedure return addresses, procedure parameters and local variables. It generally starts by
holding the highest (last) address in the segment. As data is added to the stack, SP decreases so that it
always points to the last data item added. As data is removed from the stack, SP increases.
74
SS (Stack Segment Register) Special Purpose
This register is used to hold the starting (lowest numbered) address of the segment of memory with
space reserved for local variables and parameters needed by the functions in your program. DOS
reserves the amount of space that you specify at the same time it loads your program into memory.
Your program must load SS with the correct value if you are using this segment. Your program must
also load SP with the address of the memory cell at the end of your reserved block of segment
memory. For example, if SS starts at address 5 and you reserve 10 bytes, then SP is loaded with the
address 14 because you reserved 10 bytes of memory starting at address 5 and so address 14 is the last
reserved block. There are specific instructions designed to use the stack segment. General instructions
only use the stack segment when going through the BP register, so if you need stack data otherwise,
you have to specifically state so.
75