Square Roots

Square Root (8-bit)
Find the sqaure root (integer) of an 8-bit number. The number to be square rooted should be loaded into A; the result will be returned in B.

ld b,255 loop inc b    inc b     sub b     jr nc,loop srl

Square Root (16-bit)
Find the square root (integer) of a 16-bit number. The number to be square rooted should be loaded into HL; the result will be returned in A.

ld a,255 ld d,a ld e,a loop add hl,de inc a    dec e     dec de     jr c,loop