Skip to content

Repository files navigation

Simple x86 Assembly Bootloader Examples

This is a basic x86 bootloader project that demonstrates the fundamentals of OS development. The bootloader prints "Hello, World!" to the screen using BIOS interrupts.

Project Structure

  • hello_world.asm - A bootloader that prints "Hello, World!" to the screen
  • hello_world_func.asm - Same as hello_world.asm but using a function call to print
  • single_char.asm - A minimal bootloader that prints a single character
  • single_char_min.asm - An even more minimal version of single_char.asm
  • bochs_config.bxrc - Configuration file for the Bochs emulator

Prerequisites

To build and run this project, you'll need:

  • FASM (Flat Assembler) for compiling the assembly code
  • Bochs x86 emulator for running the bootloader

Installing FASM

  1. Download FASM from the official website
  2. For Windows:
    • Download "flat assembler for Windows" package
    • Extract the zip file
    • The package includes an integrated editor with syntax highlighting
    • Documentation is provided in PDF format

Installing Bochs

  1. Download the latest Bochs release (currently 2.8) from the official Bochs releases page
  2. For Windows:
    • Download the .exe installer
    • Either run the installer directly
    • Or extract the files using 7-Zip if you prefer a portable installation

Building

To compile the bootloaders, run either:

fasm hello_world.asm hello_world.bin

or

fasm single_char.asm single_char.bin

Running

To run a bootloader in Bochs, first update the bochs_config.bxrc file to point to the desired .bin file, then:

bochs -f bochs_config.bxrc

Technical Details

The bootloader implements these key features:

  • Loads at memory address 0x7C00 (a fixed address chosen by IBM in 1981)
  • Runs in 16-bit real mode
  • Uses BIOS interrupt 0x10 with function 0x0E for teletype output, which automatically advances the cursor after printing
  • Uses lodsb instruction to efficiently load and process string bytes into AL register while auto-incrementing SI
  • Stores string characters using db (Define Byte) directive with a null terminator (0)
  • Uses null-terminated strings for text output processing
  • Implements an infinite loop after printing to prevent executing past our code
  • Fits within the required 512 bytes for boot sectors:
    • Main code and data in first 510 bytes
    • Automatically pads unused space with zeros
    • Includes standard boot signature (0x55, 0xAA) in final 2 bytes, required by BIOS to mark the sector as bootable

References

Learning Resources

Assembly and FASM Documentation

BIOS and Hardware References

Tools and Software

License

This project is open source and available under the MIT License.

About

Simple Bootloader Project

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages