Does anyone know why this does not seem to work?


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\INCLUDE\windows.inc
INCLUDE \masm32\INCLUDE\kernel32.inc
INCLUDE \masm32\INCLUDE\user32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\INCLUDE\masm32.inc
INCLUDELIB \masm32\lib\masm32.lib

.DATA

MyDecimalString DB "Hello Cruel World",0
ok db "ok",0

.DATA?


.CODE

atodw proc String:DWORD

; ----------------------------------------
; Convert decimal string into dword value
; return value in eax
; ----------------------------------------

push esi
push edi

xor eax, eax
mov esi, [String]
xor ecx, ecx
xor edx, edx
mov al, [esi]
inc esi
cmp al, 2D
jne proceed
mov al, byte ptr [esi]
not edx
inc esi
jmp proceed

@@:
sub al, 30h
lea ecx, dword ptr [ecx+4*ecx]
lea ecx, dword ptr [eax+2*ecx]
mov al, byte ptr [esi]
inc esi

proceed:
or al, al
jne @B
lea eax, dword ptr [edx+ecx]
xor eax, edx

pop edi
pop esi

ret

atodw endp

START:
invoke atodw,ADDR MyDecimalString
invoke MessageBox,0,addr ok,0,0 <<-- I use this to error check
invoke MessageBox,0,eax,0,0 <---This is where the proggie is having problems..
invoke ExitProcess,NULL
END START


It translates ok but when it goes to display the results it returns an error...I tried displaying the results as the heading of the dialog box, changing .386 to .686, practically everything I know trying to make it work but it doesnt..Any ideas?

Thx
RIF
Posted on 2002-11-02 14:04:20 by resistance_is_futile
1) You're converting a string "Hello cruel world" to a dword. atodw converts strings with numbers in them, like "2371" and such to values that can be manipulated.

2) You're sending a value to MessageBox(). MessageBox() is expecting a string, so it's treating your value as a pointer to a string. This is bad. ;)

3) You pass eax as a parameter, but eax is the return value of the preceding call to MessageBox.

If your goal is to display "Hello Cruel World" in a message box then you don't need any sort of conversion. Just pass MessageBox() a pointer to your string. i.e:
 invoke MessageBox 0, addr myString, 0, MB_OK


Good luck
Posted on 2002-11-02 14:24:35 by iblis
Well how would I go about converting the ascii (string) to hex? Anyone know? Im not just trying to show a message in a box but convert the string to hex then display it in a box.
Posted on 2002-11-02 14:28:00 by resistance_is_futile
Why are you trying to convert "Hello Cruel World" to hex? :confused:


I think what you want to do is convert a numeric value to a string, and then show the string in a MessageBox. You'll need dw2a for that.

[size=12]

.data
strBuffer db 12 dup(0)
...

.code
...
mov eax, 1234
invoke dw2a, eax, addr strBuffer
invoke MessageBox, 0, addr strBuffer, 0, MB_OK
...[/size]
Posted on 2002-11-02 14:30:50 by iblis
What you (probably) need is to convert a number like 0F3D44 to a string like "0F3D44". You may proceed nibble by nibble, storing the result in a buffer. If al contains 0Fh, then:

cmp al, 10
sbb al, 69h
das

al will be containing 46h, which is "F"
Posted on 2002-11-02 14:41:23 by micmic
lol I want to convert what the user enters as his name into hex. Say he puts in Jim Haun as his name. I want to convert that to hex. can this even be done is asm?
Posted on 2002-11-02 15:02:01 by resistance_is_futile
You're trying to generate a CRC of some sort? You're trying to tokenize the string? Explain precisely what you want to do.
Posted on 2002-11-02 15:19:03 by iblis
1. User types in name. Put in a buffer
2. User types in serial. put in a buffer
3. User presses "register" button
4. Program counts how many letters are in users name
5. Program converts users name to hex
6. Program takes each hex and multiplies it by the number of letters in users name
7. Take the result and put in buffer
8. compare result with user serial
9. if equal register proggie
10. if not equal display bad message
Posted on 2002-11-02 15:34:01 by resistance_is_futile
Hello all,

