
120 Assembly Language Programming for the 68000 Family
TST.B - 1 (AO) HAVE WE HIT A NULL?
BNE STRCMP1 NOW MORE BYTES LEFT
STRRET: MOVEM.L (SP)+,A0-A1 RESTORE REGS
RTS
This subroutine sets the condition code register according to the last two
bytes compared, if they were unequal; the zero condition is set if the
strings match. We can then determine not only the equality or inequality
of the strings, but also their alphabetical order. Fortunately, the ASCII
character set is ordered properly from A to Z. These last two subroutines
are minor variations of the techniques used in Chapter 6.
The standard I/O subroutines introduced in Chapter 4 only provide
a mechanism to input or output a single character. We must be able to
input and output a complete character string. Two subroutines, INS and
OUTS, will be used to input and output null-terminated strings. OUTS
merely calls PUTC for each character in the string until the null is found.
* OUTS - OUTPUT A NULL TERMINATED STRING TO THE SCREEN
* aO -> STRING
OUTS: MOVEM.L AO/DO,-(SP)
0UTS1: CLR.L DO
MOVE.B (AO)+/D0
BEQ OUTSRET
JSR PUTC
BRA OUTS1
OUTSRET:MOVEM.L (SP)+,AO/DO
RTS
SAVE REGISTERS
CLEAR HIGH ORDER BYTES OF DO
MOVE A CHARACTER INTO DO
QUIT IF NULL
OUTPUT THE CHARACTER
LOOP FOR ANOTHER
RESTORE REGISTERS
Inputting a character string is almost as simple. There is one minor
detail to keep in mind: the size of the array that we are reading the string
into is of a certain size. For this example, the maximum size data string
is a total of NDATA characters long. Since the string must be terminated
with a null, we must reserve one of these characters for the null byte.
Therefore, we can only read a total of NDATA-1 characters from the
keyboard. The INS subroutine will read characters using GETC until a
carriage return is entered or NDATA-1 characters have been entered.
* INS - INPUT A STRING UNTIL CR OR NDATA-1 CHARACTERS
* AO -> STRING
INS: MOVEM.L A0/D0-D1,- (SP) SAVE REGISTERS
MOVE.W #NDATA-2,D1 SET UP LOOP COUNT
INS1: JSR GETC GET A CHARACTER
MOVE.B D0,(A0)+ STORE IT IN STRING
CMP.B #CR,D0 CR?
DBEQ Dl,INS1 LOOP UNTIL COUNT RUNS OUT OR CR
Comments to this Manuals