Question

I'm doing it again but I'm close this time. Working with a 6502 chip.

I am writing a program of an assembly print buffer.

The one problem I'm having is checking if the string is null.

Here is my code so far: (human readable)

buffer = $03ff
x = $01

[START]: $0500

    LDX buffer      // load buffer (at safe memory address $03ff)
    LDY #$00        // loading the y register with 0 so that you can count up
                // checking for a null string; if null, branch to the break instruction
LOOP:   LDA buffer+1, y     // get byte using the buffer
    STA (x), y  // store the value at the pointer
    INY         // increment y
    DEX         // decrement x (counting down with the x register)
    BEQ $500?       // if x is equal to 0, program is done
    BNE LOOP:       // if x is not equal to 0, keep going
    BRK             // if brk, it’s null

How would I go about checking if the string is null?

Thanks!

Was it helpful?

Solution

Probably just do an explicit test for zero first:

[START]: $0500

    LDY #$00
    LDX buffer

    BEQ ENDOFLOOP

LOOP:  
    LDA buffer+1, y
    STA (x), y
    INY
    DEX

    BNE LOOP

ENDOFLOOP:
    BRK

LDX sets the zero flag so there's no need to do anything to X before the test.

OTHER TIPS

I'd just move the comparison to the front...

    ...
    LDY #$00
LOOP:
    LDA buffer+1, y
    BEQ ENDOFLOOP:
    STA (x), y
    INY
    DEX
    JMP LOOP:
ENDOFLOOP:
    ...

My 6502 is really rusty, but you get the idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top