Marius Posted April 24, 2011 Share Posted April 24, 2011 There is something strange going on with the BIT instruction. I was wondering: is this instruction only giving a usable result when you check the status of one bit at the time? Please take a look at this code: On memory location $0600 I saved value #$14 (%00010100) .OR $5000 START LDA #$04 BIT $0600 BNE TRUE FALSE LDA #$00 STA COLPF2 RTS TRUE LDA #$C0 STA COLPF2 RTS OK this works great. It tests for bit 2 (#$04) and indeed this bit is SET so the screen turns green (the TRUE routine) But now the same code, except for the START line... On memory location $0600 I saved value #$14 (%00010100) .OR $5000 START LDA #$24 BIT $0600 BNE TRUE FALSE LDA #$00 STA COLPF2 RTS TRUE LDA #$C0 STA COLPF2 RTS And AGAIN the screen turns Green (the TRUE routine!) ... this is strange in my opinion since bit 5 isn't true on $0600. I thought: this should result in a black screen. This routine gives a black screen: On memory location $0600 I saved value #$14 (%00010100) .OR $5000 START LDA #$20 BIT $0600 BNE TRUE FALSE LDA #$00 STA COLPF2 RTS TRUE LDA #$C0 STA COLPF2 RTS So I only can conlude: the BIT routine is only usable for BIT checking, one bit at a time. Is this a right conclusion? thanks Marius Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted April 24, 2011 Share Posted April 24, 2011 On memory location $0600 I saved value #$14 (%00010100) .OR $5000 START LDA #$04 BIT $0600 BIT performs a logical AND between the accumulator and the memory location (as well as updating the N and V flags with bits 7 and 6 respectively from the memory location) so %00000100 AND %00010100 = %00000100 Which is a result not equal to zero. On memory location $0600 I saved value #$14 (%00010100) .OR $5000 START LDA #$24 BIT $0600 %00100100 AND %00010100 = %00000100 Which is a result not equal to zero. If you want to check multiple bits you'll have to AND #MASK and CMP #MASK unless you can get the bits of interest into bits 6 and 7. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.