参见英文答案 >
What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?1个
; NASM push 30 ; '0' mov rax,4 ; write mov rbx,1 ; stdout mov rcx,rsp ; ptr to character on stack mov rdx,1 ; length of string = 1 int 80h
解决方法
amd64使用与int 0x80不同的系统调用方法,虽然这可能仍然适用于安装32位库等.而在x86上可以做到:
mov eax,SYSCALL_NUMBER mov ebx,param1 mov ecx,param2 mov edx,param3 int 0x80
在amd64上,我会改为:
mov rax,SYSCALL_NUMBER_64 ; different from the x86 equivalent,usually mov rdi,param1 mov rsi,param2 mov rdx,param3 syscall
对于您想要做的,请考虑以下示例:
bits 64 global _start section .text _start: push 0x0a424242 mov rdx,04h lea rsi,[rsp] call write call exit exit: mov rax,60 ; exit() xor rdi,rdi ; errno syscall write: mov rax,1 ; write() mov rdi,1 ; stdout syscall ret