I thought following yesterday's post you might want to see what exclusive or on a TMS1000 is like. This is it :)
(It isn't the most incomprehensible thing I've ever written. That goes to my multi-way scrolling and sprite engine for the TI83 calculator - about half the code was self modifying just to make it run fast enough)
ExclusiveOr:
tcy XORResult ; clear XOR Result
tcmiy 0
tcy XORCounter ; set counter to 4
tcmiy 4
ExclusiveOrLoop:
tcy XORResult ; shift the result one bit left.
tma
amaac
tam ; store it back.
tcy XORNibble1 ; read Nibble 1
tma
tcy XORNibble2 ; point at Nibble 2
tbit1 3 ; if bit 3 of Nibble 2 is set
br XOBit3Set ; add 8 to A, eg xor of MSB of Nibble
br XOBit3Unchanged ; because add = exor with no carry in
XOBit3Set: ; no carry in is why we cant just add
a8aac
XOBit3Unchanged: ; bit 3 of A is XOR bit 3 of N1,N2.
alec 7 ; if it is set, set LSB of result
br XONextBit
tcy XORResult ; this bit will be shifted into place
sbit 0
XONextBit:
tcy XORNibble1 ; shift nibble 1 left
tma
amaac
tam
tcy XORNibble2 ; shift nibble 2 left
tma
amaac
tam
tcy XORCounter ; Decrement XOR Counter
dman
tam ; write back
mnez ; check counter not zero
br ExclusiveOrLoop ; and keep going till all four bits.
tcy XORResult ; Load the result into A
tma
retn
No comments:
Post a Comment