概述
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
#if 0//汇编右位移指令shr,左位移指令shl
int a = 40;
int b;
asm ("movl %1, %%eax;
shl %%eax;
shl %%eax;
movl %%eax, %0;"
: "=r" (b)
: "r" (a)
: "%eax");
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
#if 0//异或运算xor
int a = 40;
int b;
asm ("movl %1, %%eax;
xor %%eax,%%eax;
movl %%eax, %0;"
: "=r" (b)
: "r" (a)
: "%eax");
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
#if 0//取反运算not
int a = 40;
int b;
asm ("movl %1, %%eax;
not %%eax;
movl %%eax, %0;"
: "=r" (b)
: "r" (a)
: "%eax");
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
#if 0//或运算or
int a = 40;
int b;
asm ("movl %1, %%eax;
or %%eax,%%eax;
movl %%eax, %0;"
: "=r" (b)
: "r" (a)
: "%eax");
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
#if 0//循环左移ROL,右移ROR
int a = 6;
int b = 0;
asm ("movl %1, %%eax;
rol %%eax;
movl %%eax, %0;"
: "=r" (b)
: "r" (a)
: "%eax");
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
#if 0//循环左移ROL,右移ROR
int s1 = 6;
int s2 = 1;
asm ("movl $0x01 , %%eax ; nt"
"xorl %%edx , %%edx ;nt"
"cpuid ;nt"
"movl %%edx ,%0 ;nt"
"movl %%eax ,%1 ; nt"
:"=m"(s1),"=m"(s2));
printf ("a = %dnb = %dn", s1, s);
system("pause");
#endif
#if 1
int a = 6;
int b = 2;
//asm volatile("movl %0,%1" : "=r" (b) : "m" (a));
asm volatile("addl %2,%0":"=r"(a): "r"(a),"r"(b));
printf ("a = %dnb = %dn", a, b);
system("pause");
#endif
return app.exec();
}
最后
以上就是动人口红为你收集整理的关于汇编示例的全部内容,希望文章能够帮你解决关于汇编示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复