Add failing tests for `add` and `sub` on locations other than `a`.
Chris Pressey
6 years ago
851 | 851 |
| }
|
852 | 852 |
? ForbiddenWriteError: a
|
853 | 853 |
|
|
854 |
You can `add` a byte constant to a byte memory location.
|
|
855 |
|
|
856 |
| byte lives
|
|
857 |
| define main routine
|
|
858 |
| inputs a, lives
|
|
859 |
| outputs lives
|
|
860 |
| trashes a, c, z, v, n
|
|
861 |
| {
|
|
862 |
| st off, c
|
|
863 |
| add lives, 3
|
|
864 |
| }
|
|
865 |
= ok
|
|
866 |
|
|
867 |
`add`ing a byte constant to a byte memory location trashes `a`.
|
|
868 |
|
|
869 |
| byte lives
|
|
870 |
| define main routine
|
|
871 |
| inputs a, lives
|
|
872 |
| outputs lives
|
|
873 |
| trashes c, z, v, n
|
|
874 |
| {
|
|
875 |
| st off, c
|
|
876 |
| add lives, 3
|
|
877 |
| }
|
|
878 |
? UnmeaningfulOutputError: a
|
|
879 |
|
854 | 880 |
You can `add` a word constant to a word memory location.
|
855 | 881 |
|
856 | 882 |
| word score
|
|
994 | 1020 |
| sub a, 0
|
995 | 1021 |
| }
|
996 | 1022 |
? ForbiddenWriteError: a
|
|
1023 |
|
|
1024 |
You can `sub` a byte constant from a byte memory location.
|
|
1025 |
|
|
1026 |
| byte lives
|
|
1027 |
| define main routine
|
|
1028 |
| inputs a, lives
|
|
1029 |
| outputs lives
|
|
1030 |
| trashes a, c, z, v, n
|
|
1031 |
| {
|
|
1032 |
| st on, c
|
|
1033 |
| sub lives, 3
|
|
1034 |
| }
|
|
1035 |
= ok
|
|
1036 |
|
|
1037 |
`sub`ing a byte constant from a byte memory location trashes `a`.
|
|
1038 |
|
|
1039 |
| byte lives
|
|
1040 |
| define main routine
|
|
1041 |
| inputs a, lives
|
|
1042 |
| outputs lives
|
|
1043 |
| trashes c, z, v, n
|
|
1044 |
| {
|
|
1045 |
| st on, c
|
|
1046 |
| sub lives, 3
|
|
1047 |
| }
|
|
1048 |
? UnmeaningfulOutputError: a
|
997 | 1049 |
|
998 | 1050 |
You can `sub` a word constant from a word memory location.
|
999 | 1051 |
|
1024 | 1024 |
= $0842 JMP ($0846)
|
1025 | 1025 |
= $0845 RTS
|
1026 | 1026 |
|
|
1027 |
### add, sub
|
|
1028 |
|
|
1029 |
Various modes of `add`.
|
|
1030 |
|
|
1031 |
| byte lives
|
|
1032 |
| word score
|
|
1033 |
| define main routine
|
|
1034 |
| inputs lives, score
|
|
1035 |
| outputs lives, score
|
|
1036 |
| trashes a, x, y, c, z, v, n
|
|
1037 |
| {
|
|
1038 |
| ld a, 0
|
|
1039 |
| ld x, 0
|
|
1040 |
| ld y, 0
|
|
1041 |
| st off, c
|
|
1042 |
| add a, 7
|
|
1043 |
| add a, lives
|
|
1044 |
| // add x, 7
|
|
1045 |
| // add y, 7
|
|
1046 |
| add lives, 2
|
|
1047 |
| add score, 1999
|
|
1048 |
| }
|
|
1049 |
= $080D CLC
|
|
1050 |
= $080E LDA $081F
|
|
1051 |
= $0811 ADC #$CF
|
|
1052 |
= $0813 STA $081F
|
|
1053 |
= $0816 LDA $0820
|
|
1054 |
= $0819 ADC #$07
|
|
1055 |
= $081B STA $0820
|
|
1056 |
= $081E RTS
|
|
1057 |
|
1027 | 1058 |
### word operations
|
1028 | 1059 |
|
1029 | 1060 |
Adding a constant word to a word memory location.
|