Last active
November 17, 2015 12:44
-
-
Save bzdgn/daf302dfdf832f2dc42c to your computer and use it in GitHub Desktop.
C Inline Asm Printf Example For Visual Studio #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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