【发布时间】:2021-02-23 18:49:13
【问题描述】:
我想在 NASM System V ABI x86-64(英特尔语法)中编写一个可以在 C 程序中使用的函数。
这是函数的原型:
char *rindex(const char *s, int c);
因此我按顺序检索参数(const char *s = rdi, int c = rsi)
首先,我将寄存器rsi中存储的字符放入ah:
segment .text
global rindex:function
rindex:
mov ah, byte [rsi] ;; get the character
[...]
不幸的是,这行代码使我的程序崩溃了:
rindex("hello world", 'o') // segfault
为什么无法获取 char,正确的方法是什么?
【问题讨论】:
-
Char 由 rdi 指向,而不是 rsi。
-
我认为参数应该按以下顺序传递:
rdi、rsi、rdx、rcx。不是这样吗?
标签: linux assembly x86-64 nasm calling-convention