ILLUSTRATIVE PROGRAM 3: BLOCK TRANSFER OF DATA BYTES USING Z80 SPECIAL INSTRUCTIONS

ILLUSTRATIVE PROGRAM 3: BLOCK TRANSFER OF DATA BYTES USING Z80 SPECIAL INSTRUCTIONS

 

nn

This program transfers data from one memory block to another using the Z80 instruction LDIR.

Problem Statement

Modify the illustrative program (Section 8.6.3) using the instruction LDIR with the problem statement as follows: Transfer 1024 (1K) bytes from the memory block SOURCE (0000H) to the memory block OUTBUF (1900H), and indicate the end of data transfer by displaying 01 at PORT0.

Problem Analysis

To use the instruction LDIR, the HL register should be used to point to memory SOURCE and the DE register to the destination OUTBUF, and the register BC should be used as the counter with the 16-bit count (03FFH = 1024 bytes).

Program

Label

Mnemonics

Comments

START:

LD HL, SOURCE

;Set up HL as pointer for SOURCE memory

LD DE, OUTBUF

;Set up DE as pointer for OUTBUF memory

LDBC, 03FFH

;Specify the number of bytes in BC

LDIR

;Transfer data byte from SOURCE to OUT-

; BUF and repeat until BC = 0

LDA, OIH

;Load display indicator

OUT (PORTO), A

;Display end of data transfer

HALT

;End of program

Program Description

In this program, the instruction LDIR is the workhorse: it replaces several in­structions from the illustrative program in Section The instruction performs three operations: (1) copies a data byte from the memory location shown by the HL register into the memory location indicated by the DE register, (2) updates memory pointers (HL and DE) and the counter (BC), and (3) makes the decision· to repeat or terminate the loop based on the count in the BC register. When all 1024 (1K) bytes are copied into new locations, the counter BC becomes· zero, and the program goes on to display 01 at PORT0

Leave a comment

Your email address will not be published. Required fields are marked *