Fast 8 Bit Square Root
;***********************************************
;
; 8 bit Fast Square root
;
; Input: x (not changed)
; Output: y
; Temporary: Temp
;
; Instructions: 29
; Execution time (includng return):
; 31 cycles
;
; August 9, 2000 by Nikolai Golovchenko
;
;***********************************************
sqrt8fast
mov W, x ;1
mov Temp, W
clr y
;find bit 3 of result
mov W, #$40 ;4
sub Temp, W
rl y
sb y.0
add Temp, W ;restore Temp
;find bit 2 of result
or W, #$10 ;9
sb y.0
xor W, #$40
sub Temp, W
rl y
sb y.0
add Temp, W ;restore Temp
;find bit 1 of result
mov W, <>y ;y = 16 * result<3:2>
or W, #$04 ;set bit 1
sub Temp, W ;Temp - (4 * (4 * result<3:2> + 1))
rl y ;store result
sb y.0 ;20
add Temp, W ;restore Temp
;find bit 0 of result
xor W, #$0E ;set bit 0 and compensate for set bit 0 in previous substaction
sb y.0 ;24
xor W, #$08
rl Temp ;shift left the remainder (carry ignored)
sub Temp, W ;Temp - (4 * (4 * result<3:1> + 1))
rl y ;if borrow clear bit 0 and set otherwise
ret ;31
;***********************************************