5,442,164 members and growing! (17,875 online)
Email Password   helpLost your password?
General Reading » Hardware & System » System     Beginner License: The Code Project Open License (CPOL)

Boot into your own Hello World Application

By arnavguddu

Here I will present a simple "Hello World" application that you can boot into from Floppy Drive, like an Operating System.
ASM

Posted: 23 Jul 2008
Updated: 23 Jul 2008
Views: 1,847
Bookmarked: 10 times
Announcements



Search    
Advanced Search
Sitemap
7 votes for this Article.
Popularity: 2.37 Rating: 2.80 out of 5
1 vote, 14.3%
1
2 votes, 28.6%
2
1 vote, 14.3%
3
2 votes, 28.6%
4
1 vote, 14.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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 Floopy 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.

       
;**************************************************
; 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 issueing the -W option in debug program, the binary is RAW written to the boot sector of the Floppy disk and after which we quit the debug application.

So we are done with our OS, now restart the system and boot from the floopy 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 instuction.

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 is limited to 512 kb (1 sector). So my code size do not exceed 512 kb which includes the data section.
Apart from that I guess the code itself is self explanatory. The only tricky part is to note that the loader always try 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 is 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, everytime I try updating the code above I have to first format the floppy everytime and then copy the boot sector binary (boot.bin).
So I welcome any suggestions to modify the code above so that the formatted data doesn't get destroyed.

Arnav

License

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

About the Author

arnavguddu


I am a student and C++ programmer interested in Multimedia, Graphics, Networking and Electronics.
I am currently designing tools that would simplify my programming job and here at CodeProject, I would upload some info about them.
To know more, visit my Homepage : http://pendorasoft.byethost15.com/
Occupation: Other
Company: Student
Location: India India

Other popular Hardware & System articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralDisk format info should also appear in sectormembersupercat97:04 24 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Jul 2008
Editor:
Copyright 2008 by arnavguddu
Everything else Copyright © CodeProject, 1999-2008
Web12 | Advertise on the Code Project