Ok it works but what's with the mov esi, esp thing?
>>add esp, 4
That would be the stack clean up am I right?
thanks :)
Main Topics
Browse All TopicsHello experts
I'm trying to use standart C functions from the VC inline assembler but the program crashes at run time.
Here is the code:
#include <stdio.h>
char hello[] = "Hello";
void main(void)
{
__asm
{
mov eax, offset hello
push eax
call puts
pop ebx
}
}
Links to good tutorials on inline assembler in VC would be appreciated too.
thanks in advance
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Looking at your code, I see that you use incorrect calling convention. puts function is defined as:
int __cdecl puts(__in_z const char * _Str);
__cdecl calling convention description:
http://msdn2.microsoft.com
"Calling function pops the arguments from the stack" - this is add esp, 4
mov esi,esp
I guess this is function return address. Read details here:
http://webster.cs.ucr.edu/
You can learn many things reading C++ compiler output. To get more details, read "Art of Assembly Language" book, 16-bits Edition, this is core Assembly, and make correction for 32-bits edition.
Business Accounts
Answer for Membership
by: AlexFMPosted on 2006-09-19 at 07:01:32ID: 17551931
char hello[] = "Hello";
sj/0298/ho od0298.asp x
int _tmain(int argc, _TCHAR* argv[])
{
__asm
{
mov esi,esp
push offset hello
call dword ptr [puts]
add esp,4
}
return 0;
}
http://www.microsoft.com/m
__asm block is copied from C++ code produced by compiler:
puts(hello);
004113AE mov esi,esp
004113B0 push offset hello (417000h)
004113B5 call dword ptr [__imp__puts (4182B8h)]
004113BB add esp,4