From anonymous, 6 Years ago, written in x86 Assembler.
Embed
  1. ; Tell NASM that the code's base will be at 7c00h.
  2. ; Otherwise it will assume offset 0 when calculating addresses.
  3. org 7c00h
  4.  
  5. ; jump over data
  6. jmp short init
  7.  
  8. message:
  9.     db "Error", 0 ; null-terminated message
  10.  
  11. clearmsg:
  12.     db "     ", 0
  13.  
  14. init:
  15.     ; Video initalisation
  16.     mov ah, 0x00 ; Set video mode
  17.     mov al, 0x12 ; VGA mode
  18.     int 0x10     ; Video function call interrupt
  19.     ; Register initialisation
  20.     xor ax, ax   ; clear ax
  21.     mov ds, ax   ; ds needs to be 0 for lodsb
  22.     cld          ; clear direction flag for lodsb
  23.     mov dh, 0x0a    ; row 10
  24.     mov dl, 0x28    ; col 40
  25.  
  26. main:
  27.     ; Set cursor position
  28.     mov ah, 0x02    ; cursor position
  29.     mov bh, 0x00    ; page 0
  30.     int 0x10        ; Video function call interrupt
  31.     mov si, clearmsg
  32.     call string
  33.  
  34.     mov ah, 0x02    ; cursor position
  35.     mov bh, 0x00    ; page 0
  36.     inc dh
  37.     inc dl
  38.     int 0x10        ; Video function call interrupt
  39.     mov si, message ; move the message's address into si for lodsb
  40.     call string      ; jump to the string routine
  41.     jmp waitblah
  42.  
  43. ; Displays a character
  44. ; al: character
  45. char:
  46.     mov ah, 0x0e ; Teletype output mode
  47.     mov bh, 0x00 ; page number
  48.     mov bl, 0x0c ; color (bright red)
  49.     int 0x10     ; Video function call interrupt
  50.  
  51. ; print a string
  52. string:
  53.     lodsb       ; lodsb loads ds:esi into al
  54.     cmp al, 0x0
  55.     jnz char    ; display character if not null
  56.     mov cx, 0xFFFF
  57.     ret
  58.  
  59. waitblah:
  60.     mov bx, 0xFF
  61.     dec cx
  62.    
  63. waitinner:
  64.     dec bx
  65.     cmp bx, 0x0
  66.     jnz waitinner
  67.  
  68.     cmp cx, 0x0
  69.     jnz waitblah
  70.     jmp main
  71.  
  72.  
  73. ; infinite loop
  74. end:
  75.     jmp short end
  76.  
  77. times 0x0200 - 2 - ($ - $$)  db 0 ; NASM directive: zerofill up to 510 bytes
  78.  
  79. dw 0x0AA55 ; Magic boot sector signature
  80.