views:

67

answers:

2

I'm building a boot loader that boots the content that is located at the 1000h part of the floppy. I was doing that using Fasm(because my friend only uses Fasm, and he was helping me with this), but I prefer to use Nasm, and now I'm having problems with the syntax, then I want to know how could I do this in Nasm:

org 7C00h
    %include "boot.asm"

org 1000h
    %include "kernel.asm"

PS: I already put the %include directive using Nasm-syntax style, on Fasm it should be just include.

+4  A: 

See here for the description of your problem or what I think it is since it's a little hard to tell from the question. It's a good idea when posting questions with "I'm having problems with the syntax" to actually show what the syntax problem is :-)

See here for the solution (but it may not work, see below).

Basically, the org statement in NASM is meant to set the base address for the section and cannot be used to arbitrarily insert bytes into the stream. It suggests you use something like:

org 1000h
%include "kernel.asm"
times 7c00h-($-$$) db 0 ; pad it out with zero bytes
%include "boot.asm"

However, have you thought about what you're trying to do. If you're creating a flat binary file to load into memory, I don't think you want both the boot sector and kernel in a single file anyway.

The BIOS will want to load your boot sector as a single chunk at 7c00:0 and will almost certainly be confused when it has the kernel at the start of that chunk. I think what you will need to do is to create two totally separate flat binary files, one for the boot sector and another for the kernel. BIOS will load your boot sector, then your boot sector will load your kernel.

Then you can put the relevant org statement in the two source files and your problem should hopefully be solved.

paxdiablo
+1  A: 

The simple answer is that this cannot be done in NASM. The org statement works the same in FASM as it does in NASM but differently in MASM. In NASM the example code would have to be assembled separately and then combined to create the final image.

The happy answer is that this is the rare (and probably only) case where code with different start addresses needs to be combined (with NASM) or assembled (with FASM) into a single image. The boot sector is transferred to 7C00h by the BIOS. It is immediately followed on the media (floppy disk, hard drive, USB flash drive) by the payload which is transferred to it's start address by the boot sector - boot loader.

Mike Gonta