git @ Cat's Eye Technologies SixtyPical / 97d0063
Initial work on adding 16-bit constants to a 16-bit location. Chris Pressey 3 years ago
2 changed file(s) with 51 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11
22 from sixtypical.ast import Program, Routine, Block, Instr
33 from sixtypical.model import (
4 TYPE_BYTE, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType,
4 TYPE_BYTE, TYPE_WORD, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType,
55 ConstantRef, LocationRef, IndirectRef, AddressRef,
66 REG_A, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
77 )
232232 )
233233 context.assert_meaningful(src)
234234 context.set_written(dest)
235 elif opcode in ('add', 'sub'):
235 elif opcode == 'add':
236 if src.type == TYPE_BYTE:
237 self.assert_type(TYPE_BYTE, src, dest)
238 context.assert_meaningful(src, dest, FLAG_C)
239 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
240 else:
241 self.assert_type(TYPE_WORD, src, dest)
242 context.assert_meaningful(src, dest, FLAG_C)
243 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
244 context.set_unmeaningful(REG_A)
245 elif opcode == 'sub':
236246 self.assert_type(TYPE_BYTE, src, dest)
237247 context.assert_meaningful(src, dest, FLAG_C)
238248 context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V)
371371 | add a, 0
372372 | }
373373 ? ForbiddenWriteError: a in main
374
375 You can `add` a word constant to a word memory location.
376
377 | word score
378 | routine main
379 | inputs a, score
380 | outputs score
381 | trashes a, c, z, v, n
382 | {
383 | st off, c
384 | add score, 1999
385 | }
386 = ok
387
388 `add`ing a word constant to a word memory location trashes `a`.
389
390 | word score
391 | routine main
392 | inputs a, score
393 | outputs score, a
394 | trashes c, z, v, n
395 | {
396 | st off, c
397 | add score, 1999
398 | }
399 ? UnmeaningfulOutputError: a in main
400
401 Not sure why this doesn't also raise an error? `a` is trashed...
402
403 | word score
404 | routine main
405 | inputs score
406 | outputs score
407 | trashes c, z, v, n
408 | {
409 | st off, c
410 | add score, 1999
411 | }
412 ? UnmeaningfulOutputError: a in main
374413
375414 ### sub ###
376415