Thanks for that article, Michael. I think I'll have to read that more than a couple of times to get the hang of the math.
In other news, I was playing around with MJM's MS float routine, and I found what I thought was an interesting little resting point:
Code:
ACC = $80
ARG = $82
TMP = $84
sqrt:
lda ACC+1
sta ARG+1
lda ACC
sta ARG ; Move ACC to ARG
lda #0 ; Zero ACC & TMP
sta ACC
sta TMP
sta ACC+1
sta TMP+1
ldx #16 ; Gen X bits of sqrt
bne start ; (always)
loop:
asl ARG ; Left shift TMP
rol ARG+1
rol TMP
rol TMP+1
asl ARG ; by 2 bits.
rol ARG+1
rol TMP
rol TMP+1
lda TMP+1 ; Compare __ bits of TMP
cmp ACC+1 ; with current sqrt.
bne check
lda TMP ; Compare next byte
cmp ACC
bne check
start:
lda ARG+1 ; Compare final byte
cmp #$40
check:
bcc shift0 ; TMP > sqrt
lda ARG+1 ; TMP <= sqrt, so subtract
sbc #$40
sta ARG+1
lda TMP
sbc ACC
sta TMP
lda TMP+1
sbc ACC+1
sta TMP+1
shift0:
rol ACC ; Rotate C into sqrt
rol ACC+1
dex ; Done?
bne loop ; -No, keep looping.
rts
Load the 16-bit integer into ACC, and it appears to come back as the square root, in 8.8 fixed point format! I still don't understand how it works, but it seems I can get just the truncated integer result by dumbing the ldx #16 down to ldx #8.
There appears to be room for improvement if the truncated result is all that's needed, but I'm chuffed at the current state of affairs. Can anyone with a better brain than mine try to explain what's going on here?
_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some
VTL02C on it and see how it grows on you!
Mike B.
(about me) (learning how to github)