mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 17:29:50 +00:00
Fixed the result of the % operator for longs
git-svn-id: svn://svn.cc65.org/cc65/trunk@1409 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
3aab67401e
commit
689202057c
@ -8,13 +8,28 @@
|
|||||||
; values if $80000000, in which case the negate will fail.
|
; values if $80000000, in which case the negate will fail.
|
||||||
|
|
||||||
.export tosdiveax
|
.export tosdiveax
|
||||||
.import poplsargs, udiv32, adjlsres
|
.import poplsargs, udiv32, negeax
|
||||||
.importzp ptr1
|
.importzp ptr1, tmp1, tmp2
|
||||||
|
|
||||||
tosdiveax:
|
tosdiveax:
|
||||||
jsr poplsargs ; Get arguments from stack, adjust sign
|
jsr poplsargs ; Get arguments from stack, adjust sign
|
||||||
jsr udiv32 ; Do the division
|
jsr udiv32 ; Do the division, result is in (ptr1:sreg)
|
||||||
lda ptr1 ; Result is in (ptr1:sreg)
|
ldx ptr1+1 ; Load byte 1 of result
|
||||||
ldx ptr1+1
|
|
||||||
jmp adjlsres ; Adjust the sign of the result if needed
|
; Adjust the sign of the result
|
||||||
|
|
||||||
|
lda tmp1 ; Get sign of left operand
|
||||||
|
eor tmp2 ; Calculate sign of result
|
||||||
|
bpl Pos ; Jump if result positive
|
||||||
|
|
||||||
|
; Result is negative
|
||||||
|
|
||||||
|
lda ptr1 ; Load byte 0
|
||||||
|
jmp negeax ; Negate value
|
||||||
|
|
||||||
|
; Result is positive
|
||||||
|
|
||||||
|
Pos: lda ptr1
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,19 +8,33 @@
|
|||||||
; values if $8000, in which case the negate will fail.
|
; values if $8000, in which case the negate will fail.
|
||||||
|
|
||||||
.export tosmodeax
|
.export tosmodeax
|
||||||
.import poplsargs, udiv32, adjlsres
|
.import poplsargs, udiv32, negeax
|
||||||
.importzp sreg, ptr1, ptr2, tmp3, tmp4
|
.importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
|
||||||
|
|
||||||
tosmodeax:
|
tosmodeax:
|
||||||
jsr poplsargs ; Get arguments from stack, adjust sign
|
jsr poplsargs ; Get arguments from stack, adjust sign
|
||||||
jsr udiv32 ; Do the division
|
jsr udiv32 ; Do the division, remainder is in (ptr2:tmp3:tmp4)
|
||||||
lda ptr1 ; Remainder is in (ptr2:tmp3:tmp4)
|
|
||||||
lda ptr2
|
; Load the result with the exception of the low byte
|
||||||
|
|
||||||
ldx ptr2+1
|
ldx ptr2+1
|
||||||
ldy tmp3
|
ldy tmp3
|
||||||
sty sreg
|
sty sreg
|
||||||
ldy tmp4
|
ldy tmp4
|
||||||
sty sreg+1
|
sty sreg+1
|
||||||
jmp adjlsres ; Adjust the sign of the result if needed
|
|
||||||
|
|
||||||
|
; Check the sign of the result. It is the sign of the left operand.
|
||||||
|
|
||||||
|
lda tmp1 ; Check sign of left operand
|
||||||
|
bpl Pos ; Jump if result is positive
|
||||||
|
|
||||||
|
; Result is negative
|
||||||
|
|
||||||
|
lda ptr2 ; Load byte 0 of result
|
||||||
|
jmp negeax ; Negate result
|
||||||
|
|
||||||
|
; Result is positive
|
||||||
|
|
||||||
|
Pos: lda ptr2 ; Load byte 0 of result
|
||||||
|
rts ; Done
|
||||||
|
|
||||||
|
@ -7,23 +7,18 @@
|
|||||||
; When negating values, we will ignore the possibility here, that one of the
|
; When negating values, we will ignore the possibility here, that one of the
|
||||||
; values if $80000000, in which case the negate will fail.
|
; values if $80000000, in which case the negate will fail.
|
||||||
|
|
||||||
.export poplsargs, adjlsres
|
.export poplsargs
|
||||||
.import getlop, negeax
|
.import getlop
|
||||||
.importzp sreg, tmp1, ptr1, ptr3, ptr4
|
.importzp sreg, tmp1, tmp2, ptr1, ptr3, ptr4
|
||||||
|
|
||||||
poplsargs:
|
poplsargs:
|
||||||
jsr getlop ; Get the operands
|
jsr getlop ; Get the operands
|
||||||
|
|
||||||
; Calculate the sign of the result, that is sign(op1) * sign(op2) and
|
; Remember the signs of the operands (that is, the high bytes) in tmp1 and
|
||||||
; remember it.
|
; tmp2. Make both operands positive.
|
||||||
|
|
||||||
lda sreg+1
|
lda sreg+1 ; Is the left operand negative?
|
||||||
eor ptr4+1
|
sta tmp1 ; Remember the sign for later
|
||||||
sta tmp1 ; Save it across call
|
|
||||||
|
|
||||||
; Make both operands positive
|
|
||||||
|
|
||||||
lda sreg+1 ; Is the operand negative?
|
|
||||||
bpl L1 ; Jump if not
|
bpl L1 ; Jump if not
|
||||||
|
|
||||||
clc ; Make it positive
|
clc ; Make it positive
|
||||||
@ -44,7 +39,8 @@ poplsargs:
|
|||||||
adc #$00
|
adc #$00
|
||||||
sta sreg+1
|
sta sreg+1
|
||||||
|
|
||||||
L1: lda ptr4+1 ; Is the operand nagative?
|
L1: lda ptr4+1 ; Is the right operand nagative?
|
||||||
|
sta tmp2 ; Remember the sign for later
|
||||||
bpl L2 ; Jump if not
|
bpl L2 ; Jump if not
|
||||||
|
|
||||||
clc ; Make it positive
|
clc ; Make it positive
|
||||||
@ -67,10 +63,3 @@ L1: lda ptr4+1 ; Is the operand nagative?
|
|||||||
|
|
||||||
L2: rts
|
L2: rts
|
||||||
|
|
||||||
; Adjust the result of a mod/div/mul operation
|
|
||||||
|
|
||||||
adjlsres:
|
|
||||||
ldy tmp1 ; Check if we must adjust the sign
|
|
||||||
bpl L2
|
|
||||||
jmp negeax ; Netage value
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user