Created
May 15, 2013 12:53
-
-
Save mcb30/5583788 to your computer and use it in GitHub Desktop.
Simple bare-metal "Hello world" program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Compile with | |
| * | |
| * as --32 -o vga.o vga.s && objcopy -Obinary vga.o vga.bin | |
| * | |
| */ | |
| .arch i386 | |
| .text | |
| .code16 | |
| .org 0 | |
| start: | |
| /* Fix segment registers so that local labels work */ | |
| ljmp $0x7c0, $1f | |
| 1: push %cs | |
| popw %ds | |
| push %cs | |
| popw %es | |
| push %cs | |
| popw %ss | |
| /* Set up 16kB stack. Must do this immediately after loading %ss */ | |
| movw $0x4000, %sp | |
| /* Set up %fs for access to VGA memory */ | |
| movw $0xb800, %ax | |
| movw %ax, %fs | |
| /* Write "Hello!" to start of VGA memory */ | |
| movw $( 0xc700 | 'H' ), %fs:0 | |
| movw $( 0xc700 | 'e' ), %fs:2 | |
| movw $( 0xc700 | 'l' ), %fs:4 | |
| movw $( 0xc700 | 'l' ), %fs:6 | |
| movw $( 0xc700 | 'o' ), %fs:8 | |
| movw $( 0xc700 | '!' ), %fs:10 | |
| /* Hang system */ | |
| 1: cli | |
| hlt | |
| jmp 1b | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment