		.ORIG   x3400
		
		ST      R0,r0orig		;; save r0
		ST      R1,r1orig		;; save r1
		ST      R2,r2orig		;; save r2

		and	r2,r2,#0
		LDR     R0,R5,#7		;; loads value
		LDR     R1,R5,#6		;; loads base

start		add	R2,R2,R0		;; value * base
		add	R1,R1,#-1
		brp	start
	
		LDR     R1,R5,#5		;; loads type
		LDR     R0,R5,#4		;; loads char
		add	R1,R1,#-3		;; test if type = 3
		brz	isHexadecimal 

		add	r2,r0,r2		;; value * base +char
		ld	r0,point1
		add	r2,r0,r2		;; value * base +char - 48
		br	end

isHexadecimal 	ld	r1,Remove
		and	r0,r0,r1
		add	r2,r0,r2		;; value * base + (char&0xFFDF)
		ld	r0,point2
		add	r2,r0,r2		;; value * base + (char&0xFFDF) - 55

end		STR	r2,r5,#3		;; store the result in r5 - 3

		ld	R0,r0orig		;; load r0 with start value
		ld	R1,r1orig		;; load r1 with start value
		ld	R2,r2orig		;; load r2 with start value
		RET

r0orig  	.BLKW   x1
r1orig  	.BLKW   x1
r2orig  	.BLKW   x1
point1		.FILL   #-48
point2		.FILL   #-55
Remove		.FILL   Xffdf

		.END