2014-04-04 12:06:12 +00:00
|
|
|
Anayzling SixtyPical Programs
|
|
|
|
=============================
|
|
|
|
|
|
|
|
-> Tests for functionality "Analyze SixtyPical program"
|
|
|
|
|
|
|
|
-> Functionality "Analyze SixtyPical program" is implemented by
|
|
|
|
-> shell command "bin/sixtypical analyze %(test-file)"
|
|
|
|
|
2014-04-04 13:22:19 +00:00
|
|
|
Analysis determines what storage locations have been modified by a
|
|
|
|
routine.
|
|
|
|
|
|
|
|
| reserve byte score
|
|
|
|
| routine main {
|
|
|
|
| lda #4
|
|
|
|
| sta score
|
|
|
|
| }
|
2014-04-04 14:05:58 +00:00
|
|
|
= main ([])
|
2014-04-04 13:22:19 +00:00
|
|
|
= A: UpdatedWith (Immediate 4)
|
|
|
|
= NamedLocation (Just Byte) "score": UpdatedWith A
|
|
|
|
|
2014-04-04 12:06:12 +00:00
|
|
|
A routine cannot expect registers which a called routine does not
|
|
|
|
preserve, to be preserved.
|
|
|
|
|
|
|
|
| assign byte border_colour 4000
|
|
|
|
| reserve byte score
|
|
|
|
| routine update_score
|
|
|
|
| {
|
|
|
|
| lda #8
|
|
|
|
| sta score
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| lda #4
|
|
|
|
| jsr update_score
|
|
|
|
| sta border_colour
|
|
|
|
| }
|
2014-04-04 13:22:19 +00:00
|
|
|
? routine does not preserve 'A'
|
2014-04-04 12:06:12 +00:00
|
|
|
|
|
|
|
But if it does it can.
|
|
|
|
|
|
|
|
| assign byte border_colour 4000
|
|
|
|
| reserve byte score
|
|
|
|
| routine update_score
|
|
|
|
| {
|
|
|
|
| ldx score
|
|
|
|
| inx
|
|
|
|
| stx score
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| lda #4
|
|
|
|
| jsr update_score
|
|
|
|
| sta border_colour
|
|
|
|
| }
|
2014-04-04 14:05:58 +00:00
|
|
|
= main ([])
|
2014-04-04 13:22:19 +00:00
|
|
|
= A: UpdatedWith (Immediate 4)
|
|
|
|
= X: PoisonedWith (Immediate 1)
|
|
|
|
= NamedLocation (Just Byte) "border_colour": UpdatedWith A
|
|
|
|
= NamedLocation (Just Byte) "score": PoisonedWith X
|
|
|
|
=
|
2014-04-04 14:05:58 +00:00
|
|
|
= update_score ([])
|
2014-04-04 13:22:19 +00:00
|
|
|
= X: UpdatedWith (Immediate 1)
|
|
|
|
= NamedLocation (Just Byte) "score": UpdatedWith X
|
2014-04-04 13:52:14 +00:00
|
|
|
|
|
|
|
We can't expect to stay named variables to stay unmodified either.
|
|
|
|
|
|
|
|
| assign byte border_colour 4000
|
|
|
|
| reserve byte score
|
|
|
|
| routine update_score
|
|
|
|
| {
|
|
|
|
| lda #8
|
|
|
|
| sta score
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| jsr update_score
|
|
|
|
| ldx score
|
|
|
|
| }
|
|
|
|
? routine does not preserve 'NamedLocation (Just Byte) "score"'
|
|
|
|
|
|
|
|
What the solution to the above is to notate `update_score` as intentionally
|
|
|
|
modifying score, as an "output" of the routine.
|
|
|
|
|
|
|
|
| assign byte border_colour 4000
|
|
|
|
| reserve byte score
|
|
|
|
| routine update_score outputs (score)
|
|
|
|
| {
|
|
|
|
| lda #8
|
|
|
|
| sta score
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| ldx score
|
|
|
|
| jsr update_score
|
|
|
|
| ldx score
|
|
|
|
| }
|
2014-04-04 14:05:58 +00:00
|
|
|
= main ([])
|
|
|
|
= A: PoisonedWith (Immediate 8)
|
|
|
|
= X: UpdatedWith (NamedLocation (Just Byte) "score")
|
|
|
|
= NamedLocation (Just Byte) "score": UpdatedWith A
|
2014-04-04 13:52:14 +00:00
|
|
|
=
|
2014-04-04 14:05:58 +00:00
|
|
|
= update_score ([NamedLocation Nothing "score"])
|
|
|
|
= A: UpdatedWith (Immediate 8)
|
|
|
|
= NamedLocation (Just Byte) "score": UpdatedWith A
|