	AREA lab4d, DATA


Test	DCD 1, 3, 5, 7, 9, 8, 6, 4, 2, 0

TextA	DCB "Lab 4, Home Assigment 1\n",0
TextB	DCB "The max is: ",0
TextC	DCB "\nDone\n",0

	AREA lab4c, CODE
        
; This function prints a null-terminated string 
; a1 points to the string
wrline	MOV a2,a1		; Copy the pointer to a2
	MOV a1,#0x4		; Set the SYS_WRITE0 code
	SWI 0x123456		; Make the system call
	MOV pc,lr		; return from this function

; This function prints a number (less then 10) 
; a1 contains the number 
wrnum	ADD a2,a1,#0x30		; Copy the number to a2 and add 0x20 to 
				; make an ASCII character
	STMFD sp!,{a2}		; Push character on stack
	MOV a2,sp			; Put address to character in a2
	MOV a1,#0x3		; Set the SYS_WRITEC code
	SWI 0x123456		; Make the system call
	ADD sp,sp,#4		; Pop without mem.ref.
	MOV pc,lr		; return from this function

	GLOBAL FindMax		; Make the symbol FindMax visible outside
				; this file

FindMax
	STMFD	sp!,{v1,v2}	; Push v1 and v2 (modify as needed)

        ;;;  Add code to find maximum value element here! ;;;

	LDMFD	sp!,{v1,v2}	; Pop v1 and v2
	MOV	pc,lr		; Jump back to calling routine

	;;EXTERN FindMaxC	; Uncomment if FindMaxC is used
	ENTRY			; Comment if main in C program is used
main
	LDR	a1,=TextA	; Load address to welcome text
	BL	wrline
	LDR	a1,=Test	; Load address to vector
	BL	FindMaxC	; Call FindMax subroutine
	MOV	v1,a1		; Save the result in v1

	LDR	a1,=TextB	; Load address to result text
	BL	wrline		
	MOV	a1,v1		; Copy result to a1
	BL	wrnum		; print the result

	LDR	a1,=TextC   	; Load address to goodbye text
	BL	wrline

stop	MOV	r0,#0x18
	LDR	r1,=0x20026
	SWI	0x123456

	END

