Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active November 17, 2015 12:44
Show Gist options
  • Save bzdgn/daf302dfdf832f2dc42c to your computer and use it in GitHub Desktop.
Save bzdgn/daf302dfdf832f2dc42c to your computer and use it in GitHub Desktop.
C Inline Asm Printf Example For Visual Studio #2
#include <stdio.h>
// function declarations
void printInteger(int *, char[]);
void printIntegerValue(int, char[]);
void printOneString(char[], char[]);
// implementations
void printInteger(int *number, char printFormat[])
{
__asm
{
mov eax, number
mov ebx, [eax]
push ebx
mov eax, printFormat
push eax
call printf
pop ebx
pop ebx
}
}
void printIntegerValue(int number, char printFormat[])
{
int *address = &number;
__asm
{
mov eax, address
mov ebx, [eax]
push ebx
mov eax, printFormat
push eax
call printf
pop ebx
pop ebx
}
}
void printOneString(char string[], char printFormat[])
{
__asm
{
mov eax, string
push eax
mov eax, printFormat
push eax
call printf
pop ebx
pop ebx
}
}
// main
void main()
{
char printFormat1[] = "Deger: %x\n";
char printFormat2[] = "Deger: %s\n";
int i = 0x12345678;
char str[] = "En buyuk fener!";
printInteger(&i, printFormat1);
printIntegerValue(i, printFormat1);
printOneString(str, printFormat2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment