Hardware Reference
In-Depth Information
AH
and the value 2 being loaded into
AL
. Then line 5 adds
AL
to
AH
, making
AH
equal to 3. On line 6, the contents of the variable
times
(10) are copied into
CX
.
On line 7, the address of the variable
muldat
, which is 2 because it is at the second
byte of the DATA segment, is loaded into
BX
. This is the instant in time at which
the dump of Fig. C-13(b) was made.
Note that
AH
is 3,
AL
is 2, and
AX
is 770,
which is to be expected, as 3
×
256
+
2
=
770.
start:
! 3
CS: 00 DS=SS=ES:002
AH:03 AL:02 AX: 770
BH:00 BL:02 BX: 2
CH:00 CL:0a CX: 10
DH:00 DL:00 DX: 0
SP: 7fe0 SF O DS Z C
BP: 0000 CC - > p - -
S I : 0000 IP:0009:PC
DI : 0000 start + 4
CS: 00 DS=SS=ES:002
AH:38 AL:80 AX: 14464
BH:00 BL:02 BX: 2
CH:00 CL:04 CX: 4
DH:00 DL:01 DX: 1
SP: 7fe0 SF O DS ZC
BP: 0000 CC v > p - c
S I : 0000 IP:0011:PC
DI : 0000 start + 7
MOV
AX,258
! 4
ADDB AH,AL
! 5
MOV
CX,(times)
! 6
MOV
BX,muldat
! 7
MOV
AX,(BX)
! 8
llp: MUL
2(BX)
! 9
LOOP llp
! 10
.SECT .DATA
! 11
times: .WORD 10
! 12
muldat :.WORD 625, 2
! 13
(a)
(b)
(c)
Figure C-13.
(a) Part of a program. (b) The tracer register window after line 7
has been executed. (c) The registers.
The next instruction (line 8) copies the contents of
muldat
into
AX
. Thus, after
the return key is hit,
AX
will be 625.
We are now ready to enter a loop that multiplies the contents of
AX
by the word
addressed by
2BX
(i.e.,
muldat + 2
), which has the value 2. The implied destina-
tion of the
MUL
instruction is the
DX
:
AX
long register combination. In the first
iteration of the loop, the result fits in one word, so
AX
contains the result (1250),
and
DX
remains 0.
The contents of all the registers after 7 multiplications are
shown in Fig. C-13.
Since
AX
started at 625, the result after those seven multiplications by 2 is
80,000. This result does not fit in
AX
, but the product is held in the 32-bit register
formed by the concatenation of
DX
:
AX
,so
DX
is 1 and
AX
is 14,464. Numerically,
this value is 1
65,536 + 14,464, which is, indeed, 80,000. Note that
CX
is 4 here,
because the
LOOP
instruction decrements it every iteration. Because it started at
10, after seven executions of the
MUL
instruction (but only six iterations of the
LOOP
instruction) we have
CX
set to 4.
In the next multiplication, trouble crops up. Multiplication involves
AX
but not
DX
,sothe
MUL
multiples
AX
(14464) by 2 to get 28,928. This results in
AX
being
set to 28,928 and
DX
being set to 0, which is numerically incorrect.
×
The next example,
vecprod.s
is a small program that computes the inner prod-
uct of two vectors,
vec1
and
vec2
. It is listed in Fig. C-14.