9.4.1. SWI handlers in assembly language

The easiest way to call the handler for the requested SWI number is to use a jump table. If r0 contains the SWI number, the code in Example 9.6 can be inserted into the top-level handler given in Example 9.5, following on from the BIC instruction.

Example 9.6. : SWI Jump Table

	ADR	r2, SWIJumpTable
	LDR	pc, [r2,r0,LSL #2]
SWIJumpTable
	DCD	SWInum0
	DCD	SWInum1
					; DCD for each of other SWI routines
					;
SWInum0					; SWI number 0 code
	B	EndofSWI
SWInum1					; SWI number 1 code
	B	EndofSWI
					;
					; Rest of SWI handling code
					;
EndofSWI
					; Return execution to top level 
					; SWI handler so as to restore
					; registers and return to program.
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D
Non-Confidential