Advertisement
iocoder

We love complicated solutions

Jan 9th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [bits 16]               ;protected mode
  2. [org 0x7c00]    ;bootloader base - loaded by kernel
  3.  
  4.         ;set ds to 0
  5.         mov ax, 0x0000
  6.         mov ds, ax
  7.  
  8.         ; set ss and sp
  9.         mov ss, ax
  10.         mov sp, ax
  11.         nop
  12.  
  13.         ;init print colors
  14.         mov ah, 0x0e
  15.         mov bh, 0x00
  16.  
  17.         mov si, msg ;set hello world message in si
  18.         call printstring
  19.  
  20.         jmp $ ;hang
  21.  
  22. printstring:
  23.  
  24. .next_char:
  25.         mov al, [si]    ;load current character in string
  26.         or al, al               ;see if al is zero
  27.         jz .char_done   ;if al is zero, jump to end (end of string reached)
  28.         call change_attr
  29.         int 0x10                ;call print character command
  30.         inc si                  ;increase si, next character
  31.         jmp .next_char
  32.  
  33. .char_done:
  34.         ret
  35.  
  36. change_attr:
  37.         push ax
  38.         push bx
  39.         push cx
  40.         push dx
  41.         push di
  42.         push ds
  43.  
  44.         ; get cursor location
  45.         mov ah, 03h
  46.         mov bh, 00h
  47.         int 10h
  48.  
  49.         ; calculate the location of attr byte
  50.         mov al, 80
  51.         mul dh      ; AX = 80*ROW
  52.         mov dh, 0
  53.         add ax, dx  ; AX = 80*ROW + COL
  54.         shl ax, 1   ; AX = 2*(80*ROW + COL)
  55.         inc ax      ; AX = 2*(80*ROW + COL) + 1
  56.  
  57.         ; now ax contains location of attr inside 0xb800
  58.         mov di, ax
  59.         mov ax, 0b800h
  60.         mov ds, ax
  61.         mov al, 04h
  62.         mov [di], al
  63.  
  64.         ; restore context
  65.         pop ds
  66.         pop di
  67.         pop dx
  68.         pop cx
  69.         pop bx
  70.         pop ax
  71.  
  72.         ; return
  73.         ret
  74.  
  75.  
  76. ;data section - never reaced
  77. msg db 'hello mostafa :P', 13, 10, 0
  78.  
  79. times 510 - ($ - $$) db 0       ;fill rest of file (needs a size of 512 bytes)
  80. dw 0xaa55 ;end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement