OK, so, the bare-metal program does not have the support of the operating system, want to use C language, you can only use assembly language to manually configure the C language needs of the environment, sounds very tall, in fact, need to do is very simple: specifying the value of the stack pointer is good .
So before you complete this simple thing, understand the following concepts of the C-language stack:
1. empty stack and full stack: These two concepts are not that the stack is empty or full, the empty stack refers to the stack pointer to the top of the stack of the next address of the element. Full stack refers to the stack top pointer refers to the top element of the stack.
2. stack up and down: the stack is up and down the stack.
Note: ARM is a full-fall stack.
3. stack frame: This is necessary to understand,in C, each stack frame corresponds to a function that is not finished running. You can understand the imaging Ucos: each process has a separate stack space, which is the stack frame. But the stack frame in C is a connected one, such as a function call B function, then the B function execution, the stack frame of a function is the stack frame of the B function, the B function finishes, the SP moves up, completes the stack.
such as (main function call func1): all stack frames are concatenated, which is the complete stack . The most recent stack frame boundary is determined by the FP pointer, and the lower boundary is specified by the SP pointer, where LR and SP point to the upper and lower bounds of the stack frame of the caller of the function corresponding to the stack frame, respectively.
From for notes (Wiz)
Write from assembly language to C language