mirror of
https://github.com/hazemKrimi/hack-assembler.git
synced 2026-05-01 18:20:28 +00:00
Produce machine code in the path of the assembly file
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
// This file is part of www.nand2tetris.org
|
|
||||||
// and the book "The Elements of Computing Systems"
|
|
||||||
// by Nisan and Schocken, MIT Press.
|
|
||||||
// File name: projects/06/add/Add.asm
|
|
||||||
|
|
||||||
// Computes R0 = 2 + 3 (R0 refers to RAM[0])
|
|
||||||
|
|
||||||
@2
|
|
||||||
D=A // hi
|
|
||||||
@3
|
|
||||||
D=D+A
|
|
||||||
@0
|
|
||||||
M=D
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// This file is part of www.nand2tetris.org
|
|
||||||
// and the book "The Elements of Computing Systems"
|
|
||||||
// by Nisan and Schocken, MIT Press.
|
|
||||||
// File name: projects/06/max/MaxL.asm
|
|
||||||
|
|
||||||
// Symbol-less version of the Max.asm program.
|
|
||||||
|
|
||||||
@0
|
|
||||||
D=M
|
|
||||||
@1
|
|
||||||
D=D-M
|
|
||||||
@12
|
|
||||||
D;JGT
|
|
||||||
@1
|
|
||||||
D=M
|
|
||||||
@2
|
|
||||||
M=D
|
|
||||||
@16
|
|
||||||
0;JMP
|
|
||||||
@0
|
|
||||||
D=M
|
|
||||||
@2
|
|
||||||
M=D
|
|
||||||
@16
|
|
||||||
0;JMP
|
|
||||||
+2
-2
@@ -49,8 +49,8 @@ fn main() {
|
|||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
{
|
{
|
||||||
"asm" => {
|
"asm" => {
|
||||||
let filename = path.file_stem().unwrap().to_str().unwrap();
|
let filepath = path.canonicalize().unwrap().to_str().unwrap().replace("asm", "hack");
|
||||||
let mut file = fs::File::create(format!("{}.hack", filename)).unwrap();
|
let mut file = fs::File::create(filepath).unwrap();
|
||||||
let content = fs::read_to_string(&path).expect("You must provide a correct filepath!");
|
let content = fs::read_to_string(&path).expect("You must provide a correct filepath!");
|
||||||
let re = Regex::new(r"\s*\/\/.*").unwrap();
|
let re = Regex::new(r"\s*\/\/.*").unwrap();
|
||||||
let processed: String = content
|
let processed: String = content
|
||||||
|
|||||||
Reference in New Issue
Block a user