TITLE "decimal print routine" USE "hawk.macs" USE "monitor.h" S START EXT UNUSED SUBTITLE "subroutine to print a decimal number" ; activation record structure RETAD = 0 REM = 4 ARSIZE = 8 ; receiving sequence DSPNUM: ; expects R3 -- number to print ; R1 -- return address STORE R1,R2,RETAD ADDI R2,R2,ARSIZE ; push AR ; body begins here CMPI R3,9 BLE DSPNO ; if (number > 9) ; parameter 1, dividend = number LIS R4,10 ; parameter 2, divisor = 10 LIL R1,DIVU JSRS R1,R1 ; call divu(number,10) ; returns quotient in R3 ; returns remainder in R4 ; parameter 1, number = quotient STORE R4,R2,REM-ARSIZE; store remainder in rem JSR R1,DSPNUM ; call dspnum(number) LOAD R3,R2,REM-ARSIZE; recover number from rem DSPNO: ; endif ADDI R3,'0' ; convert number to character ; parameter 1, number LIL R1,DSPCH JSRS R1,R1 ; call dspch(number) ; return sequence ADDI R2,R2,-ARSIZE ; pop AR LOAD R1,R2,RETAD JUMPS R1 SUBTITLE "main program" ; activation record for main program NUM = 0 ARSIZE = 4 START: LIL R2,UNUSED ; set up the stack ADDI R2,R2,ARSIZE LIL R1,DSPINI JSRS R1,R1 ; call monitor routine to initialize LIL R3,1234567 STORE R3,R2,NUM-ARSIZE; initialize loop count TESTLP: LIS R3," " LIL R1,DSPCH JSRS R1,R1 ; call monitor routine to output blank LOAD R3,R2,NUM-ARSIZE; get number to print JSR R1,DSPNUM ; test the print routine LOAD R3,R2,NUM-ARSIZE LIL R4,-111111 ADD R3,R3,R4 STORE R3,R2,NUM-ARSIZE; count = count - 1 BGT TESTLP LIL R1,EXIT JSRS R1,R1 ; call monitor routine to stop! ADDI R2,R2,-ARSIZE END