SECTION statement

XCSB automatically allocates RAM for use as variables. All global variables are gathered together into one area called the prog_data section. All variables, parameters and evaluation stacks are gathered together into seperate sections on a function basis.

All local variables belonging to a function are gathered together into a locals section that belongs to the function. The name of the section is derived from the function name and ends with "_func_locals"

e.g.

function fred has a locals data section called fred_func_locals

All parameters belonging to a function are gathered together into a parameters section that belongs to the function. The name of the section is derived from the function name and ends with "_func_args"

e.g.

function fred has a locals data section called fred_func_locals

All temporary RAM used during the evaluation of an expression during the execution of a function is gathered together into an evaluation stack section that belongs to the function. The name of the section is derived from the function name and ends with "_func_eval_stk"

e.g.

function fred has a locals data section called _func_eval_stk

All three sections are collectively known as the function context. They are kept physically close to each other in RAM to improve locallity and reduce RAM page switching.

The section statement is used to declare a RAM section and associated allocation priority. Variables can be explicitly assigned to a user declared section. This is done by adding the the section name to the variable declaration.

e.g.
	section	XYZ_SECT:10

	int  XYZ_SECT  count
The section allocation priority determins the order in which RAM is allocated. The lower the value the high the priority. the prog_data section has the highest priority and is always allocated first. To move global variables out of the prog_data section simply assign the variable to a user declared section.

If the prog_data section exceads the size of the largest available RAM page the compilation will fail. Moving global variables to user declared sections is a way to fix this problem.

Large arrays that are refered to mainly by pointers are a good candidate for moving to the end of RAM. Do this by using a user declared section with a very large allocation priority.

e.g.
	section	ABC_SECT:1000

	byte  ABC_SECT  buff[40]

A function context may also be explicitly assigned to a user declared section. This should only be done when the user needs to take control of a function context (e.g. wrapper function for external asm library). Takeing control of a function context will seriously impair optimisation. Do not do this without a very good reason

e.g.
	section	FRED_SECT:1000

	proc FRED_SECT fred(int arg1)
		byte	arr[10]
	endproc