mirror of
https://github.com/mi57730/a2d.git
synced 2024-11-25 10:30:50 +00:00
Use better mul/div routines
This commit is contained in:
parent
2546a639db
commit
382763aec2
@ -254,53 +254,80 @@ op: lda dummy1234
|
|||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
;;; ============================================================
|
;;; ============================================================
|
||||||
;;; Input: numbers in A,X, Y
|
;;; Input: numbers in A,X, Y (all unsigned)
|
||||||
;;; Output: number in A,X
|
;;; Output: number in A,X (unsigned)
|
||||||
|
|
||||||
.proc Multiply_16_8_16
|
.proc Multiply_16_8_16
|
||||||
stax num16
|
stax num1
|
||||||
sty num8
|
sty num2
|
||||||
copy16 #0, accum
|
|
||||||
ldx num8
|
|
||||||
beq done
|
|
||||||
|
|
||||||
loop: add16 num16, accum, accum
|
;; Accumulate directly into A,X
|
||||||
dex
|
lda #0
|
||||||
|
tax
|
||||||
|
beq test
|
||||||
|
|
||||||
|
add: clc
|
||||||
|
adc num1
|
||||||
|
tay
|
||||||
|
|
||||||
|
txa
|
||||||
|
adc num1+1
|
||||||
|
tax
|
||||||
|
tya
|
||||||
|
|
||||||
|
loop: asl num1
|
||||||
|
rol num1+1
|
||||||
|
test: lsr num2
|
||||||
|
bcs add
|
||||||
bne loop
|
bne loop
|
||||||
|
|
||||||
done: ldax accum
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
num16: .word 0
|
num1: .word 0
|
||||||
num8: .byte 0
|
num2: .byte 0
|
||||||
accum: .word 0
|
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
;;; ============================================================
|
;;; ============================================================
|
||||||
;;; Input: numerator in A,X, divisor in Y
|
;;; Input: dividend in A,X, divisor in Y (all unsigned)
|
||||||
;;; Output: result in A,X
|
;;; Output: quotient in A,X (unsigned)
|
||||||
|
|
||||||
.proc Divide_16_8_16
|
.proc Divide_16_8_16
|
||||||
stax numerator
|
result := dividend
|
||||||
|
|
||||||
|
stax dividend
|
||||||
sty divisor
|
sty divisor
|
||||||
copy16 #0, result
|
lda #0
|
||||||
|
sta divisor+1
|
||||||
|
sta remainder
|
||||||
|
sta remainder+1
|
||||||
|
ldx #16
|
||||||
|
|
||||||
loop: sub16_8 numerator, divisor, numerator
|
loop: asl dividend
|
||||||
bmi done
|
rol dividend+1
|
||||||
inc16 result
|
rol remainder
|
||||||
jmp loop
|
rol remainder+1
|
||||||
|
lda remainder
|
||||||
|
sec
|
||||||
|
sbc divisor
|
||||||
|
tay
|
||||||
|
lda remainder+1
|
||||||
|
sbc divisor+1
|
||||||
|
bcc skip
|
||||||
|
sta remainder+1
|
||||||
|
sty remainder
|
||||||
|
inc result
|
||||||
|
|
||||||
done: ldax result
|
skip: dex
|
||||||
|
bne loop
|
||||||
|
ldax dividend
|
||||||
rts
|
rts
|
||||||
|
|
||||||
numerator:
|
dividend:
|
||||||
.word 0
|
.word 0
|
||||||
divisor:
|
divisor:
|
||||||
.byte 0
|
.word 0
|
||||||
|
remainder:
|
||||||
result: .word 0
|
.word 0
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
;;; ============================================================
|
;;; ============================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user