Blah
Free supporter
- 1,924
- Posts
- 12
- Years
- Unknown Island
- Seen Feb 19, 2025
I think the simplest way would be like this:
What it does is it multiplies the numerator by 100 so the result is a percentage, then adds half of the denominator to make sure the result is correctly rounded (no need to process the remainder), and then divides. I haven't tested this code, but I'm pretty sure it works.Code:mov r0, numerator mov r1, denominator mov r2, #100 mul r0, r2 lsr r2, r1, #1 add r0, r2 swi #6
In a case like:
Numerator = 35
Denomenator = 102
-
you'd do, swi(3551, 102)
which is 34, and the modulo return is 83.
The expected return would be 35. I don't think you can get away with not checking the remainder. You could multiply by 1000 at the start, then you can shed the last digit if it's less than 5, but that's not faster, since swi does the modulo itself.