2 .section .init;
3 .globl _start;
4 .type _start,@function
5
6
7 _start:
8 # this sequence of directives temporarily disables relaxation while loading the
9 # address of a symbol into the global pointer register `_gp`.
10 .option push
11 .option norelax
12 la gp, __global_pointer$
13 .option pop
14
15 # loads the address of the symbol `_sp` into the register `sp`
16 # sp points to the current top of the stack
17 la sp, _sp
18 #ifdef SIMULATION
19 li x26, 0x00
20 li x27, 0x00
21 #endif
22
23 /* Load data section */
24 la a0, _data_lma /* TODO What is the data stored at _data_lma, 0 or not? */
25 la a1, _data
26 la a2, _edata
27 # if a1 >= a2, then jump forward to label 2
28 bgeu a1, a2, 2f
29
30 # Copy data segement
31 1:
32 lw t0, (a0)
33 sw t0, (a1)
34 addi a0, a0, 4
35 addi a1, a1, 4
36 # if a1 < a2(end address), then back jump to label 1. So it is a lool here to initialize the data segement.
37 bltu a1, a2, 1b
38
39 2:
40 /* Clear bss section */
41 la a0, __bss_start
42 la a1, _end
43 bgeu a0, a1, 2f
44 1:
45 # store 0 to the address that a0 refers to
46 sw zero, (a0)
47 addi a0, a0, 4
48 bltu a0, a1, 1b
49 2:
50
51 call _init
52 call main
53
54 #ifdef SIMULATION
55 li x26, 0x01
56 #endif
57
58 loop:
59 j loop
12-15
2247
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)