maybe RIF want to make this (don't know :)):


KRoutine proc
LOCAL strl : DWORD
pusha
invoke GetWindowTextLength,hEditName
.if eax < 1
invoke SetWindowText,hEditOutput,ADDR szShortName
popa
ret
.endif
invoke GetWindowText,hEditName,ADDR szName, 101
mov strl, eax
mov szOutput, 0
xor eax, eax
xor esi, esi
_loop:
add esi, 1
mov ebx, [offset szName]
movzx ebx, byte ptr [ebx+esi-1]
invoke wsprintf,ADDR szTemp, ADDR szHexFormat, ebx
invoke lstrcat, ADDR szOutput, ADDR szTemp
cmp esi, strl
jnz _loop

invoke SetWindowText, hEditOutput, ADDR szOutput

popa
ret
KRoutine endp




sF
Posted on 2002-11-02 15:52:38 by stealthFIGHTER

5. Program converts users name to hex



Conversion is already done for you.
Each character in a string is stored as an 8 bit value.

[size=12]myString db "Hello World", 0[/size]

is the same thing as:
[size=12]myString db 48h, 65h, 6Ch, 6Ch, 6Fh, 20h, 57h, 6Fh, 72h, 6Ch, 64h, 0[/size]


Just loop through the string and do your multiplications on each alpha.
Posted on 2002-11-02 16:15:07 by iblis
Yea, I'm confused too when you say you want to convert the user name to hex. Remember, hex is just a shorthand way of displaying 4 binary bits as a single "digit", or an 8 bit binary byte as a pair of "digits". Unless iblis answered the question, I'm don't know what you're trying to do... :)
Posted on 2002-11-02 16:43:02 by S/390
yea he did thx for all the input though. Im a little confuse on how im going to loop through the string to get all the letters multiplied...lol Any help on that is appreciated as well..
Posted on 2002-11-02 19:25:02 by resistance_is_futile


.data
MsgTitle db 'Below you can see me in hex',0
hxtbl db '0123456789ABCDF',0
.data?
MsgText db 64 dup (?)
.code
mov esi,offset MsgTitle
mov edi,offset MsgTxt
xor eax,eax
xor ebx,ebx
@@:
mov al,[esi]
mov bl,[esi]
inc esi
test al,al
je @F
and al,0fh
shr bl,4
mov al,hxtbl[eax]
mov bl,hxtbl[ebx]
mov al,[edi+1]
mov bl,[edi]
add edi,2
jmp @B
@@:
mov byte ptr [edi],al
invoke MessageBox,0,offset MsgTxt,offset MsgTitle,0
Posted on 2002-11-02 20:59:15 by The Svin
umm this code:


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\INCLUDE\windows.inc
INCLUDE \masm32\INCLUDE\kernel32.inc
INCLUDE \masm32\INCLUDE\user32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\INCLUDE\masm32.inc
INCLUDELIB \masm32\lib\masm32.lib

.data
MsgTitle db 'Below you can see me in hex',0
hxtbl db '0123456789ABCDF',0

.data?
MsgText db 64 dup (?)

.code
start:
mov esi,offset MsgTitle
mov edi,offset MsgTxt
xor eax,eax
xor ebx,ebx
@@:
mov al,[esi]
mov bl,[esi]
inc esi
test al,al
je @F
and al,0fh
shr bl,4
mov al,hxtbl[eax]
mov bl,hxtbl[ebx]
mov al,[edi+1]
mov bl,[edi]
add edi,2
jmp @B
@@:
mov byte ptr [edi],al
invoke MessageBox,0,offset MsgTxt,offset MsgTitle,0
end start


gives out this error



Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: c:\masm32\ascii2hex.asm
c:\masm32\ascii2hex.asm(40) : error A2006: undefined symbol : MsgTxt
c:\masm32\ascii2hex.asm(40) : error A2114: INVOKE argument type mismatch : argum
ent : 2
c:\masm32\ascii2hex.asm(21) : error A2006: undefined symbol : MsgTxt
_
Assembly Error
Press any key to continue . . .

using masm
Posted on 2002-11-02 21:11:32 by resistance_is_futile
RIF,

Hum... what could an error at line 40 & 21 saying that MsgTxt is undefined mean ?

