.NLIST TOC,SYM .TITLE $DIV .SBTTL ULBLIB 012 - Integer Divide (magnitude) .IDENT \V01.01\ .PSECT .LIBC. .ENABL LC,GBL ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ;+ ; $DIV ; The Integer Divide (magnitude) divides two words giving both a ; quotient and a remainder. ; ; R0 = dividend ; R1 = divisor ; ; CALL $DIV ; ; R0 = quotient ; R1 = remainder ;- $DIV:: MOV #20,-(SP) ;Set loop count MOV R1,-(SP) ;Save divisor for subtracts CLR R1 ;Clear remainder 1$: ASL R0 ;Double precision left shift ROL R1 ; CMP R1,@SP ;Subtract out divisor BLO 2$ ;Branch if not SUB @SP,R1 ;Do it INC R0 ;Add in low bit 2$: DEC 2(SP) ;Decrement loop count BGT 1$ ;If GT, more to do CMP (SP)+,(SP)+ ;Clean the stack RETURN .END