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/init/stdlib.c | |
parent | 44d308149282debf314cb48789b9084767c1c288 (diff) |
init printf: implement %x
Diffstat (limited to 'src/init/stdlib.c')
-rw-r--r-- | src/init/stdlib.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; |