5 void sprintn ( unsigned int num
, int base
);
6 void sputchar (char car
);
7 char getascii (char c
);
9 #define _syscall0(numero,retorno) __asm__ __volatile__ ("int $0x50" : "=a" (retorno) : "a" (numero))
10 #define _syscall1(numero,retorno,param1) __asm__ __volatile__ ("int $0x50" : "=a" (retorno) : "a" (numero), "b" (param1))
11 #define _syscall2(numero,retorno,param1,param2) __asm__ __volatile__ ("int $0x50" : "=a" (retorno) : "a" (numero), "b" (param1), "c" (param2))
14 int sleep(int segundos
)
18 _syscall1( SYS_TIMER
| SYS_SLEEP
, retorno
, segundos
);
23 int exec (char *tarea
)
25 __asm__
__volatile__ ("movl %0, %%eax ; movl %1, %%ebx" : : "g" (SYS_PROCESS
| SYS_EXEC
) , "g" (tarea
) : "eax" , "ebx");
26 __asm__
__volatile__ ("int $0x50");
29 __asm__
__volatile__ ("movl %%eax, %0" : "=g" (retorno
) );
38 __asm__
__volatile__ ("movl %0, %%eax ; movl %1, %%ebx" : : "g" (SYS_CONSOLE
| SYS_GETS
) , "g" (str
) : "eax" , "ebx" );
39 __asm__
__volatile__ ("int $0x50");
45 __asm__
__volatile__ ("movl %0, %%eax" : : "g" (SYS_PROCESS
| SYS_FORK
) : "eax");
46 __asm__
__volatile__ ("int $0x50");
52 __asm__
__volatile__ ("movl %0, %%eax" : : "g" (SYS_PROCESS
| SYS_VOID
) : "eax");
53 __asm__
__volatile__ ("int $0x50");
57 // Funcion de libraria "putchar"
58 int putchar (char car
)
66 // llamada al sistema (similar a write pero hacia stdout)
70 __asm__
__volatile__ ("movl %0, %%eax ; mov %1, %%ebx ; mov %2, %%ecx" : : \
71 "g" (SYS_CONSOLE
| SYS_PRINT
), "g" (str
), "g" (strlen(str
)) : "eax", "ebx", "ecx" );
73 __asm__
__volatile__ ("int $0x50");
78 __asm__
__volatile__ ("movl %0, %%eax" : : "g" (SYS_CONSOLE
| SYS_CLRSCR
));
79 __asm__
__volatile__ ("int $0x50");
82 #define MAX_STRING 100
85 char string_stdio
[MAX_STRING
];
87 void sputchar (char car
)
89 string_stdio
[sposicion
] = car
;
90 string_stdio
[++sposicion
] = '\0';
93 void printf ( char *stri
, ...)
105 va_start(argumentos
, stri
);
107 for ( p
=stri
; *p
; p
++ ) {
116 car
=va_arg(argumentos
, int);
117 sputchar( (char) car
);
121 i
= va_arg(argumentos
, unsigned int );
126 i
= va_arg(argumentos
, unsigned int);
131 i
= va_arg(argumentos
, unsigned int);
136 d
= va_arg(argumentos
, char *);
137 strcat(string_stdio
, d
);
138 sposicion
= sposicion
+ strlen(d
);
154 void sprintn( unsigned int num
, int base
)
157 if ( (div
=num
/base
) )
159 sputchar( getascii(num
%base
) );
165 //****************************************************************************************************
166 // printf ( char *string, ...) y funciones requeridas por ella
167 //****************************************************************************************************
169 char getascii_ ( char c );
170 void printn_ ( unsigned int num, int base);
172 void printf ( char *string, ...)
184 va_start(argumentos, string );
186 for ( p=string; *p ; p++ ) {
195 car=va_arg(argumentos, int);
196 putchar( (char) car);
200 i = va_arg(argumentos, unsigned int );
205 i = va_arg(argumentos, unsigned int);
210 i = va_arg(argumentos, unsigned int);
215 d = va_arg(argumentos, char *);
229 void printn_ ( unsigned int num, int base)
232 if ( (div=num/base) ) printn_(div,base);
233 putchar( getascii_(num%base) );
236 char getascii ( char c
)
238 char valor
= '0' + c
;
240 if ( valor
> '9' ) valor
+= 7;