Click here to Skip to main content
16,017,100 members
Articles / Programming Languages / ASM

Boot Into Your Own Hello World Application

Rate me:
Please Sign up or sign in to vote.
3.91/5 (12 votes)
23 Jul 2008CPOL2 min read 43.9K   28   6
Here I will present a simple "Hello World" application that you can boot into from Floppy Drive, like an Operating System.

Introduction

Simply stating, it is an Operating System that does nothing but displays a simple message "Hello World". The source code is written in assembly language (NASM), and can be booted from a floppy disk.

Background

The reader must be familiar with all the OS terminology and boot loader mechanism along with a minimal knowledge of a 16 bit Assembly language and working knowledge with NASM (freely downloadable) and the MSDOS program name Debug.Exe.

Using the Code

Without describing anything, let me write the boot loader code.

MASM
;**************************************************
; Hello World OS Boot loader
; Designed by Arnav
; http://pendorasoft.byethost15.com/
;**************************************************

[BITS 16] [ORG 0x0000] 
; code located at 0000:7C00, adjust segment registers
          cli
          mov     ax, 0x07C0
          mov     ds, ax
          mov     es, ax
          mov     fs, ax
          mov     gs, ax

; create stack
          mov     ax, 0x0000
          mov     ss, ax
          mov     sp, 0xFFFF
          sti

; post message
          mov     si,msgHello
          call    DisplayMessage
          mov     si, msgEnd
          call    DisplayMessage
          hlt  
   

; Display Message
DisplayMessage:
          lodsb                                       ; load next character
          or      al, al                              ; test for NUL character
          jz      .DONE
          mov     ah, 0x0E                            ; BIOS teletype
          mov     bh, 0x00                            ; display page 0
          mov     bl, 0x07                            ; text attribute
          int     0x10                                ; invoke BIOS
          jmp     DisplayMessage
     .DONE:
          ret          
          
; data section
msgHello  db 0x0D, 0x0A, "Hello World", 0x0D, 0x0A, 0x00          
msgEnd  db 0x0D, 0x0A, "That's all folks!!!", 0x0D, 0x0A, 0x00           
          
;ASM Signature
          TIMES 510-($-$$) DB 0
          DW 0xAA55

Save the above code in a file, say boot.asm.

Next we have to generate a RAW Binary code file for the above code. So I used NASM. Assuming that NASM is in the system path, we write the following at the COMMAND prompt:

D:\>NASM boot.asm -o boot.bin -f bin

Next we need a floppy disk from which we will boot the OS. So place a floppy disk in the A Drive and before continuing, please backup any data that may be on the floppy Disk, because we would require to format the floppy in this step:

D:\>format a: /q

I have quick formatted the disk to save a lot of time, but full format will also do.

Now we need to copy our OS binary to the floppy disk. So we use the Debug.Exe program as follows:

D:\>debug boot.bin
-W 100 0 0 1
-Q
D:\>

On issuing the -W option in debug program, the binary is RAW written to the boot sector of the floppy disk after which we quit the debug application.

So we are done with our OS. Now restart the system and boot from the floppy disk. We will see the following output on the screen:

Hello World

That's all folks!!!

And then the computer halts as it now receives the HLT instruction.

Points of Interest

The first point to note here is that this is not a real OS but a kernel boot-loader. And thus the activities I can do here are limited to 512 kb (1 sector). So my code size does not exceed 512 kb which includes the data section.

Apart from that, I guess the code itself is self explanatory. The only tricky part to note is that the loader always tries to search for the Signature 0xAA55 in the boot loader to mark it as valid for loading. So at the end of the 510 byte of my code (and data) space, the extra 2 bytes are provided for the 2 byte signature for the loader to verify my code as valid.

Problems

The only problem in this OS is that after the OS is copied to the floppy disk, Windows or MSDOS starts thinking that the floppy is not formatted and then onwards, every time I try updating the code above, I have to first format the floppy and then copy the boot sector binary (boot.bin).

I welcome any suggestions to modify the code above so that the formatted data doesn't get destroyed.

History

  • 23rd July, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student Institute of RadioPhysics & Electronics
India India
......

Comments and Discussions

 
Questionexecuting a dir command/how to make an iso file from it Pin
Saeedek10-Feb-14 22:40
Saeedek10-Feb-14 22:40 
QuestionSickening *8-b Pin
TheRaven18-Sep-11 11:56
TheRaven18-Sep-11 11:56 
Generalcool Pin
Mubi | www.mrmubi.com4-Aug-10 11:04
professionalMubi | www.mrmubi.com4-Aug-10 11:04 
QuestionHi!it boot delete all data? Pin
tuan111115-Jun-09 16:54
tuan111115-Jun-09 16:54 
I vietnam
How to boot not Format HDD(HDD have Partition disks & files)
By tuan1111 Big Grin | :-D
GeneralNice code... Pin
kinkad9-Sep-08 4:43
kinkad9-Sep-08 4:43 
GeneralDisk format info should also appear in sector Pin
supercat924-Jul-08 6:04
supercat924-Jul-08 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.