【问题标题】:Assembly convert byte and push it into stack汇编转换字节并将其推入堆栈
【发布时间】:2017-03-23 18:11:28
【问题描述】:

我想告诉编译器 AL 是 2 字节变量,我想将 AL 压入堆栈。

然后我想弹出值,告诉它是 1 个字节并将其移动到 dl。 我想到了类似的东西:

push word ptr al
pop byte ptr dl

我该怎么做?
我不想更改 AH 和 DH 中的值

【问题讨论】:

标签: assembly x86


【解决方案1】:

堆栈被组织为一个 WORDS 数组。您不能推送或弹出 BYTE。要存储 AL,您可以将 AH 设置为 0 并按下 AX。如果您不想更改 AH,您可以 PUSH AX 并在堆栈上操作 AH 的压入值。

mov ax, 0102h               ; Any value for testing

; PUSH WORD PTR AL
push ax
mov bp, sp                  ; BP needed for indexed operations
mov BYTE PTR [bp+1], 0      ; Clear high byte (pushed AH)

; POP BYTE PTR DL
mov bp, sp                  ; BP needed for indexed operations
mov dl, BYTE PTR [bp]       ; Load low byte (pushed AL) into DL
add sp, 2                   ; POP

【讨论】:

  • Op 也可以压入一个零,然后用他的字节手动覆盖一半。
猜你喜欢
  • 1970-01-01
  • 2014-08-04
  • 2011-04-22
  • 2018-05-26
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多