Kodewerx https://www.kodewerx.org/forum/ |
|
Hex to ASCII conversion in arm9? https://www.kodewerx.org/forum/viewtopic.php?f=2&t=6703 |
Page 1 of 1 |
Author: | dragonboy269 [ Wed Apr 15, 2009 3:05 pm ] |
Post subject: | Hex to ASCII conversion in arm9? |
Has anyone done something like this? I made a routine that does it but I think it's very inefficient (just wait till A_Random_Person replies saying how I fail XD) This is what I have (it's part of a code I made for AC:WW) By the way it's in THUMB Code: @where r5 is the address you're loading a value from (for example you might load FFF1 from address 21D88FE) @r2 is #0xF @r0 is specified earlier in the code, if you're loading an 8 bit value it's #0x0, if it's a 16 bit value it's #0x1, if it's 32 bit it's #0x3 @and r1 is the typed text address (so when the code is done, it displays the hex code on the text, which is why it has to convert from hex to ascii) textconvert:ldrb r3,[r5] add r5,#0x1 mov r4,r3 lsr r3,#0x4 and r4,r2 cmp r3,#0x9 ble notletters1 add r3,#0x7 notletters1:add r3,#0x30 cmp r4,#0x9 ble notletters2 add r4,#0x7 notletters2:add r4,#0x30 strb r3,[r1] add r1,#0x1 strb r4,[r1] sub r1,#0x3 sub r0,#0x1 bpl textconvert so for example, you have something that's a value of 14FD it'll load a byte at a time, so first it'll put 14 in r3 and r4 r3 will focus on converting the 1 and r4 will focus on converting the 4 Then in the end it stores both in the text address. Also the reason why it goes backwards is because that way it'll put for example 000014FD |
Author: | Parasyte [ Thu Apr 16, 2009 4:30 pm ] |
Post subject: | Re: Hex to ASCII conversion in arm9? |
1) Use a table: Code: ascii_tab: .asciz "0123456789ABCDEF" 2) After splitting the byte into nybbles, just offset acsii_tab with the nybble. 3) Copy the byte from the resulting pointer to the destination. 4) Repeat. 5) ???? 6) Profit! |
Page 1 of 1 | All times are UTC - 8 hours [ DST ] |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |