summaryrefslogtreecommitdiffstats
path: root/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/BASICASM/JUMP.S
blob: fbcb4eb111ae9b44c17e595e6f2b9387a9e69147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	AREA 	ArithGate, CODE	; name this block of code
	ENTRY					; mark the first instruction to call
main	
	MOV		r0, #2			; set up three parameters
	MOV		r1, #5
	MOV		r2, #15
	BL		arithfunc		; call the function
	SWI		0x11			; terminate

arithfunc					; label the function
	CMP		r0, #4			; Treat code as unsigned integer
	BHI		ReturnA1		; If code > 4 then return first
							; argument
	ADR		r3, JumpTable	; Load address of the jump table
	LDR		pc,[r3,r0,LSL #2] ; Jump to appropriate routine

JumpTable
	DCD		ReturnA1
	DCD		ReturnA2
	DCD		DoAdd
	DCD		DoSub
	DCD		DoRsb

ReturnA1
	MOV		r0, r1			; Operation 0, >4
	MOV	pc,lr
ReturnA2
	MOV		r0, r2			; Operation 1
	MOV		pc,lr
DoAdd
	ADD		r0, r1, r2		; Operation 2
	MOV		pc,lr
DoSub
	SUB		r0, r1, r2		; Operation 3
	MOV		pc,lr
DoRsb
	RSB		r0, r1, r2		; Operation 4
	MOV		pc,lr

	END						; mark the end of this file