Created
October 30, 2017 22:43
-
-
Save Et7f3/176c44d94d6de80e26e20868e5689632 to your computer and use it in GitHub Desktop.
implementation de printf
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 <stdarg.h> | |
void format(char * f, va_list ap); | |
int printf(char *f,...){ | |
va_list ap; | |
va_start(ap, f); | |
char retour asm ("reto");/* point de retour*/ | |
asm("push %eipd\r\npop reto");//on affecte la valeur à reto | |
format(f,ap); | |
va_end(ap); | |
} | |
void format(char * f, va_list ap){ | |
while(*f){ | |
if (*f!='%'){ | |
asm("push %0": : "r" (*f)); | |
}else | |
if(*(f+1)=='s'){//juste s sans traiter length | |
char * c = &(va_arg(ap, char)); | |
while(*c){ | |
asm("push %0": : "r" (*c)); | |
c++; | |
} | |
f++; | |
} | |
} | |
asm volatile("mov %ebp %esp"); | |
asm volatile("add $12, reto") | |
asm volatile("mov reto, %eip"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment