macro/ex4a.mac
2022-03-10 20:40:38 +09:00

49 lines
1.3 KiB
Plaintext

TITLE REVERSE - Example 4-A
SEARCH MONSYM
Comment $
Program to reverse the characters on each line of input.
Program will stop when an empty line is input.
This program demonstrates the last-in, first-out property
of push-down stacks. Also, it shows the PBIN and PBOUT
JSYS calls.
$
A=1 ;symbolic name for ac 1
P=17 ;symbolic for stack pointer
PDLEN==200 ;define the stack size
PDLIST: BLOCK PDLEN ;reserve space for the stack.
START: RESET
MOVE P,[IOWD PDLEN,PDLIST] ;initialize stack pointer
GETLIN: HRROI A,[ASCIZ/Please type a line: /]
PSOUT
INLOOP: PBIN ;read one character
CAIN A,15 ;skip unless carriage return
JRST INLOOP ;discard carriage return
CAIN A,12 ;skip unless end of line
JRST INDONE ;LF was seen. We are done now.
PUSH P,A ;store character on the stack
JRST INLOOP
;Here at the end of the input line
INDONE: CAMN P,[IOWD PDLEN,PDLIST] ;is the stack empty?
JRST STOP ;empty line, stop running.
HRROI A,[ASCIZ/The reversed line: /]
PSOUT
OUTLOO: POP P,A ;get one character from stack
PBOUT ;send it to the terminal
CAME P,[IOWD PDLEN,PDLIST] ;is the stack empty now?
JRST OUTLOO ;not yet. Loop again.
HRROI A,[ASCIZ/
/]
PSOUT ;send CR and LF.
JRST GETLIN ;repeat
STOP: HALTF ;stop at blank line
JRST STOP ;stay stopped
END START