processor-creative-kit-0.1.0.1: a creation kit for instruction sets and cpu simulators and development tools

Safe HaskellNone
LanguageHaskell2010

Language.Pck.Tool.Assembler

Contents

Synopsis

Assembler drivers

parseInst :: ByteString -> Either [String] [Inst] Source

parse instructions from a ByteString data

Example:

 > parseInst (B.pack "mov r0,1\n halt\n")
 [MOVI R0 1,HALT]

parseInstFile :: FilePath -> IO [Inst] Source

parse instructions from a file

Example:

 > parseInstFile "examples/test0.asm"
 [MOVI R0 1,HALT]

Assembler parse examples

Parse Example:

from text to the Inst data type

 text               ->   Inst data type
 ----------------------------------------
 nop                ->   NOP
 halt               ->   HALT
 mov  r1, 100       ->   MOVI  R1  100
 mov  r1, r2        ->   MOV   R1  R2
 mov  r1, pc        ->   MOVPC R1
 add  r1, r2, r3    ->   ADD   R1 R2 R3
 sub  r1, r2, r3    ->   SUB   R1 R2 R3
 cmp  r1, r2        ->   CMP   R1 R2
 abs  r1, r2        ->   ABS   R1 R2
 ash  r1, r2, r3    ->   ASH   R1 R2 R3
 mul  r1, r2, r3    ->   MUL   R1 R2 R3
 div  r1, r2, r3    ->   DIV   R1 R2 R3
 and  r1, r2, r3    ->   AND   R1 R2 R3
 or   r1, r2, r3    ->   OR    R1 R2 R3
 not  r1, r2        ->   NOT   R1 R2
 xor  r1, r2, r3    ->   XOR   R1 R2 R3
 lsh  r1, r2, r3    ->   LSH   R1 R2 R3
 b    eq, -3        ->   BRI   FCEQ (-3)
 jmp  3             ->   JRI   3
 jmp  r1            ->   J     R1
 call r1            ->   CALL  R1
 ret                ->   RET
 ld   r1, m(r2)     ->   LD    R1 R2
 st   m(r1), r2     ->   ST    R1 R2

Comment descriptions:

 # a comment line
 /* a comment block */