Hardware Reference
In-Depth Information
MOV BP,SP ! 5
PUSH vec2 ! 6
PUSH vec1 ! 7
MOV CX,vec2-vec1 ! 8
SHR CX,1
CS: 00 DS=SS=ES:004
AH:00 AL:00 AX: 0
BH:00 BL:00 BX: 0
CH:00 CL:05 CX: 5
DH:00 DL:00 DX: 0
SP: 7fb4 SF O D S Z C
BP: 7fb6 CC - > p z -
S I : 0018 IP:0031:PC
DI : 0022 vecmul+7
PUSHBP ! 22
MOV BP,SP ! 23
MOV CX,4(BP) ! 24
MOV SI,6(BP) ! 25
MOV DI,8(BP) ! 26
PUSH0 ! 27
LODS ! 28
MUL ( D I ) ! 29
ADD -2(BP),AX ! 30
=>0000
7fc0
1 0011
0005 =>1:
0018
0022
! 9
PUSHCX
! 10
CALL vecmul
! 11
----------
vecmul :
! 21
PUSHBP
! 22
MOV BP,SP
! 23
I
1 <= inpstart + 7
MOV CX,4(BP)
! 24
MOV SI,6(BP)
! 25
>
MOV DI,8(BP)
! 26
vec1+0 =0018: 3 0 4070b0........... 3
vec2+0 =0022: 2 0 603010........... 2
pfmt +0 =0000:54 68 65 20 69 6e 20 70 The in prod 26708
pfmt+18 =0012:25 64 21 a 0030%d!........25637
PUSH 0
! 27
1: LODS
! 28
MUL (DI)
! 29
ADD -2(BP),AX
! 30
ADD DI,2
! 31
LOOP 1b
! 32
Figure C-15. Execution of vecprod.s when it reaches line 28 for the first time.
C.8.4 Debugging an Array Print Program
In the previous examples, the programs examined were simple but correct.
Now we will show how the tracer can help debug incorrect programs. The next
program is supposed to print the integer array, which is supplied after the label
vec1 . However, the initial version contains three errors. The assembler and tracer
will be used to correct those errors, but first we will discuss the code.
Because every program needs system calls, and thus must define constants by
which to identify the call numbers, we have put the constant definitions for those
numbers in a separate header file ../syscalnr.h , which is included on line 1 of the
code. This file also defines the constants for the file descriptors
STDIN = 0
STDOUT = 1
STDERR = 2
which are opened at the start of the process, and header labels for the text and the
data segments. It is sensible to include it at the head of all assembly source files,
as these are much used definitions. If a source is distributed over more than one
file, the assembler includes only the first copy of this header file, to avoid defining
the constants more than once.
The program arrayprt is shown in Fig. C-16. Comments have been omitted
here, as the instructions should be well known by now. This layout allows a two-
column format. Line 4 puts the address of the empty stack in the base pointer reg-
ister to allow the stack cleanup can be made on line 10 by copying the base pointer
to the stack pointer, as described in the previous example. We also have seen the
computation and pushing of the stack arguments before the call on lines 5 through
9 in the previous example. Lines 22 to 25 load the registers in the subroutine.
 
Search WWH ::




Custom Search