After booting, the BIOS of the computer reads 512 bytes from the boot devices and, if it detects a two-byte "magic number" at the end of those 512 bytes, loads the data from these 512 bytes as code and runs it.
This kind of code is called a "bootloader" (or "boot sector") and we're writing a tiny bit of assembly code to make a virtual machine run our code and display "Hello world" for the fun of it. Bootloaders are also the very first stage of booting an operating system.
You might have wondered what happens when you press the "power" button on your computer. Well, without going into too much detail - after getting the hardware ready and launching the initial BIOS code to read the settings and check the system, the BIOS starts looking at the configured potential boot devices for something to execute.
It does that by reading the first 512 bytes from the boot devices and checks if the last two of these 512 bytes contain a magic number (0x55AA). If that's what these last two bytes are, the BIOS moves the 512 bytes to the memory address 0x7c00 and treats whatever was at the beginning of the 512 bytes as code, the so-called bootloader. In this article we will write such a piece of code, have it print the text "Hello World!" and then go into an infinite loop. Real bootloaders usually load the actual operating system code into memory, change the CPU into the so-called protected mode and run the actual operating system code.
Writing an x86 "Hello world" bootloader with assembly
Author : Maryam Saeedmehr
Language : assembly The Intel syntax edition
For This Project You Need below Requirements :
- nasm : assembler
- qemu : emulator
$ sudo apt install nasm
$ sudo apt-get install qemu
$ nasm -o boot.bin boot.asm
$ qemu-system-x86_64 boot.bin
/boot.asm
: This is the Main Assembly File/Markdown.pdf
: This is a Report of the project in Persian
Reach out to me at one of the following places!
- Telegram at @BitterOcean
- Gmail at maryamsaeedmehr@gmail.com
- MIT license
- Copyright 2018 © BootLoader Project.