作者:-生命之水- | 来源:互联网 | 2023-09-12 13:46
运行例程中GPIO工程时,总会加载startup_stm32f103xb.s文件.如此文件注释所说此文件实现了-SettheinitialSP设置初始sp指针-Settheinit
运行例程中GPIO工程时,总会加载startup_stm32f103xb.s文件.如此文件注释所说
;******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
;* File Name : startup_stm32f103xb.s
;* Author : MCD Application Team
;* Version : V1.4.0
;* Date : 29-April-2016
;* Description : STM32F103xB Devices vector table for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the clock system
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the Cortex-M3 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;********************************************************************************
此文件实现了 -Set the initial SP //设置初始sp指针
- Set the initial PC == Reset_Handler //pc拿到句柄,mian()的汇编指令的首地址
本周作业:
开始寻找main()函数的汇编指令, 以及main函数中的SystemClock_Config函数的汇编指令.
以往总是认为程序一定是从main函数入口, 但是通过调试知道GPIO这个例程知道startup_stm32f103xb.s是比main函数还有要早执行的文件. 文件是由汇编指令组成, 其中有几条语句看似简单, 其实是整个main的函数的生命开始.
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0
LDR R0, =__main // 将main指令集的首地址传给R0
BX R0 // pc指针指向R0存储的地址
ENDP
work