当前位置:网站首页>STM32的C语言与汇编语言混合编程
STM32的C语言与汇编语言混合编程
2022-06-28 01:03:00 【m0_61811389】
目录
二.将原汇编语言 Init_1函数的类型改为 int Init_1(init) ,此函数功能修改为 传入一个整型数x,函数运行后返回整型数 x+100。
一.Keil下C语言调用汇编程序
在项目下新建文件main.c和Function.s

main.c
# include<stdio.h>
extern void Init_1(void);
int main(){
Init_1();
return 0;
}
Function.s
AREA MY_FUNCTION,CODE,READONLY
EXPORT Init_1
Init_1
MOV R1,#0
MOV R2,#0
LOOP
CMP R1,#10
BHS LOOP_END
ADD R2,#1
ADD R1,#1
B LOOP
LOOP_END
NOP
END
编译调试:

二.将原汇编语言 Init_1函数的类型改为 int Init_1(init) ,此函数功能修改为 传入一个整型数x,函数运行后返回整型数 x+100。
修改main.c文件内容
main.c
# include<stdio.h>
extern int Init_1(int x);
int main(){
int xx = Init_1(10);
printf("%d", xx);
return 0;
}Function.s
AREA MY_Function,CODE,READONLY
EXPORT Init_1
Init_1
ADD R0,#100
MOV PC,LR
LOOP
CMP R1,#10
BHS LOOP_END
ADD R2,#1
ADD R1,#1
B LOOP
LOOP_END
NOP
END 结果

三.在汇编函数中调用一个C语言写的函数
main.c
# include<stdio.h>
extern void Init_1(void);
int get5(void);
int main(){
printf("Begin...\n");
Init_1();
return 0;
}
int get5(){
return 5;
}
Function.s
AREA MY_Function,CODE,READONLY
EXPORT Init_1
IMPORT get5
Init_1
MOV R1,#0
MOV R2,#0
LOOP
CMP R1,#10
BHS LOOP_END
ADD R2,#1
ADD R1,#1
BL get5
B LOOP
LOOP_END
NOP
END 结果

四.总结
通过这次实验,我对C语言调用函数参数的传递方式以及ARM寄存器使用方法有了更好理解。
边栏推荐
- Graduation summary
- Digital intelligence learning Lake Warehouse Integration Practice and exploration
- 毕业总结
- Complex and inefficient logistics? Three steps to solve problems in enterprise administration
- 一种低成本增长私域流量,且维护简单的方法
- 【方块编码】基于matlab的图像方块编码仿真
- Interpretation of bilstm-crf in NER forward_ algorithm
- SQL报了一个不常见的错误,让新来的实习生懵了
- 面试:Bitmap像素内存分配在堆内存还是在native中
- Flask基础:模板渲染+模板过滤使用+控制语句
猜你喜欢

【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam

ROS+Gazebo中红绿黄交通灯如何实现?

如何开启多语言文本建议?Win11打开多语言文本建议的方法

Win11不能拖拽图片到任务栏软件上快速打开怎么办

Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times

Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch

Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法

How does win11 add printers and scanners? Win11 add printer and scanner settings

Design e-commerce seckill system

What if win11 can't drag an image to the taskbar software to open it quickly
随机推荐
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
SQL报了一个不常见的错误,让新来的实习生懵了
[today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown
SQL reported an unusual error, which confused the new interns
【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established
Skills in schematic merging
ScheduledThreadPoolExecutor源码解读(二)
数据清洗工具flashtext,效率直接提升了几十倍数
面试:List 如何根据对象的属性去重?
把腾讯搬上云:云服务器 CVM 的半部进化史
STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动
Truth table of common anode digital tube
Architecture high reliability application knowledge map ----- microservice architecture map
Interpretation of the source code of scheduledthreadpoolexecutor (II)
如何系统学习LabVIEW?
4G-learn from great partners
Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance
在线文本按行批量反转工具
Leetcode topic [array] -228- summary interval