TITLE "putdec.a -- decimal output subroutine" ; this code was written during the lecture on Mondahy Feb 25, 2013 ; it includes a main program and a decimal print routine ; comparable to the PUTDECU routine in the Hawk monitor, but ; without second parameter (the field width). USE "hawk.h" USE "monitor.h" INT MAIN S MAIN ; activation record for putnum: ; RETAD = 0 REM = 4 QUO = 8 ARSIZE = 12 PUTNUM: ; expects R3 = param STORES R1,R2 ; save return address ; ; -- parameter R3 divisor LIS R5,10 ; -- parameter R5 ADDI R2,R2,ARSIZE ; -- push activation record LIL R1,DIVIDEU JSRS R1,R1 ; R3,R4 = divideu(param, 10) ADDI R2,R2,-ARSIZE ; -- pop activation record STORE R3,R2,QUO ; QUO = R3 STORE R4,R2,REM ; REM = R4 TEST R2,QUO BEQ PENDIF ; if (QUO != 0) { LOAD R3,R2,QUO ; -- parameter ADDI R2,R2,ARSIZE ; -- push activation record JSR R1,PUTNUM ; putnum( quo ) ADDI R2,R2,-ARSIZE ; -- pop activation record PENDIF: ; } LOAD R3,R2,REM ADDI R3,'0' ; -- parameter ADDI R2,R2,ARSIZE ; -- push activation record LIL R1,PUTCHAR JSRS R1,R1 ; putchar('0' + rem ) ADDI R2,R2,-ARSIZE ; -- pop activation record LOADS R1,R2 ; restore return address JUMPS R1 ; return ; activation record for main, tests putnum: ; RETAD = 0 ARSIZE = 4 ; main program: MAIN: STORES R1,R2 ; save return address ADDI R2,R2,ARSIZE ; push activation record ; ------- Begin body of main program LIS R8,1 ; count = 1 LOOP: ; do { MOVE R3,R8 ; -- param JSR R1,PUTNUM ; putnum( count ) LIS R3,' ' ; -- parameter LIL R1,PUTCHAR JSRS R1,R1 ; putchar(' ') ADD R8,R8,R8 ; count = count * 2 CMPI R8,10000 BLT LOOP ; } while (count < 10000) ; ------- End body of main program ADDI R2,R2,-ARSIZE ; pop activation record LOADS R1,R2 ; restore return address JUMPS R1 ; return END