简体   繁体   English

Linux x86-64 Hello World并注册参数使用情况

[英]Linux x86-64 Hello World and register usage for parameters

I found this page which has a Hello World example for x86-64 on Linux: 我发现此页面有一个Linux上的x86-64的Hello World示例:

http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/

; 64-bit "Hello World!" in Linux NASM

global _start            ; global entry point export for ld

section .text
_start:

    ; sys_write(stdout, message, length)

    mov    rax, 1        ; sys_write
    mov    rdi, 1        ; stdout
    mov    rsi, message    ; message address
    mov    rdx, length    ; message string length
    syscall

    ; sys_exit(return_code)

    mov    rax, 60        ; sys_exit
    mov    rdi, 0        ; return 0 (success)
    syscall

section .data
    message: db 'Hello, world!',0x0A    ; message and newline
    length:    equ    $-message        ; NASM definition pseudo-instruction

The Author says: 作者说:

An integer value representing the system_write call is placed in the first register, followed by its arguments. 代表system_write调用的整数值放置在第一个寄存器中,后跟其参数。 When the system call and its arguments are all in their proper registers, the system is called and the message is displayed. 当系统调用及其参数都在其适当的寄存器中时,将调用系统并显示消息。

  • What does he mean by "proper" registers/What would be an im"proper" register? 他所说的“适当”寄存器是什么意思/什么是不适当的寄存器?
  • What happens if I have a function with more arguments than I have registers? 如果我的函数的参数多于寄存器的值,会发生什么?
  • Does rax always point to the function call (this would always be a system call?)? rax是否始终指向函数调用(这始终是系统调用?)? Is that its only purpose? 这是唯一的目的吗?

By "the proper registers", the author means the registers specified by the x86-64 ABI , in the Linux Kernel Calling Conventions section. 作者用“适当的寄存器”表示Linux内核调用约定部分中x86-64 ABI指定的寄存器。 The system call number goes in rax , and arguments go in rdi , rsi , rdx , r10 , r8 and r9 , in that order. 系统调用编号以rax进入,参数以rdirsirdxr10r8r9顺序进入。

This calling convention (especially the use of syscall !) is only used for system calls, which can only have up to six arguments. 该调用约定(尤其是使用syscall !)仅用于系统调用,最多只能有六个参数。 Application functions use a different (but similar) calling convention which spills some arguments to the stack, or to other registers. 应用程序函数使用不同(但类似)的调用约定,这会将一些参数溢出到堆栈或其他寄存器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM