News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Converting Hex Byte to String

Started by drunkenmyno, November 27, 2019, 08:29:22 AM

Previous topic - Next topic

drunkenmyno

Hello MASM Programmers :)

i'm new to this Forum and looking for some help,. I hope you can help me with my Problem.

I have a buffer variable in MASM declared with NameBuffer db   80 dup(?)

in this Buffer i have a array of 60 bytes

like 0x4E 0xCE 0x78

i need to convert this bytes to a string so that i have

4ECE78 as string

i look already in the masm32 help and found the function dw2ah but i dont think its the correct one or??

if yes then i cant use it im getting

error A2006: undefined symbol : dw2ah

Hope someone can help me

Thank you very much

Mikl__

#1
; GUI #
include win64a.inc
.data
NameBuffer db 20 dup (4Eh,0CEh,78h),0
aTitle db "drunkenmyno",0
format db '%I64X',0
.code
WinMain proc
local buffer[200h]:byte
k = 0
rept 7
        mov r8,qword ptr NameBuffer+k*8
        bswap r8
invoke wsprintf,&buffer+16*k,&format
k = k + 1
endm
invoke MessageBox,0,&buffer,&aTitle,MB_OK
invoke ExitProcess,NULL
WinMain endp
end

drunkenmyno

Thanks Mikl but this dont work for me on masm32 bit its for 64bit masm ?

(587): Include File
error A2008: syntax error : &

is the message i got


Mikl__

Hi, drunkenmyno!
It's your own fault. There are no psychics on the forum. For what OS is your program for (DOS, Linux, Win64) intended you must to write yourself and not make others guess. I suggested how to write a program, and the rest you have to do yourself

drunkenmyno

Excuse Me :) my fault.  :undecided:

The Programm is for Windows 32bit .686 

Mikl__

Is this program designed for college or university? Take my program as a basis and write it yourself
The rules of the forum
QuoteThe NO HOMEWORK Rule
9. The forum is a technical help forum for assembler language programmers, it will not be used as a location for grovelling to get someone to do your homework. Members who are learning assembler programming at school or similar are welcome but they must do their own work. In this context they will receive assistance if they need it but any dumping of problems in the forum will be removed. Also note that 16 bit DOS code will be moved to the 16 bit DOS forum as this forum is primarily a 32 bit Windows assembler forum.

jj2007

Hi drunkenmyno,

Welcome to the Forum :thup:

As Mikl has already pointed out, we are not here to do your homework. Below is a snippet that works, but your teacher will not be happy that you are using a Masm32 library function. You need to use your brain to find out how to convert the byte value 4Eh into its string equivalent. Not too difficult, actually, and there is the Forum search, too. Have a look at \Masm32\m32lib\dw2ah.asm, too :bgrin:

Once you have started some serious attempts to solve the mystery, come back, and we'll help you. Please, always post complete code - no snippets. See Tips, Tricks and Traps, "Last but not least" :smiley:

include \masm32\include\masm32rt.inc

.data
MyArray db 4Eh, 0CEh, 078h, 0
TmpBuffer db 10 dup(?)
NameBuffer db 80 dup(?)

.code
start:
  mov esi, offset MyArray ; source
  mov edi, offset NameBuffer ; destination
  push edi
  .While 1
xor eax, eax
lodsb
.Break .if !al
dw2ah PROTO :DWORD, :DWORD ; missing in the includes
invoke dw2ah, eax, offset TmpBuffer
movzx eax, word ptr TmpBuffer[6]
stosw
  .Endw
  pop edi
  MsgBox 0, edi, "Congrats:", MB_OK
  exit

end start

drunkenmyno

Thank for your help but found out already ;D


DoConvert proc hWin:DWORD

xor esi, esi
xor edi , edi
mov edi, 80h

convertName:
mov al, byte ptr ds:[NameBuffer+esi]
invoke wsprintf, addr TempBuffer, addr Format, al
invoke lstrcat, addr HexConvert,addr TempBuffer
inc esi
dec edi
jne convertName


invoke SetDlgItemText,hWin,TXTConverted,addr HexConvert+3


Ret
DoConvert endp


This works but i have a problem with SetDlgItem the Edit box (TXTConverted) is empty but if i debug i see the correct converted string in my variable
has it something todo with the access outside of the main Proc ?

I have defined it in my include file

TXTConverted equ 1012

and i can use SetDlgItemText inside the WinProc when i click on my button but not in another proc

my DoConvert proc is defined as

DoConvert PROTO :DWORD



jj2007

Quote from: drunkenmyno on November 27, 2019, 09:17:01 PM
Thank for your help but found out already ;D

I am pretty sure that your prof will not appreciate that you are using wsprintf :mrgreen:

Quote from: drunkenmyno on November 27, 2019, 09:17:01 PM
has it something todo with the access outside of the main Proc ?

Absolutely no idea!

Quote- Last but not least: A few Rules for the Forum
...
* Post your complete code. Some believe that older members are eager to construct the missing headers around your snippets, but this belief is FALSE

hutch--

 :biggrin:

> Some believe that older members are eager to construct the missing headers around your snippets, but this belief is FALSE   :skrewy:

xandaz

 Aren't we talking about something like:
.data

Number       db      3Ah
hexTable     db      "01234567890ABCDEF"
hexString    db      3 dup(0)
.code

lea       esi,Number
lea       edi,hexString
mov    ecx,2
cld
loop_1:
lodsb
sub     al,30H
xlat
stosb
loop_1
mov    al,'H'
stosb

jj2007

You are close :biggrin:
include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

.data
Number db 0BAh, 0ADh, 0F0h, 00Dh
hexString db 100 dup(?)

.code
hexTable db "0123456789ABCDEF"
start:
mov esi, offset Number
mov edi, offset hexString
mov ebx, offset hexTable
mov ecx, sizeof Number
push edi

@@:
  lodsb
  push eax
  shr eax, 4
  and eax, 15
  xlat
  stosb
  pop eax
  and eax, 15
  xlat
  stosb
loop @B

mov eax, 'H'
stosd
pop edi
inkey edi, " is the result"
exit
end start

xandaz

    Yes JJ. Not close enough. Been long time since i don't program. I'm just glad of being helpful not enough.
    tx