Submitted by Steve Fewell
Routine: icomp
Name: Integer Compliment
Starting Address: &ACDE
Entry criteria: The IWA
contains the integer to compliment.
Exit: IWA contains the compliment integer [i.e. IWA = - IWA]
Description:
Subtracts each byte of the IWA from
zero. The least significant byte is processed first. The
carry flag is set at the beginning because its reset state (0) indicates that a
borrow has occurred. This routine makes clever usage of the Y register to hold
the value of zero, and to transfer the value to A before each byte is
subtracted. This is a lot faster than if A was loaded with #&00 each time.
On exit, A is loaded with #&40, which indicates that an integer value is being processed.
Disassembly for the integer compliment routine
ACDE | 8 | 056 | 38 | SEC |
ACDF | 169 000 | A9 00 | LDA#&00 | |
ACE1 | 168 | A8 | TAY | |
ACE2 | * | 229 042 | E5 2A | SBC &2A |
ACE4 | * | 133 042 | 85 2A | STA &2A |
ACE6 | 152 | 98 | TYA | |
ACE7 | + | 229 043 | E5 2B | SBC &2B |
ACE9 | + | 133 043 | 85 2B | STA &2B |
ACEB | 152 | 98 | TYA | |
ACEC | , | 229 044 | E5 2C | SBC &2C |
ACEE | , | 133 044 | 85 2C | STA &2C |
ACF0 | 152 | 98 | TYA | |
ACF1 | - | 229 045 | E5 2D | SBC &2D |
ACF3 | - | 133 045 | 85 2D | STA &2D |
ACF5 | @ | 169 064 | A9 40 | LDA#&40 |
ACF7 | ` | 096 | 60 | RTS |