Z80 SPECIAL INSTRUCTIONS

Z80 SPECIAL INSTRUCTIONS

tt

The Z80 instruction set includes some instructions that perform more than one task. These instructions improve programming efficiency considerably. Some of these instructions are:

Mnemonics

Description

DJNZ d

Decrement B and Jump Relative on no zero (Z = 0)

The instruction decrements register B, and if B # 0, it jumps to the memory address specified by the offset value d.

LDI

Load and Increment

The instruction copies a data byte from the memory location shown by HL into the memory location indicated by DE_. Reg­isters HL and DE are incremented. and BC is decrement

LDIR

Load, Increment, and Repeat

This is similar to the instruction LDI, except that it is repeated until BC= 0.

LDD

Load and Decrement

The instruction copies a data byte from the memory location shown by HL into the memory location pointed to by DE. Registers HL, DE, and BC are decremented.

LDDR

Load, Decrement; and Repeat

This instruction is similar to LDD, except that it is repeated until BC= 0

Example

Modify the illustrative program Addition with Carry (Section 8. 7) using the in­struction DJNZ and the offset value.

Solution

The following mnemonics are repeated from a segment of the program in Figure; we assume that the segment is stored in memory locations starting from l808H.

Location

Label

Mnemonics

Comments

1808

NXTBYT:

LD D, (HL)

;Get data byte from input buffer

1809

ADDA,D

;Add data byte

180A

JP NC, SKIPCY

;If no carry, do not save CY

180D

INCC

;Save carry bit

180E

SKIPCY:

INC HL

;Point to next memory location

180F

DJNZ F7H

;Decrement counter B, and if B # 0, jump to location 1008 to get the next byte

Program Description and Calculation of the Offset Value In this program, the instruction DJNZ replaces two instructions-DEC B and JP NZ, NXTBYT-from the program in Figure 8.10. The instruction DJNZ assumes that register B is used as a counter. When the Z80 executes the 2-byte instruction DJNZ, the program counter holds the address 1811H. This is a backward jump; therefore, the offset value must be in 2’s complement. The offset value for the jump location NXTBYT (1808H) is obtained as follows:

Program Counter:

1 8

11

Jump Location:

I 8

08

09H

F7H

(0 0 0 0 1 0 0 1)

2’s Complement of 09H

(1111 0 111)

for backward jump:

Leave a comment

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