Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux汇编:如何调用syscall?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

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

section .data 
s0: db "Largest basic function number supported:%s\n",0
s0len: equ $-s0

section .text 
global main
extern write
main: 
sub rsp,16
xor eax,eax
cpuid

mov [rsp],ebx
mov [rsp+4],edx
mov [rsp+8],ecx 
mov [rsp+12],word 0x0

mov eax,4
mov ebx,1
mov ecx,rsp
mov edx,4 
int 80h

mov eax,s0
mov edx,s0len 
int 80h

mov eax,1
int 80h

解决方法

要在64位Linux中进行系统调用,请将系统调用号放在rax中,然后将其参数按顺序放在rdi,rsi,rdx,r10,r8和r9中,然后调用syscall.

这是一个例子

.global _start

        .text
_start:
        # write(1,message,13)
        mov     $1,%rax                # system call 1 is write
        mov     $1,%rdi                # file handle 1 is stdout
        mov     $message,%rsi          # address of String to output
        mov     $13,%rdx               # number of bytes
        syscall

        # exit(0)
        mov     $60,%rax               # system call 60 is exit
        xor     %rdi,%rdi              # return @R_407_6756@
        syscall
message:
        .ascii  "Hello,World\n"

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。