TITLE "mp3.a by Douglas Jones" ; this program interactively requests a heptavintimal number ; and then converts it to decimal USE "hawk.h" USE "monitor.h" ; activation record of main program ;RETAD = 0 BUFFER = 4 ; buffer to hold 20 characters ARSIZE = 24 INT MAIN S MAIN MAIN: STORES R1,R2 ; --- begin application code --- MAINLP: ; do { ; -- first erase the previous output, if any ADDI R2,R2,ARSIZE LIS R3,24 ; -- param LIS R4,1 ; -- param LIL R1,PUTAT JSRS R1,R1 ; putat( 24, 1 ) LIL R3,FEWSP ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( FEWSP ) -- erase previous input LIS R3,8 ; -- param LIS R4,2 ; -- param LIL R1,PUTAT JSRS R1,R1 ; putat( 8, 2 ) LIL R3,MORESP ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( MORESP ) -- erase previous output LIS R3,8 ; -- param LIS R4,3 ; -- param LIL R1,PUTAT JSRS R1,R1 ; putat( 8, 3 ) LIL R3,FEWSP ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( FEWSP ) -- erase prompt for more ; -- second, prompt for input LIS R3,8 ; -- param LIS R4,1 ; -- param LIL R1,PUTAT JSRS R1,R1 ; putat( 8, 1 ) LIL R3,HEPTSTR ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( HEPTSTR ) ; -- third, get and process input ADDI R2,R2,-ARSIZE LEA R3,R2,BUFFER ; -- param (address of buffer) ADDI R2,R2,ARSIZE LIL R1,GETS JSRS R1,R1 ; gets( buffer ) ADDI R2,R2,-ARSIZE LEA R3,R2,BUFFER ; -- param (address of buffer) ADDI R2,R2,ARSIZE JSR R1,HTOI ; i = htoi( buffer ) MOVE R8,R3 ; -- set i aside ; -- fourth, display the results LIS R3,8 ; - param LIS R4,2 ; - param LIL R1,PUTAT JSRS R1,R1 ; putat( 8, 2 ) LIL R3,DECISTR ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( DECISTR ) MOVE R3,R8 ; -- param LIS R4,1 ; -- param LIL R1,PUTDECU JSRS R1,R1 ; putdecu( i, 1 ) ; -- last, prompt to ask if more work LIS R3,8 ; - param LIS R4,3 ; - param LIL R1,PUTAT JSRS R1,R1 ; putat( 8, 3 ) LIL R3,MORESTR ; -- param LIL R1,PUTS JSRS R1,R1 ; puts( MORESTR ) LIL R1,GETCHAR JSRS R1,R1 ; ch = getchar() ADDI R2,R2,-ARSIZE CMPI R3,'y' BEQ MAINLP ; while (ch == 'y') ; --- end application code --- LOADS R1,R2 JUMPS R1 ; --- begin application constants --- HEPTSTR:ASCII "Heptavigintimal: ",0 DECISTR:ASCII "Decimal: ",0 MORESTR:ASCII "More? (y/n)",0 MORESP: ASCII " " ; null terminator deliberately left out FEWSP: ASCII " ",0 ; previous string flows into this one ALIGN 4 ; -- array A for translating character digits to integer A: W -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 ; control W -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 ; control W -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 ; ' ' to '/' W 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1 ; '0' to '?' W -1,10,11,12, 13,14,15,16, 17, 1,-1,18, 1,19,20, 0 ; '@' to 'O' W 21, 0,22, 5, 23,24,24,24, 25, 1,26,-1, -1,-1,-1,-1 ; 'P' to '_' W -1,10,11,12, 13,14,15,16, 17, 1,-1,18, 1,19,20, 0 ; '`' to 'o' W 21, 0,22, 5, 23,24,24,24, 25, 1,26,-1, -1,-1,-1,-1 ; 'p' to del SUBTITLE "Heptavintimal to Binary Converter" ; activation record ;RETAD = 0 ; return address SAVER8 = 4 ; saved copy of R8 SAVER9 = 8 ; saved copy of R9 ARSIZE = 12 HTOI: ; expects R3 = s, a pointer to a null terminated string ; returns R3 = a, the integer value of the string ; may use R4-R7 STORES R1,R2 ; -- save return address STORE R8,R2,SAVER8 ; -- save R8 STORE R9,R2,SAVER9 ; -- save R9 MOVE R8,R3 ; -- from here on, R8 is s LIS R3,0 ; a = 0 -- the accumulator for the value HTOILP: ; for (;;) { LOADS R9,R8 EXTB R9,R9,R8 ; ch = s[] -- the next char in string BZS HTOIQT ; if (ch == '\000') break; TRUNC R9,7 ; ch = ch & 0x7F -- don't want 8-bit values LEA R4,A ADDSL R9,R4,2 ; -- compute address of array element LOADS R9,R9 ; d = A[ch] -- the value of one digit MOVE R4,R3 ; -- parameter a LIS R5,27 ; -- parameter 27 ADDI R2,R2,ARSIZE LIL R1,TIMESU JSRS R1,R1 ; a = timesu( a, 27 ) ADDI R2,R2,-ARSIZE ADD R3,R3,R9 ; a = a + d ADDSI R8,1 ; s = s + 1 -- advance to next character BR HTOILP HTOIQT: ; } LOAD R8,R2,SAVER8 ; -- restore R8 LOAD R9,R2,SAVER9 ; -- restore R9 LOADS R1,R2 ; -- restore return address JUMPS R1 ; return a END