From 27fc6836ccc1cbab6b0274b68f34b71d0add771e Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 10 Sep 2018 17:09:28 -0500 Subject: [PATCH] Fix div() and ldiv() to return properly-signed remainders. They could previously give the wrong sign on the remainder in certain cases where one or both of the arguments were negative, because they were using the wrong condition to decide whether to negate it. --- stdlib.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib.asm b/stdlib.asm index 0ee837c..1fb9be7 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -282,7 +282,7 @@ addr equ 1 jsl ~DIV2 sta div_t save the results stx div_t+2 - tay if the result is negative then + lda n if the numerator is negative then bpl lb1 sub2 #0,div_t+2,div_t+2 make the remainder negative lb1 lla addr,div_t return the address @@ -427,7 +427,7 @@ addr equ 1 jsl ~DIV4 pl4 div_t pl4 div_t+4 - lda div_t+2 if the result is negative then + lda n+2 if the numerator is negative then bpl lb1 sub4 #0,div_t+4,div_t+4 make the remainder negative lb1 lla addr,div_t return the result