mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-06-07 20:29:28 +00:00
Add an 16-bit unsigned multiply routine suitable for use in C.
This differs from the existing ~UMul2 in SysLib in that it gives the low-order 16 bits of the true result in the event of overflow. The C standards require this behavior for computations on unsigned types.
This commit is contained in:
parent
12f8d74c99
commit
7b6cb049b7
57
cc.asm
57
cc.asm
|
@ -375,6 +375,63 @@ start ds 2 start of the command line string
|
|||
targv ds 4
|
||||
end
|
||||
|
||||
****************************************************************
|
||||
*
|
||||
* ~CUMul2 - unsigned multiply
|
||||
*
|
||||
* Inputs:
|
||||
* X,A - operands
|
||||
*
|
||||
* Outputs:
|
||||
* A - result
|
||||
*
|
||||
* Notes:
|
||||
* This routine is used for array index calculations and
|
||||
* for unsigned multiplies. It returns the low-order
|
||||
* 16 bits of the true result in case of overflow.
|
||||
*
|
||||
****************************************************************
|
||||
*
|
||||
~CUMul2 start
|
||||
n1 equ 3
|
||||
n2 equ 5
|
||||
;
|
||||
; Initialization
|
||||
;
|
||||
phx save the operands
|
||||
pha
|
||||
phd set up our DP
|
||||
tsc
|
||||
tcd
|
||||
cpx n1 make sure n1 is the smaller argument
|
||||
bge in1
|
||||
lda n1
|
||||
stx n1
|
||||
sta n2
|
||||
in1 anop
|
||||
;
|
||||
; Do the multiply
|
||||
;
|
||||
lda #0
|
||||
|
||||
lsr n1
|
||||
lb0 bcc lb1
|
||||
clc
|
||||
adc n2
|
||||
lb1 asl n2
|
||||
|
||||
lsr n1
|
||||
bne lb0
|
||||
bcc aa1
|
||||
clc
|
||||
adc n2
|
||||
|
||||
aa1 pld return the result
|
||||
plx
|
||||
plx
|
||||
rtl
|
||||
end
|
||||
|
||||
****************************************************************
|
||||
*
|
||||
* ~Exit - call exit routines and clean up open files
|
||||
|
|
Loading…
Reference in New Issue
Block a user