I have this code:
jsr cls
ldx #$00 ;loads 0 into x
stx tmp ; stores x in tmp
ldx #<scr1
ldy #>scr1
printToScreen
stx zpb+0
sty zpb+1
lda (zpb),y
ldx tmp. ; loads x from tmp
beq done
sta screen_start,x
inx
stx tmp ; stores new x in tmp
bne printToScreen
done
rts
tmp = $C8
zpb = $fb
scr1 byte 'some text'
byte 0
I want to create routine which prints a string to the screen. The arguments are the address of the string and the X register, which is used as a counter. Since X is used inside the function as well I'm storing its value in the tmp variable.
But this code prints nothing. I'm totally new to assembly, so probably I don't understand how this is supposed to work. Please see code comments. What am I doing wrong here?
I would do that way. To be honest I didn't test the code I've written above. I've changed it the way I think it should be done.
Concerning your code: It is not needed to overwrite zpb and zpb+1 in every loop iteration. You forgot to set Y index register before you do "lda (zpb),y" - and probably it should be zero. After "ldx tmp" you don't compare it wth anything (should be cpx #something) so as default you compare it with zero (beq done) and cpu quits the program because X==0. So your program writes one byte somewhere in the memory and just exits.