Q2 Computer - Integer Square Root
; Compute the integer square root of x0 ; Returns the result in x0. ; Destroys x0, x1, x2, x3 (assumed to be in the zero page). isqrt: sta =x3 lea =1 sta =x1 ; x1 = 1 lea =3 sta =x2 ; x2 = 3 isqrt_loop: lda =x0 nor #0 add =x1 jfc isqrt_cont ; if x0 >= x1 continue shr =x2 ; return x0 = (x2 / 2) - 1 add #-1 sta =x0 jmp @=x3 isqrt_cont: lda =x1 add =x2 sta =x1 ; x1 += x2 lea =2 add =x2 sta =x2 ; x2 += 2 jmp isqrt_loop