Jump to content
IGNORED

6502 BIT instruction confusing


Recommended Posts

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

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...