#assembly #object-file #simulator #lc3 #parser #ast-parser #isa

lc3-ensemble

LC-3 parser, assembler, and simulator intended for Georgia Tech's CS 2110 course

8 releases (4 breaking)

0.5.0 Jun 29, 2024
0.4.2 May 15, 2024
0.3.0 May 3, 2024
0.2.1 Apr 29, 2024
0.1.0 Apr 6, 2024

#70 in Simulation

Download history 68/week @ 2024-03-31 97/week @ 2024-04-07 1/week @ 2024-04-14 177/week @ 2024-04-21 386/week @ 2024-04-28 309/week @ 2024-05-05 119/week @ 2024-05-12 19/week @ 2024-05-19 1/week @ 2024-06-09 87/week @ 2024-06-23 124/week @ 2024-06-30

212 downloads per month

MIT license

265KB
4K SLoC

Rust 3.5K SLoC // 0.0% comments Assembly 623 SLoC // 0.0% comments

ensemble (LC-3 parser, assembler, and simulator)

Welcome!

This is a parser, assembler, and simulator library for the LC-3 ISA written in Rust!

It also comes built-in with a basic CLI, which has the ability to assemble and simulate.


lib.rs:

A LC-3 parser, assembler, and simulator.

This is meant to be a general suite to use LC-3 assembly (meant as a backend for Georgia Tech's CS 2110 LC3Tools).

Usage

To convert LC-3 source code to an object file, it must be parsed and assembled:

use lc3_ensemble::parse::parse_ast;
use lc3_ensemble::asm::{assemble, assemble_debug, ObjectFile};

let code = "
    .orig x3000
    AND R0, R0, #0
    AND R0, R0, #7
    HALT
    .end
";
let ast = parse_ast(code).unwrap();

// Assemble AST into object file:
let obj_file: ObjectFile = assemble(ast).unwrap();
// OR:
let obj_file: ObjectFile = assemble_debug(ast, code).unwrap();

Once an object file has been created, it can be executed with the simulator:

use lc3_ensemble::sim::Simulator;

let mut simulator = Simulator::new(Default::default());
simulator.load_obj_file(&obj_file);
simulator.run().unwrap(); // <-- Result can be handled accordingly

If more granularity is needed for simulation, there are also step-in and step-out functions. See the [sim] module for more details.

Dependencies

~2MB
~11K SLoC