TITLE Odd Base Print Routine, by Douglas Jones ;------------------------ ; this routine outputs signed numbers in any base from 2 to 36 ;------------------------ USE "/group/22c018/hawk.macs" ; linkage to monitor routines EXT DSPCH,DIVIDE PDSPCH: W DSPCH PDIVIDE:W DIVIDE ;------------------------ INT ODDPR ; AR format, indexed using R2: ; 0 ; return address ODDRM = 4 ; remainder after division by 10 ODDBAS = 8 ; base ODDAR = 12 ; total size ODDPR: ; output R3 in base given by R4 ; wipes out R3-6 STORES R1,R2 ; save ret addr in ar STORE R4,R2,ODDBAS TESTR R3 ; check sign of number BNR ODDPOS STORE R3,R2,ODDRM ; set aside number (misuse of ODDRM!) LIS R3,"-" LOAD R1,PDSPCH JSRS R1,R1 ; output - (wipe out R4-5) LOAD R3,R2,ODDRM ; restore number NEG R3,R3 ; and negate it LOAD R4,R2,ODDBAS ; restore base (lost to DSPCH) ODDPOS: LOAD R1,PDIVIDE JSRS R1,R1 ; divide number by base (wipe out R5-6) STORE R4,R2,ODDRM TESTR R3 ; check quotient after save remainder BZS ODDQT ; if zero, we have final digit LOAD R4,R2,ODDBAS ADDI R2,ODDBAS ; setup for recursion JSR R1,ODDPR ; recursive call ADDI R2,-ODDBAS ; (note that field width not needed) ODDQT: LOAD R3,R2,ODDRM ADDI R3,'0' ; convert remainder to ASCII CMPI R3,'9' ; see if too big for digit BLE ODDOK ADDI R3,'A'-('9'+1) ; fix oversize digits ODDOK: LOAD R1,PDSPCH JSRS R1,R1 ; output digit (wipe out R4-5) LOADS R1,R2 ; recover ret addr from ar JUMPS R1 ; return END