
Print Fixed-Point Values Without printf Float Support
Print Q15 and Q16.16 numbers as decimals in C with integer arithmetic only: split, round, pad the fraction, carry, handle the sign, skip printf float code.
Tag
362 posts

Print Q15 and Q16.16 numbers as decimals in C with integer arithmetic only: split, round, pad the fraction, carry, handle the sign, skip printf float code.

Convert floats to Q15 and back in C with rounding, saturation and NaN handling, build compile-time Q15 constants, and convert whole sample blocks safely.

Build the smallest RISC-V kernel that boots on QEMU virt: a linker script at 0x80200000, an entry stub, a C main printing through the UART, and a GDB check.

Learn what Q15, Q31 and Q16.16 mean, how a stored integer maps to a real value, and how to compute the range and resolution of any Q format in C.

Drive the NS16550A UART at 0x10000000 on QEMU's RISC-V virt machine with volatile MMIO in C: initialize it, send and poll bytes, then add receive interrupts.

How Mach ports, port rights and mach_msg work on macOS 15, with a complete client and server in C using the bootstrap server, plus where XPC sits on top.

Write a bitmap physical memory manager in C: place the bitmap in usable RAM, mark reserved and kernel frames, allocate and free 4 KiB frames, and allocate runs.

Program the 8253 PIT for a periodic tick, then calibrate the local APIC timer against it and run a 1000 Hz tick, with a tick counter and a sleep function.

Write a PS/2 keyboard driver for a hobby kernel: the 8042 ports, scancode set 1, make and break codes, the 0xE0 prefix, shift and caps lock, and a ring buffer.

Remap the two 8259 PICs away from the CPU exception vectors, mask and unmask IRQ lines, send the end-of-interrupt and detect spurious IRQ 7 and IRQ 15.

Build your own x86 GDT in C: descriptor layout, kernel and user segments, a TSS slot, lgdt and segment register reloads, and the 64-bit changes.

atexit registers cleanup functions that run in reverse order when a program ends normally. on_exit also passes the status. Neither runs after _exit or abort.