.NLIST TOC,SYM .TITLE $CBDSG, $CBDMG, $CBOSG, $CBOMG .SBTTL ULBLIB 011 - General conversion routines .IDENT \V01.00\ .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. ;+ ; $CBDSG ($CBOSG) ; The Convert Binary to Decimal (Octal) Signed routine converts a one ; word binary number to ASCII, as a signed number. ; ; $CBDMG ($CBOMG) ; The Convert Binary to Decimal (Octal) Magnitude routine converts a one ; word binary number to ASCII, as an unsigned number. ; ; R0 = address to store first byte in output string ; R1 = value to be converted ; R2 = zero suppression indicator ; R2 = 0 => suppress zero ; R2 <> 0 => include lead zeros ; ; CALL $CB(D,O)(M,S)G ; ; R0 = address past last digit stored ;- .ENABL LSB $CBDSG:: TST R1 ;Negative number? BPL $CBDMG ;Branch if not MOVB #'-,(R0)+ ;Store the minus sign NEG R1 ;Make the value positive $CBDMG:: JSR R5,$SAVRG ;Save non-volatile registers MOV #5,R3 ;5 digits maximum MOV #10.,R5 ;Set base 10 conversion radix BR 1$ ; $CBOSG:: TST R1 ;Negative value? BPL $CBOMG ;Branch if not MOVB #'-,(R0)+ ;Insert the minus sign NEG R1 ;Make it positive $CBOMG:: JSR R5,$SAVRG ;Save non-volatile registers MOV #6,R3 ;6 digits MOV #8.,R5 ;Base 8 1$: MOV R0,R4 ;Save next byte address MOV R1,R0 ;R0 = dividend 2$: MOV R5,R1 ;Set conversion radix CALL $DIV ;Divide 'em up MOV R1,-(SP) ;Save the remainder DEC R3 ;Any digits left? BLE 4$ ;Branch if not TST R2 ;Include leading zero's? BNE 3$ ;Branch if not TST R0 ;Zero quotient? BEQ 4$ ;If so, all done 3$: CALL 2$ ;Divide again 4$: ADD #'0,@SP ;Make it ASCII MOVB (SP)+,(R4)+ ;Store the digit MOV R4,R0 ;Save the terminal address RETURN .DSABL LSB .END