Small number output in PDP11 machine code ========================================= ; Fixed digits decimal output ; =========================== ; A quick two-digit binary to decimal conversion ; Outputs '00' to '99' for input of 0-99 ; On entry, R1=0-99 ; Uses R0 for digit ; MOVB #ASC"0"-1,R0 ; Start with '0'-1 for tens .PrDecTens INC R0 ; Increment tens digit SUB #10,R1 ; Subtract 10 from R0 BCC PrDecTens ; Loop until <0 JSR PC,output_character ; Output the character in R0 ADD #ASC"0"+10,R1 ; Convert R1 to units digit JSR PC,output_character ; Output the character in R0 ; You can also write the digits to a buffer with the following ; On entry, R1=0-99 ; R0=>buffer ; MOVB #ASC"0"-1,(R0) ; Start with '0'-1 for tens .PrDecTens INCB (R0) ; Increment tens digit SUB #10,R1 ; Subtract 10 from R0 BCC PrDecTens ; Loop until <0 INC R0 ; Step past the tens digit ADD #ASC"0"+10,R1 ; Convert R1 to units digit MOVB R1,(R0)+ ; Store the units digit ; You can increase the number of digits by adding extra loops ; MOVB #ASC"0"-1,(R0) ; Start with '0'-1 for hundreds .PrDecHundreds INCB (R0) ; Increment hundreds digit SUB #100,R1 ; Subtract 100 from R0 BCC PrDecHundreds ; Loop until <0 INC R0 ; Step past hundreds digit ADD #100,R1 ; Balance last SUB #100 MOVB #ASC"0"-1,(R0) ; Start with '0'-1 for tens .PrDecTens INCB (R0) ; Increment tens digit SUB #10,R1 ; Subtract 10 from R0 BCC PrDecTens ; Loop until <0 INC R0 ; Step past the tens digit ADD #ASC"0"+10,R1 ; Convert R1 to units digit MOVB R1,(R0)+ ; Store the units digit ; If doing more than three digits it is more efficient to use a table ; of powers of ten and loop through them