Skip to content

Instantly share code, notes, and snippets.

@Et7f3
Created October 30, 2017 22:43
Show Gist options
  • Save Et7f3/176c44d94d6de80e26e20868e5689632 to your computer and use it in GitHub Desktop.
Save Et7f3/176c44d94d6de80e26e20868e5689632 to your computer and use it in GitHub Desktop.
implementation de printf
#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