In my program I'm asking the user for some hex data, I convert this data from ASCII hex to real hex ('0'/30h to 00h), load each part into a slot in an array, and then reverse the bytes like when using bswap. The code below is my attempt at the reversing.

To help clear it up...The user enters something like "0234A8FC", program converts it to (0,2,3,4,A,8,F,C), and then I try to make it in to (F,C,A,8,3,4,0,2).

Are there any huge flaws in it? Is there an easier way to do this?

eax has the address of a local variable.

  mov ecx, 7

mov edx, [intoffset]
add edx, 7

reverseit:
dec ecx
mov ebx, byte ptr [eax+ecx]
inc ecx
mov byte ptr [edx-ecx], ebx

mov ebx, byte ptr [eax+ecx]
dec ecx
mov byte ptr [edx-ecx], ebx

dec ecx
cmp ecx, 0
jne reverseit
Posted on 2002-08-27 04:26:24 by ddh


include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

.code
invoke atodw, eax
bswap eax


The end

Mirno
Posted on 2002-08-27 05:10:32 by Mirno
And if I did that using an array, it'd only load one part of the array into eax and swap that around...In this case it'd be 00000002 and be swapped to 02000000. Not what I want.

temparray+0 = 02
temparray+1 = 0A
temparray+3 = 0F
etc

bswap on eax then would return the same data. No? bswap works on stuff such as 020A0FC3h..not (02,0A,0F,C3)...Or am I wrong in that?
Posted on 2002-08-27 05:40:35 by ddh
It should be htodw I used the wrong function... Oops :o

What it will do is take a pointer to a character string (say: "01234567"), and convert it into a number (in this case 01234567h, or 19088743 in decimal), which is returned in eax.
BSWAP takes a register, and swaps the bytes over.

If you then want to store each nibble within that 32 bit result as an array of bytes I guess you could...
It'd just be a simple loop then though.

I'm not entirly sure this is what you want anymore though...

Mirno
Posted on 2002-08-27 06:10:43 by Mirno
Actually that's exactly what I wanted. Thanks. I wasn't correct in my thinking about the functions.
Posted on 2002-08-27 06:20:12 by ddh