Last active
June 22, 2019 01:19
-
-
Save bzdgn/72741b4d3e41d4a0b392 to your computer and use it in GitHub Desktop.
C Inline Asm Printf Example For Visual Studio
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 *); | |
void printIntegerValue(int); | |
void printOneString(char []); | |
char printFormat1[] = "Deger: %x\n"; | |
char printFormat2[] = "Deger: %s\n"; | |
void printInteger(int *number) | |
{ | |
__asm | |
{ | |
mov eax, number | |
mov ebx, [eax] | |
push ebx | |
mov eax, offset printFormat1 | |
push eax | |
call printf | |
pop ebx | |
pop ebx | |
} | |
} | |
void printIntegerValue(int number) | |
{ | |
int *address = &number; | |
__asm | |
{ | |
mov eax, address | |
mov ebx, [eax] | |
push ebx | |
mov eax, offset printFormat1 | |
push eax | |
call printf | |
pop ebx | |
pop ebx | |
} | |
} | |
void printOneString(char string[]) | |
{ | |
__asm | |
{ | |
mov eax, string | |
push eax | |
mov eax, offset printFormat2 | |
push eax | |
call printf | |
pop ebx | |
pop ebx | |
} | |
} | |
void main() | |
{ | |
int i = 0x12345678; | |
char str[] = "En buyuk fener!"; | |
printInteger(&i); | |
printIntegerValue(i); | |
printOneString(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment