[英]How to use an external C function in assembly?
I am creating code that calls a C function that gets the square root of an integer.我正在创建调用 C function 的代码,该代码获得 integer 的平方根。 The C function is external and in my folder.
C function 是外部的,在我的文件夹中。 When calling it, i do not know how to give it a parameter so it knows what to calculate
调用它时,我不知道如何给它一个参数,所以它知道要计算什么
I am using NASM Intel x86_64, Assembler is gcc, i do not know the current edition.我正在使用 NASM Intel x86_64,汇编程序是 gcc,我不知道当前版本。 I am using Linux
我正在使用 Linux
Currently my code is:目前我的代码是:
xor rsi, rsi ;just clears rsi
mov rsi, r15 ;r15 held the value that is supposed to be the parameter
call square
It currently just prints out a 0 as it is not taking a correct value.它目前只打印出一个 0,因为它没有采用正确的值。
How do i get it to take in the parameter?我如何让它接受参数?
Thank you.谢谢你。
According to the System V AMD64 ABI calling convention the first argument should be in the rdi
register.根据System V AMD64 ABI 调用约定,第一个参数应该在
rdi
寄存器中。
You need to copy the value to rdi
instead of rsi
.您需要将值复制到
rdi
而不是rsi
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.