【问题标题】:what are the differences between these nasm stack pushes?这些 nasm 堆栈推送之间有什么区别?
【发布时间】:2024-01-03 07:38:01
【问题描述】:

这是 16 位,实模式,NASM。

 ; ---- variables ------
    cursorRow db 1
 .
 .
 .

 ; what are the differences between these two pushes?
 push cursorRow ; is this the address of?

 push [cursorRow] ; is this the value of?

我在以 cursorRow 为参数的函数中更改此变量时遇到问题。 我发布的一个相关问题:Updating variable that lives in the data segment from the stack and its segment

【问题讨论】:

  • 我认为这两者都会根据您的汇编程序推动 cursorRow 的 value (您可以随时反汇编文件以确定)。 mov ax, offset cursorRow; push ax 至少应该推送地址。 lds si, [cursorRow]; push ds; push si 应该推一个远指针,但是我已经有一段时间没有做多段 16 位程序了。
  • 我正在使用 NASM,据我所知,它没有 offset 关键字。昨晚我通过使用以下指令推送 cursorRow 的地址来让我的程序工作:push cursorRow
  • 你读过 nasmdoc 吗?我记得有一节专门描述这部分与其他汇编程序(如 MASM 和 TASM)不同。

标签: assembly stack nasm 16-bit


【解决方案1】:

cursorRow 是值,[cursorRow] 是光标所在位置的值。如果您需要将 cursorRow 的地址放入堆栈,那么您需要推送 bp+1 或变量的实际地址是什么

【讨论】:

    【解决方案2】:

    如果 cursorRow (不是 [cursorRow] )在数据段中启动,它就像一个 C 指针。使用 [cursorRow] 将取消引用它并返回存储在那里的值,您必须在 [cursorRow] 前面加上值的大小,例如 mov al, byte [cursorRow]

    【讨论】: