Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [bits 16] ;protected mode
- [org 0x7c00] ;bootloader base - loaded by kernel
- ;set ds to 0
- mov ax, 0x0000
- mov ds, ax
- ; set ss and sp
- mov ss, ax
- mov sp, ax
- nop
- ;init print colors
- mov ah, 0x0e
- mov bh, 0x00
- mov si, msg ;set hello world message in si
- call printstring
- jmp $ ;hang
- printstring:
- .next_char:
- mov al, [si] ;load current character in string
- or al, al ;see if al is zero
- jz .char_done ;if al is zero, jump to end (end of string reached)
- call change_attr
- int 0x10 ;call print character command
- inc si ;increase si, next character
- jmp .next_char
- .char_done:
- ret
- change_attr:
- push ax
- push bx
- push cx
- push dx
- push di
- push ds
- ; get cursor location
- mov ah, 03h
- mov bh, 00h
- int 10h
- ; calculate the location of attr byte
- mov al, 80
- mul dh ; AX = 80*ROW
- mov dh, 0
- add ax, dx ; AX = 80*ROW + COL
- shl ax, 1 ; AX = 2*(80*ROW + COL)
- inc ax ; AX = 2*(80*ROW + COL) + 1
- ; now ax contains location of attr inside 0xb800
- mov di, ax
- mov ax, 0b800h
- mov ds, ax
- mov al, 04h
- mov [di], al
- ; restore context
- pop ds
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- ; return
- ret
- ;data section - never reaced
- msg db 'hello mostafa :P', 13, 10, 0
- times 510 - ($ - $$) db 0 ;fill rest of file (needs a size of 512 bytes)
- dw 0xaa55 ;end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement