TITLE "Test decimal print" USE "hawk.macs" USE "monitor.h" S START COMMON STACK,#1000 PSTACK: W STACK ; the program starts here! START: LOAD R2,PSTACK ; set up the stack LOAD R1,PDSPINI JSRS R1,R1 ; dspini() LIS R3,1 JSR R1,PUTDEC ; dspdec ( 1 ) LIS R3,' ' LOAD R1,PDSPCH ; dspch ( ' ' ) JSRS R1,R1 LIS R3,12 JSR R1,PUTDEC ; dspdec ( 12 ) LIS R3,' ' LOAD R1,PDSPCH ; dspch ( ' ' ) JSRS R1,R1 LIS R3,123 JSR R1,PUTDEC ; dspdec ( 123 ) LIS R3,' ' LOAD R1,PDSPCH ; dspch ( ' ' ) JSRS R1,R1 LIL R3,123456 JSR R1,PUTDEC ; dspdec ( 123456 ) LOAD R1,PEXIT ; exit () JSRS R1,R1 SUBTITLE "decimal print routine" ; activation record structure for decimal print routine RETAD = 0 DIGIT = 4 ARSIZE = 8 PUTDEC: ; R1 = return address ; R3 = number to print ; R3-7 may be wiped out ; R8-15 will be restored STORES R1,R2 LIS R4,10 LOAD R1,PDIVU ADDI R2,R2,ARSIZE ; push my AR JSRS R1,R1 ; R3 = R3/R4; R4=R3 mod R4 ADDI R2,R2,-ARSIZE ; pop my AR STORE R4,R2,DIGIT ; save the digit to print TESTR R3 BZS NORECUR ; if quotient nonzero ADDI R2,R2,ARSIZE ; push my AR JSR R1,PUTDEC ; dspdec ( quotient ) ADDI R2,R2,-ARSIZE ; pop my AR NORECUR: ; endif LOAD R3,R2,DIGIT ; get the digit to print ADDI R3,R3,'0' ; convert to ASCII LOAD R1,PDSPCH ADDI R2,R2,ARSIZE ; push my AR JSRS R1,R1 ; call dspch with the digit ADDI R2,R2,-ARSIZE ; pop my AR LOADS R1,R2 JUMPS R1 ; return END