Bona Fide OS Developer
View unanswered posts | View active topics It is currently Wed Sep 19, 2018 1:48 am



Post new topic Reply to topic  [ 7 posts ] 
 Update to Hello World Boot Loader 
Author Message

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Update to Hello World Boot Loader
So, I have been playing with the Hello World Boot Loader, trying to turn it into something useful and I thought I would go ahead and clear up some of the code and make the loader smaller and faster.
Code:
[BITS 16]      ; 16 bit code generation
[ORG 0x7C00]   ; Origin location

; Main program
main:      ; Label for the start of the main program
 mov ax,0x0000   ; Setup the Data Segment register
      ; Location of data is DS:Offset
 mov ds,ax   ; This can not be loaded directly it has to be in two steps.
      ; 'mov ds, 0x0000' will NOT work due to limitations on the CPU
 mov si, HelloWorld   ; Load the string into position for the procedure.

 mov ah,0x13      ; 0x13 Prints a full String
 mov bh,0x00   ; Page number
 mov bl,0x07   ; Normal text attribute
 lodsb      ; I think of this as LOaD String Block
      ; (Not sure if thats the real meaning though)
      ; Loads [SI] into AL and increases SI by one
 int 0x10   ; Run the BIOS video interrupt

jmp $      ; Never ending loop

; Data
HelloWorld db 'Loading Stage 1...',13,10,0

; End Matter
times 510-($-$$) db 0   ; Fill the rest with zeros
dw 0xAA55      ; Boot loader signature

This is optimized. So what did I do? I removed the loop, because the author was using the BIOS code for White TTY Character (0x0E). Instead I decided on 0x13 which is White TTY String.

Also, LODSB stands for Load String Bytes. :-)

_________________
Charles Timko
push %esp ;Musings of a computer addict


Mon May 03, 2010 8:20 pm
Profile WWW

Joined: Mon Oct 26, 2009 2:33 pm
Posts: 38
Location: United Kingdom
Post Re: Update to Hello World Boot Loader
Does having the 13,10,0 bytes at the end of the string actually do anything? I was under the impression that those would be implemented by the OS and therfore don't actually do a thing when using the BIOS Interrupts?

Save yourself an extra 3 bytes ;)

_________________
Andy Esser
neogenix Broadcast


Tue May 04, 2010 8:09 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Update to Hello World Boot Loader
Yea, the whole 13 was from the original so I didn't change it since I didn't understand its purpose. I was more worried about removing the loop, when the BIOS is already able to support it.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Tue May 04, 2010 2:46 pm
Profile WWW

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Update to Hello World Boot Loader
Also, yea, I am going to be saving as many bytes as possible, so I can achieve my goal with the boot loader....super optimized..

_________________
Charles Timko
push %esp ;Musings of a computer addict


Tue May 04, 2010 2:51 pm
Profile WWW
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: Update to Hello World Boot Loader
The 13 & 10 are carrage return (CR) and line feed (LF) and the 0 byte is used as a string terminator.

_________________
Thank you for reading,

Kieran C G Foot


Tue May 04, 2010 4:50 pm
Profile WWW

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Update to Hello World Boot Loader
ok, so that line can be changed to:
Code:
HelloWorld db .asciiz "Hello World"
Where the tag .asciiz tells NASM that the string is zero terminated.

@Kerian, yea, I knew what the zero was for and i understood what was going on after I said that. I just really wasn't reading the code (and I am a little rusty on my ASM).

_________________
Charles Timko
push %esp ;Musings of a computer addict


Tue May 04, 2010 8:17 pm
Profile WWW

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: Update to Hello World Boot Loader
So, right, in theory my fix is supposed to work and when I tested it, I thought it did, until I realized that the original loop was still in the logic...and I removed it and tried again and it didn't work. So maybe I didn't correctly understand the other setting for printing a string. I will look into it and see if I can simplify the process down more.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Fri May 07, 2010 11:26 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.