Hello everyone!
I, once again need your help :).
I've expanded my hanging boot loader, to a hello world boot loader. Or, at least that's what it's supposed to be, when I get it running.
This is my Assembly code:

[bits 16]
[org 0x7c00]

message db "Hello, world!", 0

booter:
    mov si, message
    call output
output:
    mov ah, 0x0e
    mov al, [si]
    cmp al, 0
    jz hang
    mov bh, 0x00
    mov bl, 0x07
    int 0x10
    inc si
    jmp output
hang:
    jmp $
times 510 - ($ -$$) db 0
dw 0xaa55

It assembles fine, but when I run it, in Microsoft Virtual PC, as an *.iso file, nothing happens. It doesn't print out anything at all. It's probably a simple mistake, but please help me :).

Can you post an objdump of the code? I want to see how Nasm is addressing

message db "Hello, world!", 0

If you can't provide an objdump of the code then try moving message db "Hello, world!", 0 to the end of your code....Initially your instruction pointer may be trying to execute

message db "Hello, world!", 0

This is a guess since I'm not sure how Nasm handles memory for 16 bit code...

Can you post an objdump of the code? I want to see how Nasm is addressing

message db "Hello, world!", 0

If you can't provide an objdump of the code then try moving message db "Hello, world!", 0 to the end of your code....Initially your instruction pointer may be trying to execute

message db "Hello, world!", 0

This is a guess since I'm not sure how Nasm handles memory for 16 bit code...

Thanks. I'll post an objdump when I get home from school. I just have
one litte question about objdumping. To objdump this file would I just
type: "objdump -Dslx bootloader.bin"?

You could try setting up a data segment before using 'data'. I really have no clue where your message data is existing at on your computer. Some dimension created by the bios perhaps.

Thanks. I'll post an objdump when I get home from school. I just have
one litte question about objdumping. To objdump this file would I just
type: "objdump -Dslx bootloader.bin"?

With GCC utilities use

objdump -D assembler>testfile

the file testfile now contains your assembler code..

I rewrote the code, to this:

[bits 16]
[org 0x7c00]

booter:
    mov si, message
    call output
    jmp $
output:
    mov ah, 0x0e
    mov al, [si]
    cmp al, 0
    jz hang
    mov bh, 0x00
    mov bl, 0x07
    int 0x10
    inc si
    jmp output
hang:
    ret booter
	
message db "Hello, world!", 0

times 510 - ($ -$$) db 0
dw 0xaa55

And now in Microsoft Virtual PC, it outputs this little smiley face, at the bottom of the window...

You could try setting up a data segment before using 'data'. I really have no clue where your message data is existing at on your computer. Some dimension created by the bios perhaps.

Adding my text and data segment, will make the *.bin file 540 bytes..

Woohooo :). I figured it out. It was because I forgot to initialize the offset of my data register.
This is the code that did the job:

[bits 16]
[org 0x7c00]
booter:
    mov ax, 0x0000
    mov ds, ax
    mov si, message
    call output
    jmp $
output:
    mov ah, 0x0e
    mov al, [si]
    cmp al, 0
    jz hang
    mov bh, 0x00
    mov bl, 0x07
    int 0x10
    inc si
    jmp output
hang:
    ret booter
	
message db "Hello, world!", 0
	
times 510 - ($ -$$) db 0
dw 0xaa55

I'm not quite sure if this was what sysop_fb wanted me to do. If it was, then sorry. I thought you meant, declare a data segment like this:

[section .data]

So if that was the case, sorry for my ignorance :P.

Woohooo :). I figured it out. It was because I forgot to initialize the offset of my data register.
This is the code that did the job:

[bits 16]
[org 0x7c00]
booter:
    mov ax, 0x0000
    mov ds, ax
    mov si, message
    call output
    jmp $
output:
    mov ah, 0x0e
    mov al, [si]
    cmp al, 0
    jz hang
    mov bh, 0x00
    mov bl, 0x07
    int 0x10
    inc si
    jmp output
hang:
    ret booter
	
message db "Hello, world!", 0
	
times 510 - ($ -$$) db 0
dw 0xaa55

I'm not quite sure if this was what sysop_fb wanted me to do. If it was, then sorry. I thought you meant, declare a data segment like this:

[section .data]

So if that was the case, sorry for my ignorance :P.

Yes that's all good...but do you know why you had to place the data at the end of your code?

Yes that's all good...but do you know why you had to place the data at the end of your code?

I'm not sure... but I suppose it's because it'll try to move undeclared bytes into si otherwise.

I'm not sure... but I suppose it's because it'll try to move undeclared bytes into si otherwise.

Writing code at this level requires a lot of knowledge to get a little done. Try reading this for starters

http://linuxgazette.net/issue77/krishnakumar.html

Writing code at this level requires a lot of knowledge to get a little done. Try reading this for starters

http://linuxgazette.net/issue77/krishnakumar.html

