Intel 210200-002 Baby Furniture User Manual


 
ARCHITECTURE
AND
INSTRUCTIONS
The need for
an
assumption about DS
is
that
some assembly-language instructions in the
code segment access
data
directly, particu-
larly, the byte SUM. The assembler must
generate
machine~language
instructions that
address
SUM
. using the direct addressing
mode. These generated instructions specify
the offset of
SUM
and some segment register,
typically DS, containing the starting address
of
the segment (namely MY_DATA) contain-
ing SUM.
The assembler needs to know which segment
registers (if any) will contain
MY_
DATA's
starting address,
at
the time these instructions
are executed. With this information, the
assembler can determine if a segment-over-
riding prefix
is
required on these instructions,
and if so, which segment register should be
specified by
the
prefix.
It
would be the case
if,
for example, MY..,.DATA's starting address
were contained only in ES. Furthermore, if
none
of
the registers will contain
MY_
DATA's starting address
at
instruction-
execution time, the assembler knows that it
cannot generate any instructions capable of
accessing
SUM
and
will
be able to report this
error
at
instruction-assembly time.
SUMMARY
So, why assume some segment register would
contain
MY
_DATA's
starting address
at
instruction-execution time? So that
SUM
can
be accessed. Why
is
DS
used? Because no
segment-overriding prefix
is
necessary. Make
sure this assumption
is
satisfied by executing
certain instructions (lines 7
and
8)
prior to the
first access
to
SUM.
PORTS3AND 4
Line 6 specifies that PORT_VAL
is
equiva-
lent to the constant
3.
This permits
PORT_
V
AL
to be used in place of 3 on succeeding
lines. This makes
PORT_VAL a symbolic
name for port 3 and refers to
PORT_VAL
whenever port 3
is
wanted. Now if
we
decide
2-22
to
rewrite the program to use port 4 instead,
we
need make only one change: line 6
is
changed to:
The instructions on lines 7 through
17
will
keep adding inputs from
port
3 until the sum
exceeds
100,
output that sum to
port
3,
then
halt. This
is
accomplished as follows: The
instruction on line 7 puts - the
16
most-
significant bits
of
- the starting address of
segment
MY..D
A T A into register AX; on line
8 this value
is
moved from AX to DS. This
makes
SUM
accessible in succeeding in-
structions.
The instruction on line 9 initializes
SUM
to
O.
Observe that on lines
7,
8,
and
9,
the desti-
nations, such as
SUM
on line
9,
are always
written before the sources, as 0 on line
9.
Line
10
compares (CMP) the value in
SUM
to
100
and sets processor flags, indicating
comparison results.
Line
11
tests the flags and jumps, if
SUM
was
not
above
100
(JNA). The target
of
,the
jump
is
the instruction labeled
NOLDONE
(line
15).
If
the
jump
on line
11
is
not
taken
(SUM
> 100), the
SUM
is
moved into
AL
(line
12);
the contents
of
AL
is
sent to
output
port
3
(line
13),
and the processor halts (line
14).
If
the
jump
on line
11
is
taken
(SUM
< 100),
the value on input port 3
is
sent to
AL
(line
15),
added to
SUM
(line
16),
and the
jump
on
line
17
transfers control back to line
10.
General Conclusions
Now, from the above example, what can be
noticed about the structure
of
an
ASM-86
program?
It
consists
of
one or more segment
blocks followed by
an
END
statement. Each
segment block starts with a
SEGMENT
statement and ends with
an
ENDS
(end-of-
segment) statement. Between the SEG MENT
and
ENDS
statements
is
a sequence of other