1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +00:00
cc65/libsrc/runtime/div.s

30 lines
960 B
ArmAsm
Raw Normal View History

;
2018-05-24 01:55:40 +00:00
; Christian Krueger, 24-May-2018
;
; CC65 runtime: division for signed ints
;
; When negating values, we will ignore the possibility here, that one of the
2018-05-24 01:55:40 +00:00
; values is $8000, in which case the negate will fail.
.export tosdiva0, tosdivax
2018-05-24 01:55:40 +00:00
.import absvaludiv, negax
.importzp sp, ptr1, tmp1
tosdiva0:
ldx #0
tosdivax:
2018-05-24 01:55:40 +00:00
pha ; check if high-bytes indicate
txa ; different sign, so that we
ldy #1 ; negate the result after the operation
eor (sp),y ; eor with lhs high byte
sta tmp1 ; save post negation indicator to tmp1
pla ; back to entry accu
jsr absvaludiv
ldx ptr1+1
lda ptr1
ldy tmp1 ; fetch idicator
bmi negate
rts
2018-05-24 01:55:40 +00:00
negate: jmp negax