TITLE "decimal print routine" ; developed during lecture, Feb 24, 2014 USE "hawk.h" USE "monitor.h" EXT UNUSED SUBTITLE "subroutine to print a decimal number" ; activation record for PUTINT RETAD = 0 ; the return address REM = 4 ; the saved remainder ARSIZE = 8 PUTINT: ; expects R3 = n -- the number to print ; R1 = return address STORE R1,R2,RETAD ; parameter n (already in R3!) LIS R5,10 ; parameter 10 ADDI R2,R2,ARSIZE LIL R1,DIVIDEU JSRS R1,R1 ; quo = R3 = n / 10 ADDI R2,R2,-ARSIZE STORE R4,R2,REM ; rem = R4 = n % 10 ; CMPI R3,0 BEQ PUTDONE ; if (quo != 0) { ; -- parameter n (already in R3!) ADDI R2,R2,ARSIZE JSR R1,PUTINT ; putint( quo ) ADDI R2,R2,-ARSIZE PUTDONE: ; } LOAD R4,R2,REM ADDI R3,R4,"0" ; -- parameter rem+"0" ADDI R2,R2,ARSIZE LIL R1,PUTCHAR JSRS R1,R1 ; putchar( rem + "0" ) ADDI R2,R2,-ARSIZE LOAD R1,R2,RETAD JUMPS R1 ; return SUBTITLE "main program" ARSIZE = 4 INT MAIN S MAIN MAIN: ; entry point STORES R1,R2 ADDI R2,R2,ARSIZE ; --- begin aplication code --- LIS R8,0 ; i = 0 LIS R9,1 ; j = 1 LOOP: CMPI R8,10 BGT DONE ; while (i <= 10) { LIS R3," " ; -- parameter LIL R1,PUTCHAR JSRS R1,R1 ; putchar( " " ) MOVE R3,R9 ; -- parameter JSR R1,PUTINT ; putint( j ) ADDSI R8,1 ; i = i + 1 ADD R9,R9,R9 ; j = j*2 BR LOOP DONE: ; } ; --- end aplication code --- ADDI R2,R2,-ARSIZE LOADS R1,R2 JUMPS R1 ; return