CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Location
    San Francisco, USA
    Posts
    24

    how to pop a "hello world!"messagebox?

    hello:
    i am a beginner in assembly,and i can't wait to test some code. i want to write a simple "hello world" program using inline assembly, how can i pass the string argument to the MessageBoxA()?
    if i pass all the NULL value, it works,but not what i want.
    i am using wxDevC++7.0, windows xp sp3. thanks, have a good day!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    int main(int argc, char *argv[])
    {
       LPCTSTR user32="user32.dll";
       HMODULE hd=LoadLibrary(user32);
       if(hd)
            printf("User32.dll is loaded!\n");
            
            //0x7e4507ea is the address of MessageBoxA
            
        __asm__(
         
             
             "xor %eax,%eax\n"
             "xor %ebx,%ebx\n"
             "mov $0x7e4507ea,%ebx\n"
             "push %eax\n"
             "push %eax\n"
             "push %eax\n"
             "push %eax\n"
             "call %ebx\n"
                 
                 
                 );
      
      
      
      system("PAUSE");	
      return 0;
    }

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: how to pop a "hello world!"messagebox?

    Well, I don't know wxDevC++, but this is how I did it in MS VC++ (Unicode project):

    Code:
     
    #include "stdafx.h"
    #include <Windows.h>
     
    const _TCHAR achMessage[]=_T("Hello world!");
     
    int _tmain(int argc, _TCHAR* argv[])
    {
      __asm {
        xor  eax,eax
        push eax
        push eax
        push offset achMessage
        push eax
        call dword ptr [MessageBox]
      }
      return 0;
    }
    As to your code: Hardcoding the address of the MessageBox() function is pretty dangerous! How can you rely on it always being located at the same address, especially when importing it using LoadLibrary()!? And why do you zero out EBX just before loading it with an immediate value in the next instruction? This is as redundant as can be.

    BTW: The assembly syntax used by your compiler is pretty unusual and definitely non-Intel! How come they use such a home-grown syntax? Could it be they would have needed a pretty expensive license from Intel to use the standard syntax?

    HTH

    Last edited by Eri523; July 27th, 2010 at 08:18 PM.

  3. #3
    Join Date
    Jun 2008
    Location
    Oregon, USA
    Posts
    63

    Re: how to pop a "hello world!"messagebox?

    Quote Originally Posted by Eri523 View Post
    BTW: The assembly syntax used by your compiler is pretty unusual and definitely non-Intel! How come they use such a home-grown syntax? Could it be they would have needed a pretty expensive license from Intel to use the standard syntax?

    HTH
    The syntax he's using is the AT&T syntax, which is the only syntax I know of besides Intel. I do not believe any license is required to implement the Intel syntax, many compilers recognize it. But I could be wrong.

    The AT&T syntax has been choice for GNU applications I've seen, such as their assembler (gas) and for inline assembly in their C compiler (gcc).

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: how to pop a "hello world!"messagebox?

    Quote Originally Posted by Bluefox815 View Post
    The syntax he's using is the AT&T syntax, which is the only syntax I know of besides Intel. I do not believe any license is required to implement the Intel syntax, many compilers recognize it. But I could be wrong.
    No, knowing that now, I don't think you're wrong. AT&T is a mighty company by itself, and they certainly don't have to bother paying some bucks to Intel for an assembly syntax license.

    In fact I never heard that anyone had to pay any license fee for any assembler syntax at all, I was just wondering about that syntax I never saw yet.

    If it's the AT&T syntax, I don't have to wonder any longer why so many C++ compilers use it: You certainly know that it's AT&T that stands behind Bjarne Stroustrup, and that Bjarne Stroustrup is the guy who stands behind the initial design of C++...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured