mirror of
https://github.com/cc65/cc65.git
synced 2025-01-01 03:30:20 +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
|
||||
|
||||
_div: jsr tosdivax ; Division-operator does most of the work
|
||||
lda sreg ; Unsigned remainder is in sreg
|
||||
ldx sreg+1
|
||||
ldy ptr1 ; transfer quotient to sreg
|
||||
sty sreg
|
||||
ldy ptr1+1
|
||||
sty sreg+1
|
||||
|
||||
ldy sreg ; low byte remainder from sreg
|
||||
sta sreg ; store low byte quotient to sreg
|
||||
|
||||
lda sreg+1 ; high byte remainder from sreg
|
||||
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.
|
||||
; 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
|
||||
|
||||
Pos: rts
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user