当前位置:网站首页>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 .
边栏推荐
- NER中BiLSTM-CRF解读Forward_algorithm
- What if win11 can't drag an image to the taskbar software to open it quickly
- [elevator control system] design of elevator control system based on VHDL language and state machine, using state machine
- SQL reported an unusual error, which confused the new interns
- 11 timers for STM32F103
- 第三批入围企业公示!年度TOP100智能网联供应商评选
- 如何判断线程池已经执行完所有任务了?
- [today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown
- How to realize red, green and yellow traffic lights in ros+gazebo?
- [today in history] June 12: the United States entered the era of digital television; Mozilla's original developer was born; 3com merges with American Robotics
猜你喜欢
![[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

【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用

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 13: parent-child disputes in packet switched networks; The founder of game theory was born; The embryonic form of interactive television](/img/2c/01e3be3c5b4f8e6a7853547ffd1bbd.png)
[today in history] June 13: parent-child disputes in packet switched networks; The founder of game theory was born; The embryonic form of interactive television

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

MySQL collection, here are all the contents you want

【历史上的今天】6 月 3 日:微软推出必应搜索引擎;Larry Roberts 启动阿帕网;Visual Basic 之父出生

Cloud native (30) | kubernetes' app store Helm

转载文章:数字经济催生强劲算力需求 英特尔发布多项创新技术挖掘算力潜能

Practice of low code DSL in data warehouse
随机推荐
Solutions to st link USB communication error
新手炒股开户选哪家证券平台办理是最好最安全的
Starting sequence of Turing machine
STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动
MFC CString to LPVOID
Win11 cannot create a new text document? Solution to win11 right click failure to create a new text document
云原生(三十) | Kubernetes篇之应用商店-Helm
Opencv——霍夫变换以及遇到的一些问题
在线JSON转PlainText工具
【历史上的今天】5 月 31 日:Amiga 之父诞生;BASIC 语言的共同开发者出生;黑莓 BBM 停运
【历史上的今天】6 月 17 日:术语“超文本”的创造者出生;Novell 首席科学家诞生;探索频道开播
【历史上的今天】6 月 15 日:第一个手机病毒;AI 巨匠司马贺诞生;Chromebook 发布
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
NER中BiLSTM-CRF解读Forward_algorithm
11 timers for STM32F103
【云原生】-Docker安装部署分布式数据库 OceanBase
[today in history] June 13: parent-child disputes in packet switched networks; The founder of game theory was born; The embryonic form of interactive television
【历史上的今天】6 月 6 日:世界 IPv6 启动纪念日;《俄罗斯方块》发布;小红书成立
MySQL collection, here are all the contents you want
MFC common current path