当前位置:网站首页>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;
}
边栏推荐
- k-nearest neighbor fault monitoring based on multi-block information extraction and Mahalanobis distance
- 原型&原型链
- Data source object management Druid and c3p0
- The Secrets of the Six-Year Team Leader | The Eight Most Important Soft Skills of Programmers
- 使用 External Secrets Operator 安全管理 Kubernetes Secrets
- Controller-----controller
- Creo 9.0 基准特征:基准坐标系
- Why is pnpm hitting npm and yarn dimensionality reduction?
- Creo 9.0 基准特征:基准平面
- Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
猜你喜欢

百行代码发射红心,程序员何愁命不中女朋友!

ECCV 2022 Oral 视频实例分割新SOTA:SeqFormer&IDOL及CVPR 2022 视频实例分割竞赛冠军方案...

七夕看什么电影好?爬取电影评分并存入csv文件

汇编语言(8)x86内联汇编

链表中的数字相加----链表专题

DNS 查询原理详解

Creo 9.0 基准特征:基准平面

SQL语句查询字段内重复内容,并按重复次数加序号

MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)

Creo 9.0 基准特征:基准点
随机推荐
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
明天去订票,准备回家咯~~
【ASM】字节码操作 方法的初始化 Frame
【无标题】目录
Redis cache and existing problems--cache penetration, cache avalanche, cache breakdown and solutions
让硬盘更快,让系统更稳定
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
行走社会100绝招
手机上流行的各类谜语
pnpm 是凭什么对 npm 和 yarn 降维打击的
【LeetCode】623. Add a row to the binary tree
基于多块信息提取和马氏距离的k近邻故障监测
sql server中 两表查询 平均数 分组
8.4 Summary of the mock competition
【LeetCode】623. 在二叉树中增加一行
sql server收缩日志的作业和记录,失败就是因为和备份冲突了吗?
Data source object management Druid and c3p0
XSS靶机通关以及XSS介绍
随时牵手 不要随意分手[转帖]
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file