当前位置:网站首页>汇编语言(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;
}
边栏推荐
- The toss of MM before going to the street (interesting)
- How to replace colors in ps, self-study ps software photoshop2022, replace one color of a picture in ps with another color
- egg框架
- Beautifully painted MM set
- 【无标题】目录
- TensorFlow installation steps
- tear apart loneliness
- 嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
- MM上街前的折腾(有趣)
- 基因数据平台
猜你喜欢

【LeetCode】623. Add a row to the binary tree

pytorch余弦退火学习率CosineAnnealingLR的使用

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

【ASM】字节码操作 方法的初始化 Frame

【LeetCode】623. 在二叉树中增加一行

Code Audit - PHP

Why is pnpm hitting npm and yarn dimensionality reduction?

复现一次循环和两次循环

php fails to write data to mysql

嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
随机推荐
k-nearest neighbor fault monitoring based on multi-block information extraction and Mahalanobis distance
使用 External Secrets Operator 安全管理 Kubernetes Secrets
动态库之间回调函数使用
【 a daily topic 】 1403. The increasing order of the sequence, boy
The difference between beautiful MM and ordinary MM
8.4 Summary of the mock competition
生命的颜色占卜
浅谈自动采集程序及入库
【LeetCode】623. Add a row to the binary tree
Rotation of the displayed value on the button
mySQL数据库初始化失败,有谁可以指导一下吗
Ethernet Principle
Detailed explanation of DNS query principle
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
D2--FPGA SPI interface communication2022-08-03
CVPR 2022 | 将X光图片用于垃圾分割,港中大(深圳)探索大规模智能垃圾分类
今天是元宵节~~
Undefined symbols for architecture arm64解决方案
Random code generation
thinkPHP5 realizes clicks (data increment/decrement)