diff options
author | dzwdz | 2021-10-06 06:43:27 +0000 |
---|---|---|
committer | dzwdz | 2021-10-06 06:43:27 +0000 |
commit | a41f08402e78e9066551d72a9835a352db4069e4 (patch) | |
tree | 8367a65b7c74de8fb938f7def4328c45ceff8fa5 /src | |
parent | 44d308149282debf314cb48789b9084767c1c288 (diff) |
init printf: implement %x
Diffstat (limited to 'src')
-rw-r--r-- | src/init/main.c | 2 | ||||
-rw-r--r-- | src/init/stdlib.c | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/init/main.c b/src/init/main.c index 7c827eb..2029bc9 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -29,7 +29,7 @@ int main(void) { fs_test(); test_await(); - printf("%s\n", "printf test"); + printf("%s %x\n", "printf test", 0xACAB1312); char c; while (_syscall_read(tty_fd, &c, 1, 0)) diff --git a/src/init/stdlib.c b/src/init/stdlib.c index 876c74c..a60854b 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -42,6 +42,21 @@ int printf(const char *fmt, ...) { _syscall_write(0, s, strlen(s), 0); total += strlen(s); break; + + case 'x': + unsigned int n = va_arg(argp, int); + size_t i = 4; // nibbles * 4 + while (n >> i && i < (sizeof(int) * 8)) + i += 4; + + while (i > 0) { + i -= 4; + char h = '0' + ((n >> i) & 0xf); + if (h > '9') h += 'a' - '9' - 1; + _syscall_write(0, &h, 1, 0); + total++; + } + break; } seg = fmt; break; |