ZiLOG Z80-CPU Technical Manual page 71

Table of Contents

Advertisement

B.
Let's assume that a string in memory starting at location "DATA" is to be moved into another area
of memory starting at location "BUFFER" until an ASCII $ character (used as string delimiter) is
found. Let's also assume that the maximum string length is 132 characters. The operation can be
performed as follows:
.
LD
LD
LD
LD
LOOP:CP
JR
LDI
JP
END:
HL,DATA
DE ,BUFFER
BC , 132
A,'$'
(HL)
Z ,END-$
PE ,LOOP
; STARTING ADDRESS OF DATA STRING
; STARTING ADDRESS OF TARGET BUFFER
; MAXIMUM STRING LENGTH
; STRING DELIMITER CODE
; COMPARE MEMORY CONTENTS WITH DELIMITER
; GO TO END IF CHARACTERS EQUAL
; MOVE CHARACTER (HL) to (DE)
; INCREMENT HL AND DE, DECREMENT BC
; GO TO "LOOP" IF MORE CHARACTERS
; OTHERWISE, FALL THROUGH
; NOTE: P/V FLAG IS USED
; TO INDICATE THAT REGISTER BC WAS
; DECREMENTED TO ZERO.
19 bytes are required for this operation.
C.
Let us assume that a 16-digit decimal number represented in packed BCD format (two BCD digits/
byte) has to be shifted as shown in the Figure 10.2 in order to mechanize BCD multiplication or
division. The operation can be accomplished as follows:
LD
LD
XOR
ROTAT:RLD
INC
DJNZ
HL,DATA
B,COUNT
A
HL
ROTAT - $
; ADDRESS OF FIRST BYTE
; SHIFT COUNT
; CLEAR ACCUMULATOR
; ROTATE LEFT LOW ORDER DIGIT IN ACC
; WITH DIGITS IN (HL)
; ADVANCE MEMORY POINTER
; DECREMENT B AND GO TO ROTAT IF
; B IS NOT ZERO, OTHERWISE FALL THROUGH
11 bytes are required for this operation.
4 - - - , , - - - 0
FIGURE 10.2
65

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Z80-CPU and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Z80a-cpu

Table of Contents