Zilog Z08470 Bedienungsanleitung Seite 39

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 326
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 38
UM008007-0715 Specific Z80 Instruction Examples
Z80 CPU
User Manual
27
Specific Z80 Instruction Examples
Example 1
When a 737-byte data string in memory location DATA must be moved to location BUF-
FER, the operation is programmed as follows:
LD HL, DATA ;START ADDRESS OF DATA STRING
LD DE, BUFFER ;START ADDRESS OF TARGET BUFFER
LD BC, 737 ;LENGTH OF DATA STRING
LDIR ;MOVE STRING–TRANSFER MEMORY POINTED
;TO BY HL INTO MEMORY LOCATION POINTED
;TO BY DE INCREMENT HL AND DE,
;DECREMENT BC PROCESS UNTIL BC = 0
Eleven bytes are required for this operation and each byte of data is moved in 21 clock
cycles.
Example 2
A string in memory (limited to a maximum length of 132 characters) starting at location
DATA is to be moved to another memory location starting at location BUFFER until an
ASCII $ (used as a string delimiter) is found. This operation is performed as follows:
LD HL, DATA ;STARTING ADDRESS OF DATA STRING
LD DE, BUFFER ;STARTING ADDRESS OF TARGET BUFFER
LD BC, 132 ;MAXIMUM STRING LENGTH
LD A, '$' ;STRING DELIMITER CODE
LOOP: CP (HL) ;COMPARE MEMORY CONTENTS WITH
;DELIMITER
JR Z, END-$ ;GO TO END IF CHARACTERS EQUAL
LDI ;MOVE CHARACTER (HL) to (DE)
;INCREMENT HL AND DE, DECREMENT BC
JP PE, LOOP ;GO TO
LOOP IF MORE CHARACTERS
END: ;OTHERWISE, FALL THROUGH
;NOTE: P/V FLAG IS USED
;TO INDICATE THAT REGISTER BC WAS
;DECREMENTED TO ZERO
Nineteen bytes are required for this operation.
Example 3
A 16-digit decimal number is shifted as depicted in Figure 24. This shift is performed to
mechanize BCD multiplication or division. The 16-digit decimal number is represented in
packed BCD format (two BCD digits/byte) The operation is programmed as follows:
Seitenansicht 38
1 2 ... 34 35 36 37 38 39 40 41 42 43 44 ... 325 326

Kommentare zu diesen Handbüchern

Keine Kommentare