mirror of
https://github.com/cc65/cc65.git
synced 2024-06-27 12:29:33 +00:00
Reestablished entry state of signed operation and optimized that (again).
This commit is contained in:
parent
ba5b580368
commit
8a5d1b9674
|
@ -1,22 +0,0 @@
|
||||||
;
|
|
||||||
; Christian Krueger, 23-May-2018
|
|
||||||
;
|
|
||||||
; CC65 runtime: helper call for mod/div with signed ints
|
|
||||||
;
|
|
||||||
; When negating values, we will ignore the possibility here, that one of the
|
|
||||||
; values is $8000, in which case the negate will fail.
|
|
||||||
|
|
||||||
.export absvaludiv16
|
|
||||||
.import _abs, popax, udiv16
|
|
||||||
.importzp ptr1, ptr4
|
|
||||||
|
|
||||||
|
|
||||||
absvaludiv16:
|
|
||||||
jsr _abs
|
|
||||||
sta ptr4
|
|
||||||
stx ptr4+1 ; Save right absolute operand
|
|
||||||
jsr popax
|
|
||||||
jsr _abs
|
|
||||||
sta ptr1
|
|
||||||
stx ptr1+1 ; Save left absolute operand
|
|
||||||
jmp udiv16
|
|
|
@ -1,5 +1,5 @@
|
||||||
;
|
;
|
||||||
; Christian Krueger, 24-May-2018
|
; Ullrich von Bassewitz, 07.08.1998
|
||||||
;
|
;
|
||||||
; CC65 runtime: division for signed ints
|
; CC65 runtime: division for signed ints
|
||||||
;
|
;
|
||||||
|
@ -8,22 +8,30 @@
|
||||||
; values is $8000, in which case the negate will fail.
|
; values is $8000, in which case the negate will fail.
|
||||||
|
|
||||||
.export tosdiva0, tosdivax
|
.export tosdiva0, tosdivax
|
||||||
.import absvaludiv16, negax
|
.import popsargsudiv16, negax
|
||||||
.importzp sp, ptr1, tmp1
|
.importzp ptr1, tmp1, tmp2
|
||||||
|
|
||||||
tosdiva0:
|
tosdiva0:
|
||||||
ldx #0
|
ldx #0
|
||||||
tosdivax:
|
tosdivax:
|
||||||
pha ; Check if high-bytes indicate
|
jsr popsargsudiv16 ; Get arguments from stack, adjust sign
|
||||||
txa ; different sign, so that we have to
|
; and do the division
|
||||||
ldy #1 ; negate the result after the operation.
|
ldx ptr1+1 ; Load high byte of result
|
||||||
eor (sp),y ; Eor with lhs high byte
|
|
||||||
sta tmp1 ; Save post negation indicator to tmp1
|
; Adjust the sign of the result. tmp1 contains the high byte of the left
|
||||||
pla ; Back to entry accu
|
; operand, tmp2 contains the high byte of the right operand.
|
||||||
jsr absvaludiv16
|
|
||||||
ldx ptr1+1
|
lda tmp1
|
||||||
lda ptr1
|
eor tmp2
|
||||||
ldy tmp1 ; Fetch indicator
|
bpl Pos ; Jump if sign of result positive
|
||||||
bmi negate
|
|
||||||
|
; Result is negative
|
||||||
|
|
||||||
|
lda ptr1 ; Load low byte of result
|
||||||
|
jmp negax ; Adjust the sign
|
||||||
|
|
||||||
|
; Result is positive
|
||||||
|
|
||||||
|
Pos: lda ptr1 ; Load low byte of result
|
||||||
rts
|
rts
|
||||||
negate: jmp negax
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
;
|
;
|
||||||
; Christian Krueger, 24-May-2018
|
; Ullrich von Bassewitz, 07.08.1998
|
||||||
;
|
;
|
||||||
; CC65 runtime: modulo operation for signed ints
|
; CC65 runtime: modulo operation for signed ints
|
||||||
;
|
;
|
||||||
|
@ -8,25 +8,30 @@
|
||||||
; values is $8000, in which case the negate will fail.
|
; values is $8000, in which case the negate will fail.
|
||||||
|
|
||||||
.export tosmoda0, tosmodax
|
.export tosmoda0, tosmodax
|
||||||
.import absvaludiv16, negax
|
.import popsargsudiv16, negax
|
||||||
.importzp sp, sreg, tmp1
|
.importzp sreg, tmp1
|
||||||
|
|
||||||
tosmoda0:
|
tosmoda0:
|
||||||
ldx #0
|
ldx #0
|
||||||
tosmodax:
|
tosmodax:
|
||||||
|
jsr popsargsudiv16 ; Get arguments from stack, adjust sign
|
||||||
|
; and do the division
|
||||||
|
lda sreg ; Load low byte of result
|
||||||
|
ldx sreg+1 ; Load high byte of result
|
||||||
|
|
||||||
; Prepare adjustment of the sign of the result. The sign of the result of the
|
; Adjust the sign of the result. tmp1 contains the high byte of the left
|
||||||
; modulo operation is the same as that of the left operand.
|
; operand, tmp2 contains the high byte of the right operand. The sign of
|
||||||
|
; the result of the modulo operation is the same as that of the left
|
||||||
|
; operand
|
||||||
|
|
||||||
|
bit tmp1
|
||||||
|
bpl Pos ; Jump if sign of result positive
|
||||||
|
|
||||||
|
; Result is negative
|
||||||
|
|
||||||
|
jmp negax ; Adjust the sign
|
||||||
|
|
||||||
|
; Result is positive
|
||||||
|
|
||||||
|
Pos: rts
|
||||||
|
|
||||||
pha
|
|
||||||
ldy #1 ; Prepare lhs operant hi-byte fetch
|
|
||||||
lda (sp),y
|
|
||||||
sta tmp1 ; Save post negation indicator to tmp1
|
|
||||||
pla ; Back to entry accu
|
|
||||||
jsr absvaludiv16
|
|
||||||
ldx sreg+1 ; Remainder to return registers
|
|
||||||
lda sreg
|
|
||||||
ldy tmp1 ; Fetch indicator
|
|
||||||
bmi negate
|
|
||||||
rts
|
|
||||||
negate: jmp negax
|
|
||||||
|
|
29
libsrc/runtime/shelp.s
Normal file
29
libsrc/runtime/shelp.s
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 07.08.1998
|
||||||
|
;
|
||||||
|
; CC65 runtime: helper stuff for mod/div with signed ints
|
||||||
|
;
|
||||||
|
|
||||||
|
; When negating values, we will ignore the possibility here, that one of the
|
||||||
|
; values is $8000, in which case the negate will fail.
|
||||||
|
|
||||||
|
.export popsargsudiv16
|
||||||
|
.import negax, popax, udiv16
|
||||||
|
.importzp tmp1, tmp2, ptr1, ptr4
|
||||||
|
|
||||||
|
popsargsudiv16:
|
||||||
|
stx tmp2 ; Remember sign
|
||||||
|
cpx #0
|
||||||
|
bpl L1
|
||||||
|
jsr negax ; Negate accumulator
|
||||||
|
L1: sta ptr4
|
||||||
|
stx ptr4+1 ; Save right operand
|
||||||
|
|
||||||
|
jsr popax
|
||||||
|
stx tmp1 ; Remember sign
|
||||||
|
cpx #0
|
||||||
|
bpl L2
|
||||||
|
jsr negax
|
||||||
|
L2: sta ptr1
|
||||||
|
stx ptr1+1
|
||||||
|
jmp udiv16 ; Call the division
|
Loading…
Reference in New Issue
Block a user