diff --git a/src/imath.asm b/src/imath.asm index 0c08923..5d8fbd2 100644 --- a/src/imath.asm +++ b/src/imath.asm @@ -6,20 +6,29 @@ ; r1 - The lower 32 bits of the result ; Clobbers: r2, r3, r4, r5 pub mul_low: - mov r3, 0 ; result - mov r4, 31 ; loop counter - + add r3, r2, r2 ; r3 = r2 * 2 + mov r4, 0 ; r4 has the result + mul_low_loop: - asr r5, r2, 31 - and r5, r5, r1 - lsl r5, r5, r4 - add r3, r3, r5 - lsl r2, r2, 1 - sub r4, r4, 1 - cmp r4, 0 - jge mul_low_loop - mov r1, r3 - + + and r5, r1, 1 ; a0 + neg r5, r5 ; mask + and r5, r2, r5 ; a0 ? r2 : 0 + add r4, r4, r5 + + and r5, r1, 2 ; a1 is now 0 or 2 + lsr r5, r5, 1 ; normalize to 0/1 + neg r5, r5 ; mask + and r5, r3, r5 ; a1 ? r2 * 2 : 0 + add r4, r4, r5 + + lsl r2, r2, 2 + lsl r3, r3, 2 + lsr r1, r1, 2 + cmp r1, zr + jne mul_low_loop + + mov r1, r4 jmp r13 ; Calculates the absolute value of the value provided in the r1 register