assembly hex representation from two bytes

Go To StackoverFlow.com

1

i want to enter a string like 415A6B31 and the assembly function should return AZk1 so i have to take every two bytes and convert to one byte ... 41 = A 5A = z and so on

how to make it in assembly?

2012-04-03 19:44
by aseed
The data is the same, the only thing that changes is how you look at i - BlackBear 2012-04-03 19:47
Assuming an ASCII hex string of 8 characters, how are you passing it in? Pointer in EAX - Martin James 2012-04-03 20:02
entering 4 in string is 0x34 hex, and 1 is 0x31 hex so if i have a register ebx want to enter the value of 0x34 and 0x31 to the first byte ... how to do that? - aseed 2012-04-03 22:25
i passed it by function from c, so the first argument in byte[ecx] which is 4, 0x34 hex.. and cant assume anything about the string size beside it is an eve - aseed 2012-04-03 22:28


0

Look at the numbers you are dealing with. the string is in hex yes? look up the hex values 0-9 are 0x30 to 0x39, and with 0xF to get 0-9 yes? anding 0x41 with 0xF does not result in 0xA though, so for each byte in the string

if(byte>0x39) byte = byte - 7;
byte=byte&0xF;

that gives you nibbles (nybbles) 0x4, 0x1, 0x5, 0xA, etc. Then combine the nibbles into bytes

(0x4<<8)|0x1 = 0x41, (0x5<<4)|0xA = 0x5A, etc.

C language symbols:

<< means shift left
& means and
| means or
- means subtract
0x means the number is in hexadecimal
2012-04-04 00:29
by old_timer
i think that there is another way, without using nybbles. - aseed 2012-04-04 10:52
two choices, one source character at a time (nibble) or two characters at a time (bytes) to do two characters at a time you want to use a 65536 deep lookup table. answer = table [(((uint16_t)source[n+0])<<8)|source[n+1])]; If you dont use a look up table then you are essentially breaking it into nibbles and putting those together. Your last choice other than the if>0x39 x-=7; is a 256 deep lookup table (to get the nibble) - old_timer 2012-04-04 14:22
i really dont understand your answer, because of its symbols, like byte-=7 byte&=0xF and << and - aseed 2012-04-10 20:11