aboutsummaryrefslogtreecommitdiff
path: root/printf.c
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2014-05-03 06:32:45 +0800
committerTeddy <ted.sybil@gmail.com>2014-05-03 06:32:45 +0800
commitb6e7af77a5b8f0952eba93ac722bed2af318493f (patch)
tree0edf09ac3f416dd1b717bba816ce72b3b5e82e37 /printf.c
parent0321883dc1ec526d01fb45a75a9239e97120e9c0 (diff)
add librariesmips
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/printf.c b/printf.c
new file mode 100644
index 0000000..7c9cf3a
--- /dev/null
+++ b/printf.c
@@ -0,0 +1,32 @@
+int printf(char *fmt) {
+ char *arg, ch;
+ arg = (int)&fmt + sizeof(char*);
+ while ((ch = *fmt))
+ {
+ if (ch == '%')
+ {
+ ch = *(++fmt);
+ if (ch == 'd')
+ __print_int(*(int *)arg);
+ else if (ch == 'c')
+ __print_char(*(char *)arg);
+ else if (ch == 's')
+ __print_string(*(char **)arg);
+ else
+ {
+ int len, x = *(int *)arg;
+ if (!x) len = 1;
+ else
+ for (len = 0; x; x /= 10, len++);
+ len = 4 - len;
+ while (len) __print_char('0'), len--;
+ __print_int(*(int *)arg);
+ fmt += 2;
+ }
+ arg += 4;
+ }
+ else __print_char(ch);
+ fmt++;
+ }
+}
+