【问题标题】:assembler - understanding of some lines汇编器 - 理解一些行
【发布时间】:2012-09-07 19:10:20
【问题描述】:

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

我现在的问题是,有些台词听不懂,希望你能帮助我, 或者直接告诉我,如果我是对的。

代码:

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

mov ax, 07C0h
mov ds, ax
  1. 行:启动程序@地址07C0h (我可以改变这个吗?)
  2. 为 ax 增加 288 个段落的空间
  3. ?
  4. 我的程序有 4096 个字节的空间 (存储变量和东西?)
  5. 转到起始地址
  6. ?

感谢您的帮助。

【问题讨论】:

  • 谷歌“dos 引导加载程序”。

标签: assembly nasm


【解决方案1】:
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(引导加载程序启动的段)。当您稍后在引导加载程序中引用数据标签时,它们将使用数据段,因此您的引导加载程序必须位于数据段的开头才能在内存中找到正确的位置。

【讨论】:

【解决方案2】:
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

..这就是你给的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 2017-11-02
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多