I just love the PDP11's assembly language. I needed a super-tight
subroutine to print a 16-bit value as 6 octal digits. This is as tight as I
could make it, 16 words (including writing to the serial port, which takes
5 words). Can you beat it?
;*** Subroutine *************************
;Print a 16-bit value as 6 octal digits
;Calling Sequence:
; jsr PC,PROCT6
;On Entry:
; R2 = value to print
;Trashes R1,R2
;****************************************
PROCT6: mov #100030,R1 ;Digit loop ends when '1' lands in C
;..'30' makes it ASCII
sec ;All done when this is in C again
;Extract a digit and convert it to ASCII. Check for done.
1$: rol R2 ;Shift digit out of R2 & into R1
beq 3$ ;Return when done
rol r1 ;Build next octal digit
bcc 1$ ;Done when c = shift pattern bit
;Write digit to the serial port
2$: tstb @#CTXSTA ;Wait for transmitter (clears C)
bpl 2$
movb R1,@#CTXDAT ;Transmit now
;Next digit
mov #020006,R1 ;Digit ends when "2" lands in C.
;Printing ends when "sec" bit
;..leaves R2. '6' makes ASCII
br 1$
3$: rts PC
Martin E.