Take the 2-minute tour ×

I made simple code, that should write to VGA memory.

org 07c00h
  mov eax,0xb8000
  mov bx,msg
  call printstr

  mov al,byte[bx]
  mov byte[eax],al
  inc eax
  mov byte[eax],1
  inc eax
  inc bx
  cmp byte[bx],0
  je end
  jmp printstr

  jmp end
msg: db "Hello world!",0
times 510-($-$$) db 0
dw 0xaa55

But instead of writing "Hello world" it does this when i run it in QEMU. I assembled that using NASM. Image

I want to overwrite first 12 chars at first line with "Hello world!".

Does anybody know why its giving me this result?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
  mov al,byte[bx]
  mov byte[eax],al

al is part of eax, so by reading a character into al you're trashing your screen pointer.

Besides that, shouldn't you be using segmented addressing in your bootloader? Something like this:

push 0xb800
pop es
xor di,di
stosb ; [es:di] = al, di++
share|improve this answer
Thank you. I'm not using segmented addressing, because i'm not familiar with it, and i'm not sure if i understand it well. –  Smax Aug 31 '13 at 20:29
Well, I've never written an x86 OS or a bootloader, but I would guess that the CPU starts up in real mode, and that you therefore have to use segmented addressing before you've switched over to protected mode. –  Michael Sep 1 '13 at 10:24
It's ok to use 32-bit addressing even in real mode since 386. Only the first 20 (or 21?) bits of the resulting linear address will be used though. –  avakar Sep 9 '13 at 12:40
add comment

Your Answer