Thanks. I have a few questions:
1) If I were to program, a small and simple 16-bit OS, would the boot loader then start the kernel?
2) Could I write this kernel in C, and then implement it into the boot loader, so that the boot loader would start the execution of the kernel?

Thanks. I have a few questions:
1) If I were to program, a small and simple 16-bit OS, would the boot loader then start the kernel?
2) Could I write this kernel in C, and then implement it into the boot loader, so that the boot loader would start the execution of the kernel?

For question like these I like to reference the Intel/AMD reference manuals...

http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_739_7044,00.html

http://www.intel.com/products/processor/manuals/


Like I said a lot of knowledge to get a little done...I would check the sections on "Processor Initialization and Long Mode Activation". Maybe someone here has a better answer.

Thanks. I have a few questions:
1) If I were to program, a small and simple 16-bit OS, would the boot loader then start the kernel?
2) Could I write this kernel in C, and then implement it into the boot loader, so that the boot loader would start the execution of the kernel?

Yes and yes.
Although you're going to need to setup a bit more before hand, such as setting up some stack space.

Here's a website with a number of tutorials and whitepapers on various subjects you'll encounter while writing an O/S.http://wiki.osdev.org/Main_Page

Yes and yes.
Although you're going to need to setup a bit more before hand, such as setting up some stack space.

Here's a website with a number of tutorials and whitepapers on various subjects you'll encounter while writing an O/S.http://wiki.osdev.org/Main_Page

Thanks a lot :).
I've written a basic kernel in C, that'll pretty much just tell me that the kernel has been started. And I think I got the right Assembly code for booting/implementing this kernel as well.
Otherwise, I'm sure I'll return to these forums for more great advice ;).
I just need to know: Where can I find gcc.exe and ld.exe, as I can't find neither of them on Google, and I've also installed CygWin. But I can't find gcc.exe nor ld.exe in CygWins bin folder. So could someone please help me on that as well?

Thanks a lot :).
I've written a basic kernel in C, that'll pretty much just tell me that the kernel has been started. And I think I got the right Assembly code for booting/implementing this kernel as well.
Otherwise, I'm sure I'll return to these forums for more great advice ;).
I just need to know: Where can I find gcc.exe and ld.exe, as I can't find neither of them on Google, and I've also installed CygWin. But I can't find gcc.exe nor ld.exe in CygWins bin folder. So could someone please help me on that as well?

I find it really hard to believe that you wrote a kernel in C, yet your here trying to get a simple boot image going and your looking for - gcc.exe and ld.exe...etc

I find it really hard to believe that you wrote a kernel in C, yet your here trying to get a simple boot image going and your looking for - gcc.exe and ld.exe...etc

Lol.. I haven't tested it yet.. I've only written the source.. I haven't been programming in C for months now, so I got rid of my gcc.exe and ld.exe (I got this annoying habit of uninstalling/deleting a program(s), as soon as I feel like I don't need them anymore).

The reason your data couldn't be declared at the
beginning of your code, unless there was a jump
as the first instruction, is because execution
begins at the beginning of your executable image
in memory at 0000:7C00 and if data was
at the beginning it would be executed as
instructions, and the rest of your code could be
interpreted by the processor as junk, yikes!

To create a 16-bit OS, you need kernel data structures
to keep tract of the current enviroment, a file system of
which FAT is the simplest, and the BIOS can be used
to access hardware.

There are a lot of considerations if you want your OS
to be flexible, DOS is a very good model to start
your ground work, it is a traditional operating system.

The ralf browns interrupt list RBIL has a pretty good
listing of BIOS services and functions.

Here's a very simple example of executing a line of code(the inline code) and jumping over the data which is contained in the same section...Note this is 64 bit assembler not 16 bit..

#include <stdio.h>
#include <stdlib.h>

void myfunc(void)
{
	__asm__
	(
"		pushq	%rax						\n\t"
"		pushq	%rdi						\n\t"
"		pushq	%rsi						\n\t"
"		pushq	%rdx						\n\t"

"		call	tohere						\n\t"
"	tohere:								\n\t"
"		popq	%rsi						\n\t"
"		.equ	myoff, . - mydata				\n\t"
"		addq	$-myoff + 0x1, %rsi				\n\t"


"		movq	$1, %rax					\n\t"
"		movq	$1, %rdi					\n\t"
"		movq	$mylen, %rdx					\n\t"
"		syscall							\n\t"

"		jmp	tohere2						\n\t"
"		mydata: .ascii \"this is the message to pass along!\n\"	\n\t"
"		.equ	mylen, . - mydata				\n\t"
"	tohere2:							\n\t"

"		popq	%rdx						\n\t"
"		popq	%rsi						\n\t"
"		popq	%rdi						\n\t"
"		popq	%rax						\n\t"
	);
}

int main(int argc, char**argv)
{
	myfunc();
	exit(EXIT_SUCCESS);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.