0

Just learning the whole process of storing data, I am a complete newbie to low-level programming so please be gentle. But why is this simple code not working, so far it is only populating the 00 byte at $1000 address with my simple preset test digit of #08, I thought by looping like this I would see the first 8 bytes containing 08 each in the debugger at the $1000 address, but noooo. I thought using TXA (transfer x to the accumulator) and TAX (transfer accumulator to X) would do it as CMP and BNE only work off of the accumulator, but noooooo. Very frustrating. Any help will be met with massive gratitude and smiles...

        ldx #00
loader  lda #$08
        sta $1000,x
        inx
        txa
        cmp #08
        bne exit
        tax
        jmp loader

exit    jsr*
Smokeyparkin
  • 103
  • 6
  • 1
    I think `bne exit` jumps to exit on the very first iteration, but the `$1000` address should contain the one `$08` after it. – Roman Hocke Jul 03 '21 at 16:29
  • It shouldn't be jumping because i am linking it with the CMP, right? I thought CMP and BNE combined created the condition for branching? The CMP stops it being zero as the condition. – Smokeyparkin Jul 03 '21 at 16:53
  • 2
    Aside: don't overlook that `cpx` is available on 6502, and note that you didn't need to `tax` the value back again anyway - it remained in the `x` register. – Weather Vane Jul 03 '21 at 19:26
  • 2
    The last 5 instructions of your loop could be replaced by `cpx #8`, `bne loader` – Michael Jul 03 '21 at 21:34

1 Answers1

2

Solved! I simply had to change BNE to BEQ!

Smokeyparkin
  • 103
  • 6
  • 2
    Step tracing your code with a debugger is a great way to diagnose something like this. I like to use the monitor in [vice](https://vice-emu.sourceforge.io/). – larsks Jul 03 '21 at 17:01