Simple use of keil assembly under embedded ARM


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-mdkthis 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

insert image description here
2. New construction

  • Click on Project
    insert image description here

  • New uVision Project
    insert image description here

  • Give the project a name and save it in the project folder created above (no Chinese)
    insert image description here

  • Select the chip model, here select stm32c8t6
    insert image description here

  • Check CMSIS COREand Device 3. Add project source filesStartup
    insert image description here
    .s

  • Right-click Source Group1 to add files
    insert image description here

  • Add .s assembly file
    insert image description here

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

insert image description here
insert image description here
可以看到,我们这里出现了一个错误,Undefined symbol main ……

Through my inspection, I found that I did not .sadd the source file I created to my project directory, so I reported an error saying that mainthe function , so be careful.

insert image description here

  • 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.

insert image description here

  • Debug debugging
    insert image description here

3. Analysis of HEX files

  • Find the hex file under our project file and open it with an editor.
    insert image description here

The first row of the file :020000040800F2extended 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!

Guess you like

Origin blog.csdn.net/wer4567/article/details/127206503