Hardware Reference
In-Depth Information
The second group of registers consists of the
pointer and index registers
.
The most important register of this group is the
stack pointer
, which is denoted by
SP
. Stacks are important in most programming languages. The stack is a segment
of memory that holds certain context information about the running program. Usu-
ally, when a procedure is called, part of the stack is reserved for holding the proce-
dure's local variables, the address to return to when the procedure has finished, and
other control information. The portion of the stack relating to a procedure is called
its
stack frame
. When a called procedure calls another procedure, an additional
stack frame is allocated, usually just below the current one. Additional calls allo-
cate additional stack frames below the current ones. While not mandatory, stacks
almost always grow downward, from high addresses to low addresses. Neverthe-
less, the lowest numerical address occupied on the stack is always called the top of
the stack.
In addition to their use for holding local variables, stacks can also hold tempo-
rary results. The 8088 has an instruction,
PUSH
, which puts a 16-bit word on top
of the stack. This instruction first decrements
SP
by 2, then stores its operand at
the address
SP
is now pointing to. Similarly,
POP
removes a 16-bit word from the
top of the stack by fetching the value on top of the stack and then incrementing
SP
by 2. The
SP
register points to the top of the stack and is modified by
PUSH
,
POP
,
and
CALL
instructions, being decremented by
PUSH
, incremented by
POP
, and
decremented by
CALL
.
The next register in this group is
BP
, the
base pointer
. It usually contains an
address in the stack. Whereas
SP
always points to the top of the stack,
BP
can point
to any location within the stack. In practice, a common use for
BP
is to point to the
beginning of the current procedure's stack frame, in order to make it easy to find
the procedure's local variables. Thus,
BP
often points to the bottom of the current
stack frame (the stack frame word with the highest numerical value) and
SP
points
to the top (the stack frame word with the lowest numerical value).
The current
stack frame is thus delimited by
BP
and
SP
.
In this register group, there are two index registers:
SI
, the
source index,
and
DI
, the
destination index
. These registers are often used in combination with
BP
to address data in the stack, or with
BX
to compute the addresses of data memory
locations. More extensive treatment of these registers will be deferred to the sec-
tion on addressing modes.
One of the most important registers, which is a group by itself, is the
instruc-
tion pointer
, which is Intel's name for the program counter (
PC
). This register is
not addressed directly by the instructions, but contains an address in the program
code segment of the memory. The processor's instruction cycle starts by fetching
the instruction pointed to by
PC
. This register is then incremented before the rest
of the instruction is executed. In this way this program counter points to the first
instruction beyond the current one.