Click to See Complete Forum and Search --> : how to pop a "hello world!"messagebox?


smallwolf
July 18th, 2010, 06:02 PM
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!



#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;
}

Eri523
July 25th, 2010, 12:02 AM
Well, I don't know wxDevC++, but this is how I did it in MS VC++ (Unicode project):


#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()!? :eek: 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? :ehh:

HTH

Bluefox815
July 31st, 2010, 07:15 AM
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? :ehh:

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).

Eri523
July 31st, 2010, 05:01 PM
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++... :cool: