Q2 Computer - Integer Square Root

This makes some assumptions about values in the zero page, like the common functions.

; Compute the integer square root of x0
; Returns the result in x0.
; Destroys x0, x1, x2, x3
isqrt:
  sta   =x3
  lea   =1
  sta   =x1       ; x1 = 1
  lea   =3
  sta   =x2       ; x2 = 3
isqrt_loop:
  lda   =x0
  nor   =zero
  add   =x1
  jfc   isqrt_cont  ; if x0 >= x1 continue
  shr   =x2         ; return x0 = (x2 / 2) - 1
  add   =neg1
  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