Produce machine code in the path of the assembly file

This commit is contained in:
Hazem Krimi
2024-03-13 23:18:49 +01:00
parent 29b0babd19
commit fd8e48e904
3 changed files with 2 additions and 40 deletions
-13
View File
@@ -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
-25
View File
@@ -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
View File
@@ -49,8 +49,8 @@ fn main() {
.unwrap_or("")
{
"asm" => {
let filename = path.file_stem().unwrap().to_str().unwrap();
let mut file = fs::File::create(format!("{}.hack", filename)).unwrap();
let filepath = path.canonicalize().unwrap().to_str().unwrap().replace("asm", "hack");
let mut file = fs::File::create(filepath).unwrap();
let content = fs::read_to_string(&path).expect("You must provide a correct filepath!");
let re = Regex::new(r"\s*\/\/.*").unwrap();
let processed: String = content