In   -
Out  math
Type AOF
Ver  1.01h

; this is a simple library to do some maths stuff - none of it is
; guarenteed to be quick !

#Area "JFP:Math" Code ReadOnly
#Rem =Rem
#CodePrefix =Prefix
; *******************************************************************
; Subroutine:   sqrt(x)
; Description:  Find square root of x
; Parameters:   r0 = number
; Returns:      r0 = root
; Note:         This is an awful routine, but it works ok
; *******************************************************************
>|sqrt|
   STMFD   (sp)!,{r1,r2,link}            ; Stack registers
   MOV     r1,#0                         ; start at 1
$loop
   MUL     r2,r1,r1                      ; r2 = r1 squared
   CMP     r2,r0                         ; is it bigger ?
   ADDLT   r1,r1,#1                      ; if smaller, compare
   BLT     $loop                         ; and go for more
   MOV     r0,r1                         ; r0 = result
   LDMFD   (sp)!,{r1,r2,pc}^             ; Return from call
