当前位置:网站首页>汇编语言(8)x86内联汇编
汇编语言(8)x86内联汇编
2022-08-05 08:53:00 【Day-3】
1 单行汇编
#include <stdio.h>
#include <stdlib.h>
int main()
{
int nNum = 0;
_asm mov nNum, 100
printf("%d\n", nNum);
system("pause");
return 0;
}
2 多行汇编
2.1 库函数
#include <stdio.h>
#include <stdlib.h>
int main()
{
char * szFormat = "%d\n";
int nNum = 0;
_asm {
mov nNum, 100
push nNum
mov eax, szFormat
push eax
call printf
add esp, 8
}
system("pause");
return 0;
}
2.2 自写函数
#include <stdio.h>
#include <stdlib.h>
int MyAdd(int a, int b)
{
return a + b;
}
int main()
{
char * szFormat = "%d\n";
int nNum = 0;
_asm {
push 1
push 2
call MyAdd
add esp, 8
mov esi,eax
push esi
mov eax, szFormat
push eax
call printf
add esp, 8
}
system("pause");
return 0;
}
3 自定义函数与主函数的互动
使用esi可以,使用ecx就不行,原因自定义函数在运行开始初始化时,改变了ecx的值。
#include <stdio.h>
#include <stdlib.h>
int MyAdd(int a, int b)
{
int nNum = 0;
_asm mov nNum, edx
if (nNum != 12313)
{
_asm jmp x1
}
else
{
_asm jmp esi
}
x1:
return a + b;
}
int main()
{
char * szFormat = "%d\n";
int nNum = 0;
_asm {
mov edx, 12313
mov esi, thisx
}
thisx:
system("pause");
return 0;
}
4 栈实现主函数与自定义函数的互动
#include <stdio.h>
#include <stdlib.h>
int MyAdd(int a, int b)
{
int nNum = 0;
_asm mov nNum, ebp - 4
if (nNum != 12313)
{
_asm jmp x1
}
else
{
_asm jmp ebp - 8
}
x1:
return a + b;
}
int main()
{
char * szFormat = "%d\n";
int nNum = 0;
_asm {
push 12313
push thisx
call MyAdd
}
thisx:
system("pause");
return 0;
}
5 数组遍历
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[] = {
1,2,3,4,5,3,3,1,1,1,0 };
char * szFormat = "%d\n";
_asm {
xor esi,esi
jmp lookX
lookM:
inc esi
lookX:
mov edi, [arr + esi * 4]
push edi
mov eax, szFormat
push eax
call printf
add esp, 8
cmp edi, 0
jne lookM //若不相等则跳转
}
system("pause");
return 0;
}
6 按数组长度遍历
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[] = {
0,1,2,3,4,5 };
char * szFormat = "%d\n";
_asm {
mov edi, 5h
xor esi,esi
jmp look1
look:
inc esi
look1:
push [arr + esi * 4]
mov eax, szFormat
push eax
call printf
add esp, 8
cmp esi, edi
jne look
}
system("pause");
return 0;
}
边栏推荐
猜你喜欢
sql server中 两表查询 平均数 分组
使用HBuilder离线本地打包ipa教程
Chapter 12 贝叶斯网络
express hot-reload
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)
ps怎么替换颜色,自学ps软件photoshop2022,ps一张图片的一种颜色全部替换成另外一种颜色
【LeetCode】623. 在二叉树中增加一行
代码审计—PHP
EA谈单机游戏:仍是产品组合中极其重要的部分
The Coolest Kubernetes Network Solution Cilium Getting Started Tutorial
随机推荐
苹果官网商店新上架Mophie系列Powerstation Pro、GaN充电头等产品
(转)[Json]net.sf.json 和org.json 的差别及用法
最 Cool 的 Kubernetes 网络方案 Cilium 入门教程
egg框架
egg框架中解决跨域的三种方案
使用HBuilder离线本地打包ipa教程
DTcloud 装饰器
【Excel实战】--图表联动demo_001
How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
国际原子能机构总干事称乌克兰扎波罗热核电站安全形势堪忧
Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
动态库之间回调函数使用
sphinx匹配指定字段
Chapter 12 贝叶斯网络
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file
16 kinds of fragrant rice recipes
今天是元宵节~~
CROS和JSONP配置