Hardware Reference
In-Depth Information
.SECT .TEXT
#include "../syscalnr.h"
! 1
stcstart:
! 1
PUSH mesg1
! 2
start: MOV DI,str
! 2
PUSH mesg2
! 3
PUSH AX
! 3
CALL strngcpy
! 4
MOV BP,SP
! 4
ADD SP,4
! 5
PUSH PUTCHAR
! 5
PUSH 0
! 6
MOVB AL,'\n'
! 6
PUSH 1
! 7
MOV CX,-1
! 7
SYS
! 8
REPNZ SCASB
! 8
strngcpy:
! 9
NEG CX
! 9
PUSH CX
! 10
STD
! 10
PUSH SI
! 11
DEC CX
! 11
PUSH DI
! 12
SUB DI,2
! 12
PUSH BP
! 13
MOV SI,DI
! 13
MOV BP,SP
! 14
1: LODSB
! 14
MOV AX,0
! 15
MOV (BP),AX
! 15
MOV DI,10(BP)
! 16
SYS
! 16
MOV CX,
1
! 17
LOOP 1b
! 17
REPNZ SCASB
! 18
MOVB (BP),'\n'
! 18
NEG CX
! 19
SYS
! 19
DEC CX
! 20
PUSH 0
! 20
MOV SI,10(BP)
! 21
PUSH EXIT
! 21
MOV DI,12(BP)
! 22
SYS
! 22
PUSH DI
! 23
.SECT .DATA
! 23
REP MOVSB
! 24
str: .ASCIZ "reverse\n"
! 24
CALL stringpr
! 25
MOV SP,BP
! 26
POP BP
! 27
POP DI
! 28
POP SI
! 29
POP CX
! 30
RET
! 31
.SECT .DATA
! 32
mesg1: .ASCIZ "Have a look\n"
! 33
mesg2: .ASCIZ "qrst\n"
! 34
.SECT .BSS
(a)
(b)
Figure C-17. (a) Copy a string ( strngcpy.s ). (b) Print a string backward ( rever-
spr.s ).
Fig. C-17(a) is a subroutine for copying a string. It calls a subroutine, stringpr ,
which can also be found in a separate file stringpr.s . It is not listed in this
appendix. In order to assemble programs containing subroutines in separate source
files, just list all source files in the as88 command, starting with the source file for
 
Search WWH ::




Custom Search