大会,你好世界问题
我正在Linux上学习asm(noobuntu 10.04) 我得到以下代码: http://asm.sourceforge.net/intro/hello. html
I'm learning asm on Linux (noobuntu 10.04) I got the following code off of: http://asm.sourceforge.net/intro/hello.html
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string
这是一个简单的问候世界.在Linux上运行+直接(显然)调用内核. 谁能解释一下这里到底发生了什么?我认为它会读取eax&中的整数ebx处理器寄存器和ecx,edx数据,它定义了调用内核时的系统调用.如果是这样,在调用int 0x80时,整数的不同组合是否定义了不同的系统调用?
It's a simple hello world. Runs on Linux + calls the kernel directly (apparently). Can anyone please explain what is really going on here? I think it reads the integers in the eax & ebx processor registers & ecx, edx data and that defines the system call when the kernel is called. If so, do different combinations of integers define different system calls when int 0x80 is called?
我对手册页不好,但是已经阅读了我能找到的所有相关手册,任何手册页都告诉我哪些组合定义了哪些系统调用吗?
I'm not good with man pages, but have read every related one I can find, does any man page tell me what combinations define what syscalls?
感谢您的帮助.一行一行的解释将是惊人的... -提前致谢 杰里米
ANY help is appreciated. A line by line explanation would be amazing... -Thanks in advance Jeremy
调用int 0x80
时,内核会查看eax
寄存器的值以确定要调用的函数(这是"syscall"数字").根据该数字,其余寄存器将被解释为表示特定的事物. sys_write
调用要求按以下步骤设置寄存器:
When you call int 0x80
, the kernel looks at the value of the eax
register to determine the function you want to call (this is the "syscall number"). Depending on that number, the rest of the registers are interpreted to mean specific things. The sys_write
call expects the registers to be set up as follows:
-
eax
包含4 -
ebx
包含文件描述符 -
ecx
包含要写入的数据的地址 -
edx
包含字节数
-
eax
contains 4 -
ebx
contains the file descriptor -
ecx
contains the address of the data to write -
edx
contains the number of bytes
有关更多详细信息,请参见 Linux系统调用.
For further extensive information, see Linux System Calls.