AppleIIAsm-Collection/disks/disk4_math/T.SUBT16

103 lines
2.4 KiB
Plaintext
Raw Normal View History

*
*``````````````````````````````*
* SUBT16 :: SUBTRACT WORDS *
*- -*
* SUBTRACT ONE 16BIT NUMBER *
* FROM ANOTHER, RETURNING THE *
* RESULT IN .Y (LOW), .X (HI). *
* SIGNED OR UNSIGNED. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* LDA #>1000 ; MINUEND *
* PHA *
* LDA #<1000 *
* PHA *
* LDA #>500 ; SUBTRAHEND *
* PHA *
* LDA #<500 *
* PHA *
* JSR SUBT16 *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* LOW BYTE OF SUBTRAHEND *
* HIGH BYTE OF SUBTRAHEND *
* LOW BYTE OF MINUEND *
* HIGH BYTE OF MINUEND *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* .Y = RESULT LOW BYTE *
* .X = RESULT HIGH BYTE *
* .A = LOW BYTE OF RET ADDR *
* *
* [RETURN] = RESULT (2 BYTES) *
* [RETLEN] = 2 (RESULT LENGTH) *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
SUBT16
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET PARAMETERS
*
PLA
STA :SUBT
PLA
STA :SUBT+1 ; SUBTRAHEND
PLA
STA :MINU
PLA
STA :MINU+1 ; MINUEND
*
** MINUEND - SUBTRAHEND
*
LDA :MINU
SEC
SBC :SUBT
TAY ; LOW BYTE
STY RETURN
LDA :MINU+1
SBC :SUBT+1
TAX ; HIGH BYTE
STX RETURN+1
LDA #2
STA RETLEN
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** DATA
*
:MINU DS 2
:SUBT DS 2
*