Chapter
1.
Assembly
Language
and
Processors
The auxiliary carry flag
is
affected
by
all
add, subtract, increment, decrement, compare, and
all
logical AND,
OR, and exclusive OR instructions. (See the descriptions
of
these instructions
in
Chapter 3.) There
is
some
difference
in
the handling
of
the auxiliary carry flag
by
the logical
AND
instructions
in
the
8080
processor and
the
8085 processor. The 8085 logical
AN
D instructions always set the auxiliary flag ON. The
8080
logical
AN
D
instructions set the
flag to reflect the logical OR
of
bit 3
of
the values involved
in
the
AND
operation.
Stack and Stack
Pointer
1-12
To understand the purpose and effectiveness
of
the stack,
it
is
useful to understand the concept
of
a subroutine.
Assume that your program requires a
multiplication routine. (Since the
8080
has
no
multiply instructions, this
can
be
performed through repetitive addition. For example, 3x4
is
equivalent to 3+3+3+3.) Assume further
that
your program needs this multiply routine seve:al times. You can recode this routine inline each time it
is
needed,
but
this can use a great
deal
of
memory. Or, you can code a subroutine:
Inline Coding Subroutine
1
1
inline routine
CALL
I
I
inline routine CALL
subroutine
I
I
inline routine
CALL
I I
The
8080
provides instructions
that
call
and return from a subroutine. When the
cdll
instruction
is
executed, the
address
of
the next instruction (the contents
of
the program counter)
is
pushed
onto
the stack. The contents
of
the program counter are replaced by the address
of
the desired subroutine.
At
the end
of
the subroutine, a
return instruction pops that previously-stored address off the stack and puts it back into the program countcr.
Program execution then continues
as
though the subroutine had been coded inline.
The mechanism
that
makes this possible
is,
of
course, the stack. The stack
i~
simply an
arCd
of random acee,s
memory addressed by the stack pointer. The ',tack pointer
is
a hdrdware register maintained
by
the proce,>sor.
However, your program must initialize the stack pointer. This means that your program
mu~t
load the base
address
of
the stack into the stack pointer. The base address of the stack
is
commonly assigned to the highest
available address
in
RAM.
This
is
because the stack ,expands
by
decrementing the stack pointer.
As
items are