Skip to content

Commit

Permalink
Fixed remainder for U/MOD
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoeppen committed Feb 6, 2014
1 parent 7c79739 commit 79ef7a6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions generic/CoreForth.s
Expand Up @@ -696,14 +696,16 @@ unsigned_div_mod: @ r0 / r1 = r3, remainder = r0
b 1b
3: movs r3, #0 @ initialize quotient
2: cmp r0, r2 @ can we subtract r2?
adcs r3, r3 @ double r3
cmp r0, r2
ble 4f
adcs r3, r3 @ double r3
subs r0, r0, r2 @ if we can, do so
4: lsrs r2, #1 @ halve r2,
cmp r2, r1 @ and loop until
bhs 2b @ less than divisor
bx lr
cmp r0, r1
bne 5f
movs r0, #0
5: bx lr

defcode "U/MOD", UDIVMOD
pop {r1}
Expand Down

0 comments on commit 79ef7a6

Please sign in to comment.