easy6502
easy6502 copied to clipboard
STA instruction is troubemaker
I tried the tutorial and I noted a bug with STA instruction. This is an example from tutorial (##Indexed indirect: ($c0,X)###):
Address Hexdump Dissassembly
-------------------------------
$0600 a2 01 LDX #$01
$0602 a9 05 LDA #$05
$0604 85 0a STA $0a
$0606 a9 06 LDA #$06
$0608 85 02 STA $02
$060a a0 0a LDY #$0a
$060c 8c 05 06 STY $0605
$060f a1 00 LDA ($00,X)
First run, value $05 was written to address $0001. It is a bug:
A=$0a X=$01 Y=$0a
SP=$ff PC=$0611
NV-BDIZC
00110000
0000: 00 05 06 00 00 00 00 00 00 00 00 00 00 00 00 00
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
RESET:
A=$00 X=$00 Y=$00
SP=$ff PC=$0600
NV-BDIZC
00110000
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Second run, note that value $05 is written to memory $000a: That is OK:
A=$a2 X=$01 Y=$0a
SP=$ff PC=$0611
NV-BDIZC
10110000
0000: 00 00 06 00 00 00 00 00 00 00 05 00 00 00 00 00
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
OK, maybe there is other problem, The original code is
LDX #$01
LDA #$05
STA $01
LDA #$06
STA $02
LDY #$0a
STY $0605
LDA ($00,X)
There is instruction "STY $0605" in the list, it modifies the code at address $0605, 'STA $01' is replaced with 'STA $0a'; that explains the mystery. Not good example, it is confusing...
This is better example; it doesn't modify code, but it writes data to display memory, so it is visible.
LDA #$0a
STA $0306
LDX #$01
LDA #$06
STA $01
LDA #$03
STA $02
LDA ($00,X)
I miss in the tutorial explanation of memory mapping of this "computer". It should be at the beginning of the tutorial, something like this.
$0000-$00ff: RAM, zero page
$00fe-$00fe: RAM, RND generator ?? sysRandom
$00ff-$00ff: RAM, KEYBOARD input, ASCII code ?? sysLastKey
$0100-$01ff: RAM, STACK
$0200-$05ff: RAM, video; 32x32 points; colors $00-$0f
$0600-$ffff: RAM, program; reset sets PC register to $0600.
Other important information is that this asembler is case senstive, so LOOP1 and loop1 are two different labels; when label is not defined, it is not an error but default value $ffff is used.
define agent $07
loop1:
LDA agent
LDX Agent
JMP loop1
JMP LOOP1
Address Hexdump Dissassembly
-------------------------------
$0600 a5 07 LDA $07
$0602 ae ff ff LDX $ffff
$0605 4c 00 06 JMP $0600
$0608 4c ff ff JMP $ffff
Thanks for the feedback.
That use of self-modifying code in the tutorial for indexed indirect is somewhat unexpected and not ideal. I agree that we should update the example and commentary - I'd suggest we don't index from $00 either, as that is not helping explain the effect:
LDA #$0a
STA $0306
LDX #$02
LDA #$06
STA $42
LDA #$03
STA $43
LDA ($40,X)
This mode is rarely used: the meaning is that there is an array of pointers in zero page, and we need to select our pointer using X and then use it. The commentary should say this.
You're right that case-sensitive labels could be noted somewhere. Perhaps in the messages window, when it writes 'Indexing labels ...' it could say 'Indexing labels (case-sensitive) ...'
(I'm reluctant to change it to be insensitive in case anyone already has made use of it as-is.)
There is the Notes button, to the right of Disassemble, which puts up some notes. Perhaps those notes could be placed in the messages window by default, and could include some extra info:
- the WDM opcode for console output
- the initial PC value of $0600
- the case-sensitivity of labels
Maybe it would be worth listing undefined labels too, at the end of assembly