Fix order of operands in word-sized `cmp`.
Chris Pressey
6 years ago
397 | 397 |
|
398 | 398 |
Subtracts the contents of src from dest (without considering carry) but
|
399 | 399 |
does not store the result anywhere, only sets the resulting flags.
|
|
400 |
This means that `z` is set if src and dest are equal,
|
|
401 |
and `c` is set if dest is greater than or equal to src
|
|
402 |
(`c` is unset if dest is less than src.)
|
400 | 403 |
|
401 | 404 |
* It is illegal if src OR dest is uninitialized.
|
402 | 405 |
|
|
406 | 409 |
In addition, if dest is of `word` type, then src must also be of `word`
|
407 | 410 |
type, and in this case this instruction trashes the `a` register.
|
408 | 411 |
|
409 | |
Note that, like `cmp` is not suitable for making a
|
|
412 |
Note that `cmp` is not suitable for making a
|
410 | 413 |
signed comparison; this article, which mentions
|
411 | 414 |
techniques that a SixtyPical compiler could use to
|
412 | 415 |
implement `cmp`, also explains why that is:
|
393 | 393 |
if isinstance(src, LocationRef) and src.type == TYPE_WORD:
|
394 | 394 |
src_label = self.get_label(src.name)
|
395 | 395 |
dest_label = self.get_label(dest.name)
|
396 | |
self.emitter.emit(LDA(Absolute(src_label)))
|
397 | |
self.emitter.emit(CMP(Absolute(dest_label)))
|
|
396 |
self.emitter.emit(LDA(Absolute(dest_label)))
|
|
397 |
self.emitter.emit(CMP(Absolute(src_label)))
|
398 | 398 |
end_label = Label('end_label')
|
399 | 399 |
self.emitter.emit(BNE(Relative(end_label)))
|
400 | |
self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
|
401 | |
self.emitter.emit(CMP(Absolute(Offset(dest_label, 1))))
|
|
400 |
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
|
|
401 |
self.emitter.emit(CMP(Absolute(Offset(src_label, 1))))
|
402 | 402 |
self.emitter.resolve_label(end_label)
|
403 | 403 |
return
|
404 | 404 |
cls = {
|