Since tokumaru posted that link to the 6502 Simulator, I've been able to actually try some of this basic stuff that I've been reading.... and I mean VERY basic. I'm pretty much just trying to learn my way around the 6502 right now. Something that bugs me is the concept of subroutines. I've been thinking of them in terms of functions, but I'm not sure if that's the correct way to think of them. I thought maybe it was something you could call on when needed. Anyway, I've been fiddling with the simulator, and did this (this isn't supposed to make sense):
When I look at the Command Log, it shows that after jumping back from the subroutine, that it loads the #$50 into X, then it runs through the subroutine again. I'm not sure how I would get it to skip over the subroutine, or if I should be housing it somewhere else in the code so it won't read unless called upon...
Also, in my book it says something about the stack is used by subroutines... but I can't understand what it means. When I look at the Register window in the simulator, the stack is filled with 00 all across the board. Any tips would be appreciated.
Code:
.ORG $8000
LDX #$40
STX $01
LDA #$30
STA $02
LDY #$20
STY $03
JSR testit
LDX #$50
testit:
CLC
CLD
LDA $02
ADC $03
STA $04
RTS
LDX #$40
STX $01
LDA #$30
STA $02
LDY #$20
STY $03
JSR testit
LDX #$50
testit:
CLC
CLD
LDA $02
ADC $03
STA $04
RTS
When I look at the Command Log, it shows that after jumping back from the subroutine, that it loads the #$50 into X, then it runs through the subroutine again. I'm not sure how I would get it to skip over the subroutine, or if I should be housing it somewhere else in the code so it won't read unless called upon...
Also, in my book it says something about the stack is used by subroutines... but I can't understand what it means. When I look at the Register window in the simulator, the stack is filled with 00 all across the board. Any tips would be appreciated.