Last active
December 18, 2015 19:19
-
-
Save hiway/5832498 to your computer and use it in GitHub Desktop.
Program that boots an emulator/computer from a floppy and prints 'Hello, world.'
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
[bits 16] ; Tell assembler to use 16 bit code. | |
[org 7c00h] ; BIOS will load us to this address. | |
;=================================================================== | |
mov si, string_hello ; store string pointer into SI | |
call print_string | |
call sleep | |
;=================================================================== | |
print_string: | |
;expect pointer to string's beginning to be in SI | |
next_character: | |
mov al,[si] ; gets a byte from string and stores in AL | |
inc si ; increment si pointer | |
or AL, AL ; check if value in AL is zero (end of string) | |
jz exit_print_string ; if end of string, exit | |
call print_character ; else print character in AL | |
jmp next_character | |
exit_print_string: | |
ret | |
;=================================================================== | |
print_character: | |
;expect ASCII value of character to be printed in AL | |
mov ah, 0x0e ; teletype mode, sets BIOS to print one character | |
mov bh, 0x00 ; page number | |
mov bl, 0x07 ; text attribute (light gray on black) | |
int 0x10 ; BIOS video interrupt | |
ret ; return to calling procedure | |
;=================================================================== | |
sleep: | |
hlt ; halt cpu till next instruction | |
jmp sleep ; loop forever | |
;=================================================================== | |
string_hello db 'Hello, world.', 0 ; string ending with 0 | |
;=================================================================== | |
times 510 - ($-$$) db 0 ; fill rest of the sector with 0 | |
dw 0xaa55 ; add boot signature to mark as bootable. |
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
#!/bin/bash | |
# Usage: ./run.sh hello.asm | |
# Assumes you have nasm and Q.app installed. | |
dd if=/dev/zero of=floppy.img bs=512 count=2880 | |
nasm $1 -o binary.out | |
dd if=binary.out of=floppy.img conv=notrunc | |
/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu -hda floppy.img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment