Advanced Assembly language interpreter.
Grammar: Defines the data structures used in the abstract syntax tree (AST) and CPU state.Lexer: Provides lexical analysis functions and basic parsing utilities.Parser: Parses assembly source code and converts it into an AST.Evaluator: Executes the parsed instructions by simulating a CPU state.Interface: Offers convenient functions to run programs and interact with the evaluator.Main: A sample pr
- Arithmetic Operations:
inc,dec,add,sub,mul,div - Bitwise Operations:
xor,and,or,not,neg - Shift Operations:
shr,shl,rol,ror - Control Flow:
jmp,je,jne,jg,jl,jge,jle,jz,jo,jc,jp,js,jnz,jno,jnc,jnp,jns,call,ret - Stack Operations:
push,pop,pushf,popf - Miscellaneous:
mov,cmp,msg,end
import Interface (runStrIO)
main :: IO ()
main = do
let code = "mov ax, 5\nmsg 'ax is ', ax\nend"
runStrIO codeimport Interface (runFileIO)
main :: IO ()
main = do
runFileIO "code.asm"Compile and run the Main.hs file:
ghc Main.hs -o assembler
./assemblerNote
Running this program using the Main module or runFileIO function will execute the loop until ax reaches 0 and then display the final value.
- GHC (The Glasgow Haskell Compiler): Available via the Haskell Platform.
- Parsec Library: For constructing parser combinators.
- Data Structures:
Data.Vector: For program lines.Data.Sequence: For output messages.Data.HashMap.Strict: For registers and CPU state.
- Custom Modules:
Grammar: AST and CPU state definitions.Lexer: Lexical analysis and parsing utilities.Parser: Code parsing into an AST.Evaluator: Instruction execution.Interface: User-friendly program functions.
-
Clone:
git clone https://github.com/Shinbatsu/Assembler-Interpreter.git cd Assembler-Interpreter -
Prepare:
Use Stack to install Haskell dependencies.
-
Build:
Using Stack:
stack build
-
Run:
stack exec assemblerWhen prompted, enter the filepath to the code (e.g.,
code.asm).