microc

convert microc code to asm code


Keywords
bsd3, compiler, library, program, Propose Tags , ParseMicroc, https://momiji.hiroshima-u.ac.jp/syllabusHtml/2017_58_U4090201.html
License
BSD-3-Clause
Install
cabal install microc-1.0.0.1

Documentation

MICROC compiler

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

Example1

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

Example2

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