Last active
March 14, 2019 20:41
-
-
Save id4ehsan/066a7e53c0ce2b2d34a23194c5a9d823 to your computer and use it in GitHub Desktop.
experimental loop boot Master Boot Record (do nothing)
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
; ; A simple boot sector program that demonstrates addressing. ; | |
mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine | |
; First attempt | |
mov al, the_secret | |
int 0x10 | |
; Does this print an X? | |
; Second attempt | |
mov al, [the_secret] | |
int 0x10 | |
; Does this print an X? | |
; Third attempt | |
mov bx, the_secret | |
add bx, 0x7c00 | |
mov al, [bx] | |
int 0x10 | |
; Does this print an X? | |
; Fourth attempt | |
mov al, [0x7c1e] | |
int 0x10 | |
; Does this print an X? | |
jmp $ ; Jump forever. | |
the_secret: db "X" | |
; Padding and magic BIOS number. | |
times 510-($-$$) db 0 | |
dw 0xaa55 | |
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
org 0x7c00 | |
; ; A simple boot sector program that demonstrates addressing. ; | |
mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine | |
; First attempt | |
mov al, the_secret | |
int 0x10 | |
; Does this print an X? | |
; Second attempt | |
mov al, [the_secret] | |
int 0x10 | |
; Does this print an X? | |
; Third attempt | |
mov bx, the_secret | |
add bx, 0x7c00 | |
mov al, [bx] | |
int 0x10 | |
; Does this print an X? | |
; Fourth attempt | |
mov al, [0x7c1e] | |
int 0x10 | |
; Does this print an X? | |
jmp $ ; Jump forever. | |
the_secret: db "X" | |
; Padding and magic BIOS number. | |
times 510-($-$$) db 0 | |
dw 0xaa55 | |
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
loop: | |
jmp loop | |
times 510-($-$$) db 0 | |
dw 0xaa55 |
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
mov bx, 30 | |
if (bx <= 4) { | |
mov al, ’A’ | |
} else if (bx < 40) { | |
mov al, ’B’ | |
} else { | |
mov al, ’C’ | |
} | |
mov ah, 0x0e ; int=10/ah=0x0e -> BIOS tele -type output | |
int 0x10 ; print the character in al | |
jmp $ | |
; Padding and magic number. | |
times 510-($-$$) db 0 | |
dw 0xaa55 | |
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
; ; A simple boot sector that prints a message to the screen using a BIOS routine. ; | |
mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine | |
mov al, 'H' | |
int 0x10 | |
mov al, 'e' | |
int 0x10 | |
mov al, 'l' | |
int 0x10 | |
mov al, 'l' | |
int 0x10 | |
mov al, 'o' | |
int 0x10 | |
jmp $ ; Jump to the current address (i.e. forever). | |
; ; Padding and magic BIOS number. ; | |
times 510-($-$$) db 0 ; Pad the boot sector out with zeros | |
dw 0xaa55 ; Last two bytes form the magic number , | |
; so BIOS knows we are a boot sector. | |
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
; | |
; A simple boot sector program that demonstrates the stack. | |
; | |
mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine | |
mov bp, 0x8000 ; Set the base of the stack a little above where BIOS | |
mov sp, bp ; loads our boot sector - so it won’t overwrite us. | |
push 'A' ; Push some characters on the stack for later | |
push 'B' ; retreival. Note , these are pushed on as | |
push 'C' ; 16-bit values , so the most significant byte | |
; will be added by our assembler as 0x00. | |
pop bx ; Note , we can only pop 16-bits , so pop to bx | |
mov al, bl ; then copy bl (i.e. 8-bit char) to al | |
int 0x10 ; print(al) | |
pop bx ; Pop the next value | |
mov al, bl | |
int 0x10 ; print(al) | |
mov al, [0x7ffe] ; To prove our stack grows downwards from bp, | |
; fetch the char at 0x8000 - 0x2 (i.e. 16-bits) | |
int 0x10 ; print(al) | |
jmp $ ; Jump forever. | |
; Padding and magic BIOS number. | |
times 510-($-$$) db 0 | |
dw 0xaa55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment