繁体   English   中英

汇编语言Bootloader代码问题

[英]Assembly language bootloader code problem

我正在尝试了解Bootloader的内容,但是在下面给定的代码部分中遇到了一些麻烦,请帮忙。 我在这里提到评论,这将对您有所帮助,为什么我们使用07C0h,是固定位置还是任意位置,所以第二行中的544是什么。

Bootloader_start:    
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 ;set data segment to where we are loaded
mov ds, ax

cmp dl, 0
je no_change
mov [bootdev], dl    ;save boot device number   
mov ah, 8                 ;get drive parameters
int 13h
jc fatal_disk_error
and cx, 3fh              ;maximum sector number 
mov [SectorsPerTrack], cx  ;Sector numbers start at 1
movzx dx, dh        ;maximum head number
add dx, 1.             ;head number starts at 0 - add 1 for total
mov [Sides], dx

......继续

 Bootloader_start: 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 ;set data segment to where we are loaded mov ds, ax 

首先,明显的优化可以避免彼得对不使用汇编时间添加的正确批评:

Bootloader_start:    
mov ax, 07C0h  ;set up 4k of stack space above buffer
MOV DS, AX
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

那为什么是544?

作者希望在引导加载程序的正上方有一个8192字节的缓冲区以及一个4096字节的堆栈,该引导加载程序位于线性地址7C00h的内存中。

做数学运算,知道线性地址7C00h是第07C0h段:

              Paragraph
              ---------
                07C0h    Bootloader 512 bytes ==  32 paragraphs (20h)
07C0h + 0020h = 07E0h    Buffer    8192 bytes == 512 paragraphs (200h)
07E0h + 0200h = 09E0h    Stack     4096 bytes
                                                 ---
                                                 544

堆栈的底部位于09E0h段,即07C0h + (32 + 512)07C0h + 544
然后将堆栈指针SP设置为偏移量4096,因此我们拥有完整的SS:SP

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM