max*_*axm 27 x86 assembly x86-64
我是汇编编程的新手,在GNU汇编程序v2.20.1的Ubuntu x86_64桌面上使用Programming Ground Up.
我已经能够组装/链接执行我的代码,直到我使用pushl/popl指令来操作堆栈.以下代码无法汇编:
.section .data # empty
.section .text
.globl _start
_start:
pushl $1 # push the value 1 onto the stack
popl %eax # pop 1 off the stack and into the %eax register
int $0x80 # exit the program with exit code '1'
Run Code Online (Sandbox Code Playgroud)
使用"as test.s -o test.o",这些错误出现在终端上并且未创建test.o:
test.s: Assembler messages:
test.s:9: Error: suffix or operands invalid for 'push'
test.s:10: Error: suffix or operands invalid for 'popl'
Run Code Online (Sandbox Code Playgroud)
我检查了文档,我用于pushl和popl的操作数是有效的.这不是一个调试问题 - 所以我的代码出了什么问题?或者是我的汇编程序?
Tho*_*nin 31
在64位模式下,您无法推送和弹出32位值; 你需要pushq
和popq
.
此外,你不会以这种方式得到正确的退出.在32位x86上,您需要设置%eax
为1以选择exit()
系统调用,并设置%ebx
为您实际希望的退出代码.在64位x86(这就是你正在使用的)上,约定是不同的:系统调用号exit()
是60,而不是1; 第一个系统调用参数进入%rdi
,而不是%rbx
; 系统调用操作代码不是int $0x80
特殊的,仅限x86-64的操作码syscall
.
这导致:
.section .data
.section .text
.globl _start
_start:
pushq $60
popq %rax
pushq $1
popq %rdi
syscall
Run Code Online (Sandbox Code Playgroud)
(当然,每个push
/ pop
序列都可以用简单的mov
(类似mov $60, %eax
)替换;我想你正在尝试显式测试push
和pop
优化代码大小,或者避免0
机器代码中的字节(对于漏洞有效载荷))
有关:
您需要替换push/pop序列
pushq $1 # push the value 1 onto the stack
popq %rax # pop 1 off the stack and into the %eax register
Run Code Online (Sandbox Code Playgroud)
请注意错误消息是" 后缀或操作数无效",您只检查了OR
错误消息中逻辑的第二部分,可能是因为您不确定后缀的含义:它是"l".
编辑:请参阅托马斯的答案,以解释为什么你的代码无论如何都无法运行,即使它汇编了.
归档时间: |
|
查看次数: |
25325 次 |
最近记录: |