2012-09-14 41 views
0

在一些教程的帮助下,我写了一小段代码, 显示我一个字符串,从我的软盘启动后。汇编 - 了解一些行

我的问题是现在,那不懂一些线条,我希望你能帮助我, 或只是告诉我,如果我是正确的。

代码:

mov ax, 07C0h 
add ax, 288   ; (512 + 4096)/16 = 288 
mov ss, ax 
mov sp, 4096 

mov ax, 07C0h 
mov ds, ax 
  1. 线:(?我可以改变这个)@的ADRESS 07C0h 启动该程序段288
  2. 增加空间斧子
  3. 空间的4096个字节我的程序 (存储变量和东西吗?)
  4. 转至开始ADRESS

感谢您的帮助。

+0

Google“dos引导装载程序”。 –

回答

4
mov ax, 07C0h 
add ax, 288   ; (512 + 4096)/16 = 288 
mov ss, ax 

这使堆栈段(SS)的开始在段号07C0h + 288.引导程序在段号07C0h的开始装载。自举程序的大小是512字节,每个段是16个字节。这意味着堆栈段在引导加载程序结束后开始4096个字节。

mov sp, 4096 

这设置堆栈指针〜4096这意味着现在堆栈的顶部是4096个字节过去堆栈段的开始。实际上,这为堆栈分配了4096个字节。

mov ax, 07C0h 
mov ds, ax 

这将数据段设置为07C0h(引导加载程序启动的段)。稍后在引导加载程序中引用数据标签时,它们将使用数据段,因此您的引导加载程序必须位于数据段的起始位置才能在内存中找到正确的位置。

+0

我觉得这个文档很有用:http://duartes.org/gustavo/blog/post/how-computers-boot-up/ – Zack

3
mov ax, 07C0h // copy the address 07C0h into the register ax 
add ax, 288  // add the number 288 to the address in ax 
mov ss, ax  // copy the result to the stack segment register (07C0h + 288) 
mov sp, 4096 // set the stack pointer to 4096 

mov ax, 07C0h // copy the address 07C0h to ax again 
mov ds, ax  // copy the address 07c0h from ax into ds 

..这就是你给出的一切。

+0

好的,非常感谢。 – user1571682