[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

170.0. "Loop Invariants" by TURTLE::GILBERT () Tue Oct 23 1984 14:42

Is anyone familiar enough with loop invariants to provide one for this tiny
VAX macro subroutine?  It's effectively the same as a division algorithm.

; This little routine computes the multiplicative inverse of any odd longword.
; The input (r0) is an odd longword integer.  The output (also r0) satisfies:
;
;	input * output = 1 (mod 2**32)
;
invsub:	movq	r1, -(sp)	; save r1, r2 on the stack
	subl3	#1, r0, r2	; subtract 1 from the input
	movq	#1, r0		; set r0 to 1, clear r1
10$:	bbc	r1, r0, 20$	; branch if r0 has bit r1 clear
	subl2	r2, r0
20$:	incl	r1
	addl2	r2, r2
	bneq	10$
	movq	(sp)+, r1	; restore r1, r2 from the stack
	rsb			; return
T.RTitleUserPersonal
Name
DateLines