Advertisement
metalx1000

Example Assembly Boot Loader

Oct 15th, 2013
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;http://www.daniweb.com/software-development/assembly/threads/333365/boot-loader
  2.     BITS 16
  3.     start:
  4.         mov ax, 07C0h   ; Set up 4K stack space after this bootloader
  5.         add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
  6.         mov ss, ax
  7.         mov sp, 4096
  8.         mov ax, 07C0h   ; Set data segment to where we're loaded
  9.         mov ds, ax
  10.         mov si, text_string ; Put string position into SI
  11.         call print_string ; Call our string-printing routine
  12.         text_string db 'This is my cool new OS!', 0
  13.         print_string: ; Routine: output string in SI to screen
  14.         mov ah, 0Eh ; int 10h 'print char' function
  15.     .repeat:
  16.         lodsb ; Get character from string
  17.         cmp al, 0
  18.         je .background_colors ; If char is zero, end of string
  19.         int 10h ; Otherwise, print it
  20.         jmp .repeat
  21.     .background_colors:
  22.         mov ah,0Bh
  23.         mov bh,0
  24.         mov bl,02h
  25.         int 10h
  26.         jmp .cursor_pointer
  27.     .cursor_pointer:
  28.         mov ah,2h ;set the value to "ah" to move the cursor pointer
  29.         mov bh,0 ;select page
  30.         mov dh,22 ;set row position of the cursor
  31.         mov dl,0 ;set column position of the cursor
  32.         int 10h ;tell bios "hey dude now we are done,take action!!!"
  33.         jmp .character_write
  34.     .character_write:
  35.         mov ah,9h
  36.         mov al,65 ;ascii value
  37.         mov bh,0 ;display page
  38.         mov bl,5h ;display attribute
  39.         mov cx,10 ;display times
  40.         int 10h
  41.         jmp .cursor_pointer2
  42.     .cursor_pointer2:
  43.         mov ah,2h ;set the value to "ah" to move the cursor pointer
  44.         mov bh,0 ;select page
  45.         mov dh,23 ;set row position of the cursor
  46.         mov dl,0 ;set column position of the cursor
  47.         int 10h ;tell bios "hey dude now we are done,take action!!!"
  48.         jmp .character_read
  49.     .character_read:
  50.         mov ah,00h ;remeber set the value to "ah" now you are going to read a keyboard input
  51.         int 16h ;this interrupt is given to control keystrokes of keyboard
  52.         jmp .print_input ;now lets print what we took as input
  53.     .print_input:
  54.         mov ah,9h ;set the value to "ah" to print one character to std out
  55.         mov bh,0 ;set page number
  56.         mov bl,5h ;set the color attribute of the font to be print
  57.         mov cx,10 ;set the value how many time the character in "al" should be print
  58.         int 10h ;tell bios "hey dude now we are done,take action!!!"
  59.         jmp .done
  60.     .done:
  61.         ret
  62.         times 510-($-$$) db 0 ; fill up the rest part of the boot secotr with 0 s
  63.         dw 0xAA55 ; The standard PC boot signature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement