Difference between revisions of "Programming:Square Root"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
 
 
Line 26: Line 26:
 
ret
 
ret
 
</pre>
 
</pre>
 +
 +
[[Category:Programming]]

Latest revision as of 08:34, 10 March 2007

Square Root of 16bit value by Ricardo Bittencourt

;Square root of 16-bit value
;In:  HL = value
;Out:  D = result (rounded down)

.Sqr16	ld de,#0040
	ld a,l
	ld l,h
	ld h,d
	or a
	ld b,8
.Sqr16_Loop
	sbc hl,de
	jr nc,Sqr16_Skip
	add hl,de
.Sqr16_Skip
	ccf
	rl d
	add a,a
	adc hl,hl
	add a,a
	adc hl,hl
	djnz Sqr16_Loop
	ret