# Tutorials for Building Operating Systems and Compilers in Project-Based Learning

> Explore practical tutorials for building operating systems and compilers. Learn to write a boot sector kernel and construct a C compiler with step-by-step project-based learning guides.

- Repository: [practical-tutorials/project-based-learning](https://github.com/practical-tutorials/project-based-learning)
- Tags: tutorial
- Published: 2026-02-24

---

**Yes, the Project-Based Learning repository contains curated tutorials for building both operating systems and compilers**, including step-by-step guides for writing a boot sector and kernel from scratch and constructing a C compiler in C++.

The `practical-tutorials/project-based-learning` repository serves as a comprehensive index of hands-on programming tutorials. If you are searching for **tutorials for building operating systems or compilers**, this curated list provides direct links to external resources that guide you through creating a functional OS kernel and a complete compiler pipeline.

## Operating System Development Tutorials

The repository indexes two primary operating system tutorials located in [`README.md`](https://github.com/practical-tutorials/project-based-learning/blob/main/README.md) between lines 44 and 46. These community-maintained series teach you to write an OS from scratch, starting with bootloader basics and progressing to kernel development and multitasking.

**"Write an OS from scratch"** and **"How to create an OS from scratch"** both follow a similar pedagogical structure:

- **Bootloader implementation** – Write the 512-byte boot sector that the BIOS loads, using x86 assembly
- **Kernel initialization** – Transition from 16-bit real mode to 32-bit protected mode
- **Memory management** – Implement basic paging and segmentation
- **Multitasking** – Create a minimal scheduler and interrupt handlers

The tutorials require **NASM** (Netwide Assembler), **GCC**, **Make**, and **QEMU** for emulation.

## Compiler Construction Tutorials

For compiler development, the repository lists a comprehensive tutorial at lines 66-70 of [`README.md`](https://github.com/practical-tutorials/project-based-learning/blob/main/README.md) titled **"Write a C compiler"**. This multi-part series walks you through building a simple C compiler in C++, covering the complete compilation pipeline from source code to assembly.

The tutorial progresses through four major stages:

1. **Lexical analysis** – Tokenize input source code into identifiers, keywords, and operators
2. **Parsing** – Implement a recursive-descent parser that builds an abstract syntax tree (AST)
3. **Semantic analysis** – Perform type checking and symbol table management
4. **Code generation** – Emit x86-64 assembly from the AST

You will need a modern C++ compiler (**Clang** or **GCC**) and **Make** to follow along.

## Tutorial Structure and Prerequisites

Both the OS and compiler tutorials follow an incremental learning pattern. According to the repository's curation in [`README.md`](https://github.com/practical-tutorials/project-based-learning/blob/main/README.md), each tutorial is organized into distinct phases:

### Phase 1: Foundation

**Operating systems** begin with the bootloader—a 512-byte assembly program that fits into the Master Boot Record (MBR). **Compilers** begin with the lexer, which converts raw text into structured tokens.

### Phase 2: Core Logic

The OS tutorials move into protected mode and kernel initialization, while the compiler tutorials implement the parser and AST construction.

### Phase 3: Advanced Features

Operating system tutorials cover multitasking, memory paging, and system calls. Compiler tutorials cover optimization passes and assembly generation.

### Required Tools

- **For OS development**: `nasm`, `gcc`, `make`, `qemu-system-x86_64`
- **For compiler development**: `g++` or `clang++`, `make`, `gdb` (optional debugging)

## Code Examples from the Tutorials

Below are minimal, self-contained examples illustrating the starting points for both tutorial types.

### Minimal 512-Byte Boot Sector

This assembly code represents the first step in the OS tutorials—a boot sector that prints a message and hangs:

```nasm
; boot.asm – 16-bit bootloader that prints "Hello"
bits 16
org 0x7c00

start:
    mov si, msg       ; DS:SI points to string
    call print_str

hang:
    jmp hang

print_str:
    mov ah, 0x0e      ; BIOS teletype function
.print_char:
    lodsb             ; load byte at DS:SI into AL, increment SI
    or al, al
    jz .done
    int 0x10
    jmp .print_char
.done:
    ret

msg db 'Hello, OS!',0

times 510-($-$$) db 0   ; pad to 510 bytes
dw 0xAA55               ; boot signature

```

Compile and run with:

```bash
nasm -f bin boot.asm -o boot.bin
qemu-system-x86_64 -drive format=raw,file=boot.bin

```

### Simple Lexer for Compiler Construction

This C++ code demonstrates the lexical analysis phase from the compiler tutorial:

```cpp
// lexer.cpp – tokenises a tiny arithmetic language
#include <cctype>
#include <iostream>
#include <string>

enum TokenKind { TK_Number, TK_Plus, TK_Minus, TK_EOF };

struct Token {
    TokenKind kind;
    std::string text;
};

Token getToken(const char *&p) {
    while (isspace(*p)) ++p;
    if (isdigit(*p)) {
        const char *start = p;
        while (isdigit(*p)) ++p;
        return {TK_Number, std::string(start, p)};
    }
    if (*p == '+') { ++p; return {TK_Plus, "+"}; }
    if (*p == '-') { ++p; return {TK_Minus, "-"}; }
    return {TK_EOF, ""};
}

int main() {
    const char *src = "12 + 34 - 5";
    Token tk;
    while ((tk = getToken(src)).kind != TK_EOF) {
        std::cout << "Token: " << tk.text << '\n';
    }
}

```

Compile and execute with:

```bash
g++ lexer.cpp -o lexer && ./lexer

```

## Summary

- The **Project-Based Learning** repository curates external tutorials for building operating systems and compilers in its [`README.md`](https://github.com/practical-tutorials/project-based-learning/blob/main/README.md).
- **OS tutorials** (lines 44-46) cover bootloader creation, protected mode, kernel development, and multitasking using NASM and QEMU.
- **Compiler tutorials** (lines 66-70) provide a complete pipeline from lexical analysis to x86-64 code generation using C++.
- Both tutorial types require standard build tools (GCC, Make) and follow incremental, hands-on learning patterns.

## Frequently Asked Questions

### Does the repository contain the actual source code for these tutorials?

No, the **Project-Based Learning** repository functions as a curated index. The actual tutorials and source code reside in external repositories and personal blogs. The [`README.md`](https://github.com/practical-tutorials/project-based-learning/blob/main/README.md) file at the root of the repository provides direct hyperlinks to these resources at specific line ranges (44-46 for OS tutorials and 66-70 for compiler tutorials).

### What programming languages are used in these tutorials?

The operating system tutorials primarily use **x86 assembly** (NASM syntax) for the bootloader and early kernel stages, transitioning to **C** for higher-level kernel functionality. The compiler tutorial is implemented in **C++** and targets a subset of the **C** language, teaching you to build a compiler that translates C code into x86-64 assembly.

### Do I need prior experience with assembly language or computer architecture?

While helpful, prior assembly experience is not strictly required. Both the OS and compiler tutorials start from fundamentals—the OS tutorials begin with a simple 512-byte boot sector, and the compiler tutorials start with basic lexical analysis. However, you should be comfortable with **C** or **C++** programming and basic command-line tools before attempting these projects.

### How long does it take to complete these tutorials?

Completion time varies by experience level, but expect to spend **several weeks to a few months** on each tutorial. The operating system tutorials typically require 40-60 hours to reach a basic multitasking kernel. The compiler tutorial spans multiple posts and usually takes 20-30 hours to implement the full pipeline from lexer to code generator. Both are designed to be completed incrementally, one chapter at a time.