Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/09/05 23:26
Read: times


 
#89373 - iteration
Responding to: ???'s previous message
;************************************************************
	;
	; SQUARE ROOT
	;
	;************************************************************
	;
ASQR:	ACALL	AABS		;GET THE SIGN
	JNZ	SQ_ERR		;ERROR IF NEGATIVE
	ACALL	C_T2		;COPY VARIABLE TO T2
	ACALL	POP_T1		;SAVE IT IN T1
	MOV	R0,#LOW FPT1
	MOVX	A,@R0		;GET EXPONENT
	JZ	ALN-2		;EXIT IF ZERO
	ADD	A,#128		;BIAS THE EXPONENT
	JNC	SQR1		;SEE IF < 80H
	RR	A
	ANL	A,#127
	SJMP	SQR2
	;
SQR1:	CPL	A		;FLIP BITS
	INC	A
	RR	A
	ANL	A,#127		;STRIP MSB
	CPL	A
	INC	A
	;
SQR2:	ADD	A,#128		;BIAS EXPONENT
	MOVX	@R0,A		;SAVE IT
	;
	; NEWGUESS = ( X/OLDGUESS + OLDGUESS) / 2
	;
SQR4:	ACALL	P_T2		;TOS = X
	ACALL	PUSH_T1		;PUT NUMBER ON STACK
	ACALL	ADIV		;TOS = X/GUESS
	ACALL	PUSH_T1		;PUT ON AGAIN
	ACALL	AADD		;TOS = X/GUESS + GUESS
	ACALL	DBTWO		;TOS = ( X/GUESS + GUESS ) / 2
	ACALL	TEMP_COMP	;SEE IF DONE
	JNB	F0,SQR4
	;
	AJMP	PUSH_T1		;PUT THE ANSWER ON THE STACK
	;
$EJECT

This is the square root code in Basic52. This does not sound to me as a log/exp,approach... Clearly an iteration.
The problem might be in the way how it was - quite brutally - optimized. See for example
JZ	ALN-2		;EXIT IF ZERO
, the ALN denotes the logarithm routine and is just after the end of this one; but moving it away, or replacing the final AJMP by LJMP makes this fail.

Jan Waclawek

List of 7 messages in thread
TopicAuthorDate
8052BASIC details            01/01/70 00:00      
   Sorry            01/01/70 00:00      
   Basic Square Root            01/01/70 00:00      
      Newton Method            01/01/70 00:00      
         iteration            01/01/70 00:00      
            Tis Newton            01/01/70 00:00      
            sq root            01/01/70 00:00      

Back to Subject List