SHARE
TWEET

bootloader & io.asm

a guest Aug 25th, 2019 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;; bootloader.asm
  2. ;;;; Bootloader for the OS
  3. org 0x7c00
  4. bits 16
  5.  
  6. ;;; Start/main function
  7. start:
  8.     jmp boot
  9.  
  10. ;;; Includes
  11. %include "io.asm"
  12.  
  13. ;;; Boot function
  14. boot:
  15.     cli                 ; no interrupts
  16.     cld                 ; only thing needed to init
  17.     mov     dh, 5       ; move decimal 5 into dh (row)
  18.     mov     dl, 5       ; move decimal 5 into dl (column)
  19.     call    movCursor   ; call movCursor
  20.     call    print       ; call putChar
  21.     hlt                 ; halt the OS
  22.  
  23. ;;; 512 available bytes, clear the rest with 0
  24. times 510 - ($-$$) db 0
  25. dw 0xAA55                   ; Boot signature
  26.  
  27.  
  28. ;;;; io.asm
  29. ;;;; IO subroutines/functions for the OS
  30. movCursor:
  31.     ; dh = Y coord, dl = X coord, bh = page #
  32.     ; void return
  33.     mov     ah, 02h         ; move 0x02 into ah
  34.     mov     bh, 0           ; move decimal 0 into bh (page number)
  35.     or      dh, 5           ; if dh != 5
  36.     jnz     incCursorPosH   ; jump to incCursorPosH
  37.     int     0x10            ; call
  38.     add     dh, 1           ; increase register dh by 1
  39.     ret
  40.  
  41. incCursorPosH:
  42.     ; dh = row #
  43.     ; void return
  44.     add     dh, 1       ; increase register dh by one
  45.     int     0x10        ; call
  46.     ret
  47.  
  48. incCursorPosV:
  49.     ; not needed right now
  50.     ; dl = column #
  51.     ; void return
  52.     add     dl, 1       ; increase register dl by one
  53.     int     0x10        ; call
  54.     ret
  55.  
  56. putChar:
  57.     ; al = char, bl = text color, cx = # of times printed
  58.     ; bh = page number
  59.     ; void return
  60.     lodsb               ; load a byte from si
  61.     or      al, al      ; OR to check al
  62.     jz      done        ; if 0, there's nothingo left for the string, so end
  63.     mov     ah, 0eh     ; move 0x0a into ah
  64.     mov     bh, 0       ; move decimal to page number of register bh
  65.     mov     bl, 4       ; move decimal 4 to text color of register bl
  66.     mov     cx, 1       ; move decimal 1 into cx (print character once)
  67.     int     10h         ; call
  68.     call    movCursor   ; call movCursor and go the next position
  69.     jmp     putChar     ; loop back & restart putChar
  70.  
  71. done:
  72.     ret
  73.  
  74. print:
  75.     ; ds:si = null-terminated string
  76.     ; void return
  77.     mov     ax, 0x07c0      ; move 0x07c0 into ax
  78.     mov     ds, ax          ; move that segment into ds (segment)
  79.     mov     si, message     ; move the message into si (offset)
  80.     call    putChar         ; call putChar
  81.     call    movCursor       ; call movCursor
  82.  
  83. ;;; Variables
  84. message db 'Hello World', 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top