Last active
May 17, 2022 18:59
-
-
Save bitRAKE/85217a0993a912b77c351fddfb6db8f5 to your computer and use it in GitHub Desktop.
general square root for fasmg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; with the remainder calculations can be split into pieces and extended later | |
calminstruction ROOT? result*, remainder*, N* | |
local rem, prox, bit, temp | |
compute rem, 0 | |
check N = 0 | |
jyes done | |
compute prox, 0 | |
compute bit, 1 shl (((bsr N) + 1) and -2) | |
check N > 0 | |
jyes more | |
arrange bit, =err 'square root of negative number' | |
assemble bit | |
exit | |
more: | |
compute temp, rem + bit + prox | |
check N < temp | |
compute rem, rem shr 1 | |
jyes reduce | |
compute rem, rem + bit | |
compute prox, temp | |
reduce: | |
compute bit, bit shr 2 | |
check bit | |
jyes more | |
done: | |
publish result, rem | |
compute rem, N - prox | |
publish remainder, rem | |
end calminstruction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N = result * result + remainder. In this version the remainder is always >= 0.