1

Because the first sector is only 512 bytes while the rest of the code is huge, I think I need a separated assembler code for the .lst file. I'm not sure that this is called binding but I want to bind this assembler file when I make a .img file with NASM.

first one

    ORG     0x7c00      
start:
    JMP     entry
    DB      0x90
    ; Start of BIOS Parameter Block         
    DB      "MyOS    "      
    DW      512         
    DB      1           
    DW      1           
    DB      2           
    DW      224         
    DW      2880            
    DB      0xf0            
    DW      9   
    DW      18          
    DW      2           
    DD      0           
    DD      2880            
    DB      0,0,0x29        
    DD      0xffffffff      
    DB      "MyOS-Vol   "       
    DB      "FAT12   "      
    TIMES   18 DB 0         
    ; End of BIOS Parameter Block           

entry:
    MOV     AX, 0           
    MOV     SS,AX
    MOV     SP,0x7c00 
    MOV     DS,AX 
    MOV     ES,AX 
    MOV     SI,msg
loop:
    MOV     AL,BYTE [SI]
    ADD     SI, 1           
    CMP     AL,0
    JE      fin
    MOV     AH, 0x0e        
    MOV     BX, 0xe1        
    INT     0x10            
    JMP     putloop
fin:
    HLT                 
    JMP     fin         

msg:
    DB      0x0a, 0x0a      
    DB      "hello, world"
    DB      0x0a            
    DB      0

maker:      
    TIMES   0x01fe-(maker-start) DB 0   
    DB      0x55, 0xaa      

second one

DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
TIMES   4600 DB 0
DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
TIMES   1469432 DB 0

How can I append second code to first code? Not by copy-pasting the text but like when it links the object file together.


For those who are looking for fat12 disk format. DOS Boot Record Format for FAT12 and FAT16

Peter
  • 301
  • 4
  • 17
  • 1
    I assume you are talking about the limits on booting on x86 PC hardware. There is no magical way to link things so that you can have the first part in the boot sector and the rest elsewhere. The bootloader has to handle the loading of the additional code and execute it. – Sami Kuhmonen Mar 26 '16 at 12:02
  • I got your point. I think I didn't describe my point clearly. Sorry about that. What I was trying to ask is this. How can I bind asm files together before loading into hardware? I know compiler links the object files before making executable file. But How about assembler? I came up with making small program reading the file and appending another file as string function. But that seems not the way. Is there any options for nasm? I couldn't find one :( – Peter Mar 26 '16 at 12:27
  • 1
    Since you have `org 0x7c00` at the top of your asm file then that implies you are assembling your code with the `-f bin` option (like `nasm -f bin boot.asm -o boot.bin`). Output from `nasm -f bin` is already a fully linked flat binary image that can't be _linked_ in the traditional sense. It is literally written to the bootloader (usually with a tool like _DD_). Are you on Windows / OSX, or Linux? And which linker are you wanting to use (_LD_, _GCC_ etc)? – Michael Petch Mar 26 '16 at 15:14
  • 1
    Usually what you do is use _DD_ to write the bootsector to an image, And then use _DD_ to write any other data to the disk image. I write a [Stackoverflow answer](http://stackoverflow.com/a/34108769/3857942) with some basic information that might help if you have _DD_ – Michael Petch Mar 26 '16 at 15:17
  • If I didn't know better it would almost appear you are trying to preformat your disk image as FAT12 with the second file. – Michael Petch Mar 26 '16 at 15:20
  • Yup, This is what I looking for. Thanks a lot :) And I'm working it on OSX, but I didn't think that this is going to be matter since I'm using virtual disk and qemu emulator. and I have DD as well. – Peter Mar 26 '16 at 15:36

1 Answers1

3

The easiest way to do it would be to just join the two assembly files together and assemble with the -f bin option to produce your floppy image directly. The size of the listing file won't be a problem, your second file produces a listing file that looks like this:

     1 00000000 F0FFFF0000000000            DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
     2 00000008 00                    TIMES   4600 DB 0
     3 00001200 F0FFFF0000000000            DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
     4 00001208 00                    TIMES   1469432 DB 0

If you want to keep the two source code files separate you can use NASM's %include directive:

%include "bootsector.asm"
%include "fat12.asm"

Alternatively you can join the two files together after assembling them directly into binaries with the cat command:

nasm -f bin bootsector.asm -o bootsector.bin
nasm -f bin fat12.asm -o fat12.bin
cat bootsector.bin fat.bin > floppy.img

You don't need to use a linker to create your floppy image unless you're linking together files that refer to symbols outside their own file. Even then it would be much simpler to use the %include directive to "link" everything together. Going the linker route means writing a linker script which isn't worth the trouble in this case.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112