Hex to Binary in PPC ASM
#1
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
3860FFFF 4C820020
5403A8C6 500391CE
50037AD6 500363DE
50034CE6 500335EE
50031EF6 500307FE
4E800020
Reply


Messages In This Thread
Hex to Binary in PPC ASM - by Vega - 01-12-2020, 12:00 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)