Home
- Build-your-own-X
- Color
- Practical Guide to Bare Metal C++
- Anatomy of a Program in Memory
- The Kernel Boot Process
- CPU Rings, Privilege, and Protection
- Protected mode programming tutorial
- Linux Inside
- Linux System Calls, Error Numbers, and In-Band Signaling
- Linux containers in 500 lines of code
- Linux Performance
- Video: Give me 15 minutes and I'll change your view of Linux tracing
- gist Linux kernel initialization, translated to bash
- The Collapse of the UNIX Philosophy
- spawn() of Satan
- Repo with bare metal example/documentation
Compiling&Linking
- A ToC of the 20 part linker essay
- Designing Linker Scripts with GNU Linker
- From Zero to main(): Demystifying Firmware Linker Scripts
- LD command language
- Breaking the links: Exploiting the linker
Two's complement
It's used to represent signed integers. The formula is
$$ w = - a_{N - 1}\, 2^{N - 1} + \sum_{i = 0}^{N - 2} a_i\,2^i $$
in practice the MSB has much more weight with respect to the others; This system can represent the range \([-2^{N - 1}, 2^{N - 1} - 1]\).
Below a simple python function to calculate the value
def twos_complement(input_value, num_bits):
'''Calculates a two's complement integer from the given input value's bits'''
mask = 2**(num_bits - 1)
return -(input_value & mask) + (input_value & ~mask)
- Twos complement: Negative numbers in binary video
- Number Systems
- The CARRY flag and OVERFLOW flag in binary arithmetic