.TITLE BASE ; This routine displays the entered number in binary,octal ,decimal & hex. ; on the crt. The base of the number can be any of the entered bases. .MCALL BINDIS,OCTDIS,DECDIS,HEXDIS,.TTYOUT,.TTYINR,TTYO .MCALL BINDNR,OCTDNR,DECDNR,HEXDNR .NLIST BEX,TTM,TOC,SYM ; BASE: TTYO #STRMES ;Print start message TTYO #BASMES ;Print base message JSR PC,CLEAR ;Clear work buffers BIS #10000,@#44 ;Set special TT: mode bit WAIT: .TTYINR BCS WAIT ;Wait for base to be entered CMP #66.,R0 ;Binary base ? BNE O1 JMP BINARY O1: CMP #79.,R0 ;Octal base ? BNE O2 JMP OCTAL O2: CMP #68.,R0 ;Decimal base ? BNE O3 JMP DECIML O3: CMP #72.,R0 ;Hexidecimal base ? BNE O4 JMP HEXDEC O4: TTYO #ERRM1 ;Illegal base JMP WAIT ; ; BINARY: TTYO #BINMES ;Print binary enter message MOV #2,BASECT ;Two possible characters for binary JSR PC,GETNUM ;Get characters for input number ; Construct 16 bit number from entered characters CLR NUMBER MOV #1,R3 ;Multiplier BINMUL: CLC MOV R3,R1 ;Copy multiplier to R1 ; R4 Points to address of last value entered +2 MUL -(R4),R1 ;Multiply entered character ADD R1,NUMBER DEC CHARCT ;Added all characters yet ? BEQ DONE1 CLC ROL R3 ;Multilpy multipplier by 2 JMP BINMUL DONE1: TTYO #HEADER BINDNR NUMBER ;Display entered number JMP DIS ;Display result ; ; OCTAL: TTYO #OCTMES ;Print octal enter message MOV #8.,BASECT ;8 possible # to be entered JSR PC,GETNUM ;Get #'s from key board ; Construct 16 bit number from entered characters CLR NUMBER MOV #1,R3 ;Multiplier OCTMUL: CLC MOV R3,R1 ;Copy multiplier to R1 ; R4 Points to address of last value entered +2 MUL -(R4),R1 ;Multiply entered character BCC OKAY1 JMP ERR OKAY1: ADD R1,NUMBER DEC CHARCT ;Added all characters yet ? BEQ DONE3 CLC MUL #8.,R3 JMP OCTMUL DONE3: TTYO #HEADER OCTDNR NUMBER ;Display entered number JMP DIS ;Display Results ; ; DECIML: TTYO #DECMES ;Print decimal enter message MOV #10.,BASECT ;10 possible # to be entered JSR PC,GETNUM ;Get #'s from key board ; Construct 16 bit number from entered characters CLR NUMBER MOV #1,R3 ;Multiplier DECMUL: CLC MOV R3,R1 ;Copy multiplier to R1 ; R4 Points to address of last value entered +2 MUL -(R4),R1 ;Multiply entered character BCC OK1 JMP ERR OK1: ADD R1,NUMBER DEC CHARCT ;Added all characters yet ? BEQ DONE4 CLC MUL #10.,R3 ;Multiply multiplier by 10 BCC OK2 JMP ERR OK2: JMP DECMUL DONE4: TTYO #HEADER DECDNR NUMBER ;Display entered number JMP DIS ;Display Results ; ; ; HEXDEC: TTYO #HEXMES ;Print hex enter message MOV #16.,BASECT ;16 possible characters JSR PC,GETNUM ;Get #'s from key-board ; Construct 16 bit number from entered characters CLR NUMBER MOV #1,R3 ;Multiplier HEXMUL: CLC MOV R3,R1 ;Copy multiplier to R1 ; R4 Points to address of last value entered +2 MUL -(R4),R1 ;Multiply entered character ADD R1,NUMBER DEC CHARCT ;Added all characters yet ? BEQ DONE5 CLC MUL #16.,R3 ;Multiply multiplier by 16. BCS ERR ;Multiplication error JMP HEXMUL ERR: TTYO #MULERR JMP BASE DONE5: TTYO #HEADER HEXDNR NUMBER ;Display entered number JMP DIS ;Display Results ; ; ; Get number from key-board & check for validity GETNUM: MOV #INBLCK,R4 ;Point R4 to value storage block INPUT: .TTYINR BCS INPUT .TTYOUT ;Echo entered character ;Check for or to be entered CMP #12,R0 BEQ DONE2 CMP #15,R0 BEQ DONE2 MOV #CHARS,R1 ;Point to possible characters MOV BASECT,R2 ;Copy possible # of characters MOV #VALUES,R3 ;Point to char. value table CLR LOPCTR ;Counts # of checks until match found LOOP: CMP (R1)+,R0 ;Check through possible characters BEQ MATCH ;Skip if a match is found ADD #2,LOPCTR DEC R2 ;Have we tried all possible chars. yet? BNE LOOP ; No match found for entered character. Start again TTYO #ERRM1 JMP INPUT ; Match found MATCH: INC CHARCT ;Increment character counter ADD LOPCTR,R3 ;Increment pointer to proper value MOV (R3),(R4)+ ; Store value to storage block JMP INPUT ;Get more characters ; Return has been entered. Exit subroutine DONE2: .TTYINR ;Get from pair CMP #0,CHARCT ;Is the character count = 0 ? BEQ GETNUM ;Go back if it is RTS PC ; ; ; Display result in Binary Octal Decimal & Hexidecimal ; ; DIS: TTYO #BIN BINDNR NUMBER TTYO #OCT OCTDNR NUMBER TTYO #DEC DECDNR NUMBER TTYO #HEX HEXDNR NUMBER JMP BASE ; Clear the locations to be used ; CLEAR: MOV #INBLCK,R1 MOV #16.,R2 CL1: CLR (R1)+ DEC R2 BNE CL1 CLR LOPCTR CLR BASECT CLR NUMBER CLR CHARCT RTS PC ; ; MESSAGES ** ** ** ** ** ** STRMES: .ASCII <15><12>/ -- BASE CONVERSION ROUTINE --/<12><15> .ASCII /Displays number in binary ; octal ; decimal & hex/<12><15> .BYTE 0 .EVEN BASMES: .ASCII /Enter 1-character to select base of input #/ .ASCII / - B ; O ; D ; H/<12><15> .BYTE 0 .EVEN ERRM1: .ASCII / ILLEGAL CHARACTER - TRY AGAIN/<12><15> .BYTE 0 .EVEN ERRM2: .ASCII <12><15>/ILLEGAL NUMBER - START AGAIN/<12><15> .BYTE 0 .EVEN MULERR: .ASCII <12><15>/ Multiplication error/<12><15> .BYTE 0 .EVEN BINMES: .ASCII /Enter Binary # to be converted : / .BYTE 0 .EVEN OCTMES: .ASCII /Enter Octal # to be converted : / .BYTE 0 .EVEN DECMES: .ASCII /Enter Decimal # to be converted : / .BYTE 0 .EVEN HEXMES: .ASCII /Enter Hex. # to be converted : / .BYTE 0 .EVEN HEADER: .ASCII <12><15>/ Input number = / .BYTE 0 .EVEN BIN: .ASCII <12><15>/ Binary = / .BYTE 0 .EVEN OCT: .ASCII <12><15>/ Octal = / .BYTE 0 .EVEN DEC: .ASCII <12><15>/ Decimal = / .BYTE 0 .EVEN HEX: .ASCII <12><15>/ Hexidecimal = / .BYTE 0 .EVEN CHARS: .WORD 48.,49.,50.,51.,52.,53.,54.,55. .WORD 56.,57.,65.,66.,67.,68.,69.,70. VALUES: .WORD 0,1,2,3,4,5,6,7,8.,9.,10.,11.,12.,13.,14.,15. CHARCT: .WORD 0 NUMBER: .WORD 0 LOPCTR: .WORD 0 BASECT: .WORD 0 ;Stores the # of possible base characters INBLCK: .BLKW 16. ;Stores the value of the entered character .END BASE