Boot sector: hello in 512 bytes

Contents
The setup
Printing in real mode
The signature

The setup

A boot sector is 512 raw bytes the BIOS loads at physical address 0x7C00 and jumps to. Assemble with -f bin, set the origin, and switch to 16-bit mode, because the CPU starts in real mode:

bits 16 org 0x7C00 start: ; real-mode code here

Printing in real mode

In real mode there are no syscalls: the BIOS provides services through INT 10h. Function 0Eh of INT 10h prints one character in AL to the screen, teletype style:

mov si, msg print_loop: lodsb ; AL = [SI], SI++ or al, al jz done mov ah, 0x0E int 0x10 jmp print_loop

The signature

The last two bytes must be 0x55 then 0xAA, or the BIOS rejects the disk. Pad to 510 bytes and append the signature with TIMES:

times 510-($-$$) db 0 dw 0xAA55

Next: Capstone: command-line calculator

Article author: Arthur Isaev

Related articles
Assembler
Assembler course: zero to hero in 50 lessons
What is assembly language
Install NASM and check the version
NASM syntax basics
Your first program
Registers
MOV and data transfer
Number bases and operands
Defining strings and data
Flags and the status register
Conditional jumps
Loops
The stack
Procedures
LEA and addressing modes
Memory layout: sections
Linux syscalls
Arithmetic
Bitwise operations
Arrays
Structures
Macros
Calling C functions
Debugging with GDB
The ELF format
Time and date syscalls
File I/O
Command-line arguments
Environment variables
Floating point (SSE)
SIMD basics
Interrupts
Sockets
A tiny HTTP client
Output formats: bin, elf, elf64
Advanced macros and %include
Linking object files
32-bit vs 64-bit
The System V ABI
Makefiles for assembly
Optimization basics
Error codes and logging
Parsing CSV
Data structures: linked list
A tiny HTTP server
Boot sector: hello in 512 bytes
Capstone: command-line calculator
Capstone: hex editor
Performance: cycles and cache
Modern x86: AVX tour
Hero roadmap: the whole course on one page
Install NASM on Windows 11
Install NASM on Ubuntu
Install NASM on Rocky Linux
Install NASM on macOS
Install NASM on FreeBSD
Assembly in Docker
ARM assembly
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: