我正在制作一个引导加载程序,但它失败了 %include [英] I'm making a bootloader but it fails with %include
问题描述
我有一些关于制作引导加载程序的问题.我有点不确定这是否是 32 位程序集,但如果您看到它是 16 位...
I have some problems... about making a bootloader. I'm a little bit unsure if this is a 32-bit assembly but if you see there it's 16-bit...
这是我的代码:(fortr_foload.asm)
Here's my code: (fortr_foload.asm)
[ bits 16 ]
[ org 0x7c00 ]
bootstart:
xor ax,ax
mov bx,ax
mov cx,ax
mov dx,ax
mov es,ax
mov ax,0x8000
mov si,fortr_loadbOutp
call fortr_outpf
fortr_loadbOutp db 'booted!!!'
fortr_outpf:
mov ah,0x0E
%include "fortr_kernel.asm"
call fortrk_start
.repboot_fortr:
lodsb
cmp al,0
je .rebboot
int 0x10
jmp .repboot_fortr
.rebboot
ret
times (510 - ($ - $$)) db 0x00
DW 0xAA55
这是第二个:(fortr_kernel.asm)
And here's the second: (fortr_kernel.asm)
[ bits 16 ]
fortrk_start:
xor ax,ax
mov bx,ax
mov cx,ax
mov dx,ax
mov bx,0x7000
mov si,fortr_outp
call fortr_printf
fortr_outp db 'Stage 2... Done!'
fortr_printf:
mov ah,0x0E
但是,如果我使用以下代码编译它:
But, if I compile it using this code:
nasm -f bin -o "fortr_foload.asm" "fortrSt.iso"
在 QEMU 中播放它不会启动它只会输出一个白色光标,好吧,什么都没有.
And play it in QEMU it does not boot it'll just output a white cursor and well, nothing.
但是如果我删除这些行:
But if I remove the lines:
%include "fortr_kernel"
call fortrk_start
我什至试图重新排列线条,但遗憾的是,它甚至不起作用:(它将成功启动!我怎样才能解决这个问题?提前TYSM!:D哦!顺便说一句,我真的是组装新手,所以请帮助我:D!
And I even tried to rearrange the lines but sadly, it won't even work :( It will boot successfully! How can I fix this? TYSM in advance! :D Oh! And by the way, I'm really REALLY NEW to assembly so please help me out :D!
推荐答案
当您%include
一个文件时,它会准确地放置在您包含它的位置.
When you %include
a file, it's placed exactly where you include it.
所以,
[...]
fortr_outpf:
mov ah,0x0E
%include "fortr_kernel.asm"
call fortrk_start
.repboot_fortr:
[...]
变成
[...]
fortr_outpf:
mov ah,0x0E
[ bits 16 ]
fortrk_start:
xor ax,ax
[...]
call fortr_printf
fortr_outp db 'Stage 2... Done!'
fortr_printf:
mov ah,0x0E
call fortrk_start
.repboot_fortr:
[...]
您直接在代码路径中间注入包含的文件.如果您想以这种方式做事(您可能需要重新考虑、组装和链接单独的源文件),%include
将它放在处理器将执行的指令之外的地方.
You're directly injecting the included file in the middle of your codepath. If you want to do things this way (which you may want to reconsider, assembling and linking separate source files), %include
it somewhere out of the way of the instructions the processor will execute.
这篇关于我正在制作一个引导加载程序,但它失败了 %include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!