Assembly Motorola 68k, how to branch if a tested bit is zero?
Question
I am writing a program in assembly using easy68k, I was looking for a way to make a branch if a tested bit is equal to zero [Z=0 in SR].
I searched a lot but didn't get an answer,
for example, I have this line:
BTST #0,D2 ;Testing the LSB bit in data register 0
Now I want a way, or if there exists, an instruction to check Z in the SR, so I can know if the tested bit is zero or not.
Solution
The instruction to test condition codes and branch based on them is generically referred to as Bcc
. The individual names for these conditional branch instructions are based on what they would mean if the immediately preceding instruction was CMP
.
But, by themselves, all they do is test a condition code and take the branch. So, you can do:
BTST #0,D2 ;Testing the LSB bit in data register 0
BEQ LabelForZSet
;Code for Z clear
OTHER TIPS
Branch on Z-Flag:
btst #0,d2
beq bitIsCleared
; or
bne bitIsSet
Z-Flag to register:
btst #0,d2
sne d0
; d0 (byte only) will now be 0xFF if bit was set, 0x00 otherwise)
; if a word is required add ext.w d0
; if a long is required add also ext.l d0