******************************************************************************* * Examples of various (inefficient) ways of determining if a * particular bit of the status register is set using various bit * operations. Recall that the lower five bits are, from highest to * lowest: X, N , Z, V, C. * * All functions (XS, NS, ZS, VS, CS) return through (d0.w) a non-zero * value if and only if the given bit was set. ******************************************************************************* START section 0 _main: * Various tests cases. Comment/uncomment to use, and add your own. * move.b #$80,d2 * jsr NS * move.b #$80,d2 * lsl.b #1,d2 * jsr XS * move.b #$10,d2 * asl.b #4,d2 * jsr VS * move.b #$80,d2 * lsl.b #1,d2 * jsr CS move.b #$70,d2 lsl.b #1,d2 jsr CS andi.l #$FFFF,d0 ; clear upper word move.l d0,d1 ; print result as long move.l #3,d0 trap #15 move.b #9,d0 ; exit trap #15 ******************************************************************************* ZS: move sr,d0 andi.w #$4,d0 ; use a mask rts ; so that (d0) is zero if and only if Z was ; not set * helper function for NS fill: tst.w d0 ; if (d0.w) = 0, return (d0.w) = 0, else beq filldone ; return (d0.w) = $FFFF move.w #-1,d0 filldone rts NS: move sr,d0 btst #3,d0 ; use btst jsr ZS ; (d0) is non-zero if and only if N was 0 jsr fill ; so complement it not.w d0 rts XS: move sr,d0 lsl.b #3,d0 ; shift so that X bit becomes left-most of byte jsr NS ; and test if the result is negative rts VS: move sr,d0 btst #1,d0 ; use btst and then branch bne VSdone clr.w d0 VSdone rts CS: move sr,d0 bset #0,d0 ; bset also has effect of btst bne CSdone clr.w d0 CSdone rts end START