(brainfuck.tal) Modernizing
This commit is contained in:
parent
57396faa94
commit
a41f1ce3e8
|
@ -1,71 +1,64 @@
|
||||||
( Brainfuck:
|
( usage: cat program.bf | uxncli brainfuck.rom )
|
||||||
> Move the pointer to the right
|
|
||||||
< Move the pointer to the left
|
|
||||||
+ Increment the memory cell at the pointer
|
|
||||||
- Decrement the memory cell at the pointer
|
|
||||||
. Output the character signified by the cell at the pointer
|
|
||||||
, Input a character and store it in the cell at the pointer
|
|
||||||
[ Jump past the matching ] if the cell at the pointer is 0
|
|
||||||
] Jump back to the matching [ if the cell at the pointer is nonzero )
|
|
||||||
|
|
||||||
|0100 ( -> )
|
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|
||||||
|
|
||||||
;memory
|
|0100
|
||||||
;program
|
|
||||||
&while
|
|
||||||
LDAk LIT "> NEQ ,&movr JCN [ SWP2 INC2 SWP2 ] &movr
|
|
||||||
LDAk LIT "< NEQ ,&movl JCN [ SWP2 #0001 SUB2 SWP2 ] &movl
|
|
||||||
LDAk LIT "+ NEQ ,&incr JCN [ OVR2 STH2k LDA INC STH2r STA ] &incr
|
|
||||||
LDAk LIT "- NEQ ,&decr JCN [ OVR2 STH2k LDA #01 SUB STH2r STA ] &decr
|
|
||||||
LDAk LIT ". NEQ ,&emit JCN [ OVR2 LDA #18 DEO ] &emit
|
|
||||||
LDAk LIT "[ NEQ ,&next JCN [ ,goto-next JSR ] &next
|
|
||||||
LDAk LIT "] NEQ ,&prev JCN [ ,goto-back JSR ] &prev
|
|
||||||
INC2 LDAk ,&while JCN
|
|
||||||
POP2
|
|
||||||
( halt )
|
|
||||||
#010f DEO
|
|
||||||
|
|
||||||
BRK
|
@on-reset ( -> )
|
||||||
|
;on-console .Console/vector DEO2
|
||||||
|
BRK
|
||||||
|
|
||||||
@goto-next ( -- )
|
@on-console ( -> )
|
||||||
|
.Console/read DEI DUP #20 GTH ?{
|
||||||
|
POP <eval>
|
||||||
|
#0000 .Console/vector DEO2
|
||||||
|
#010f DEO
|
||||||
|
BRK }
|
||||||
|
[ LIT2 &ptr =program ] INC2k ,&ptr STR2
|
||||||
|
STA
|
||||||
|
BRK
|
||||||
|
|
||||||
OVR2 LDA #00 EQU JMP JMP2r
|
@<eval> ( -- )
|
||||||
( depth ) LITr 00
|
;on-console/ptr LDA2 ;program
|
||||||
INC2
|
&while ( -- )
|
||||||
&loop
|
LDAk [ LIT "+ ] NEQ ?{
|
||||||
LDAk LIT "[ NEQ JMP INCr
|
OVR2 STH2k LDA INC STH2r STA }
|
||||||
LDAk LIT "] NEQ ,&no-end JCN
|
LDAk [ LIT "- ] NEQ ?{
|
||||||
STHkr #00 EQU ,&end JCN
|
OVR2 STH2k LDA #01 SUB STH2r STA }
|
||||||
LITr 01 SUBr
|
LDAk [ LIT "> ] NEQ ?{ SWP2 INC2 SWP2 }
|
||||||
&no-end
|
LDAk [ LIT "< ] NEQ ?{
|
||||||
INC2 LDAk ,&loop JCN
|
SWP2 #0001 SUB2 SWP2 }
|
||||||
&end
|
LDAk [ LIT ". ] NEQ ?{
|
||||||
( depth ) POPr
|
OVR2 LDA #18 DEO }
|
||||||
|
LDAk [ LIT "[ ] NEQ ?{ goto-next }
|
||||||
|
LDAk [ LIT "] ] NEQ ?{ goto-back }
|
||||||
|
INC2 LDAk ?&while
|
||||||
|
POP2 JMP2r
|
||||||
|
|
||||||
JMP2r
|
@goto-next ( mem* prg* -- )
|
||||||
|
OVR2 LDA ?{ JMP2r }
|
||||||
|
( depth ) [ LITr 00 ] INC2
|
||||||
|
&loop ( -- )
|
||||||
|
LDAk [ LIT "[ ] NEQ JMP
|
||||||
|
INCr LDAk [ LIT "] ] NEQ ?&>no-end
|
||||||
|
STHkr #00 EQU ?&end
|
||||||
|
LITr 01 SUBr &>no-end
|
||||||
|
INC2 LDAk ?&loop
|
||||||
|
&end ( depth )
|
||||||
|
POPr JMP2r
|
||||||
|
|
||||||
@goto-back ( -- )
|
@goto-back ( mem* prg* -- )
|
||||||
|
OVR2 LDA ?{ JMP2r }
|
||||||
|
( depth ) [ LITr 00 ] #0001 SUB2
|
||||||
|
&loop ( -- )
|
||||||
|
LDAk [ LIT "] ] NEQ JMP
|
||||||
|
INCr LDAk [ LIT "[ ] NEQ ?&>no-end
|
||||||
|
STHkr #00 EQU ?&end
|
||||||
|
LITr 01 SUBr &>no-end
|
||||||
|
#0001 SUB2 LDAk ?&loop
|
||||||
|
&end ( depth )
|
||||||
|
POPr JMP2r
|
||||||
|
|
||||||
OVR2 LDA #00 NEQ JMP JMP2r
|
@program
|
||||||
( depth ) LITr 00
|
|
||||||
#0001 SUB2
|
|
||||||
&loop
|
|
||||||
LDAk LIT "] NEQ JMP INCr
|
|
||||||
LDAk LIT "[ NEQ ,&no-end JCN
|
|
||||||
STHkr #00 EQU ,&end JCN
|
|
||||||
LITr 01 SUBr
|
|
||||||
&no-end
|
|
||||||
#0001 SUB2 LDAk ,&loop JCN
|
|
||||||
&end
|
|
||||||
( depth ) POPr
|
|
||||||
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
@program ( Hello World! )
|
|
||||||
|
|
||||||
"++++++++[>++++[>++>+++>+++>+<<<<
|
|
||||||
"-]>+>+>->>+[<]<-]>>.>---.+++++++
|
|
||||||
"..+++.>>.<-.<.+++.------.-------
|
|
||||||
"-.>>+.>++. $1
|
|
||||||
|
|
||||||
@memory
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.
|
||||||
|
|
Loading…
Reference in New Issue