microcCompilerLine :: String -> String
Convert a line of microc code to asm
microcCompilerStr :: String -> String
Convert microc code to asm
microcCompiler::IO()
Input:Stdin / Output:Stdout
microcCompilerFromFile:: String -> IO()
Input:Filename / Output:Stdout
module Main where
import ParseMicroc
main::IO()
main = microcCompiler
./microc < count.c > count.asm
count.c
n=in;
L1:
out(n);
unless(n) goto L2;
n=n-1;
goto L1;
L2:
halt;
int n;
↓↓↓
count.asm
IN
POP n
L1:
PUSH n
OUT
PUSH n
JZ L2
PUSH n
PUSHI 1
SUB
POP n
JMP L1
L2:
HALT
n: 0
module Main where
import ParseMicroc
main::IO()
main = do
args <- getArgs
microcCompilerFromFile $ head args
./microc count.c > count.asm
count.c
n=in;
L1:
out(n);
unless(n) goto L2;
n=n-1;
goto L1;
L2:
halt;
int n;
↓↓↓
count.asm
IN
POP n
L1:
PUSH n
OUT
PUSH n
JZ L2
PUSH n
PUSHI 1
SUB
POP n
JMP L1
L2:
HALT
n: 0
Hiroshima Univ. / Embedded Software
https://momiji.hiroshima-u.ac.jp/syllabusHtml/2017_58_U4090201.html