git @ Cat's Eye Technologies SixtyPical / 5f535c9
Subtract word (constant or memory location) from word memory location. Chris Pressey 3 years ago
5 changed file(s) with 124 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
88 in a `copy` to a vector is a routine that is defined further down in the source.
99 * Initialized `word` memory locations.
1010 * Can `copy` a literal word to a word table.
11 * Subtract word (constant or memory location) from word memory location.
1112 * Fixed bug which was preventing `if` branches to diverge in what they initialized,
1213 if it was already initialized when going into the `if`.
1314 * Fixed a bug which was making it crash when trying to analyze `repeat forever` loops.
272272 else:
273273 self.assert_type(TYPE_WORD, dest)
274274 elif opcode == 'sub':
275 self.assert_type(TYPE_BYTE, src, dest)
276275 context.assert_meaningful(src, dest, FLAG_C)
277 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
276 if src.type == TYPE_BYTE:
277 self.assert_type(TYPE_BYTE, src, dest)
278 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
279 else:
280 self.assert_type(TYPE_WORD, src, dest)
281 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
282 context.set_touched(REG_A)
283 context.set_unmeaningful(REG_A)
278284 elif opcode in ('inc', 'dec'):
279285 self.assert_type(TYPE_BYTE, dest)
280286 context.assert_meaningful(dest)
229229 self.emitter.emit(SBC(Immediate(Byte(src.value))))
230230 else:
231231 self.emitter.emit(SBC(Absolute(self.labels[src.name])))
232 elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and dest.type == TYPE_WORD:
233 if isinstance(src, ConstantRef):
234 dest_label = self.labels[dest.name]
235 self.emitter.emit(LDA(Absolute(dest_label)))
236 self.emitter.emit(SBC(Immediate(Byte(src.low_byte()))))
237 self.emitter.emit(STA(Absolute(dest_label)))
238 self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
239 self.emitter.emit(SBC(Immediate(Byte(src.high_byte()))))
240 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
241 elif isinstance(src, LocationRef):
242 src_label = self.labels[src.name]
243 dest_label = self.labels[dest.name]
244 self.emitter.emit(LDA(Absolute(dest_label)))
245 self.emitter.emit(SBC(Absolute(src_label)))
246 self.emitter.emit(STA(Absolute(dest_label)))
247 self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
248 self.emitter.emit(SBC(Absolute(Offset(src_label, 1))))
249 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
250 else:
251 raise UnsupportedOpcodeError(instr)
232252 else:
233253 raise UnsupportedOpcodeError(instr)
234254 elif opcode == 'inc':
589589 | {
590590 | st off, c
591591 | sub a, 0
592 | }
593 ? ForbiddenWriteError: a in main
594
595 You can `sub` a word constant from a word memory location.
596
597 | word score
598 | routine main
599 | inputs a, score
600 | outputs score
601 | trashes a, c, z, v, n
602 | {
603 | st on, c
604 | sub score, 1999
605 | }
606 = ok
607
608 `sub`ing a word constant from a word memory location trashes `a`.
609
610 | word score
611 | routine main
612 | inputs a, score
613 | outputs score, a
614 | trashes c, z, v, n
615 | {
616 | st on, c
617 | sub score, 1999
618 | }
619 ? UnmeaningfulOutputError: a in main
620
621 You can `sub` a word memory location from another word memory location.
622
623 | word score
624 | word delta
625 | routine main
626 | inputs score, delta
627 | outputs score
628 | trashes a, c, z, v, n
629 | {
630 | st off, c
631 | sub score, delta
632 | }
633 = ok
634
635 `sub`ing a word memory location from a word memory location trashes `a`.
636
637 | word score
638 | word delta
639 | routine main
640 | inputs score, delta
641 | outputs score
642 | trashes c, z, v, n
643 | {
644 | st off, c
645 | sub score, delta
592646 | }
593647 ? ForbiddenWriteError: a in main
594648
894894 = $081D STA $0822
895895 = $0820 RTS
896896
897 Subtracting a constant word from a word memory location.
898
899 | word score
900 | routine main
901 | inputs score
902 | outputs score
903 | trashes a, c, z, v, n
904 | {
905 | st on, c
906 | sub score, 1999
907 | }
908 = $080D SEC
909 = $080E LDA $081F
910 = $0811 SBC #$CF
911 = $0813 STA $081F
912 = $0816 LDA $0820
913 = $0819 SBC #$07
914 = $081B STA $0820
915 = $081E RTS
916
917 Subtracting a word memory location from another word memory location.
918
919 | word score
920 | word delta
921 | routine main
922 | inputs score, delta
923 | outputs score
924 | trashes a, c, z, v, n
925 | {
926 | st on, c
927 | sub score, delta
928 | }
929 = $080D SEC
930 = $080E LDA $0821
931 = $0811 SBC $0823
932 = $0814 STA $0821
933 = $0817 LDA $0822
934 = $081A SBC $0824
935 = $081D STA $0822
936 = $0820 RTS
937
897938 ### Buffers and Pointers
898939
899940 Load address into pointer.