代码之家  ›  专栏  ›  技术社区  ›  Nathan Campos

Putting Two ORGs Together

  •  2
  • Nathan Campos  · 技术社区  · 14 年前

    我正在构建引导加载程序,它引导位于 1000h 软盘的一部分。我用的是 Fasm (because my friend only uses Fasm, and he was helping me with this), but I prefer to use Nasm ,现在我的语法有问题,那么我想知道如何在NASM中做到这一点:

    org 7C00h
        %include "boot.asm"
    
    org 1000h
        %include "kernel.asm"
    

    附言:我已经把 %include 使用nasm语法样式的指令,在fasm上它应该只是 include .

    2 回复  |  直到 14 年前
        1
  •  4
  •   paxdiablo    14 年前

    here for the description of your problem or what I 认为 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 -)

    here

    基本上, org NASM中的语句用于设置节的基地址,不能用于在流中任意插入字节。它建议您使用如下内容:

    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.

    BIOS希望在7c00:0时将引导扇区作为单个块加载,并且当它在块的开头有内核时,几乎肯定会混淆。我认为您需要做的是创建两个完全独立的平面二进制文件,一个用于引导扇区,另一个用于内核。BIOS将加载引导扇区,然后引导扇区将加载内核。

    org statement in the two source files and your problem should hopefully be solved.

        2
  •  1
  •   Mike Gonta    14 年前

    The simple answer is that this cannot be done in NASM. 这个 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.

    令人高兴的答案是,这是一种罕见的(可能也是唯一的)情况,在这种情况下,具有不同起始地址的代码需要组合(与NASM)或组装(与FASM)成单个图像。 引导扇区转移到 7C00h 通过BIOS。在媒体(软盘、硬盘、USB闪存驱动器)上紧接着是有效负载,有效负载由引导扇区引导加载程序传输到其起始地址。