当前位置:网站首页>Mixed programming of C language and assembly language in stm32
Mixed programming of C language and assembly language in stm32
2022-06-28 02:50:00 【m0_ sixty-one million eight hundred and eleven thousand three h】
Catalog
One .Keil Next C Language call assembler
3、 ... and . Calling one in assembly function C Functions written in language
One .Keil Next C Language call assembler
Create a new file under the project main.c and 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
Compile debugging :

Two . Original assembly language Init_1 Change the type of the function to int Init_1(init) , This function function is modified to Pass in an integer number x, The function returns an integer number after running x+100.
modify main.c The contents of the document
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 result

3、 ... and . Calling one in assembly function C Functions written in language
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 result

Four . summary
Through this experiment , I am right. C The transfer method of language call function parameters and ARM Better understanding of register usage .
边栏推荐
猜你喜欢

迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比

【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形

Get 5 offers after being notified of layoffs

Reprinted article: the digital economy generates strong demand for computing power Intel releases a number of innovative technologies to tap the potential of computing power
![[today in history] June 15: the first mobile phone virus; AI master simahe was born; Chromebook launch](/img/d4/413c84a75f16a09867cfaa3d7f8736.png)
[today in history] June 15: the first mobile phone virus; AI master simahe was born; Chromebook launch

Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦

isEmpty 和 isBlank 的用法區別

STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动

Unity WebGL打包后怎么运行(火狐配置)

math_ (function & sequence) meaning of limit & misunderstanding and symbol sorting / neighborhood & de centring neighborhood & neighborhood radius
随机推荐
转载文章:数字经济催生强劲算力需求 英特尔发布多项创新技术挖掘算力潜能
Arduino Esp8266 Web LED控制
【历史上的今天】6 月 11 日:蒙特卡罗方法的共同发明者出生;谷歌推出 Google 地球;谷歌收购 Waze
MySQL query related knowledge (advanced level 7: sub query
Online JSON to plaintext tool
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
The first place on the list - the carrying rate of front-end equipment is up to 10%, and the top 10 suppliers of digital key solutions
Prometheus 2.27.0 新特性
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
树莓派-环境设置和交叉编译
Unity WebGL打包后怎么运行(火狐配置)
Keil "St link USB communication error" solution
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
[today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
【云原生】-Docker安装部署分布式数据库 OceanBase
STM32的C语言与汇编语言混合编程
面试:Bitmap像素内存分配在堆内存还是在native中
【历史上的今天】6 月 3 日:微软推出必应搜索引擎;Larry Roberts 启动阿帕网;Visual Basic 之父出生
CRF+BiLSTM代码分步骤解读
Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法