Jump to content

display a number in msgbox

- - - - -

  • Please log in to reply
8 replies to this topic

#1
7marco08

7marco08

    Newbie

  • Members
  • Pip
  • 2 posts
hello,
my name is marco, i'm new in win asm and i ask if someone can help me,
i want to do arithmetic operation and here no problem,but i want to display the result in a message box or dialog box and i can't do it.
i have tried with str$ or dwtoa but the first is not regognized in win asm and dwtoa give an ascii string not the value.
can someone give me the solution?
thanks in advance!

#2
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
I am sure the mods will move this to the ASM forum not tutorials, but to answer you anyways... You have a number and want to display it in a message box? Well you have to convert it first to an ascii string which dwtoa does...

So, how would this not work?
    xor        eax, eax
    add        eax, 10
    
    invoke    dwtoa, eax, offset lpNum    
    invoke    MessageBox, NULL, offset lpNum, NULL, MB_OK


#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US

Quote

    xor        eax, eax

    add        eax, 10

    

    invoke    dwtoa, eax, offset lpNum    

    invoke    MessageBox, NULL, offset lpNum, NULL, MB_OK
Be careful about using EAX with INVOKE.

If you use EAX with INVOKE while one of the arguments is an ADDR, MASM32 will complain.

#4
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Not really.... If eax is BEFORE addr then yes, eax will get over written IF addr is referencing a local.... IF NOT then no problems. NO PROBS using OFFSET or ADDR if it is NOT a local.... I only use ADDR where it is needed really for LOCALS

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US

Quote

Not really.... If eax is BEFORE addr then yes, eax will get over written IF addr is referencing a local.... IF NOT then no problems. NO PROBS using OFFSET or ADDR if it is NOT a local.... I only use ADDR where it is needed really for LOCALS
Well, yeah. I was just saying to be careful. Anyway, MASM32 would notify you if that's the case.

#6
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Better? :P

     push    ebp
    mov     ebp, esp
    sub     esp , 10

    xor		eax, eax
    add		eax, 10
    
    push	ebp
    push	eax
    call	dwtoa
    
    push	MB_OK
    push	NULL
    push	ebp
    push	NULL
    call	MessageBox
    add		esp, 10
    pop		ebp


#7
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Yeah, but this is the syntax I'm used to:
enter 10, 0 


xor eax, eax 

add eax, 10 


push dword ptr offset someStr 

push eax 

call dwtoa 


push dword ptr 0 

push dword ptr 0 

push dword ptr offset someStr 

push dword ptr 0 

call MessageBox 


leave 


#8
7marco08

7marco08

    Newbie

  • Members
  • Pip
  • 2 posts
thank you very much it works now!
only another question please...is correct if i have two edit box where i type numbers and i use atodw to convert and add the numbers?

#9
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
Well, as long as it works, and does what it's supposed to, it should be okay.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users