6 seth sp, #shigh(_stack)
7 add3 sp, sp, #low(_stack)
10 # Clear the BSS. Do it in two parts for efficiency: longwords first
11 # for most of it, then the remaining 0 to 3 bytes.
13 seth r2, #shigh(__bss_start)
14 add3 r2, r2, #low(__bss_start); R2 = start of BSS
16 add3 r3, r3, #low(_end) ; R3 = end of BSS + 1
18 sub r3, r2 ; R3 = BSS size in bytes
20 srli r4, #2 ; R4 = BSS size in longwords (rounded down)
21 ldi r1, #0 ; clear R1 for longword store
22 addi r2, #-4 ; account for pre-inc store
23 beqz r4, .Lendloop1 ; any more to go?
25 st r1, @+r2 ; yep, zero out another longword
26 addi r4, #-1 ; decrement count
27 bnez r4, .Lloop1 ; go do some more
29 and3 r4, r3, #3 ; get no. of remaining BSS bytes to clear
30 addi r2, #4 ; account for pre-inc store
31 beqz r4, .Lendloop2 ; any more to go?
33 stb r1, @r2 ; yep, zero out another byte
34 addi r2, #1 ; bump address
35 addi r4, #-1 ; decrement count
36 bnez r4, .Lloop2 ; go do some more
39 # Run code in the .init section.
40 # This will queue the .fini section to be run with atexit.
44 # Call main, then exit.
49 # If that fails just loop.