From 583765fd7ce0838f75fb7b5f08c27997adf5c93d Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 21 Sep 2012 11:47:45 -0400 Subject: [PATCH] Add %b to print() to print integers in binary --- boot/{start.s => start.S} | 0 kernel/print.c | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename boot/{start.s => start.S} (100%) diff --git a/boot/start.s b/boot/start.S similarity index 100% rename from boot/start.s rename to boot/start.S diff --git a/kernel/print.c b/kernel/print.c index 0e2730b..c86ec33 100644 --- a/kernel/print.c +++ b/kernel/print.c @@ -58,6 +58,16 @@ void putx(unsigned int i) { } } +void putb(unsigned int i) { + int j; + + puts("0b"); + + for (j = 0; j < 32; j++) { + putc((i>>(31-j)) & 1 ? '1' : '0'); + } +} + int print(char *fmt, ...) { char *c; va_list arg; @@ -81,6 +91,9 @@ int print(char *fmt, ...) { case 'x': putx(va_arg(arg, unsigned int)); break; + case 'b': + putb(va_arg(arg, unsigned int)); + break; default: puts("\nError: print(): Invalid formatting character: '"); putc(*c);