Skip to content

Commit

Permalink
Fix bug with printf %d, add support for %u
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Dec 2, 2023
1 parent 845a68f commit 20eaadd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ncc/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,32 @@ int printf(char* format, ...)
continue;
}

// Decimal integer
// Signed decimal integer
if (format[i+1] == 'd' || format[i+1] == 'i')
{
++i;

// Get the integer argument and print it
asm (var_arg_idx) -> void {
get_var_arg;
trunc_u32;
sx_i32_i64;
syscall print_i64;
};
++var_arg_idx;

continue;
}

// Unsigned decimal integer
if (format[i+1] == 'u')
{
++i;

// Get the integer argument and print it
asm (var_arg_idx) -> void {
get_var_arg;
trunc_u32;
syscall print_i64;
};
++var_arg_idx;
Expand All @@ -90,8 +108,6 @@ int printf(char* format, ...)

// TODO: %p for printing pointers

// TODO: %f for printing floats

// Floats (f32)
if (format[i+1] == 'f')
{
Expand Down

0 comments on commit 20eaadd

Please sign in to comment.