:rolleyes:

It's not that hard... Look over that little piece of code and try to figure it out.
Posted on 2002-11-02 21:25:30 by JimmyClif
There are some errors in the function.
I guess correct one is below




.data
MsgTitle db 'Below you can see me in hex',0
hxtbl db '0123456789ABCD[B]E[/B]F',0
.data?
MsgText db 64 dup (?)

.code
mov esi,offset MsgTitle
mov edi,offset MsgText
xor eax,eax
xor ebx,ebx

@@:
mov al,[esi]
mov bl,[esi]
inc esi
test al,al
je @F
and al,0fh
shr bl,4
mov al,hxtbl[eax]
mov bl,hxtbl[ebx]
mov [edi+1],al ;here
mov [edi],bl ; and here
add edi,2
jmp @B
@@:
mov byte ptr [edi],al
Posted on 2002-11-03 06:57:01 by LaptoniC
lol sorry for all my retarded questions guys...I think its my lack of sleep..Oh well anyway, I got the proggie working but the only problem is after it is done running, I get an error?? Its really weird because it works perfect but after I close the messagebox it says it has encountered an error...umm I think it may be the fact that its running out of a message box..anyone else have any comments on this? heres the working code:


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\INCLUDE\windows.inc
INCLUDE \masm32\INCLUDE\kernel32.inc
INCLUDE \masm32\INCLUDE\user32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\INCLUDE\masm32.inc
INCLUDELIB \masm32\lib\masm32.lib

.data
MsgTitle db 'Welcome',0
hxtbl db '0123456789ABCDEF',0
.data?
MsgText db 64 dup (?)

.code
start:
mov esi,offset MsgTitle
mov edi,offset MsgText
xor eax,eax
xor ebx,ebx

@@:
mov al,
mov bl,
inc esi
test al,al
je @F
and al,0fh
shr bl,4
mov al,hxtbl
mov bl,hxtbl
mov ,al ;here
mov ,bl ; and here
add edi,2
jmp @B
@@:
mov byte ptr ,al
invoke MessageBox,0,offset MsgText,offset MsgTitle,0

end start
Posted on 2002-11-03 13:05:40 by resistance_is_futile
sorry for all my retarded questions...I think its the fact that I dont sleep much...okay well heres the code. After I close it, it says the program has cause an error..any comments?


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\INCLUDE\windows.inc
INCLUDE \masm32\INCLUDE\kernel32.inc
INCLUDE \masm32\INCLUDE\user32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\INCLUDE\masm32.inc
INCLUDELIB \masm32\lib\masm32.lib

.data
MsgTitle db 'Hello Cruel World',0
hxtbl db '0123456789ABCDEF',0
.data?
MsgText db 64 dup (?)

.code
start:
mov esi,offset MsgTitle
mov edi,offset MsgText
xor eax,eax
xor ebx,ebx

@@:
mov al,[esi]
mov bl,[esi]
inc esi
test al,al
je @F
and al,0fh
shr bl,4
mov al,hxtbl[eax]
mov bl,hxtbl[ebx]
mov [edi+1],al ;here
mov [edi],bl ; and here
add edi,2
jmp @B
@@:
mov byte ptr [edi],al
invoke MessageBox,0,offset MsgText,offset MsgTitle,0

end start
Posted on 2002-11-03 13:06:59 by resistance_is_futile
You need:

invoke ExitProcess, 0

before end start.
Posted on 2002-11-03 13:49:41 by roaknog
ok thx...Yea I fixed the problem like right before you replied lol...Umm does anyone know how to compare two buffers? I know thisis off the subject but I figured instead of starting another thread I would ask in this one. I want to compare the Serial buffer with the MsgFinal3 buffer (these are buffers in my current program and I want to compare the two and if they equal display a good message else display a bad message). I figured this would work:


.if Serial == MsgFinal3
invoke MessageBox,hWin,addr goodtxt,addr goodcap,MB_OK
.else
invoke MessageBox,hWin,addr badtxt,addr badcap, MB_OK
.endif


but that didnt work. I dont think using cmp would work either..any suggestions?

RIF
Posted on 2002-11-03 13:54:25 by resistance_is_futile