Code Will Not Function.

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
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Code Will Not Function.

Post by ollie123 »

Hello there, I am having a slight problem. I am developing an OS called Project X5. However, when I run it, I do not get any output. This is the contents of my bootsector, BOOT.SYS:

Code: Select all

[BITS 16]
[ORG 0x7C00]

jmp start

loadmessage DB "Project X: Version 1", 0
loadmessage2 DB "Loading Project X Kernel..." , 0

start:
	mov si, loadmessage
	call print
	mov si, loadmessage2
	call print
	cli
	hlt
	
print:
	lodsb
	or al, al
	jz printdone
	mov ah, 09h
	mov bl, 0x07
	int 10h
	xor ah, ah
	xor bl, bl
	jmp print
	
printdone:
	ret

TIMES 510 - ( $-$$ ) DB 0
DW 0xAA55
All this does is halts the system! Can you please tell me how to fix this, or point me in the right direction, as I have read many tutorials.

Thanks.
NEW TO OPERATING SYSTEM DEVELOPMENT
Good OS Development Tutorials: http://www.brokenthorn.com/Resources/OSDevIndex.html
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

BTW: I will actually add the code to load the kernel later. :x
NEW TO OPERATING SYSTEM DEVELOPMENT
Good OS Development Tutorials: http://www.brokenthorn.com/Resources/OSDevIndex.html
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

If you're using int 0x10 with AH = 0x09, you have to move the page number into BH = 0...
Jules
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Add this right after the start label:

Code: Select all

push cs
pop ds
push ds
pop es
And after that,it's good to set the stack.

@suthers: BX is 0 after the bootup.

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Blue
Member
Member
Posts: 31
Joined: Thu Aug 02, 2007 6:34 am
Location: on the stack

Post by Blue »

Hi..

I'm not sure, but I don't see anywhere where you set DS which is used for lodsb (al = DS:[SI])..
Also you use the interrupt int 10h with AH = 09h, and what I read from Ralf Brown's interrupt list is that you also need to state CX as the number of time the character shall be displayed (on some systems this is ignored)..

So I guess you should add this to your code:

Code: Select all

start:
   push cs   
   pop ds    
   mov si, loadmessage 
Of course i might be wrong since I'm also new, so anyone feel free to correct me..

Edit: Two people beat me to it :oops:

Blue
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

I'd suggest function 0Eh for printing. Instead of

Code: Select all

mov ah, 09h
mov bl, 0x07
int 10h
xor ah, ah
xor bl, bl
you could try to put

Code: Select all

mov ah,0Eh
int 10h
And yes, set up DS & ES, and SS too:

Code: Select all

xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,7C00h
Did it helped?

Cheers,
CmpXchg
Every Man Must Learn David DeAngelo's Stuff, Period.
http://www.doubleyourdating.com/Catalog
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

Ok, I've updated my code to the following:

Code: Select all

[BITS 16]
[ORG 0x7C00]

jmp start

loadmessage DB "Project X: Version 1", 0
loadmessage2 DB "Loading Project X Kernel..." , 0

start:
	call setup
	mov si, loadmessage
	call print
	mov si, loadmessage2
	call print
	cli
	hlt
	
print:
	lodsb
	or al, al
	jz printdone
	mov ah,0Eh
	int 10h
	jmp print
	
printdone:
	ret

setup:
	xor ax,ax
	mov ds,ax
	mov es,ax
	mov ss,ax
	mov sp,7C00h
	ret

TIMES 510 - ( $-$$ ) DB 0
DW 0xAA55
But it still won't function!
NEW TO OPERATING SYSTEM DEVELOPMENT
Good OS Development Tutorials: http://www.brokenthorn.com/Resources/OSDevIndex.html
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

If you wan to use INT 10h with 0Eh, try this code:

Code: Select all

PutStr:       
    mov ah,0x0E   
    mov bh,0x00   
    mov bl,0x07   
   .nextchar:  
    lodsb       
    or al,al         
    jz .return         
    int 0x10   
    jmp .nextchar   
   .return:       
    ret    
It's what I use in my OS, so I know it works.
Jules
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

suthers wrote:If you wan to use INT 10h with 0Eh, try this code:

Code: Select all

PutStr:       
    mov ah,0x0E   
    mov bh,0x00   
    mov bl,0x07   
   .nextchar:  
    lodsb       
    or al,al         
    jz .return         
    int 0x10   
    jmp .nextchar   
   .return:       
    ret    
It's what I use in my OS, so I know it works.
Jules
Brilliant! This code works fine. Have a free cookie. :D :D
NEW TO OPERATING SYSTEM DEVELOPMENT
Good OS Development Tutorials: http://www.brokenthorn.com/Resources/OSDevIndex.html
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

Free cookies WHERE?!
:lol: :lol:
Jules
Post Reply