在C中执行汇编代码 [英] executing assembly code in c

查看:70
本文介绍了在C中执行汇编代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以调用.c汇编代码吗? 我要将这段代码放在我的.c文件中

I want to know if there is a way of calling in a .c assembly code? I want to put this code in my .c file

我要在.c文件中执行的汇编代码以返回地址

The assembly code i want to execute in .c file to return the address

1. mov eax, 0x2d
2. mov ebx, 0
3. int 0x80

我知道答案就是骗人的.

I know the answer is put eax.

这是.c文件的一部分:

This is the part of .c file:

1. void function(void)
2. {
3. void *sp;
4. sp = eax;
5. fprintf(stderr, "system break:   %p\n", sp);
6. }

我该怎么办?

推荐答案

执行此操作的能力是特定于编译器的. Gcc允许使用asm关键字扩展名 ,而Visual Studio实现了不同的扩展名

The ability to do this is compiler-specific. Gcc allows this using its asm keyword extension, while Visual studio implements a different extension.

请注意,除了明显的问题以外,其他体系结构都无法移植,包括任何内联程序集都会降低性能,因为编译器无法分析该程序集以确定其是否无副作用,内联是否安全,是否可以内联.访问全局资源,等等.

Note that, beside the obvious problem with non-portability to other architectures, including any inline assembly can reduce performance because the compiler is unable to analyze the assembly to determine whether it's side-effect-free, safe for inlining, whether it accesses global resources, and so on.

这篇关于在C中执行汇编代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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