10.3.7. Initializing memory required by C code

The initial values for any initialized variables (RW) must be copied from ROM to RAM. All other ZI variables must be initialized to zero.


If the application uses scatter loading, see Initialization code for details of how to initialize these areas.

Example 10.1 shows an example of code to initialize variables in RAM if the application does not use scatter loading.

Example 10.1.  Initializing variables

	IMPORT		|Image$$RO$$Limit|							; End of ROM code (=start of ROM data)
	IMPORT		|Image$$RW$$Base|							; Base of RAM to initialize
	IMPORT		|Image$$ZI$$Base| 							; Base and limit of area
 	IMPORT		|Image$$ZI$$Limit|							; to zero initialize
	LDR		r0, =|Image$$RO$$Limit|							; Get pointer to ROM data
	LDR 		r1, =|Image$$RW$$Base|							; and RAM copy
	LDR 		r3, =|Image$$ZI$$Base|							; Zero init base => top of initialized data
	CMP		r0, r1							; Check that they are different
	BEQ		%F1
0	CMP		r1, r3							; Copy init data
	LDRCC		r2, [r0], #4
	STRCC		r2, [r1], #4
	BCC		%B0
1	LDR		r1, =|Image$$ZI$$Limit|							; Top of zero init segment
	MOV  		r2, #0
2	CMP 		r3, r1                  							; Zero init
	STRCC		r2, [r3], #4
	BCC		%B2
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D