I spent a whole morning studying and wrote a program. It is small but complete. I hope that people who are learning this can spend less time searching for information and master it faster.
#include/****Define in assembly*****/ extern void delay(void) ; extern add(int a,int b); //Test assembly call code (do not want to use assembly directly to run the main program) extern void test(); /***Code segment defined in assembly****/ extern unsigned char cc; // Function defined in C language void delay_c(); unsigned int addcc(unsigned int wd1,unsigned int wd2); //Data segment defined in C language unsigned int aa; unsigned int bb; void main() { delay(); cc=add(10,15); test(); while(1); } void delay_c() { unsigned char cc; cc=0xff; while(cc--); } unsigned int addcc(unsigned int wd1,unsigned int wd2) { unsigned int cl; cl=wd1+wd2; return cl; } delay.asm NAME ONE ; name of the module ;ORG 1000H ;Starting unit where the function is stored ?PR?delay?ONE SEGMENT CODE ; mark the definition location of the function ?PR?_add?ONE SEGMENT CODE ?PR?test?ONE SEGMENT CODE cc DATA 33H ;Directly define the data address PUBLIC delay ; declared as global PUBLIC _add PUBLIC test PUBLIC cc ; declare global EXTRN DATA(aa); Note that this is extrn instead of extern in C. Defined in C EXTRN DATA(bb) EXTRN CODE(delay_c) EXTRN CODE(_addcc); I did not test the online information with parameters EXTRN CODE(addcc) successfully.
Logically, the name should be added with _fun, which is a definition method with parameters. ;EXTRN DATA(?_addcc?BYTE) ;I have not been able to successfully pass this method to upload parameters online, so I directly processed the data on the register. RSEG ?PR?delay?ONE ; (without parameter function) relocate the code position of the function delay: MOV R0 , #44H DJNZ R0,$ RET RSEG ?PR?_add?ONE ; (function with parameters) The parameters are automatically prevented from being put into the register. You can check it online.
Here 15 is stored in R7, R6 and 10 is stored in R5, R4 _add: MOV A,R5 ADD A,R7 MOV R7,A MOV A,R4 ADDC A,R6 MOV aa,R7 RET RSEG PR test ONE test: ; Use C function without parameters CALL delay_c ;Call a C function with parameters MOV R5,#15 MOV R7,#11 LCALL _addcc MOV cc,R7 RET END ; End of program
Previous article:74HC595 drives 24-bit digital tube
Next article:STC12C5A60S2 MCU PWM Program
- Popular Resources
- Popular amplifiers
- Operational Amplifier Practical Reference Handbook (Edited by Liu Changsheng, Zhao Mingying, Liu Xu, etc.)
- A Complete Illustrated Guide to Operational Amplifier Applications (Written by Wang Zhenhong)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- [SAMR21 New Gameplay] 13. Read the sensor of X-NUCLEO-IKS01A3
- Application of MSP430F415 in LCD air conditioner infrared remote control
- EBAZ4205 ore plate resource analysis
- [Reading Month] Read a good book on RT-Thread technology and write down your reading notes
- The voltage regulation value of the Zener diode
- Digital wireless sound amplification system based on BH1417F
- A DIY DC to DC negative pressure module
- TI 2018 Annual Educators Conference, friends in Wuhan, let’s get started!
- Will the power supply problem not allow 32 this year?
- Practical information is here|【TI Embedded Seminar Highlights】The site has added a lot of new content