Created
February 13, 2023 17:41
-
-
Save BobbyRaduloff/2d49c9bbf3a47fe7d36899fcb57229e2 to your computer and use it in GitHub Desktop.
bare metal hello word
This file contains 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
;; Prepare the BIOS | |
org 0x7c00 ;; BIOS jumps here upon boot | |
bits 16 ;; 16-bit mode | |
;; Set the video mode to 80x25 text mode | |
;; see (https://en.wikipedia.org/wiki/INT_10H | |
;; and http://www.columbia.edu/~em36/wpdos/videomodes.txt) | |
;; a character in this buffer is 2 bytes (ascii + color) | |
mov ax, 0x0002 ;; ah = 0x00 -> set video mode | |
;; al = 0x02 -> 80x25 text mode | |
int 0x10 ;; call BIOS interrupt | |
;; Set up printing to work with the string registers | |
cld ;; clear direction flag, | |
;; so that the string instructions will increment the index | |
;; see (https://c9x.me/x86/html/file_module_x86_id_29.html) | |
mov ax, 0xb800 ;; memory address of the video buffer | |
mov es, ax ;; set the extra segment register to the video buffer | |
mov di, 0x0000 ;; set the destination index to the start of the video buffer | |
;; Print the welcome message | |
mov ax, welcome_message ;; set the source index to the start of the message | |
mov si, ax | |
loop_welcome: | |
mov al, [si] ;; load the next character into al | |
stosb ;; store al into es:[di] and increment di | |
mov es:[di], byte 0x04 ;; make the next character red | |
;; (https://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch23/CH23-1.html) | |
inc di ;; increment the destination index (next character in video buffer) | |
inc si ;; increment the source index (next character from message) | |
cmp al, byte 0x00 | |
jnz loop_welcome ;; if not, jump back to the start of the loop | |
;; Compile time constants | |
welcome_message db "Hello, TikTok!", 0x0 | |
;; Dummy Partition Table so that the bios doesn't complain | |
;; see (https://github.com/daniel-e/tetros/blob/master/tetros.asm | |
;; and https://en.wikipedia.org/wiki/Master_boot_record) | |
times 446 - ($ - $$) db 0 | |
db 0x80 | |
db 0x00, 0x01, 0x00 | |
db 0x17 | |
db 0x00, 0x02, 0x00 | |
db 0x00, 0x00, 0x00, 0x00 | |
db 0x02, 0x00, 0x00, 0x00 | |
times 510 - ($ - $$) db 0 | |
dw 0xaa55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment