.TITLE CnvDec .PSECT Aleda,Con,Gbl ;;************************************************************************* ;; Subroutine to convert a 16 bit integer to an ascii string ;; that is the decimal representation of the integer value. ;; Expects calls of the form: Jsr R5,CnvDec ;; .Word address of CONTROL WORD. ;; .Word address of STRING buffer. ;; .Word address of VALUE to be converted. ;; Control Word Meanings ;; Bit #0: 1 = include leading zeroes; 0 = blank leading zeroes. ;; Bit #1: 1 = right justify; 0 = left justify ;; Bit #3: 1 = include trailing decimal point; 0 = no decimal point. ;; The string returned is placed in the leftmost positions of the ;; specified buffer. The string buffer should be at least 7 bytes long. ;; A count of the valid characters in the buffer is returned in register 0. ;;************************************************************************* ;; Last Modified : 26-Jul-84 : to include a FORTRAN callable entry point. ;; Expects calls of the form : ;; Ierror = LCnvTD (Value,Stringbuffer,ReturnCount,ControlWord) ;; Value,ControlWord, and Stringbuffer are required params; ReturnCount ;; is optional. ;;************************************************************************* ;; Last Modified : 27-Jul-84 : to remove leading blank on positive values. ;;************************************************************************* .globl CnvDec,LCnvTD,GetParm Macro=000000 Fortran=000001 LCnvTD: Mov #Fortran,Whocalled ;Indicate called from FORTRAN. Mov R4,-(SP) ;Save registers used. Mov R3,-(SP) Mov R2,-(SP) Mov R1,-(SP) Clr R0 ;Set for counting parameters. Mov (R5)+,R1 ;Get number of parameters. Bic #177400,R1 ;Clear high order bits. Jsr PC,GetParm ;Get parm #1: Value to convert. Bcs ForErr ;Required parm - Abort if absent. Mov (R4),Value ;Save value to convert. Jsr PC,GetParm ;Get parm #2: String buffer. Bcs ForErr ;Required parm - Abort if absent. Mov R4,String ;Save buffer address Clr RtnCount ;Default RtnCount address to 0. Jsr PC,GetParm ;Get parm #3: Return count. Bcs NextP ;Optional parameter. Mov R4,RtnCount ;Save RtnCount address. NextP: Clr Control ;Default control to 0=left justify. Jsr PC,GetParm ;Get parm #4: Control word. Bcs SetUp ;Optional parameter. Mov (R4),Control ;Save control word. SetUp: Mov Value,R1 ;Original code expects value in R1. Br Begin ;Process as if called from macro. ForErr: Neg R0 ;Error returns error code as Mov RtnCount,R1 ;functional value and, Beq NoRet ;if return code exists, Mov R0,(R1) ;in return code. NoRet: Br Restore ;Restore registers and exit. CnvDec: Mov #Macro,Whocalled ;Indicate called from macro. Mov R4,-(SP) ;Save registers used. Mov R3,-(SP) Mov R2,-(SP) Mov R1,-(SP) Mov @(R5)+,Control ;Save control word parameter. Mov (R5)+,String ;Save string address parameter. Mov @(R5)+,R1 ;Pick up value to be converted. Begin: Mov #Power,R3 Mov #Temp,R2 ;Move work area addr. to R2 Tst R1 ;Is value positive? Bge Positive ;If yes,don't worry about sign. Movb #'-,(R2)+ ;else, put minus sign in string Neg R1 ;and negate value to convert. Br Convr Positive: Movb #40,(R2)+ Convr: Clr R0 Mov R1,R4 Sub: Sub (R3),R4 Bmi Storchar ;CONVERT VALUE TO ITS Mov R4,R1 ;EQUIVALENT SIX CHARACTER FIVE Inc R0 ;DIGIT ASCII STRING WITH LEADING Br Sub ;ZEROES AND LEADING BLANK OR ;MINUS SIGN. Storchar: Add #60,R0 Movb R0,(R2)+ Tst (R3)+ Tst (R3) Bne Convr Movb #56,(R2)+ ;Add decimal point. Mov #6,R0 ;Assume decimal point not wanted. Bit #1,Control ;Fill with leading zeros? Bne Exit ;If yes, exit Mov #Temp+1,R2 ;R2 points to first digit position. Blank: Cmpb #60,(R2) ;Is character a zero? Bne Justify ;If not, all leading 0's are blanks. Cmp #Temp+5,R2 ;At last digit position? Beq Justify ;If yes, don't blank possible zero, Movb #40,(R2)+ ;else, make leading zero a blank. Br Blank ;Check next character. Justify: Bit #2,Control ;Check justification bit. Beq Left ;Not set=left justify. Cmpb #40,Temp ;Was first character a blank? Beq Exit ;If yes, exit. Movb #'-,-(R2) ;Else, move minus sign right. Cmp R2,#Temp ;Was minus sign placed in first pos? Beq Exit ;If yes, don't blank it out, else, Movb #40,Temp ;replace original minus with blank. Br Exit Left: Mov #Temp+1,R3 ;R3 points to first digit position. Loop2: Cmp R2,#Temp+7 ;All characters moved? Beq CountL ;If yes, count chars. in string, Movb (R2)+,(R3)+ ;else, move next character. Br Loop2 ;Check next position. CountL: Sub #Temp+1,R3 ;Value is # characters in string. Mov R3,R0 ;Move character count to R0. Exit: Bit #4,Control ;Decimal point wanted? Beq Move ;If not, move string, Inc R0 ;else, reflect inclusion in count. Move: Mov R0,R4 ;Copy character count. Mov String,R3 ;R3 points to string buffer. Mov #Temp,R2 ;R2 points to work area. Cmpb #'-,(R2) ;Was value negative? Beq Loop3 ;If yes, move string to user, Inc R2 ;else, ignore leading blank and Dec R4 ;and decrement character count. Dec R0 Loop3: Movb (R2)+,(R3)+ ;Move character to user buffer. Dec R4 Bgt Loop3 ;Next character. Tst WhoCalled ;Called from FORTRAN or Macro? Beq Restore ;If Macro, restore regs. and exit, Mov RtnCount,R1 ;Move char count address to R1. Beq Restore ;Exit if parameter not provided. Mov R0,(R1) ;Move count to users variable. Clr R0 ;Indicate normal completion. Restore: Mov (SP)+,R1 ;Restore Registers Mov (SP)+,R2 Mov (SP)+,R3 Mov (SP)+,R4 Tst WhoCalled ;Who made call? Beq MacExit ;If macro branch, Rts PC ;If FORTRAN, Rts PC. MacExit: Rts R5 ;Rts R5. ;;************************* Power: .word 10000.,1000.,100.,10.,1,0 Temp: .asciz / / String: .word 0 Control: .word 0 Value: .word 0 RtnCount: .word 0 WhoCalled: .word 0 ;;************************************************************************** .End