Download Print this page

ZiLOG Z80 Handbook page 224

Hide thumbs Also See for Z80:

Advertisement

LD
A,(OPERA) OPERAND A
LD
B,(OPERB)
OPERAND B
CALL
CMPARE
A:B
JR
LTHAN
RETURN HERE IF A < B
JR
EQUAL
RETURN HERE IF A = B
JR
GTHAN
RETURN HERE IF A > B
As in some high-level languages, the missing equalities of A<=B
and A>=B may be constructed by proper use of the return points,
such as this sequence that returns to location LTEQL if A<=B and
to GTTHAN if A>B.
LD
A,(OPERA) OPERAND A
LD
B,(OPERB)
OPERAND B
CALL
CMPARE
A:B
JR
LTEQL
A < B RTN
JR
LTEQL
A = B RTN
JR
GTHAN
A > B RTN
The actual code within the subroutine would be an expansion of
that in Chapter 11.
CMPARE
CP
B.
A:B
EX
(SP),HL
GET RETURN
JR
Z,EQUAL
GO IF A = B
PUSH
AF
SAVE A, FLAGS
XOR
B
JP
P,SAME
GO IF SIGNS EQUAL
POP
AF
RESTORE A, FLAGS
TEST
JP
C,LESST
A < B
JP
GREAT
A > B
SAME
POP
AF
CCF
JP
TEST
GREAT
INC
HL
BUMP TO CALL + 4
INC
HL
EQUAL
INC
HL
BUMP TO CALL + 2
INC
HL
LESST
EX
(SP),HL
RESTORE RTN
RET
RETURN
The comparison is made after first retrieving the return address
from the stack (stack pointer remains unaffected). The return ad-
dress is then incremented to a return point to +2 or +4 bytes past
the return location stored by the call to reflect the return on <,
or >.
233

Advertisement

loading
Need help?

Need help?

Do you have a question about the Z80 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel