Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STA instruction is troubemaker #35

Open
PSLLSP opened this issue Apr 22, 2018 · 3 comments
Open

STA instruction is troubemaker #35

PSLLSP opened this issue Apr 22, 2018 · 3 comments

Comments

@PSLLSP
Copy link

PSLLSP commented Apr 22, 2018

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 
@PSLLSP
Copy link
Author

PSLLSP commented Apr 22, 2018

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...

@PSLLSP
Copy link
Author

PSLLSP commented Apr 22, 2018

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

@BigEd
Copy link
Collaborator

BigEd commented Apr 26, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants