I tried converting Procs I found, but failed. I'm too use to FASM Syntax. Could someone convert the proc into FASM?
Posted on 2002-12-17 13:39:33 by CyberGuy
Something I had lying around


;********** ********** ********** ********** ********** ********** ********** ***
; DWORD GetHex( Convert ASCIIz to 32bit Hex
; lpsz // String to convert to 32bit Hex
; len // Max len to convert
; );
; Return Values:
; eax = lp after Hex
; ecx = 32 bit Hex equivilent of String.
; Remarks:
; Converts Unpacked ASCII Hex into 32 bit Intel Native
; This function works on upper and lower case since:
; Asc([A-F]) is congruent with Asc([a-f]) mod 0x10.
; Also it won't choke on out of range ASCII.
; MRP 2002 - Aug 01
;********** ********** ********** ********** ********** ********** ********** ***
proc GetHex, lpsz, len
enter
push esi
push edx
mov esi, [lpsz]
and edx, 0 ; Initialize Result Register
and eax, 0 ; Needed for sbb
cmp [len], Null
jz .Done
.Next:
lodsb ; Load Hex Digit, Most Significant Nibble First
shl edx, 4 ; Prepare for Next Digit
cmp eax, 'A' ; Is al a Character or Number?
sbb ecx, ecx ; If a Number then ecx = True
not ecx ;
and ecx, 0x09 ; If a Letter then ecx = 0x9
add eax, ecx ; Add ASCII Adjustment
and eax, 0x0F ; Mask upper bits

or edx, eax ; Save Nibble
dec [len] ; While( Len > 0)
jnz .Next ; Convert

.Done:
mov ecx, edx
mov eax, esi
pop edx
pop esi
return

;********** ********** ********** ********** ********** ********** ********** ***
; DWORD GetDec( Convert ASCIIz to 32bit Hex
; lpsz // String to convert to 32bit Hex
; len // Max len to convert
; );
; Return Values:
; eax = lp after Dec
; ecx = 32 bit Hex equivilent of String.
; Remarks:
; Converts Unpacked ASCII BCD into Intel Native
; Won't choke on out of range ASCII.
; MRP 2002 - Aug 01
;********** ********** ********** ********** ********** ********** ********** ***
proc GetDec, lpsz, len
enter
push esi
push edx
mov esi, [lpsz]
and edx, 0 ; Initialize Result Register
cmp [len], Null
jz .Done

.Next:
lodsb ; Load Dec Digit, Most Significant Nibble First
and eax, 0x0F ; Mask upper bits
shl edx, 1 ; edx *= 2
add eax, edx ;
shl edx, 2 ; edx *= 4
add edx, eax ; edx = edx*8 + edx*2 + al
dec [len] ; While( Len > 0)
jnz .Next ; Convert

.Done:
mov ecx, edx
mov eax, esi
pop edx
pop esi
return

;********** ********** ********** ********** ********** ********** ********** ***
; void Dword2Hex( Convert a 32b value into ASCII Hex
; lp // Destination Buffer
; dwHex // 32b Value to convert
; );
; Return Value:
; Returns nothing
; Notes:
; Based upon the Print16 Function
; MRP 2002 - Oct 02
; WAC 2002 - May
;********** ********** ********** ********** ********** ********** ********** ***
proc Dword2Hex, lp, dwHex
enter
push edx
push edi
mov ecx, 0x08 ;8 Hex digits
mov edx, [dwHex]
mov edi, [lp]
cld
.Next:
rol edx, 4 ; Get Next Nibble
mov al, 0x0F ; Mask al
and al, dl ; al = [00-0F]
or al, 0x90 ; al = [90-9F]
daa ; al = [90-99] or [00-05]
adc al, 0x40 ; al = [D0-D9] or [41-46]
daa ; al = [30-39] or [41-46]
stosb ; Store the ASCIIz Hex
dec ecx
jnz .Next
pop edi
pop edx
return
Posted on 2002-12-18 00:36:13 by eet_1024
Thanks alot :alright:
Posted on 2002-12-18 13:46:02 by CyberGuy