Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Xeda112358 on January 15, 2012, 09:51:37 pm
-
I want to compare bit 5 to bit 1 and bit 4 to bit 0 in the A register (the other bits are always 0). in other words, I want to xor the two nibbles of A or something similar, but as fast as possible. To start, here is one idea:
ld c,a
and $F0
sla c
sla c
sla c
sla c
xor c
That is 47 cycles, 12 bytes-- too big/slow/inelegant for me to accept as the best method.
-
I don't quite understand how XORing will help you compare, but here's one (8 bytes, 31 cycles)
ld c, a
rrca
rrca
rrca
rrca
xor c
and $F0
-
Thanks! I still wonder if there is some crazy method available, but that is a lot better!
I just want to check if they are the same or not. If not, the XOR (or in your case, the AND) will return nz whereas if they are the same, it will return z.
-
So you want to know if bits 5, 4, 1 and 0 are all alike?
-
I just want to know if bit 5 == bit 1 and bit 4 == bit 0.
-
and $00110011
jp po,bits_different
and $00010001
jp po,bits_different
If the other bits are already 0, you can go with this:
or a
jp po,bits_different
and $00010001
jp po,bits_different
-
For the second one, the OR A would not recognise if a was %00110000, right? But the first one looks a lot more beautiful, thanks!
-
For the second one, the OR A would not recognise if a was %00110000, right? But the first one looks a lot more beautiful, thanks!
The parity flag would be the same either way because it is based on the final result in A. That would indeed return PE, and go through to the second case where it returns PO.
-
oh, right XD Thanks much, this is very nice!
-
Hmm, and I guess Hot_Dog's method could be slightly improved by doing this (mainly a size optimization over mine because mine has an "early out")
ld c, a
rrca
rrca
rrca
rrca
xor c
jr nz,bits_different
-
So that is slightly slower, but I see how that works! These are great, thanks much, guys!