.NLIST .ENABL LC ; Enable lower case. .NLIST CND ; Don't list unsatisfied conditional assemblies. .LIST .TITLE CVTBTA - Convert Binary to Ascii Text .IDENT /V01.1/ ; 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. ; ++ ; FACILITY: ; ; Formatted Ascii Output ; ; ABSTRACT: ; ; The routines in this module perform binary integer to ascii ; text conversion in decimal, octal, and hexadecimal radix. ; ; ENVIRONMENT: ; ; PDP-11 processor; no operating system specific facilities ; are needed. ; ; AUTHOR: ; ; Randy Black, CREATION DATE: 15-Jan-83 ; ; MODIFIED BY: ; ; modifiers name, dd-mmm-yy, VERSION: svv.u-ep ; 01 - modification description ; ; -- .SBTTL Module Declarations ; ; INCLUDE FILES: ; ; No include files referenced ; ; MACROS: ; .MACRO DEF$ name,expr=0,scope=NOGBL .DSABL CRF,LC .IF IDN GLOBAL, name == expr .IFF name = expr .ENDC .ENABL CRF,LC .ENDM DEF$ .MACRO POP$ args .IF B TST (SP)+ .IFF .IRP arg, MOV (SP)+,arg .ENDM .ENDC .ENDM POP$ .MACRO PUSH$ args .IRP arg, .IF IDN arg,#0 CLR -(SP) .IFF MOV arg,-(SP) .ENDC .ENDM .ENDM PUSH$ .MACRO PSECT$ prgsct,attr .LIST BEX .IF NB .PSECT prgsct,attr .IFF .PSECT prgsct .ENDC .NLIST BEX .ENDM PSECT$ ; ; EQUATED SYMBOLS: ; ; ; Miscellaneous Constants ; def$ NIL 0 GLOBAL ; Define 'nil' pointer value. ; ; OWN STORAGE: ; psect$ LIB$OWN, .ASCII \ \ digits: .ASCII \0123456789ABCDEF\ ; ; EXTERNAL REFERENCES: ; .GLOBL DDIV ; Double precision divide routine. .GLOBL FAO.FILLCHAR ; Fao numeric field fill character. .SBTTL CVTBTA - Convert Binary to Ascii Text ; ++ ; FUNCTIONAL DESCRIPTION: ; ; This routine converts binary to ascii text. ; ; CALLING SEQUENCE: ; ; CALL CVTBTA ; ; INPUT PARAMETERS: ; ; ** tbs ** ; ; IMPLICIT INPUTS: ; ; ** tbs ** ; ; OUTPUT PARAMETERS: ; ; ** None ** ; ; IMPLICIT OUTPUTS: ; ; ** None ** ; ; COMPLETION CODES: ; ; ** None ** ; ; SIDE EFFECTS: ; ; ** tbs ** ; ; -- psect$ lib$code, CVTBTA:: ; Entry point to CVTBTA routine. push$ R5 ; Save pointer to FAO's parameter list. push$ 2(R4) ; Save pointer to string. MOV R0,R5 ; R5 <- numeric conversion radix. CALL CBDNUM ; Convert double binary to numeric ; with leading zero's suppressed. pop$ 2(R4) ; Restore pointer to string. pop$ R5 ; Restore pointer to FAO's parameter list. RETURN ; Return to caller. ; ; Convert Double Binary To Numeric ; CBDNUM: MOV R5,R0 ; R0 <- numeric conversion radix. CALL DDIV ; Go divide 'em up. push$ R0 ; Save the remainder on the stack. DEC R3 ; Any digits left? BLE 20$ ; If LE, no - conversion done. TST R1 ; Zero quotient? BNE 10$ ; If so, all done except for TST R2 ; field filling. Otherwise, go BNE 10$ ; divide again and again and ... MOV FAO.FILLCHAR,R0 ; R0 <- Numeric fill character bias. BGT 20$ ; If GT, suppress leading zeroes. TST @SP ; Remainder zero? BNE 10$ ; If NE, no fill character needed yet. ADD R0,@SP ; Otherwise, add fill character bias to result. 10$: CALL CBDNUM ; Go do division. 20$: pop$ R0 ; Get digit from stack. MOVB DIGITS(R0),@2(R4) ; Use remainder to get ascii digit ; and store ascii character in string. INC (R4) ; Update both length and pointer INC 2(R4) ; fields of string descriptor. 30$: RETURN ; Return to caller. .END