home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
CPMUG
/
CPMUG051.ARK
/
ALX.S2M
< prev
next >
Wrap
Text File
|
1984-04-29
|
16KB
|
499 lines
~`~`0 (+-*/) MACROS FOR 8080 ASSEMBLY LANGUAGE EXTENSION PREPROCESSOR
.HELLO~
-- ALX 2.6a 03/19/81 For CPMUG`F15~
~ ------------------------------------
.LSKIP `~ ;To increment label counter by P1
`10`F7~
.INCSYM~
`F8~
~
.INCSYM~
`01`16~
~ ---------------------------------------
`~ ;To accept an input line starting with tab
.TRIM `10~ ; remove leading spaces or tabs
^IND`76 ^TRIM`86~ ; indentation an line reference
>> `71`81~ ; output to listing channel
.STM `81~ ; process statement
.DUMP STACK~
~ ---------------------------------------
>>`| FIN`~
`10|_FIN`20`F14~
~ ---------------------------------------
>>`| UNTIL`~
`10|_UNTIL`20`F14~
~ ---------------------------------------
>>`~
`10`F14~
~ ---------------------------------------
`~ ;To accept line starting with space
`10~ ; change space to tab
~ ---------------------------------------
BEGIN`~
.HELLO~
BEGIN`10`F14~
~ ---------------------------------------
`:`~ ;To accept line with label
`10:`F14~ ; output label to listing channel
`10:`F13~ ; output label to ASM file
.IF `20= SKIP 1~
`20~ ; pass on rest of statement for processing
~ ---------------------------------------
PROCEDURE `~ ;To recognize PROCEDURE declaration
.IF ^CSP<1 SKIP 4~
^DBG`86 `81`86 .STO ^DBG=T~
.DUMP STACK~
.STO ^DBG=`80~
.ERR STACK NOT EMPTY -- CHECK CONTROL STRUCTURES~
.LET ^CSP=0~ ; clear control stack
.LET ^LEV=0~ ; control structure level
.STO ^IND=~ ; clear indentation string
^PROC`86 .PROC `10~
`F14~
- - - - - - - - - - - - - - - - - - - - - - - - - - `81`F14~
`F14~
PROCEDURE `10`F14~ ; output to listing channel
`F14~
`81: ; - - - - - - - - - - - - - - PROCEDURE `10`F13~
~ ---------------------------------------
.PROC `~
.PROC `10~
~ ---------------------------------------
.PROC `~
`10`27 ; ~ ; scan with break on " " or ";" or TAB
.STO ^PROC=`20~
~ ---------------------------------------
;`~ ;To accept comment line
;`10`F14~ ; output to listing channel
~ ---------------------------------------
`~ ;To accept any other line
.IF `10-= SKIP 1~ ; if P1 is null
`16~ ; P1 = " "
`10`F14~ ; output to listing channel
`10`F13~ ; output to ASM file
~ ---------------------------------------
.STM IF`(`)`~ ;To recognize IF statement
...IF (`20)`30~ ; output comment line to ASM file
.CHECK IF~
.PUSH `01~ ; push label n
.PUSH K~ ; push code "K" - IF or WHEN ELSE
.JCF `20,`01~ ; output conditional jump to n
.XSTM `30~ ; process remainder of line
~ ---------------------------------------
.STM WHEN`(`)`~ ;To recognize WHEN statement
...WHEN (`20)`30~ ; output comment line to ASM file
.CHECK WHEN~
.PUSH `01~ ; push label n
.PUSH `02~ ; push label n+1
.PUSH W~ ; push code "W" - WHEN
.JCF `20,`02~ ; output conditional jump to n+1
.XSTM `30~ ; process remainder of line
~ ---------------------------------------
.STM ELSE`~ ;To recognize ELSE statement
...ELSE`10~ ; output comment line to ASM file
.POP~
^CSI`96 .ELSE `91~ ; process else or flag error
.XSTM `10~ ; process remainder of line
~ ---------------------------------------
.ELSE E~
.POPL~ ; output label n+1 from stack
.PUSH K~ ; push code "K" - IF or WHEN ELSE term.
~ ---------------------------------------
.ELSE `~
.PUSH `10~ ; restore stack
.SERR ELSE~
~ ---------------------------------------
.STM BRANCH`~ ;To recognize BRANCH statement
...BRANCH`10~ ; output comment line to ASM file
.CHECK BRANCH~
.PUSH B~ ; push code "B" - BRANCH
.INCLEV~
~ ---------------------------------------
.STM SELECT`~ ;To recognize SELECT statement
...SELECT`10~ ; output comment line to ASM file
.CHECK SELECT~
.PUSH `01~ ; push label n
.PUSH S~ ; push code "S" - SELECT
.INCLEV~
~ ---------------------------------------
.STM EXECUTE`(`)`~ ;To recognize EXECUTE statement
.PUSH `01~ ; push label n
.PUSH X~ ; push code "X" - EXECUTE
.INCLEV~
.. LHLD `20~
.. PCHL ~
~ ---------------------------------------
.STM SETNEXT`(`=`)`~ ;To recognize SETNEXT statement
^TRIM`86 .TRIM `30~
.. LXI H,`81~
.TRIM `20~
.. SHLD `81~
~ ---------------------------------------
.STM (`)`~ ;To recognize SELECT or BRANCH ITEM
...(`10)`20~ ; output comment line to ASM file
.TOS~
^CSI`36 .ITEM `31(`10)`20~
~ ---------------------------------------
.ITEM B(`)`~ ;To recognize simple BRANCH ITEM
.. CPI `10~ ; output compare instruction
.. JZ `20~ ; output jump if match instruction
~ ---------------------------------------
.ITEM B(`|`)`~ ;To recognize BRANCH ITEM with OR
`10|`20`47|~ ; scan with break on OR symbol
.. CPI `40~ ; output compare instruction
.. JZ `30~ ; output jump if match instruction
`F8~ ; end of loop
~ ---------------------------------------
.ITEM B(`OTHERWISE`)`~ ;To recognize BRANCH catch all ITEM
.. JMP `30~ ; output jump instruction
~ ---------------------------------------
.ITEM S(`)`~ ;To recognize simple SELECT ITEM
.PUSH `01~ ; push label n+x
.PUSH I~ ; push code "I" - SELECT ITEM
.. CPI `10~ ; output compare instruction
.. JNZ LLZ`01~ ; output JNZ n+x
.XSTM `20~ ; process remainder of line
~ ---------------------------------------
.ITEM S(`|`)`~ ;To recognize SELECT ITEM with OR
.PUSH `02~ ; push label n+x+1
.PUSH I~ ; push code "I" - SELECT ITEM
`10|`20`47|~ ; scan with break on OR symbol
.. CPI `40~ ; output compare instruction
.IF `43-=| SKIP 2~ ; if break char. is OR
.. JZ LLZ`01~ ; output jump to match
.SKIP 1~ ; else end of line
.. JNZ LLZ`02~ ; output jump to nomatch
`F8~ ; end of scan loop
..LLZ`01: ~ ; output label n+x: for match
.XSTM `30~ ; process remainder of line
~ ---------------------------------------
.ITEM S(`OTHERWISE`)`~ ;To recognize SELECT catch all ITEM
.PUSH O~ ; push code "O" - OTHERWISE
.XSTM `30~ ; process remainder of line
~ ---------------------------------------
.ITEM X(`)`~ ;To recognize EXECUTE item (state)
.PUSH Y~
^LABEL`86 .LABEL `10~
..`81: ~
.XSTM `20~ ; process remainder of line
~ ---------------------------------------
.LABEL `~
.LABEL `10~
~ ---------------------------------------
.LABEL `~
`10`27 : ~
.STO ^LABEL=`20~
~ ---------------------------------------
.ITEM `(`)`~ ;To recognize SELECT ITEM out of place
.SERR SELECT, BRANCH ITEM~
.ITEM S(`20)`30~ ; process line anyway
~ ---------------------------------------
.STM WHILE`(`)`~ ;To recognize WHILE statement
...WHILE (`20)`30~ ; output comment line to ASM file
.CHECK WHILE~
.LOOP `01,L~ ; setup loop
.JCF `20,`01~ ; output conditional jump to n
.XSTM `30~ ; process remainder of line
~ ---------------------------------------
.STM LOOP`~ ;To recognize unconditional LOOP statement
...LOOP`10~ ; output comment line to ASM file
.CHECK LOOP~
.LOOP `01,L~ ; setup loop
.XSTM `10~ ; process remainder of line
~ ---------------------------------------
.STM REPEAT`~ ;To recognize REPEAT statement
...REPEAT`10~ ; output comment line to ASM file
.CHECK REPEAT~
.LOOP `01,R~ ; setup loop
.INCLEV~
~ ---------------------------------------
.LOOP `,`~ ;To setup loop for WHILE, REPEAT or LOOP
.PUSH `10~ ; put exit label on stack
.PUSH `01~ ; put loop label on stack
.PUSH `20~ ; put structure code on stack
..LLZ`01: ~ ; output loop label
~ ---------------------------------------
.STM UNTIL`(`)`~ ;To recognize UNTIL termination of REPEAT
...UNTIL (`20)`30~ ; output comment line to ASM file
.POP~
^CSI`96 .UNTIL `91,`20~ ; generate conditional jump or flag error
~ ---------------------------------------
.UNTIL R,`~
.DECLEV~
.POP~
^CSI`96 .JCF `10,`91~ ; output conditional jump to n
.POPL~ ; output label from stack
~ ---------------------------------------
.UNTIL `,`~
.PUSH `10~ ; restore stack
.SERR UNTIL~
~ ---------------------------------------
.STM BREAK`IF`(`)`~ ;To recognize loop BREAKout statement
...BREAK IF (`30)~ ; output comment line to ASM file
.CHECK BREAK IF~
.BRK~ ; search stack for exit label
^CSI`86 .JCT `30,`81~ ; GEN conditional branch
~ ---------------------------------------
.BRK~ ;To search control stack for exit label
.IF ^CSP>0 SKIP 2~ ; when stack empty
.SERR BREAK~ ; BREAK out of place
`F9~ ; else
.LET ^CSB=^CSP+1~ ; search pointer = stack pointer + 1
^CSB`96~
^CSP`F7~ ; for i = 1 to stack size
.LET ^CSB=^CSB-1~ ; decrement search pointer
^CS`91`86 ^BRK`81`86~
.IF `81-= SKIP 3~ ; if loop code found goto success
`F8~ ; fin
.SERR BREAK~ ; BREAK out of place
`F9~ ; exit
`91-2`96 ^CS`94`86~ ; success: point to exit label on stack
.STO ^CSI=`81~ ; save exit label
~ ---------------------------------------
.STM FIN`~ ;To recognize FIN terminator
...FIN`10~ ; output comment line to ASM file
.DECLEV~
.POP~
^CSI`96 .FIN `91~ ; process FIN by code found on stack
~ ---------------------------------------
.FIN B~ ;To terminate BRANCH
~ ---------------------------------------
.FIN I~ ;To terminate SELECT ITEM
.POP~
^CSI`96 `91`96~ ; pop label n+x
.POP~
^CSI`86 `81`86~ ; pop code "S"
.TOSJ~ ; output jump to label n (stack top)
.PUSH `80~ ; push code "S" back on stack
..LLZ`90: ~ ; output label n+x:
~ ---------------------------------------
.FIN K~ ;To terminate IF or WHEN ELSE
.POPL~ ; output label n: from stack
~ ---------------------------------------
.FIN L~ ;To terminate WHILE loop
.POPJ~ ; output jump to n+1: from stack
.POPL~ ; output label n: from stack
~ ---------------------------------------
.FIN O~ ;To terminate SELECT OTHERWISE ITEM
~ ---------------------------------------
.FIN S~ ;To terminate SELECT
.POPL~ ; output label n: from stack
~ ---------------------------------------
.FIN W~ ;To terminate WHEN branch
.POP~
^CSI`96 `91`96~ ; pop label n+1
.TOSJ~ ; output jump to label n (stack top)
.PUSH `90~ ; put label n+1 back on the stack
.PUSH E~ ; push code "E" - ELSE
~ ---------------------------------------
.FIN X~ ;To terminate EXECUTE
.POPL~
~ ---------------------------------------
.FIN Y~ ;To terminate EXECUTE ITEM
.POP~
^CSI`86 `81`86~ ; pop code "X"
.TOSJ~ ; output jump to label n (stack top)
.PUSH `80~ ; push code "X" back on stack
~ ---------------------------------------
.FIN `~ ;To recognize a wayward FIN
.INCLEV~
.PUSH `10~ ; restore stack
.SERR FIN~
~ ---------------------------------------
END-`~ ;To recognize END-OF-FILE
END-`10`F14~
^CSP`26 .IF `21<1 SKIP 3~ ; if stack not empty
.ERR STACK NOT EMPTY -- CHECK CONTROL STRUCTURES~
.STO ^DBG=T~ ; set debug mode
.DUMP STACK~ ; send stack contents to LST file
LLZ`01 Next label not used`F15~
`F0~ ; stop processing
~ ---------------------------------------
.STM `~ ;To recognize non control statements
.CHECK `10~
`10`F13~ ; output to ASM file
~ ---------------------------------------
.XSTM `~
.INCLEV~
.TRIM `10~ ; strip leading spaces and tabs
^TRIM`26 .YSTM `21~
~ ---------------------------------------
.YSTM ~
~ ---------------------------------------
.YSTM ;`~
~ ---------------------------------------
.YSTM `~
.CHECK `10~
`10`F13~ ; output to ASM file
.STM FIN~ ; generate a FIN statement
~ ---------------------------------------
.TRIM `~ ;To strip leading space
.TRIM `10~
~ ---------------------------------------
.TRIM `~ ;To strip leading tab
.TRIM `10~
~ ---------------------------------------
.TRIM `~ ;To save line without leading spaces and tabs
.STO ^TRIM=`10~
~ ---------------------------------------
.INCLEV~
.LET ^LEV=^LEV+1~
.CAT ^IND, | ~ ; append to indentation string
~ ---------------------------------------
.DECLEV~ ;To decrement control structure level
^LEV`16 .IF `11<1 SKIP 2~
.LET ^LEV=^LEV-1~
^IND`26 .UND `21~ ; remove " | " from indentation string
~ ---------------------------------------
.UND ` | ~ ;To remove one level of indentation
.STO ^IND=`10~
~ ---------------------------------------
.PUSH `~ ;To push something on the stack
.LET ^CSP=^CSP+1~
^CSP`96 .STO ^CS`91=`10~
~ ---------------------------------------
.POPL~ ;To output label from stack
.POP~
^CSI`96 ..LLZ`91: ~
~ ---------------------------------------
.POPJ~ ;To output jump to label from stack
.POP~
^CSI`96 .. JMP LLZ`91~
~ ---------------------------------------
.TOSJ~ ;To output jump to label on stack top
.TOS~
^CSI`96 .. JMP LLZ`91~
~ ---------------------------------------
.POP~
^CSP`96 .IF `91<1 SKIP 3~
^CS`91`86 .STO ^CSI=`81~
.LET ^CSP=^CSP-1~
`F9~
.STO ^CSI=*~
`FE~
~ ---------------------------------------
.TOS~
^CSP`96 .IF `91<1 SKIP 2~
^CS`91`86 .STO ^CSI=`81~
`F9~
.STO ^CSI=*~
~ ---------------------------------------
.JCT `,`~ ;To output jump condition true
.STO ^TMP=~ ; set string to null
`10`37 ~ ; scan and break on space or tab
.CAT ^TMP,`30~ ; save non space or tab characters
`F8~ ; end of loop
^TMP`16 `11`16~ ; retrieve compressed condition string
.. `11 LLZ`20~ ; get jump inst. from table and output
~ ---------------------------------------
.JCF `,`~ ;To output jump on condition false
.STO ^TMP=~ ; set string to null
`10`37 ~ ; scan and break on space or tab
.CAT ^TMP,`30~ ; save non space or tab characters
`F8~ ; end of loop
^TMP`16 -`11`16~ ; retrieve compressed condition string
.. `11 LLZ`20~ ; get jump inst. from table and output
~ ---------------------------------------
.DUMP STACK~
^DBG`56 .IF `51=T SKIP 1~
`F9~
.LET ^CNT=^CSP~
^CSP`16 `11`F7~
^CNT`26 ^CS`21`36~
^CS`21 "`31"`F14~
.LET ^CNT=^CNT-1~
`F8~
^LEV`46~
^LEV =`41`F14~
~ ---------------------------------------
.DEBUG~
.STO ^DBG=T~
~ ---------------------------------------
.UNBUG~
.STO ^DBG=F~
~ ---------------------------------------
...`~ ;To output comment line to ASM file
;; `10`F13~
~ ---------------------------------------
..` ` `~ ;To output line to ASM file
`10 `20 `30`F13~
~ ---------------------------------------
.SERR `~
.ERR "`10" NOT ALLOWED HERE~
~ ---------------------------------------
.ERR `~ ;To output error messages
>>> ERROR <<< `10`26~
`20`F13~ ; to ASM file
`20`F14~ ; to listing file
`20`F15~ ; to console
.LET ^ERR=^ERR+1~
~ ---------------------------------------
.CHECK `~ ;To check top of stack for stmt allowed
.TOS~
^CSI`26 ^^`21`26~
.IF `21=SOK SKIP 1~
.SERR `10~
~ ---------------------------------------
.CAT `,`~
`11`20`26 `F3~
~
.STO `=`~
`F3~
~
.LET `=`~
`24`26 `F3~
~
.SKIP `~
`F4~
~
.IF `=` SKIP `~
`F50~
~
.IF `-=` SKIP `~
`F51~
~
.IF `<` SKIP `~
`F6-~
~
.IF `==` SKIP `~
`F60~
~
.IF `<>` SKIP `~
`F61~
~
.IF `>` SKIP `~
`F6+~
~~ ------------ END OF MACROS ------------------- END OF MACROS ------------
.LET ^ERR=0~
.LET ^LEV=0~ CONTROL STRUCTURE LEVEL
.STO ^IND=~ EMPTY INDENTATION STRING
.LET ^CSP=0~ EMPTY STACK
.STO ^CS0=*~ EMPTY STACK ENTRY
.STO ^DBG=F~ DEBUG OFF
.STO ^^I=SOK~ STATEMENT OK IF "I" IS ON STACK
.STO ^^K=SOK~
.STO ^^L=SOK~
.STO ^^O=SOK~
.STO ^^R=SOK~
.STO ^^W=SOK~
.STO ^^Y=SOK~
.STO ^^*=SOK~
.STO ^BRKL=LOOP~ BREAK OK FOR LOOP, OR WHILE
.STO ^BRKR=LOOP~ BREAK OK FOR REPEAT
.STO CARRY=JC~
.STO NOCARRY=JNC~
.STO PLUS=JP~
.STO MINUS=JM~
.STO ZERO=JZ~
.STO NOTZERO=JNZ~
.STO EVEN=JPE~
.STO ODD=JPO~
.STO -CARRY=JNC~ CONDITIONAL JUMP LOOK UP TABLE
.STO -NOCARRY=JC~
.STO -PLUS=JM~
.STO -MINUS=JP~
.STO -ZERO=JNZ~
.STO -NOTZERO=JZ~
.STO -EVEN=JPO~
.STO -ODD=JPE~