Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
当引导扇区程序开始时,不能相信段寄存器包含任何特定值。根据您的
[org 0x7c00]
以及您进一步用于寻址内存的指令,DS
段寄存器需要包含0。您必须自己设置它:类似,您的程序经常访问堆栈,但您不确定预先存在的堆栈是否能够胜任该任务。您必须自己进行设置:
BIOS.Teletype 函数 0Eh 已使用
BL
和BH
寄存器(它们一起形成BX
)作为它的参数。因此,最好使用SI
寄存器作为提供给 printf 的指针。处理无效答案后,您可以使用
call wywtd
再次重复。在这种情况下,不调用而是跳转更有意义:我不知道这是否是故意的,但是bm1和bm2 消息会在您清除屏幕后立即删除...
这个
调用reboot
是多余的。执行也可以进入重新启动:。您可以用跳转
jmp printf
来替换这个所谓的尾调用。但最有效的方法是将 newline 代码直接放在 printf 代码之上。这甚至会减少
jmp printf
:When a bootsector program begins, the segment registers cannot be trusted to contain any particular value. In accordance with your
[org 0x7c00]
and the instructions that you further use to address memory, theDS
segment register needs to contain 0. You must set it up yourself:Similarly, your program accesses the stack a lot but you don't make sure that the pre-existing stack is up to that task. You must set it up yourself:
The BIOS.Teletype function 0Eh already uses the
BL
andBH
registers (together they formBX
) as some of its parameters. Therefore it would be better to use theSI
register as the pointer that you provide to your printf.At the conclusion of processing an invalid answer you use
call wywtd
to repeat all over again. It makes more sense to not call but rather jump in this instance:I don't know if this is on purpose, but the bm1 and bm2 messages are immediately erased by you clearing the screen...
This
call reboot
is redundant. The execution can just as well fall through into reboot:.You could replace this so-called tail call by a jump
jmp printf
.But the most efficient would be to put the newline code directly above the printf code. That would shave off even the
jmp printf
: