Common methods:
1 Embed assembly instructions in C/C++ programs
Syntax format:
__asm
{
assembly language program
}
2 Access global variables defined in C/C++ in assembly programs
Sample code is as follows:
test.c
#include
int gVar_1=12;
extern asmDouble(void)
int main(void){
printf("original value of gVar_1 is %d",gVar_1);
admDouble();
printf("modified value of gVar_1 is %d",gVar_1);
return 0;
}
test.s
AREA asmfile,CODE,READONLY
EXPORT asmDouble; declare global reference label
IMPORT gVar_1; reference
asmDouble
ldr r0,=gVar_1
ldr r1,[r0]
mov r2,#2
mul r3,r1,r2
str r3,[r0]
mov pc,lr
END
3 Calling assembly functions in c/c++ programs
The sample code is as follows:
test1.s
AREA asmfile,COCE,READONLY
EXPORT asm_strcpy; declare global reference label
asm_strcpy; function name
loop:
ldrb r4,[r0],#1
cmp r4,#0
beq over
strb r4,[r1],#1
b loop
over:
mov pc,lr; used for function return
END
test1.c
#include
extern void asm_strcpy(const char *src,char *dest);
int main(){
const char *s ="hello world";
char d[32];
asm_strcpy(s,d);
printf("source:%s",s);
printf("destination: %s",d);
return 0;
}
Does the above program have the flavor of jni?
4 Calling C/C++ functions in assembly programs
The sample code is as follows:
test2.c
int cFun(int a,int b,int c){
return a+b+c;
}
test2.s
EXPORT asmfile
AREA asmfile,CODE,READONLY
IMPORT cFun; reference function
ENTRY; specify application entry
mov r0,#11
mov r1,#22
mov r2,#33
BL cFun; return
END
Previous article:ARM study notes 4 (arm pseudo-instructions)
Next article:ARM study notes six (coprocessor)
Recommended ReadingLatest update time:2024-11-23 07:54
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Smart Home Energy Management with Levarys and Qorvo Technologies
- Analog Circuit Practical Knowledge Lectures (12 lectures) in Chinese for free
- Use FPGA to simulate USB function (written in VHDL language).rar
- The internal crystal oscillator of SMIC 5897 is inaccurate
- KEYENCE Fiber Optic Sensor Disassembly
- FPGA Simplified Design Method Case 4 [12401003385]
- 11 classic software filtering algorithms and their waveform effects (with C language program)
- DSP28335 burning program, besides CCS software, is there any third-party program download software tool? ?
- What do the front-line people think: In 2022, the local IC industry will face a "big test"
- 【Awarded】Rewarded Survey——We want you! What does a good reference design website look like?