mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-17 22:30:27 +00:00
cmp
can compare against a literal word.
This commit is contained in:
parent
d86612acce
commit
97e6e619ff
@ -10,7 +10,8 @@ History of SixtyPical
|
|||||||
* When the range of a location is known, `inc` and `dec`
|
* When the range of a location is known, `inc` and `dec`
|
||||||
on it will usually shift the known instead of invalidating it.
|
on it will usually shift the known instead of invalidating it.
|
||||||
* `cmp` instruction can now perform a 16-bit unsigned comparison
|
* `cmp` instruction can now perform a 16-bit unsigned comparison
|
||||||
of `word` memory locations (at the cost of trashing `a`.)
|
of `word` memory locations and `word` literals (at the cost of
|
||||||
|
trashing the `a` register.)
|
||||||
* Fixed pathological memory use in the lexical scanner - should
|
* Fixed pathological memory use in the lexical scanner - should
|
||||||
be much less inefficient now when parsing large source files.
|
be much less inefficient now when parsing large source files.
|
||||||
* Reorganized the examples in `eg/rudiments/` to make them
|
* Reorganized the examples in `eg/rudiments/` to make them
|
||||||
|
@ -402,6 +402,16 @@ class Compiler(object):
|
|||||||
self.emitter.emit(CMP(Absolute(Offset(src_label, 1))))
|
self.emitter.emit(CMP(Absolute(Offset(src_label, 1))))
|
||||||
self.emitter.resolve_label(end_label)
|
self.emitter.resolve_label(end_label)
|
||||||
return
|
return
|
||||||
|
if isinstance(src, ConstantRef) and src.type == TYPE_WORD:
|
||||||
|
dest_label = self.get_label(dest.name)
|
||||||
|
self.emitter.emit(LDA(Absolute(dest_label)))
|
||||||
|
self.emitter.emit(CMP(Immediate(Byte(src.high_byte()))))
|
||||||
|
end_label = Label('end_label')
|
||||||
|
self.emitter.emit(BNE(Relative(end_label)))
|
||||||
|
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
|
||||||
|
self.emitter.emit(CMP(Immediate(Byte(src.low_byte()))))
|
||||||
|
self.emitter.resolve_label(end_label)
|
||||||
|
return
|
||||||
cls = {
|
cls = {
|
||||||
'a': CMP,
|
'a': CMP,
|
||||||
'x': CPX,
|
'x': CPX,
|
||||||
|
@ -1207,6 +1207,28 @@ Some rudimentary tests for `cmp`.
|
|||||||
| }
|
| }
|
||||||
? UnmeaningfulReadError: zb
|
? UnmeaningfulReadError: zb
|
||||||
|
|
||||||
|
`cmp` can compare against a literal word.
|
||||||
|
|
||||||
|
| word za
|
||||||
|
|
|
||||||
|
| define main routine
|
||||||
|
| inputs za
|
||||||
|
| trashes a, z, c, n
|
||||||
|
| {
|
||||||
|
| cmp za, 4000
|
||||||
|
| }
|
||||||
|
= ok
|
||||||
|
|
||||||
|
| word za
|
||||||
|
|
|
||||||
|
| define main routine
|
||||||
|
| inputs za
|
||||||
|
| trashes z, c, n
|
||||||
|
| {
|
||||||
|
| cmp za, 4000
|
||||||
|
| }
|
||||||
|
? ForbiddenWriteError: a
|
||||||
|
|
||||||
### and ###
|
### and ###
|
||||||
|
|
||||||
Some rudimentary tests for `and`.
|
Some rudimentary tests for `and`.
|
||||||
|
@ -395,15 +395,21 @@ Compiling 16-bit `cmp`.
|
|||||||
| trashes a, z, c, n
|
| trashes a, z, c, n
|
||||||
| {
|
| {
|
||||||
| cmp za, zb
|
| cmp za, zb
|
||||||
|
| cmp za, 4000
|
||||||
| }
|
| }
|
||||||
= $080D LDA $EA61
|
= $080D LDA $EA61
|
||||||
= $0810 CMP $081C
|
= $0810 CMP $0828
|
||||||
= $0813 BNE $081B
|
= $0813 BNE $081B
|
||||||
= $0815 LDA $EA62
|
= $0815 LDA $EA62
|
||||||
= $0818 CMP $081D
|
= $0818 CMP $0829
|
||||||
= $081B RTS
|
= $081B LDA $EA61
|
||||||
= $081C .byte $BB
|
= $081E CMP #$0F
|
||||||
= $081D .byte $0B
|
= $0820 BNE $0827
|
||||||
|
= $0822 LDA $EA62
|
||||||
|
= $0825 CMP #$A0
|
||||||
|
= $0827 RTS
|
||||||
|
= $0828 .byte $BB
|
||||||
|
= $0829 .byte $0B
|
||||||
|
|
||||||
Compiling `if`.
|
Compiling `if`.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user