Hi again Devoum,
As expected, you want to "and" with 0x0f, not 0x0f0. There's another problem - you reverse the order of the characters in the first loop, then reverse 'em again in the second loop. I solved it like this:
_Cast:
mov esi, esp
mov ecx, 4
mov edx, 8
loop:
xor eax, eax
lodsb
push ax
shr al, 4
and al, 0x0f
mov [buffer+edx*1], al
dec edx
pop ax
and al, 0xf ; <-
mov [buffer+edx*1], al
dec edx
dec ecx
jnz loop
ret
_Convert:
mov esi, buffer
; mov ecx, 8
xor ecx, ecx
xor ebx, ebx
loop2:
lodsb
and ax, 0x00ff
mov bx, ax
mov dl, [hex+ebx]
mov [result+ecx*1], dl
; dec ecx
inc ecx
cmp ecx, 8
jnz loop2
ret
There are other ways to go about it, of course. I didn't try it in an actual MessageBox. It occurs to me that you need a zero-terminated string. Since "result" is the last thing in your code, it is "probably" zero terminated. You might want to add a byte to that buffer and zero-terminate it explicitly so it'll continue to work if you add something after it.
I'd push and pop eax, not just ax, where you do that. It is "legal" to push/pop 16 bits in 32-bit code, but not often "useful". Doesn't do any harm, but you'll get shorter(!) code if you use eax, besides leaving your stack in a better-aligned state. Really doesn't matter in this case.
Best,
Frank