Page 1 of 1

Simple assembly hello world bootloader problem

Posted: Fri Mar 05, 2010 3:24 pm
by Xunil
Hey, I'm trying to make a simple Hello World bootloader in assembly (following the tutorial at http://www.viralpatel.net/taj/operating ... torial.php). I've made it show a single character on the screen, but as soon as I try to load a string of characters, the new characters won't show up when I boot it on a real machine, it only works when I'm running it in VirtualBox. Here's the code I'm using:

Code: Select all

[BITS 16]
[ORG 0x7C00]

MOV AL, 72
CALL PrintChar
MOV SI, HelloWorldString
CALL PrintString
JMP $

PrintChar:
        MOV AH, 0x0E
        MOV BH, 0x00
        MOV BL, 0x07
        INT 0x10
        RET

PrintString:
        PrintStringNext:
                MOV AL, [SI]
                INC SI
                OR AL, AL
                JZ PrintStringExit
                CALL PrintChar
                JMP PrintStringNext
        PrintStringExit:
                RET

HelloWorldString db 101, 108, 108, 111, 0

TIMES 510 - ($ - $$) db 0
DW 0xAA55
When running it on a real machine, I only get "H", but when I'm running it in VirtualBox, I get "Hello". Can anybody see what I'm doing wrong?

Re: Simple assembly hello world bootloader problem

Posted: Fri Mar 05, 2010 5:16 pm
by Firestryke31
Technically, for HelloWorldString, most assemblers accept 'db "ello", 0' as equivalent to what you have.

Also, don't assume that the BIOS set DS to 0. You should put this after [ORG 0x7C00]

Code: Select all

  xor ax, ax ; Set ax to 0
  mov ds, ax
This should help you. I noticed some other little things but they're solely space optimizations and do nothing to fix the problem.

Re: Simple assembly hello world bootloader problem

Posted: Fri Mar 05, 2010 5:21 pm
by Xunil
Thanks, that solved the problem :)