1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-01 13:41:34 +00:00

Saved 2 bytes and fixed error in case of negative result.

This commit is contained in:
IrgendwerA8 2018-11-09 15:56:16 +01:00 committed by greg-king5
parent 2acfa5e78f
commit 923fa8fc93

View File

@ -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