当前位置:网站首页>Assembly language (8) x86 inline assembly
Assembly language (8) x86 inline assembly
2022-08-05 09:05:00 【Day-3】
1 One-line assembly
#include <stdio.h>
#include <stdlib.h>
int main()
{
int nNum = 0;
_asm mov nNum, 100
printf("%d\n", nNum);
system("pause");
return 0;
}
2 multi-line assembly
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 The interaction of the custom function with the main function
使用esi可以,使用ecx就不行,Cause the custom function is initialized at the beginning of the run,改变了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 The stack implements the interaction between the main function and the custom function
#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 Iterates by the length of the array
#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;
}
边栏推荐
- 在colab里怎样读取google drive数据
- 使用 External Secrets Operator 安全管理 Kubernetes Secrets
- selectPage 动态改变参数方法
- flink cdc支持从oracle dg库同步吗
- How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
- 线程之Happens-before规则
- 基于 Kubernetes 的微服务项目整体设计与实现
- egg框架中解决跨域的三种方案
- 请问如果想往mysql里面写数据,直接用flink-connector-jdbc就可以吧,可是我在f
- Constellation ideal lover
猜你喜欢
随机推荐
flink cdc支持从oracle dg库同步吗
程序员的七种武器
Creo 9.0 基准特征:基准轴
写出了一个CPU占用极高的代码后引发的思考
8.4 Summary of the mock competition
行走社会100绝招
15.1.1、md—md的基础语法,快速的写文本备忘录
网页直接访问链接不让安全中心拦截
动态内存开辟(C语言)
8.4模拟赛总结
DPU — 功能特性 — 网络系统的硬件卸载
Creo 9.0 基准特征:基准点
【 a daily topic 】 1403. The increasing order of the sequence, boy
mySQL数据库初始化失败,有谁可以指导一下吗
在colab里怎样读取google drive数据
sql server中 两表查询 平均数 分组
按钮上显示值的轮流切换
pnpm 是凭什么对 npm 和 yarn 降维打击的
手机上流行的各类谜语
512色色谱图









