Get Square Root of Any Hex Value: PPC ASM
#2
Here's my shorter (but not as fancy) take on this, should be called as a function:



r3 = Input value
r4 = Rounding Type, 0 = Round down towards zero, 1 = Standard rounding



Raw code (Region Free)
28030001 4C810020
39800001 39600000
7CAA2B78 7D806378
398C0001 7CAC61D6
7D632851 4180FFEC
41820018 2C040000
41820014 7D4A1850
7D2A5851 41810008
7D806378 7C0C0378
7D836378 4E800020

Code:
cmplwi r3, 1
blelr-
li r12, 1
li r11, 0
loop:
mr r10, r5
mr r0, r12
addi r12, r12, 1
mullw r5, r12, r12
sub. r11, r5, r3
blt+ loop
beq- root_found
cmpwi r4, 0
beq round_down
sub r10, r3, r10
sub. r9, r11, r10
bgt round_down
root_found:
mr r0, r12
round_down:
mr r12, r0
mr r3, r12
blr
Super Mario Eclipse, what Super Mario Sunshine could've been.
Reply


Messages In This Thread
RE: Get Square Root of Any Hex Value: PPC ASM - by JoshuaMK - 01-14-2020, 05:09 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)