当前位置:网站首页>汇编语言(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;
}
边栏推荐
- Moonbeam团队发布针对整数截断漏洞的紧急安全修复
- Creo 9.0 基准特征:基准点
- Dynamic memory development (C language)
- 请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
- Random code generation
- CROS和JSONP配置
- egg框架中解决跨域的三种方案
- Redis cache and existing problems--cache penetration, cache avalanche, cache breakdown and solutions
- Thinking and summary of the efficiency of IT R&D/development process specification
- 【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
猜你喜欢

“充钱”也难治快手的“亏亏亏”?

Chapter 12 Bayesian Networks

DTcloud 装饰器

Creo 9.0 基准特征:基准轴
![[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)](/img/39/d20f45ccc86ebc4e5aebc8e4d0115f.png)
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)

Code Audit - PHP

让程序员崩溃的N个瞬间(非程序员误入)

ps怎么把图片变清晰,自学ps软件photoshop2022,简单快速用ps让照片更清晰更有质感

ps怎么替换颜色,自学ps软件photoshop2022,ps一张图片的一种颜色全部替换成另外一种颜色

Creo 9.0 基准特征:基准平面
随机推荐
16 kinds of fragrant rice recipes
宝塔实测-搭建中小型民宿酒店管理源码
Ethernet Principle
MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
selectPage 动态改变参数方法
按钮上显示值的轮流切换
十一道家常小菜详细攻略[图文并茂]
Creo 9.0 基准特征:基准轴
Why is pnpm hitting npm and yarn dimensionality reduction?
Pagoda measurement - building small and medium-sized homestay hotel management source code
EA谈单机游戏:仍是产品组合中极其重要的部分
Dynamic memory development (C language)
原型&原型链
Luogu P3368: 【模板】树状数组 2
[Structure internal power practice] Structure memory alignment (1)
What is the connection and difference between software system testing and acceptance testing? Professional software testing solution recommendation
RedisTemplate: error template not initialized; call afterPropertiesSet() before using it
NC20164 :最大数MAXNUMBER [线段树]
How to make a puzzle in PS, self-study PS software photoshop2022, PS make a puzzle effect
tear apart loneliness