当前位置:网站首页>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;
}
边栏推荐
- DPU — 功能特性 — 存储系统的硬件卸载
- MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
- XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
- 只有一台交换机,如何实现主从自动切换之nqa
- Why is pnpm hitting npm and yarn dimensionality reduction?
- Controller-----controller
- CROS and JSONP configuration
- openpyxl操作Excel文件
- 树状数组模版+例题
- 动态库之间回调函数使用
猜你喜欢
Dynamic memory development (C language)
egg框架中解决跨域的三种方案
XSS靶机通关以及XSS介绍
使用HBuilder离线本地打包ipa教程
“充钱”也难治快手的“亏亏亏”?
DataFrame insert row and column at specified position
php fails to write data to mysql
让程序员崩溃的N个瞬间(非程序员误入)
【Excel实战】--图表联动demo_001
MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
随机推荐
ps怎么把图片变清晰,自学ps软件photoshop2022,简单快速用ps让照片更清晰更有质感
交换机端口的三种类型详解与hybrid端口实验
Rotation of the displayed value on the button
明天去订票,准备回家咯~~
8.4 Summary of the mock competition
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
thinkPHP5 realizes clicks (data increment/decrement)
动态库之间回调函数使用
express hot-reload
EA谈单机游戏:仍是产品组合中极其重要的部分
ts/js 函数传参带函数写法
Beautifully painted MM set
Adb authorization process analysis
使用 External Secrets Operator 安全管理 Kubernetes Secrets
生命的颜色占卜
为什么我推荐使用智能化async?
What is the connection and difference between software system testing and acceptance testing? Professional software testing solution recommendation
Creo 9.0 基准特征:基准点
只有一台交换机,如何实现主从自动切换之nqa
复现一次循环和两次循环