当前位置:网站首页>汇编语言(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;
}
边栏推荐
猜你喜欢

Ethernet Principle

Fiddler tool explanation
![[Structural Internal Power Cultivation] Structural Realization Stages (2)](/img/eb/c80e12edbf4a411227be7e33096ed3.png)
[Structural Internal Power Cultivation] Structural Realization Stages (2)

国际原子能机构总干事称乌克兰扎波罗热核电站安全形势堪忧

EA谈单机游戏:仍是产品组合中极其重要的部分

工程制图试题

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

接口全周期的生产力利器Apifox

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

Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
随机推荐
egg框架中解决跨域的三种方案
DNS 查询原理详解
七夕给自己new一个chatRobot当对象
Creo 9.0 基准特征:基准轴
随时牵手 不要随意分手[转帖]
微信小程序请求封装
How to replace colors in ps, self-study ps software photoshop2022, replace one color of a picture in ps with another color
routing----router
DataFrame insert row and column at specified position
512色色谱图
Linux导出数据库数据到硬盘
工程制图试题
DPU — 功能特性 — 网络系统的硬件卸载
love is a sad song
工程制图直线投影练习
Chapter 12 贝叶斯网络
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
SQL语句查询字段内重复内容,并按重复次数加序号
动态库之间回调函数使用
【 a daily topic 】 1403. The increasing order of the sequence, boy