HELLO WORLD C++/ASM

The most standard program is obviously Hello World that almost every programming language supports. This code is standard win32.

Microsoft does not support this technique with AMD64 where more C++ intrinsics are supplied to allow developers to use advanced CPU features.

// InlineAssembler_Calling_C_Functions_in_Inline_Assembly.cpp
#include <stdio.h>
char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
int main( void ) {
     __asm {
         mov eax, offset world
         push eax
         mov eax, offset hello
         push eax
         mov eax, offset format
         push eax
         call printf
         //clean up the stack so that main can exit cleanly
         //use the unused register ebx to do the cleanup
         pop ebx
         pop ebx
         pop ebx
    }
}

This code example shows how pointers to containers in C++ can used in a CPU register to call the printf function using assembler. Printf is one of the functions in the standard runtime packages used with Visual Studio.

The code example shows the proper technique to clear the stack before returning.

LEGACY

The C programming language came to the PC during the MS-DOS era. The segmented memory of the 8088 CPU make it hard for compilers to cope with larger projects. Once the 80386 CPU was released the flat memory space make it far easier for developing larger programs. The move to 32-bit with the improved memory management allowed developers the freedom to develop many of the programs that are now widely available.