base:16-bit_comparison
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
base:16-bit_comparison [2020-10-22 20:30] – created tww | base:16-bit_comparison [2020-10-27 00:34] – tww_ctr | ||
---|---|---|---|
Line 4: | Line 4: | ||
- | TWW method: | + | 16 bit equivalent of the CMP OPC: |
< | < | ||
/*! «»«»«»«»{CMP16}«»«»«»«» | /*! «»«»«»«»{CMP16}«»«»«»«» | ||
- | Does exactly the same as CMP of two values (effectively its a val1-val2) and sets the flags as follows: | + | Does exactly the same as CMP of two values (effectively its a A - M) and sets the flags as follows: |
- | | + | |
- | | + | If A > M : Carry = SET Zero = CLEAR Negative = CLEAR |
- | If val1 > val2 : Carry = SET Zero = CLEAR Negative = CLEAR | + | If A < M : Carry = CLEAR Zero = CLEAR Negative = SET |
- | If val1 < val2 : Carry = CLEAR Zero = CLEAR Negative = SET | + | |
*/ | */ | ||
- | lda val1 | + | lda A+1 |
- | sec | + | |
- | sbc val2 | + | |
- | php | + | lda A |
- | lda val1+1 | + | cmp M |
- | | + | !: |
- | | + | |
- | pla | + | </ |
- | sta temp | + | |
- | pla | + | |
- | | + | |
- | ora # | + | |
- | and temp | + | |
- | pha | + | |
- | plp | + | |
- | Somewhere on ZP: | ||
- | temp: | ||
- | .byte $00 | ||
+ | Different approach: instead of setting flags, goes to different destinations: | ||
+ | < | ||
+ | ; Val1 ≥ Val2 ? | ||
+ | LDA Val1 +1 ; high bytes | ||
+ | CMP Val2+1 | ||
+ | BCC LsThan | ||
+ | BNE GrtEqu | ||
+ | LDA Val1 ; low bytes | ||
+ | CMP Val2 | ||
+ | ;BEQ Equal ; Val1 = Val2 | ||
+ | BCS GrtEqu | ||
+ | LsThan | ||
+ | ... | ||
+ | GrtEqu | ||
+ | ... | ||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||
base/16-bit_comparison.txt · Last modified: 2021-09-13 17:23 by tww