![background image](http://html2.mh-extra.com/html/rabbit/2000/2000_user-manual_3110256039.webp)
User’s Manual
33
Some simplifications are possible if one of the unsigned numbers being compared is a
constant. Note that the carry has a reverse sense from
SBC
. In the following examples, the
pseudo-code in the form
LD DE,(65535-B)
does not indicate a load of
DE
with the
address pointed to by
65535-B
, but simply indicates the difference between 65535 and
the 16-bit unsigned integer
B
.
;test for HL>B B is constant
LD DE,(65535-B)
ADD HL,DE ; carry set if HL>B
SBC HL,HL ; HL-HL-C - result -1 if carry set, else zero
BOOL HL ; 14 total clocks - true if HL>B
; HL>=B B is constant not zero
LD DE,(65536-B)
ADD HL,DE
SBC HL,HL
BOOL HL
; 14 clocks
; HL>=B and B is zero
LD HL,1
; 6 clocks
; HL<B B is a constant, not zero (if B==0 always false)
LD DE,(65536-B)
ADD HL,DE ; not carry if HL<B
SBC HL,HL ; -1 if carry, else 0
INC HL ; 14 clocks --0 if carry, else 1 if no carry
;
; HL <= B B is constant not zero
LD DE,(65535-B)
ADD HL,DE ; ~C if HL<=B
CCF ; C if true
SBC HL,HL ; if C -1 else 0
INC HL ; 16 clocks -- 1 if true, else 0
;
; HL <= B B is zero - true if HL==0
BOOL HL
; result in HL
;
; HL==B and B is a constant not zero
LD DE,(65536-B)
ADD HL,DE ; zero if equal
BOOL HL
INC HL
RES 1,l ; 16 clocks
; HL==B and B==0
BOOL HL
INC HL
RES 1,l ; 8 clocks
For signed integers the conventional method to look at the zero flag, the minus flag and
the overflow flag. Signed 8-bit integers span the range –128 to +127 (0x80 to 0x7F).
Signed 16-bit integers span the range –32768 to + 32767 (0x8000 to 0x7FFF). The sign
and zero flag tell which is the larger number after the subtraction unless the overflow is
set, in which case the sign flag needs to be inverted in the logic, that is, it is wrong.
Summary of Contents for 2000
Page 1: ...Rabbit 2000 Microprocessor User s Manual 019 0069 041018 M...
Page 12: ...6 Rabbit 2000 Microprocessor...
Page 46: ...40 Rabbit 2000 Microprocessor...
Page 54: ...48 Rabbit 2000 Microprocessor...
Page 76: ...70 Rabbit 2000 Microprocessor...
Page 96: ...90 Rabbit 2000 Microprocessor...
Page 142: ...136 Rabbit 2000 Microprocessor...
Page 154: ...148 Rabbit 2000 Microprocessor...
Page 170: ...164 Rabbit 2000 Microprocessor...
Page 174: ...168 Rabbit 2000 Microprocessor...
Page 180: ...174 Rabbit 2000 Microprocessor...
Page 202: ...196 Rabbit 2000 Microprocessor...
Page 206: ...200 Rabbit 2000 Microprocessor...
Page 226: ......
Page 230: ...224 Rabbit 2000 Microprocessor...