[A86] Re: cp 16bit


[Prev][Next][Index][Thread]

[A86] Re: cp 16bit



In a message dated 6/7/2001 3:46:20 PM Eastern Daylight Time, Rgdtad@aol.com 
writes:


> How can I tell if a 16 bit register is zero?  I am trying to go through a 
> loop 4096 times, and I can't figure out how to do this.  

There are a number of ways to do this, depending on which registers you can 
afford to modify.  The easiest way I can think of:

 ld bc,4096
loop:
 ;... other code
 cpi    ;dec bc and set parity odd if bc = 0
 jp pe,loop   ;repeat 4096 times

The cpi command increments hl every loop, so if you can't afford to modify hl 
then then you can use the following, a more generic routine that doesn't 
require bc as the counter:

 ld de,4096
loop:
 ;... code
 dec de
 ld a,d
 or e         ;bitwise or d with e
 jr nz,loop   ;repeate 4096 times

This would work with hl, de, or bc.


----
Jonah Cohen
<ComAsYuAre@aol.com>
http://jonah.ticalc.org