Figure 24. shifting of bcd digits/bytes – Zilog Z08470 User Manual

Page 40

Advertising
background image

Hardware and Software Implementation

UM008007-0715

28

Z80 CPU
User Manual

LD

HL, DATA

;ADDRESS OF FIRST BYTE

LD

B, COUNT

;SHIFT COUNT

XOR

A

;CLEAR ACCUMULATOR

ROTAT:

RLD

;ROTATE LEFT low-order DIGIT IN ACC

;WITH DIGITS IN (HL)

INC

HL

;ADVANCE MEMORY POINTER.

DJNZ

ROTAT-$

;DECREMENT B AND GO TO ROTAT IF

;B IS NOT ZERO, OTHERWISE FALL

;THROUGH

Eleven bytes are required for this operation.

Example 4

One number is to be subtracted from another number, both of which exist in packed BCD
format and are of equal but varying length. The result is stored in the location of the minu-
end. The operation is programmed as follows:

LD

HL, ARG1

;ADDRESS OF MINUEND

LD

DE, ARG2

;ADDRESS OF SUBTRAHEND

LD

B, LENGTH

;LENGTH OF TWO ARGUMENTS

AND

A

;CLEAR CARRY FLAG

SUBDEC:LD A, (DE)

;SUBTRAHEND TO ACC

Figure 24. Shifting of BCD Digits/Bytes

0

Advertising
This manual is related to the following products: