icc内嵌汇编真方便
默认的gcc内嵌的都是晦涩的AT&T汇编
要使用Intel风格的汇编必须这么复杂....
#include <stdlib.h>
int main(){
int a=12;
char *hello="hello,world\n";
__asm__(
".intel_syntax noprefix\n"
"mov eax,4\n"
"mov ebx,1\n"
"mov ecx,%0\n"
"mov edx,%1\n"
"int 0x80\n"
".att_syntax\n"
:
:"r"(hello),"r"(a)
:"eax","ebx","ecx","edx"
);
exit(0);
}
格式是__asm(语句:输出变量:输入变量:使用的寄存器)
"r"说明后面括号里的变量是放在寄存器中的....
非常麻烦
但是现在有了icc,俺们就大大的省事了!
可以使用熟悉的Intel风格的汇编了.....
#include<stdlib.h>
int main(){
int a=12;
char *hello="Hello,world\n";
__asm__{
mov eax,4
mov ebx,0
mov ecx,hello
mov edx,a
int 80h
}
exit(0);
}
这样就搞定了,编译的时候用icc -use_msasm -o hello hello.c
比较有意思的是,大家都说这样的风格是Intel风格,Intel非说这是微软的MASM风格,所以
就有了-use_msasm,呵呵.....
icc比gcc快20%,何乐而不为讷
(唯一的缺点就是...得收费...)
|Archiver|手机版|小黑屋|软路由
( 渝ICP备15001194号-1|
渝公网安备 50011602500124号 )
GMT+8, 2025-7-12 15:20 , Processed in 0.105540 second(s), 15 queries , Gzip On, Redis On.
Powered by Discuz! X3.5 Licensed
© 2001-2025 Discuz! Team.