mirror of
https://github.com/cc65/cc65.git
synced 2025-03-01 11:29:27 +00:00
Saved 2 bytes and fixed error in case of negative result.
This commit is contained in:
parent
2acfa5e78f
commit
923fa8fc93
@ -18,12 +18,15 @@
|
|||||||
.importzp sreg, ptr1, tmp1
|
.importzp sreg, ptr1, tmp1
|
||||||
|
|
||||||
_div: jsr tosdivax ; Division-operator does most of the work
|
_div: jsr tosdivax ; Division-operator does most of the work
|
||||||
lda sreg ; Unsigned remainder is in sreg
|
|
||||||
ldx sreg+1
|
ldy sreg ; low byte remainder from sreg
|
||||||
ldy ptr1 ; transfer quotient to sreg
|
sta sreg ; store low byte quotient to sreg
|
||||||
sty sreg
|
|
||||||
ldy ptr1+1
|
lda sreg+1 ; high byte remainder from sreg
|
||||||
sty sreg+1
|
stx sreg+1 ; store high byte quotient to sreg
|
||||||
|
|
||||||
|
tax ; high byte remainder to x
|
||||||
|
tya ; low byte remainder to a
|
||||||
|
|
||||||
; Adjust the sign of the remainder.
|
; Adjust the sign of the remainder.
|
||||||
; It must be the same as the sign of the dividend.
|
; It must be the same as the sign of the dividend.
|
||||||
@ -33,4 +36,3 @@ _div: jsr tosdivax ; Division-operator does most of the work
|
|||||||
jmp negax ; Result is negative, adjust the sign
|
jmp negax ; Result is negative, adjust the sign
|
||||||
|
|
||||||
Pos: rts
|
Pos: rts
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user