在装配code调用C函数(气) [英] Calling C function in assembly code (gas)

查看:181
本文介绍了在装配code调用C函数(气)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个例子,并编辑它的气体。

I found an example and was editing it for gas.

extern printf
.global _start
.data
hello:
db "Hello", 0xa, 0
.text
_start:
mov %rdi, hello
mov %rax, 0
call printf
mov %rax, 0
ret

但它不工作。怎么了?这是什么意思:

But it doesn't work. What's wrong? What does this mean:

    hello:
db "Hello", 0xa, 0

我明白它的范围内存,但我不明白这个字符串

I understand what it scope of memory, but I don't understand this string

db "Hello", 0xa, 0

在这里

_start:
mov %rdi, hello
mov %rax, 0
call printf
mov %rax, 0
ret

操作系统:Linux(Debian的)。 Intel 64位

os: linux (debian). intel 64-bit

推荐答案

这是 空字节terminattor 。众所周知的是C-string.Such字节在结束串说得清的字符串结尾。例如,您通过指针你的字符串调用一个子程序,程序会明白,内存这类字符串的区域是从乞讨 A [0] (在C术语),直到 A [X] == 0 看到。

It's is the null-byte-terminattor. Well-know as C-string.Such byte at end-of-string say where the string ends. For example,you pass the pointer to your string to call a routine,the routine will understand that the area of such string on memory is from begging a[0](in C terminology) until a[x] == 0 is seen.

这篇关于在装配code调用C函数(气)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