Question

I wrote an answer yesterday to this: What's the coolest hack you've seen or done? and I was trying really hard to remember my 6502 assembly, and I couldn't for the life of me remember how to branch if less than...

  :1
  lda $C010
  cmp #$80
  bcc :1  ; branch if less than? I forget how to do that.
  lda $C000
  jsr $FDF0   ;output the accumulator value to the screen

Anybody know what the instruction is? BNE and BEQ are equals, BCC was for carry, and a CMP is basically an SBC and that affects the carry, but I'm not sure if it works in that case.

Was it helpful?

Solution

BCC is branch if less than; BCS is branch if greater than or equal. There's a nice tutorial here.

However stu's code can be written more concisely without CMP:

BIT $C010     ;clear the keyboard strobe
:1
LDA $C000     ;check for a keypress
BPL :1        ;taken if no keypress
JSR $FDFO     ;print the key
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top