D.
Let us assume that one number is to be subtracted from another and a) that they are both in packed
BCD format, b) that they are of equal but varying length, and c) that the result is to be stored in the
location of the minuend. The operation can be accomplished as follows:
LD
LD
LD
AND
SUBDEC:LD
SBC
DAA
LD
INC
INC
DJNZ
HL,ARGI
DE ,ARG2
B,LENGTH
A
A, (DE)
A, (HL)
(HL) ,
A
HL
DE
SUBDEC - $
; ADDRESS OF MINUEND
; ADDRESS OF SUBTRAHEND
; LENGTH OF TWO ARGUMENTS
; CLEAR CARRY FLAG
; SUBTRAHEND TO ACC
; SUBTRACT (HL) FROM ACC
; ADJUST RESULT TO DECIMAL CODED VALUE
; STORE RESULT
; ADVANCE MEMORY POINTERS
; DECREMENT B AND GO TO "SUBDEC" IF B
; NOT ZERO, OTHERWISE FALL THROUGH
17 bytes are required for this operation.
10.4 EXAMPLES OF PROGRAMMING TASKS
A.
The following program sorts an array of numbers each in the range (0,255) into ascending order using
a standard exchange sorting algorithm.
66
Need help?
Do you have a question about the Z80-CPU and is the answer not in the manual?
Questions and answers