Hardware Reference
In-Depth Information
#include "../syscalnr.h"
! 1
.SECT .TEXT
! 20
vecprint:
! 21
.SECT .TEXT
! 2
PUSH BP
! 22
vecpstrt:
! 3
MOV BP,SP
! 23
MOV BP,SP
! 4
MOV CX,4(BP)
! 24
PUSH vec1
! 5
MOV BX,6(BP)
! 25
MOV CX,frmatstr-vec1
! 6
MOV SI,0
! 26
SHR CX
! 7
PUSH frmatkop
! 27
PUSH CX
! 8
PUSH frmatstr
! 28
CALL vecprint
! 9
PUSH PRINTF
! 29
MOV SP,BP
! 10
SYS
! 30
PUSH 0
! 11
MOV -4(BP),frmatint
! 31
PUSH EXIT
! 12
1: MOV DI,(BX)(SI)
! 32
SYS
! 13
MOV -2(BP),DI
! 33
SYS
! 34
.SECT .DATA
! 14
INC SI
! 35
vec1:
.WORD 3,4,7,11,3
! 15
LOOP 1b
! 36
frmatstr: .ASCIZ "%s"
! 16
PUSH '\n'
! 37
PUSH PUTCHAR
! 38
frmatkop:
! 17
SYS
! 39
.ASCIZ "The array contains "
! 18
MOV SP,BP
! 40
frmatint: .ASCIZ " %d"
! 19
RET
! 41
Figure C-16.
The program
arrayprt
before debugging.
Lines 27 to 30 show how a string can be printed, and 31 to 34 show the
printf
system call for an integer value. Note that the address of the string is pushed on
line 27, while on line 33 the value of the integer is moved onto the stack. In both
cases the address of the format string is the first argument of PRINTF. Lines 37 to
39 show how a single character can be printed using the
putchar
system call.
Now let us try assembling and running the program. When the command
as88 arrayprt.s
is typed, we get an operand error on line 28 of the file
arrayprt.$
. This file is gen-
erated by the assembler by combining the included files with the source file to get
a composite file that is the actual assembler input. To see where line 28 really is,
we have to examine line 28 of
arrayprt.$
. We cannot look at
arrayprt.s
to get the
line number because the two files do not match on account of the header being
included line by line in
arrayprt.$
. Line 28 in
arrayprt.$
corresponds to line 7 in
arrayprt.s
because the included header file,
syscalnr.h,
contains 21 lines.
One easy way to find line 28 of
arrayprt.$
on
UNIX
is to type the command
head -28 arrayprt.$
which displays the first 28 lines of the combined file. The line at the bottom of the
listing is the one in error. In this way (or by using an editor and going to line 28)