Hex to Binary in PPC ASM - Printable Version +- Mario Kart Wii Gecko Codes, Cheats, & Hacks (https://mariokartwii.com) +-- Forum: Hacks/Modding (https://mariokartwii.com/forumdisplay.php?fid=14) +--- Forum: Coding & Hacking General Discussion (https://mariokartwii.com/forumdisplay.php?fid=23) +--- Thread: Hex to Binary in PPC ASM (/showthread.php?tid=1422) |
Hex to Binary in PPC ASM - Vega - 01-12-2020 I was bored so I wrote up this small snippet of code to take the byte input and return its binary form. The snippet of code is setup as small function meant to be called with the proper arg and a return value is sent. To cut down on source length, there are no checks for null digits. #r3 = arg (byte; positive only) #r3 returns the binary representation of the byte, or returns -1 if a valid positive byte wasn't supplied for the arg Source: #Convert byte value to its binary representation #Temporarily place Arg into r0 mr r0, r3 #Check if we actually working on a byte clrrwi. r3, r3, 24 li r3, -1 bnelr- #Place bit 24 of r0 into bit 3 of r3 #Place bit 25 to bit 7 #Place bit 26 to bit 11 #Place bit 27 to bit 15 #First digit completed rlwinm r3, r0, 21, 3, 3 #Have to use rlwinm because r3 does not start off as null rlwimi r3, r0, 18, 7, 7 rlwimi r3, r0, 15, 11, 11 rlwimi r3, r0, 12, 15, 15 #Place bit 28 of r0 into bit 19 of r3 #Place bit 29 to bit 23 #Place bit 30 to bit 27 #Place bit 31 of r0 into bit 31 of r3 rlwimi r3, r0, 9, 19, 19 rlwimi r3, r0, 6, 23, 23 rlwimi r3, r0, 3, 27, 27 rlwimi r3, r0, 0, 31, 31 #Done blr Raw ASM compiled code~ Code: 7C601B78 5463000F |