MikeOS 引导加载程序中的堆栈段
我不明白这段代码:
mov ax, 07C0h ; Set up 4K of stack space above buffer
add ax, 544 ; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
cli ; Disable interrupts while changing stack
mov ss, ax
mov sp, 4096
sti ; Restore interrupts
- mov ax, 07C0h - 这里 BIOS 加载我们的 代码。但什么是“4K”?千字节?我 没明白:)
- 添加 ax, 544 - 为什么又是“8K”?为什么我们要加上 544?为什么不是512?
- mov sp, 4096 - 在这里我们设置堆栈指针。
在设置堆栈指针之前,我们为什么要做所有这些操作呢?
I don't understand this piece of code:
mov ax, 07C0h ; Set up 4K of stack space above buffer
add ax, 544 ; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
cli ; Disable interrupts while changing stack
mov ss, ax
mov sp, 4096
sti ; Restore interrupts
- mov ax, 07C0h - here BIOS loads our
code. But what is '4K'? Kilobytes? I
didn't get it :) - add ax, 544 - Why again '8K'? And why we add 544? Why not 512?
- mov sp, 4096 - Here we set stack pointer.
What for do we do all these manipulations, before we set stack pointer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最后一行的评论总结了这一点:
内存布局看起来像这样:
关于段落的评论有点迟钝;我发现用字节来思考更容易,16 个字节组成一个段落。
这些幻数的原因:
请注意,数字 4096 = 4KB 在代码中正常显示,因为 SP 寄存器需要一个以字节为单位的值。所有其他值都在段落中,因为它们与 SS(段寄存器)相关。
I think the comment on the last line sums it up:
The memory layout looks like this:
The comment about paragraphs is slightly obtuse; I find it easier to think in bytes, where 16 bytes makes one paragraph.
The reason for these magic numbers:
Note that the number 4096 = 4KB appears as normal in the code, because the SP register needs a value in bytes. All the other values are in paragraphs because they relate to SS, which is a segment register.