Simple assembly hello world bootloader problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Xunil
Posts: 10
Joined: Thu May 28, 2009 12:20 am

Simple assembly hello world bootloader problem

Post 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?
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Simple assembly hello world bootloader problem

Post 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.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Xunil
Posts: 10
Joined: Thu May 28, 2009 12:20 am

Re: Simple assembly hello world bootloader problem

Post by Xunil »

Thanks, that solved the problem :)
Post Reply