linux汇编:如何调用syscall?

linux汇编:如何调用syscall?,第1张

概述我想在汇编调用一个系统调用.问题是我不能运行ecx,rsp. rsp是64位寄存器,ecx是32位寄存器.我想将缓冲区addr作为此系统调用的参数传递.我能做什么?谢谢. section .data s0: db "Largest basic function number supported:%s\n",0s0len: equ $-s0section .text global mai 我想在汇编中调用一个系统调用.问题是我不能运行ecx,rsp. rsp是64位寄存器,ecx是32位寄存器.我想将缓冲区addr作为此系统调用的参数传递.我能做什么?谢谢.

section .data s0: db "Largest basic function number supported:%s\n",0s0len: equ $-s0section .text global mainextern writemain: sub rsp,16xor eax,eaxcpuIDmov [rsp],ebxmov [rsp+4],edxmov [rsp+8],ecx mov [rsp+12],word 0x0mov eax,4mov ebx,1mov ecx,rspmov edx,4 int 80hmov eax,s0mov edx,s0len int 80hmov eax,1int 80h
解决方法 要在64位linux中进行系统调用,请将系统调用号放在rax中,然后将其参数按顺序放在rdi,rsi,rdx,r10,r8和r9中,然后调用syscall.

这是一个例子

.global _start        .text_start:        # write(1,message,13)        mov     ,%rax                # system call 1 is write        mov     ,%rdi                # file handle 1 is stdout        mov     $message,%rsi          # address of string to output        mov     ,%rdx               # number of bytes        syscall        # exit(0)        mov     ,%rax               # system call 60 is exit        xor     %rdi,%rdi              # return code 0        syscallmessage:        .ascii  "Hello,World\n"
总结

以上是内存溢出为你收集整理的linux汇编:如何调用syscall?全部内容,希望文章能够帮你解决linux汇编:如何调用syscall?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1022072.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存