基本上你可以通过添加到 rsp
寄存器 n * 8
来从 stack 中“删除”元素,但是如果你尝试相反的 (rsp - (n * 8)
) 它不起作用,这看起来很明显但仍然
因此,如果我像这样使用 push
推送到 stack:
push 10
push 20
所以 stack 基本上是 (20; 10)
,我怎样才能让它成为 (20; 10; 20; 10)
而无需使用寄存器(因为你是有限的)或需要重复 push
但是,如果不可能使用哪种更好的替代方案,重复 push
或使用 pop
使用寄存器然后将它们推回去?
回答1
假设 n
和 push
ed values 是常量:
- 您的问题带有 /questions/tagged/x86-64 标记,因此我假设默认操作数大小当前设置为 64 位。您的
push imm8
正在推动符号扩展四字。除非你真的需要 stack 上的四字,否则将 8 个单独的字节 values 放在 stack 上怎么样:
注意:在长模式下不可能只push ((10 * 0x100 + 20) * 0x100 + 10) * 0x100 + 20 mov [rsp + 4], dword ((10 * 0x100 + 20) * 0x100 + 10) * 0x100 + 20
push imm32
以便rsp ≔ rsp − 4
,因此mov
。 - 如果你只是想避免一遍又一遍地使用相同的常量:
push 1234 push 5678 ; first copy push qword [rsp + 8] push qword [rsp + 8] ; second copy push qword [rsp + 8] push qword [rsp + 8]
- 然而,对于
push imm8
,我会简单地选择汇编器的扩展能力:repeat 3 push 10 push 20 end repeat