Many OS tutorials start in assembly or C++. We start in machine code.
In this Raspberry Pi 4 tutorial, we'll write a self-hosted assembler in machine code. We'll then evolve that compiler (by implementing new features then using those features in the compiler source code) into something capable of wrangling a high-level language. Finally, in our high-level language, where most tutorials start, we'll write a simple web server to one day host the tutorial's own documentation.
Milestone: bootstrap machine code ?
; command for commentsMilestone: big-endian machine code ?
Milestone: labeled goto ?
J: relative branch with binaryL: label for goto (read into memory tape with scheme pos4 name )GOTO: goto labelMilestone: conditional goto ?
GOEQGONEGOGTGOLTGOGEGOLEMilestone: labeled functions ?
CALL: "goto" but with linked branchingMilestone: emitting strings
MOV reg charEMIT string: macro for series of MOV reg char and CALL emit with escape sequence supportMilestone: bootstrap assembly
RET: return after function callMOV reg hexMOV reg decMOV reg regADD reg reg [reg/value]: set the value of a registerSUB reg reg [reg/value]: set the value of a registerLDB reg reg_mem offset: load a byteSTB reg reg_mem offset: store a byteORR reg reg (reg >>/<< value)AND reg reg (reg >>/<< value)Milestone: stack-lang functions
.func [name] [num locals].call [name]Milestone: push, pop, and dup
.push constant [val]
.dup
.pop local [idx]
.push local [idx]
.pop param [idx]
.push param [idx]
.pop global [idx]
.push global [idx]
Milestone: stack-lang memory access
.load (..., addr) -> (..., val).store (..., val, addr) -> (...)Milestone: arithmetic
.add.subMilestone: heap allocation
malloc stack function (..., num bytes) -> (..., addr)Milestone: parsing and compiling
fn main)
for f in ./os/*.txt; do wc -l $f; done | Rscript bar-gen.R ; feh ./loc-stats.png