Those slow ZBIT instructions

A General Discussion forum for TI calculators

Moderator: MaxCoderz Staff

Post Reply
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Those slow ZBIT instructions

Post by King Harold »

As we all know ZBIT instructions on registers take 8 T-states.
Boolean instructions with an immediate as operant take 7 T-states.
So in some cases (when working with a) you could save 1 T-state.

Code: Select all

bit n,a

Code: Select all

and %[7-n zero's]1[n zero's]
jp pe,BitReset
;when you're here the bit is Set
this code does modify the contents of A so it is mostly useless

Code: Select all

res n,a

Code: Select all

and %[7-n one's]0[n one's]

Code: Select all

set n,a

Code: Select all

or %[7-n zero's]1[n one's]
and something new, one could call it 'cbit', a pitty it doesn't exist on the z80. it would complement the n-th bit.

Code: Select all

cbit n,a

Code: Select all

xor %[7-n zero's]1[n one's]
correct me where I'm wrong :) (probably at the pe/po part..)

although most of us probably already knew this, I just thought I'd bring it up, so that those who didn't know it yet would not waste 1 T-state.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I'm not sure why you use pe; you can just use the z flag (and so also have relative jumps if need be).
You could set up a macro for these, I suppose;
(Destructive bit, fast reset, fast set).

Code: Select all

#define dbit(n)and 1<<n
#define fres(n)and ~(1<<n)
#define fset(n)or 1<<n
#define cbit(n)xor 1<<n
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

pe/po? heard of z and nz.

It depends on the situation for which to use, AND could be used in place of bit when the rest of the contents don't matter. Bit is prefered when you may need to test different bits out of order but consecutively on the same byte.


If you need to test bits in order and consecutively you could

Code: Select all

   rrca
   jp c,set0
   rrca
   jp c,set1
which is accomplishes

Code: Select all

   bit 0,a
   jp nz,set0
   bit 1,a
   jp nz,set1
or instead of

Code: Select all

   bit 7,a
   jp nz,set7
you could

Code: Select all

   or a
   jp m,set7
and if need be you could test 2 bits of a register other than a at the same time, for example

Code: Select all

   bit 7,b
   jp nz,set7
   bit 6,b
   jp nz,set6
could be

Code: Select all

   rlc b
   jp c,set7
   jp m,set6
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

That last one looks a bit scary to me, but I think I've used most others
But what's against pe/po?

btw, that 1<<n is extremely clever Ben :)
Post Reply