MIT PDP-10 'Info' file converted to Hypertext 'html' format by Henry Baker

Previous Up Next The following program accepts a line of input (terminated by Carriage Return) from the terminal and outputs that line with the characters reversed.

        TITLE   REVERSE
A=1                             ;Symbolic AC names are defined
P=17

CHTTYO==1                       ;Channel for output
CHTTYI==2                       ;Channel for input

PDLLEN==100                     ;Length of push down stack
PDL:    BLOCK   PDLLEN          ;Storage for push down stack

BEG:    MOVE P,[-PDLLEN,,PDL-1] ;Initialize stack pointer.
                                ;Open TTY channels.
        .CALL [SETZ ? SIXBIT/OPEN/
                [.UAI,,CHTTYI] ? [SIXBIT/TTY/] ((SETZ))]
         .LOSE %LSFIL
        .CALL [SETZ ? SIXBIT/OPEN/
                [.UAO,,CHTTYO] ? [SIXBIT/TTY/] ((SETZ))]
         .LOSE %LSFIL
LOOP:   .IOT CHTTYO,["*]        ;Prompt for input.
        PUSHJ P,REVERS          ;do the work, once.
        .IOT CHTTYO,[^M]        ;Output CRLF to go to new line.
        .IOT CHTTYO,[^J]
        JRST LOOP               ;Jump back to repeat.

REVERS: .IOT CHTTYI,A           ;Read a character.
        CAIN A,^M               ;If it is a Carriage Return, the line is ended,
         POPJ P,                 ;so return.
        PUSH P,A                ;Else save this character on the stack,
        PUSHJ P,REVERS          ;call REVERS recursively,
        POP P,A                 ;get our character back
        .IOT CHTTYO,A           ;and print it.
        POPJ P,                 ;Return.

END BEG

NOTES: