<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 14 May 1990 09:09:41 GMT
From   : mcsun!unido!gmdzi!wittig@uunet.uu.net (Georg Wittig)
Subject: a<b on Z80

How to write a signed compare of two 16 bit integers in Z80 assembler? The
obvious solution doesn't work:

       LD      HL,a
       LD      DE,b
       AND     A       ; reset carry flag
       SBC     HL,DE
       JP      P,IS_GREATER_OR_EQUAL
IS_LESS:...

For example, let a=8000h, and b=1. The program should not JP in this case.

The only compact and correct solution I could find was the following one:

       LD      HL,a
       LD      DE,b
       AND     A
       SBC     HL,DE
       JP      PO,LABEL
       JP      P,IS_LESS
       JP      IS_GREATER_OR_EQUAL
LABEL: JP      P,IS_GREATER_OR_EQUAL
IS_LESS:...

But this one looks very ugly to me. Does someone know of a shorter and/or
faster solution?
-- 
Georg Wittig  GMD-Z1.IT        | email: wittig@gmdzi.gmd.de    | "Freedom's just
P.O. Box 1240          |        wittig@zi.gmd.dbp.de   |  another word for
D-5205 St. Augustin 1  |                               |  nothing left to lose"
       West Germany    | phone: (+49) 2241 14-2294     | (Kris Kristofferson)

<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>