News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

add eax,1 add ebx,1 add eax,ebx= weird character

Started by shadow, March 19, 2005, 04:10:41 AM

Previous topic - Next topic

shadow

Ok i know there's something I missed here... Why is it that when I do this....


                xor eax,eax
                xor ebx,ebx
add eax,1
add ebx,1
add eax,ebx
mov test1,eax
invoke MessageBox,NULL,addr test1,addr test1,MB_OK


I get a box (strange character) instead of 2?  hehe just starting out here as you can tell!... Thanks!  :green

Petroizki

The number '2' is not showing because it's ASCII code is actually 50, and not 2, you can find the ASCII codes from the Windows 'Character Map' program.

shadow


Petroizki

It can be done like this:
.data
test1 db '2', 0
.code
...
invoke MessageBox, NULL, ADDR test1, ADDR test1, MB_OK


The MessageBox expects null-terminated string, so you can't directly use integer values. If you want to display integer values in your message box, you must convert it to ascii string first. This can be done with 'dwtoa' function found from the MASM32 library:


.data?
MyString db 32 dup (?) ; empty 32 byte string
.code
...
mov eax, 2 ; eax holds the number you want to convert into ascii
invoke dwtoa, eax, ADDR MyString ; converts the value into ascii
invoke MessageBox, NULL, ADDR MyString, ADDR MyString, MB_OK


Mark Jones

Hi. Another method is to use the STR$ macro from macros.asm. Try these:


include macros.asm
include masm32.inc
includelib masm32.lib

.Data
szTitle DB "Test!", 0

.Code
xor eax,eax
Add Eax, 10457192  ; some big number
Invoke MessageBox, hWnd, str$(Eax), Addr szTitle, MB_OK
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Rainstorm

hi

Petroizki wrote..
Quote.data?
MyString db 32 dup (?) ; empty 32 byte string
.code
...
mov eax, 2 ; eax holds the number you want to convert into ascii
invoke dwtoa, eax, ADDR MyString ; converts the value into ascii
invoke MessageBox, NULL, ADDR MyString, ADDR MyString, MB_OK

when i run this code after running, I get the error message from windows saying
app.exe has encountered a problem & needs to close...etc
the dialogue where it has a button to send the error report to microsoft

the error dialogue comes up after I press 'OK' & have done away with the message box window.

am using Winxp Pro SP2  & a P4

ty
-

Petroizki

Hi Rainstorm,

It seems like the prog crashes after the code, you may have forgotten a 'ret' or similar from the end of your program. Post the source code, if you have more problems.

Rainstorm

hi petroizki.

here's the code.
Quote
    .486                                ; create 32 bit code
    .model flat, stdcall                ; 32 bit memory model
    option casemap :none                ; case sensitive
 
    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
   
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\Comctl32.inc
    include \masm32\include\comdlg32.inc
    include \masm32\include\shell32.inc
    include \masm32\include\oleaut32.inc
    include \masm32\include\msvcrt.inc
    include \masm32\macros\macros.asm

    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\Comctl32.lib
    includelib \masm32\lib\comdlg32.lib
    includelib \masm32\lib\shell32.lib
    includelib \masm32\lib\oleaut32.lib
    includelib \masm32\lib\msvcrt.lib

    .data?
MyString db 32 dup (?) ; empty 32 byte string

    .data


    .code

start:

mov eax, 2 ; eax holds the number you want to convert into ascii
invoke dwtoa, eax, ADDR MyString ; converts the value into ascii
invoke MessageBox, NULL, ADDR MyString, ADDR MyString, MB_OK
 

end start

thanks.

sinsi

After the "invoke MessageBox ..." you need "invoke ExitProcess,0"
Light travels faster than sound, that's why some people seem bright until you hear them.

Rainstorm


Rainstorm

if the dword value corresponds to a letter, how do i display that ?
it justs seems to show the ascii number, like i keep getting 72 the ascii value for 'H'


    .data

MsgBoxTitle  db  "Assembly msgbox",0
total db 100 dup(0)
;      tt dd 0
; OR tt dd "H"
   
    .code

start:

mov tt, "H"


invoke dwtoa,tt,addr total
;invoke udw2str,tt,addr total

    invoke MessageBox, NULL,addr total,addr MsgBoxTitle, MB_OK
    invoke ExitProcess, NULL

end start


I could use $chr to directly out put the string, but that's not what i mean.
    invoke MessageBox, NULL,chr$("H"),addr MsgBoxTitle, MB_OK

is there any other way to do it ?

gabor

Hi!

I don't want to be mean or rude, but this question about displaying numbers or letters is not new on the forum. So, I have two things to say:
- before posting a question please make a search
- before doing anything please learn the basic stuff, there are many great tutorials...
Representing numbers and characters is basic theory indeed. When people ask questions about the fundamentals stuff -I may be discriminative- I cannot think of anything else, but homework assignments. And displaying characters is a very frequent homework...
This was just thinking aloud, I don't suspect anybody, just ask to consider this!

Greets, Gábor

hutch--

Try this, what you are after is very simple.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL buffer[16]:BYTE           ; a string buffer to write to
    LOCAL pbuf  :DWORD              ; a pointer variable for the buffer

    lea eax, buffer                 ; load the effective address of buffer into EAX
    mov pbuf, eax                   ; store it in the pointer variable.

    mov ecx, 1  ; 2345678           ; put a number into ECX

    invoke dwtoa,ecx,pbuf           ; convert it to string

    fn MessageBox,0,pbuf,"Title",MB_OK

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm

hi.

Gabor, about doing a search,...actually i have done a search & this post itself is an old post from a search I have done.
about reading up.. i have read some..& the stuff i've read..usually has a string declared in the .data section & the address of the variable  directly outputs the number in the messagebox.
the last  2 weeks  havng more time available i have started reading again.(quite a bit)
- I play around with stuff & for me that's a way of learning.. its fun too that way.
I do & try stuff as I read,..& post if I have a query. - If you choose to be discriminatory for any reason
that's fine with me, I understand your point of view.

Lastly,..am not in school.

In my post, was asking if there is an alternate way to do that, a conversion,
& the last line of the post is one way i know to do it.

Rainstorm.

_