Article directory
foreword
There are single-chip microcomputers everywhere in our lives. It can be said that our current life is inseparable from single-chip microcomputers. Many things in life need single-chip microcomputers, such as air conditioners, refrigerators, washing machines, and sweeping robots. Today we will learn about ST's stm32 single-chip microcomputer, and learn the simple use of assembly language in the keil environment.
1. Construction of MDK environment
Because I have used keil-mdk
this software before and configured the relevant environment, so I will not talk about the construction of the environment here. Students who need it, please find tutorials on the Internet, and I will also provide software Baidu network disk resources.
百度网盘链接 :
https://pan.baidu.com/s/17SjKkVAz1Lyboj48hefGLA
提取码:
keil
2. The first assembly project under Keil
1. Create a project file
1. It is recommended to create a project file in your own convenient directory, and all project files will be placed here in the future, which is convenient for transplantation and management.
注意!
All directories should not have Chinese paths, otherwise there will be many problems later
2. New construction
-
Click on Project
-
New uVision Project
-
Give the project a name and save it in the project folder created above (no Chinese)
-
Select the chip model, here select stm32c8t6
-
Check CMSIS
CORE
and Device 3. Add project source filesStartup
.s
-
Right-click Source Group1 to add files
-
Add .s assembly file
2. Complete the writing of relevant codes
- Write the following code into the .s file
AREA MYDATA, DATA
AREA MYCODE, CODE
ENTRY
EXPORT __main
__main
MOV R0, #10
MOV R1, #11
MOV R2, #12
MOV R3, #13
;LDR R0, =func01
BL func01
;LDR R1, =func02
BL func02
BL func03
LDR LR, =func01
LDR PC, =func03
B .
func01
MOV R5, #05
BX LR
func02
MOV R6, #06
BX LR
func03
MOV R7, #07
MOV R8, #08
BX LR
- Compile first to see if there are any errors
可以看到,我们这里出现了一个错误,Undefined symbol main ……
Through my inspection, I found that I did not
.s
add the source file I created to my project directory, so I reported an error saying thatmain
the function , so be careful.
- In fact, we should make some changes to the default settings of some compilers before compiling.
Click the magic wand, check Create HEX File in Output, this is to generate a hex file, and the hex file is also the executable file that is finally programmed into the microcontroller.
- Debug debugging
3. Analysis of HEX files
- Find the hex file under our project file and open it with an editor.
The first row of the file
:020000040800F2
extended linear address record
02 : the number of recorded data bytes
0000 : the record of the extended linear address, address field
04 : record type 04
0800 : the upper 16 bits of the address
F2 : the checksum of the record
- end of hex file
00000001FF
00 : length of record
0000 : Load offset is 0000
01 : TYPE = 01
FF : checksum is FF
Summarize
Through the study of assembly language under keil this time, I think I am quite rewarded. First of all, I learned some relatively simple assembly syntax, and I have never touched assembly language before. Secondly, I also encountered some problems during this experiment, but they were all details. For example, I didn’t pay attention to the source file I created at the beginning and didn’t add it to the project file, which caused the compilation to stop. If you fail, you will only find out after inspection later, just be careful not to commit the same crime next time!