【发布时间】:2022-01-02 17:47:32
【问题描述】:
我目前正在尝试使用 ArchLinux 学习使用 x86 架构的汇编编程。我刚刚开始这段旅程,并了解以下程序的内部工作原理以打印Hello World。
; Jon Webb
; December 31, 2021
; ==============================================================================
; ==============================================================================
; Data Section
section .data
; Message to be printed
msg: db "Hello World", 10
; Length of message
len: equ $ - msg
; ==============================================================================
; Code section
section .text
; Define entry point
global _start
_start:
; 4 is equivalent to sys_write(std_output, msg, len)
mov eax, 4 ; Calls sys_write function from syscall
mov ebx, 1 ; File descriptor (1 standard output)
mov ecx, msg ; Message to be printed
mov edx, len ; Length of message to be printed
int 0x80 ; Make syscall
; 1 is equivalent to sys_exit(status)
mov eax, 1 ; Specify exit syscall
mov eab, 0 ; Pass a status code of zero which indicates successful conclusion
int 0x80 ; Make syscall
; ==============================================================================
; ==============================================================================
; end of file
我了解此代码的工作原理。该代码正在调用两个 Linux 系统调用函数 sys_write() 和 sys_exit(),它们分别由整数 4 和 1 定义。在每个函数中,我通过将定义整数传递给 eax 来调用函数,然后将连续变量传递给 ebx、ecx、edx 等。在这种情况下,我知道这两个函数,因为我正在阅读的书告诉我,4 代表sys_write,1 代表sys_exit;但是,我怀疑它们是其他类似的功能。我在哪里可以获得所有 Linux 系统调用函数的列表。我认为这将是一个简单的谷歌搜索回答的简单答案,但到目前为止我想出的很少。这是 x86 汇编编程的一个基本方面,虽然这些函数会在教程中列出,但到目前为止我还没有发现这是真的。
【问题讨论】:
标签: linux assembly x86 system-calls