From a5eb9dda380b18984c5c8925b327fed874b16249 Mon Sep 17 00:00:00 2001 From: Neta London <67196883+netalondon@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:07:09 +0300 Subject: [PATCH] Add load and compare-to commands to all test scripts (#418) * Add load and compare-to commands to all test scripts --- components/src/stores/chip.store.test.ts | 8 ++++---- projects/src/project_01/01_not.ts | 2 ++ projects/src/project_01/02_and.ts | 2 ++ projects/src/project_01/03_or.ts | 2 ++ projects/src/project_01/04_xor.ts | 2 ++ projects/src/project_01/05_mux.ts | 2 ++ projects/src/project_01/06_dmux.ts | 2 ++ projects/src/project_01/07_not16.ts | 2 ++ projects/src/project_01/08_and16.ts | 2 ++ projects/src/project_01/09_or16.ts | 2 ++ projects/src/project_01/10_mux16.ts | 2 ++ projects/src/project_01/11_mux4way16.ts | 2 ++ projects/src/project_01/12_mux8way16.ts | 2 ++ projects/src/project_01/13_dmux4way.ts | 2 ++ projects/src/project_01/14_dmux8way.ts | 2 ++ projects/src/project_01/15_or8way.ts | 2 ++ projects/src/project_02/01_half_adder.ts | 2 ++ projects/src/project_02/02_full_adder.ts | 2 ++ projects/src/project_02/03_add16.ts | 2 ++ projects/src/project_02/04_inc16.ts | 2 ++ projects/src/project_02/06_alu.ts | 2 ++ projects/src/project_03/01_bit.ts | 2 ++ projects/src/project_03/02_register.ts | 2 ++ projects/src/project_03/03_pc.ts | 2 ++ projects/src/project_03/04_ram8.ts | 2 ++ projects/src/project_03/05_ram64.ts | 2 ++ projects/src/project_03/06_ram512.ts | 2 ++ projects/src/project_03/07_ram4k.ts | 2 ++ projects/src/project_03/08_ram16k.ts | 2 ++ projects/src/project_04/01_mult.ts | 2 ++ projects/src/project_04/02_fill.ts | 3 +++ projects/src/project_05/01_memory.ts | 2 ++ projects/src/project_05/02_cpu.ts | 4 ++++ projects/src/project_05/03_computer.ts | 7 +++++++ projects/src/project_07/11_simple_add.ts | 4 ++++ projects/src/project_07/12_stack_test.ts | 4 ++++ projects/src/project_07/21_basic_test.ts | 4 ++++ projects/src/project_07/22_pointer_test.ts | 4 ++++ projects/src/project_07/23_static_test.ts | 4 ++++ projects/src/project_08/11_basic_loop.ts | 4 ++++ projects/src/project_08/12_fibonacci_series.ts | 4 ++++ projects/src/project_08/20_simple_function.ts | 4 ++++ projects/src/project_08/21_nested_call.ts | 4 ++++ projects/src/project_08/22_fibonacci_element.ts | 4 ++++ projects/src/project_08/23_statics_test.ts | 4 ++++ 45 files changed, 122 insertions(+), 4 deletions(-) diff --git a/components/src/stores/chip.store.test.ts b/components/src/stores/chip.store.test.ts index 06841261b..1b02204e8 100644 --- a/components/src/stores/chip.store.test.ts +++ b/components/src/stores/chip.store.test.ts @@ -163,7 +163,7 @@ describe("ChipStore", () => { expect(state.store.state.files.tst).toBe(not.tst); expect(state.store.state.controls.span).toEqual({ start: 167, - end: 186, + end: 220, line: 6, }); }); @@ -178,9 +178,9 @@ describe("ChipStore", () => { await state.store.actions.stepTest(); expect(state.store.state.controls.span).toEqual({ - start: 235, - end: 236, - line: 14, + start: 269, + end: 270, + line: 16, }); }); }); diff --git a/projects/src/project_01/01_not.ts b/projects/src/project_01/01_not.ts index 3845c60f9..f4b1342c4 100644 --- a/projects/src/project_01/01_not.ts +++ b/projects/src/project_01/01_not.ts @@ -21,6 +21,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Not.tst +load Not.hdl, +compare-to Not.cmp, output-list in out; set in 0, diff --git a/projects/src/project_01/02_and.ts b/projects/src/project_01/02_and.ts index e44a29d25..8ea9ce3e2 100644 --- a/projects/src/project_01/02_and.ts +++ b/projects/src/project_01/02_and.ts @@ -18,6 +18,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/And.tst +load And.hdl, +compare-to And.cmp, output-list a b out; set a 0, diff --git a/projects/src/project_01/03_or.ts b/projects/src/project_01/03_or.ts index fdd12db06..a8af54755 100644 --- a/projects/src/project_01/03_or.ts +++ b/projects/src/project_01/03_or.ts @@ -23,6 +23,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Or.tst +load Or.hdl, +compare-to Or.cmp, output-list a b out; set a 0, diff --git a/projects/src/project_01/04_xor.ts b/projects/src/project_01/04_xor.ts index 2120f05b7..5fad3e679 100644 --- a/projects/src/project_01/04_xor.ts +++ b/projects/src/project_01/04_xor.ts @@ -23,6 +23,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Xor.tst +load Xor.hdl, +compare-to Xor.cmp, output-list a b out; set a 0, diff --git a/projects/src/project_01/05_mux.ts b/projects/src/project_01/05_mux.ts index c57b76c9b..8e3238f4e 100644 --- a/projects/src/project_01/05_mux.ts +++ b/projects/src/project_01/05_mux.ts @@ -27,6 +27,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Mux.tst +load Mux.hdl, +compare-to Mux.cmp, output-list a b sel out; set a 0, diff --git a/projects/src/project_01/06_dmux.ts b/projects/src/project_01/06_dmux.ts index 92b46bad1..8b089083f 100644 --- a/projects/src/project_01/06_dmux.ts +++ b/projects/src/project_01/06_dmux.ts @@ -19,6 +19,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/DMux.tst +load DMux.hdl, +compare-to DMux.cmp, output-list in sel a b; set in 0, diff --git a/projects/src/project_01/07_not16.ts b/projects/src/project_01/07_not16.ts index 9c5fcfa5c..4bda9a4f2 100644 --- a/projects/src/project_01/07_not16.ts +++ b/projects/src/project_01/07_not16.ts @@ -19,6 +19,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Not16.tst +load Not16.hdl, +compare-to Not16.cmp, output-list in%B1.16.1 out%B1.16.1; set in %B0000000000000000, diff --git a/projects/src/project_01/08_and16.ts b/projects/src/project_01/08_and16.ts index 43fcd0ceb..f208a2218 100644 --- a/projects/src/project_01/08_and16.ts +++ b/projects/src/project_01/08_and16.ts @@ -19,6 +19,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/And16.tst +load And16.hdl, +compare-to And16.cmp, output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; set a %B0000000000000000, diff --git a/projects/src/project_01/09_or16.ts b/projects/src/project_01/09_or16.ts index 420af4168..81852cdba 100644 --- a/projects/src/project_01/09_or16.ts +++ b/projects/src/project_01/09_or16.ts @@ -26,6 +26,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Or16.tst +load Or16.hdl, +compare-to Or16.cmp, output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; set a %B0000000000000000, diff --git a/projects/src/project_01/10_mux16.ts b/projects/src/project_01/10_mux16.ts index 48dff4868..404163918 100644 --- a/projects/src/project_01/10_mux16.ts +++ b/projects/src/project_01/10_mux16.ts @@ -28,6 +28,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Mux16.tst +load Mux16.hdl, +compare-to Mux16.cmp, output-list a%B1.16.1 b%B1.16.1 sel out%B1.16.1; set a 0, diff --git a/projects/src/project_01/11_mux4way16.ts b/projects/src/project_01/11_mux4way16.ts index e26e7f0c9..5a4606832 100644 --- a/projects/src/project_01/11_mux4way16.ts +++ b/projects/src/project_01/11_mux4way16.ts @@ -30,6 +30,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Mux4Way16.tst +load Mux4Way16.hdl, +compare-to Mux4Way16.cmp, output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 sel%B2.2.2 out%B1.16.1; set a 0, diff --git a/projects/src/project_01/12_mux8way16.ts b/projects/src/project_01/12_mux8way16.ts index a02d72fcc..71f40cbe9 100644 --- a/projects/src/project_01/12_mux8way16.ts +++ b/projects/src/project_01/12_mux8way16.ts @@ -44,6 +44,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Mux8Way16.tst +load Mux8Way16.hdl, +compare-to Mux8Way16.cmp, output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 e%B1.16.1 f%B1.16.1 g%B1.16.1 h%B1.16.1 sel%B2.3.2 out%B1.16.1; set a 0, diff --git a/projects/src/project_01/13_dmux4way.ts b/projects/src/project_01/13_dmux4way.ts index 5eb898b87..d391617e6 100644 --- a/projects/src/project_01/13_dmux4way.ts +++ b/projects/src/project_01/13_dmux4way.ts @@ -21,6 +21,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/DMux4Way.tst +load DMux4Way.hdl, +compare-to DMux4Way.cmp, output-list in sel%B2.2.2 a b c d; set in 0, diff --git a/projects/src/project_01/14_dmux8way.ts b/projects/src/project_01/14_dmux8way.ts index 2b6045e9b..b554ca885 100644 --- a/projects/src/project_01/14_dmux8way.ts +++ b/projects/src/project_01/14_dmux8way.ts @@ -26,6 +26,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/DMux8Way.tst +load DMux8Way.hdl, +compare-to DMux8Way.cmp, output-list in sel%B2.3.2 a b c d e f g h; set in 0, diff --git a/projects/src/project_01/15_or8way.ts b/projects/src/project_01/15_or8way.ts index 0b2a3b959..cf14ce15a 100644 --- a/projects/src/project_01/15_or8way.ts +++ b/projects/src/project_01/15_or8way.ts @@ -24,6 +24,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/1/Or8Way.tst +load Or8Way.hdl, +compare-to Or8Way.cmp, output-list in%B2.8.2 out; set in %B00000000, diff --git a/projects/src/project_02/01_half_adder.ts b/projects/src/project_02/01_half_adder.ts index c482541ae..0a950fd33 100644 --- a/projects/src/project_02/01_half_adder.ts +++ b/projects/src/project_02/01_half_adder.ts @@ -23,6 +23,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/2/HalfAdder.tst +load HalfAdder.hdl, +compare-to HalfAdder.cmp, output-list a b sum carry; set a 0, diff --git a/projects/src/project_02/02_full_adder.ts b/projects/src/project_02/02_full_adder.ts index abf22406b..6067822ae 100644 --- a/projects/src/project_02/02_full_adder.ts +++ b/projects/src/project_02/02_full_adder.ts @@ -27,6 +27,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/2/FullAdder.tst +load FullAdder.hdl, +compare-to FullAdder.cmp, output-list a b c sum carry%B2.1.2; set a 0, diff --git a/projects/src/project_02/03_add16.ts b/projects/src/project_02/03_add16.ts index e28684ad4..8e17fa1cb 100644 --- a/projects/src/project_02/03_add16.ts +++ b/projects/src/project_02/03_add16.ts @@ -25,6 +25,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/2/Add16.tst +load Add16.hdl, +compare-to Add16.cmp, output-list a%B1.16.1 b%B1.16.1 out%B1.16.1; set a %B0000000000000000, diff --git a/projects/src/project_02/04_inc16.ts b/projects/src/project_02/04_inc16.ts index 99a663cc1..13624fb64 100644 --- a/projects/src/project_02/04_inc16.ts +++ b/projects/src/project_02/04_inc16.ts @@ -24,6 +24,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/2/Inc16.tst +load Inc16.hdl, +compare-to Inc16.cmp, output-list in%B1.16.1 out%B1.16.1; set in %B0000000000000000, // in = 0 diff --git a/projects/src/project_02/06_alu.ts b/projects/src/project_02/06_alu.ts index 6246d177b..3f3d5a1e0 100644 --- a/projects/src/project_02/06_alu.ts +++ b/projects/src/project_02/06_alu.ts @@ -85,6 +85,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/2/ALU.tst +load ALU.hdl, +compare-to ALU.cmp, output-list x%B1.16.1 y%B1.16.1 zx nx zy ny f no out zr ng; set x %B0000000000000000, // x = 0 diff --git a/projects/src/project_03/01_bit.ts b/projects/src/project_03/01_bit.ts index 603eac23d..310bbcf2d 100644 --- a/projects/src/project_03/01_bit.ts +++ b/projects/src/project_03/01_bit.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/a/Bit.tst +load Bit.hdl, +compare-to Bit.cmp, output-list time%S1.4.1 in load%B1.1.2 out; set in 0, diff --git a/projects/src/project_03/02_register.ts b/projects/src/project_03/02_register.ts index cd2cb4827..3e308caed 100644 --- a/projects/src/project_03/02_register.ts +++ b/projects/src/project_03/02_register.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/a/Register.tst +load Register.hdl, +compare-to Register.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/03_pc.ts b/projects/src/project_03/03_pc.ts index 203e36d67..e32612558 100644 --- a/projects/src/project_03/03_pc.ts +++ b/projects/src/project_03/03_pc.ts @@ -21,6 +21,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/03/a/PC.tst +load PC.hdl, +compare-to PC.cmp, output-list time%S1.3.1 in%D1.6.1 reset%B2.1.2 load%B2.1.2 inc%B2.1.2 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/04_ram8.ts b/projects/src/project_03/04_ram8.ts index 27d024f21..ed873d87e 100644 --- a/projects/src/project_03/04_ram8.ts +++ b/projects/src/project_03/04_ram8.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/a/RAM8.tst +load RAM8.hdl, +compare-to RAM8.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 address%D3.1.3 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/05_ram64.ts b/projects/src/project_03/05_ram64.ts index d76392287..6f636cbb7 100644 --- a/projects/src/project_03/05_ram64.ts +++ b/projects/src/project_03/05_ram64.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/a/RAM64.tst +load RAM64.hdl, +compare-to RAM64.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 address%D2.3.2 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/06_ram512.ts b/projects/src/project_03/06_ram512.ts index 06e092f16..3970f83c8 100644 --- a/projects/src/project_03/06_ram512.ts +++ b/projects/src/project_03/06_ram512.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/b/RAM512.tst +load RAM512.hdl, +compare-to RAM512.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 address%D2.3.2 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/07_ram4k.ts b/projects/src/project_03/07_ram4k.ts index 07d518141..69a8ce7fe 100644 --- a/projects/src/project_03/07_ram4k.ts +++ b/projects/src/project_03/07_ram4k.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/b/RAM4K.tst +load RAM4K.hdl, +compare-to RAM4K.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 address%D2.4.2 out%D1.6.1; set in 0, diff --git a/projects/src/project_03/08_ram16k.ts b/projects/src/project_03/08_ram16k.ts index e0afbfac0..6b60c0e52 100644 --- a/projects/src/project_03/08_ram16k.ts +++ b/projects/src/project_03/08_ram16k.ts @@ -20,6 +20,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/3/b/RAM16K.tst +load RAM16K.hdl, +compare-to RAM16K.cmp, output-list time%S1.3.1 in%D1.6.1 load%B2.1.1 address%D2.5.2 out%D1.6.1; set in 0, diff --git a/projects/src/project_04/01_mult.ts b/projects/src/project_04/01_mult.ts index 1118617bf..16d75b577 100644 --- a/projects/src/project_04/01_mult.ts +++ b/projects/src/project_04/01_mult.ts @@ -18,6 +18,8 @@ export const tst = `// This file is part of www.nand2tetris.org // Tests the program by having it multiply several sets of // R0 and R1 values. +load Mult.asm, +compare-to Mult.cmp, output-list RAM[0]%D2.6.2 RAM[1]%D2.6.2 RAM[2]%D2.6.2; set RAM[0] 0, // Sets R0 and R1 to some input values diff --git a/projects/src/project_04/02_fill.ts b/projects/src/project_04/02_fill.ts index 7962eb09d..3377be476 100644 --- a/projects/src/project_04/02_fill.ts +++ b/projects/src/project_04/02_fill.ts @@ -17,6 +17,7 @@ export const tst = `// This file is part of www.nand2tetris.org // Tests the Fill.hack program in the CPU emulator. +load Fill.asm; echo "Select the highest speed and 'enable keyboard'. Then press any key for some time, and inspect the screen."; repeat { @@ -37,6 +38,8 @@ export const autoTst = `// This file is part of www.nand2tetris.org // This is done in order to test that these registers are set to 000...0 or 111....1, // as mandated by how the Fill program should react to the keyboard events. +load Fill.asm, +compare-to FillAutomatic.cmp, output-list RAM[16384]%D2.6.2 RAM[17648]%D2.6.2 RAM[18349]%D2.6.2 RAM[19444]%D2.6.2 RAM[20771]%D2.6.2 RAM[21031]%D2.6.2 RAM[22596]%D2.6.2 RAM[23754]%D2.6.2 RAM[24575]%D2.6.2; set RAM[24576] 0, // the keyboard is untouched diff --git a/projects/src/project_05/01_memory.ts b/projects/src/project_05/01_memory.ts index b05787bf1..b38aa0157 100644 --- a/projects/src/project_05/01_memory.ts +++ b/projects/src/project_05/01_memory.ts @@ -39,6 +39,8 @@ export const tst = `// This file is part of www.nand2tetris.org // and 'Screen', which correspond to 0, %X2000, and %X4000 in Hexadecimal // (0, 8192 (8K), and 16385 (16K+1) in decimal). +load Memory.hdl, +compare-to Memory.cmp, output-list in%D1.6.1 load%B2.1.2 address%B1.15.1 out%D1.6.1; echo "Before you run this script, select the 'Screen' option from the 'View' menu"; diff --git a/projects/src/project_05/02_cpu.ts b/projects/src/project_05/02_cpu.ts index 07ed911a4..fa126b696 100644 --- a/projects/src/project_05/02_cpu.ts +++ b/projects/src/project_05/02_cpu.ts @@ -39,6 +39,8 @@ export const tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/5/CPU.tst +load CPU.hdl, +compare-to CPU.cmp, output-list time%S0.4.0 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.3 addressM%D0.5.0 pc%D0.5.0 DRegister[]%D1.6.1; @@ -280,6 +282,8 @@ export const external_tst = `// This file is part of www.nand2tetris.org // by Nisan and Schocken, MIT Press. // File name: projects/5/CPU-external.tst +load CPU.hdl, +compare-to CPU-external.cmp, output-list time%S0.4.0 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.3 addressM%D0.5.0 pc%D0.5.0; diff --git a/projects/src/project_05/03_computer.ts b/projects/src/project_05/03_computer.ts index e5a576950..44fc0ea94 100644 --- a/projects/src/project_05/03_computer.ts +++ b/projects/src/project_05/03_computer.ts @@ -30,6 +30,9 @@ export const add_tst = `// This file is part of www.nand2tetris.org // Tracks the values of the time, reset bit, A-register, D-register, // program counter, R0, R1, and R2. + +load Computer.hdl, +compare-to ComputerAdd.cmp, output-list time%S1.3.1 reset%B2.1.2 ARegister[0]%D1.7.1 DRegister[0]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; // Loads the binary program Add.hack into the computer's instruction memory @@ -77,6 +80,8 @@ export const max_tst = `// This file is part of www.nand2tetris.org // Tracks the values of the time, reset bit, A-register, D-register, // program counter, R0, R1, and R2. +load Computer.hdl, +compare-to ComputerMax.cmp, output-list time%S1.3.1 reset%B2.1.2 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; // Loads the binary program Add.hack into the computer's instruction memory @@ -144,6 +149,8 @@ export const rect_tst = `// This file is part of www.nand2tetris.org // at the top left corner of the screen. // Tracks the values of the time, A-register, D-register, program counter, R0, R1, and R2. +load Computer.hdl, +compare-to ComputerRect.cmp, output-list time%S1.3.1 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1; // Loads the binary program Rect.hack into the computer's instruction memory diff --git a/projects/src/project_07/11_simple_add.ts b/projects/src/project_07/11_simple_add.ts index 0fc220d57..def150367 100644 --- a/projects/src/project_07/11_simple_add.ts +++ b/projects/src/project_07/11_simple_add.ts @@ -18,6 +18,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates SimpleAdd.vm on the VM simulator. load SimpleAdd.vm, +compare-to SimpleAdd.cmp, set RAM[0] 256, // initializes the stack pointer @@ -36,6 +37,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests SimpleAdd.asm on the CPU emulator. +load SimpleAdd.asm, +compare-to SimpleAdd.cmp, + set RAM[0] 256, // initializes the stack pointer repeat 60 { // enough cycles to complete the execution diff --git a/projects/src/project_07/12_stack_test.ts b/projects/src/project_07/12_stack_test.ts index 028ff5c8c..69b924f9c 100644 --- a/projects/src/project_07/12_stack_test.ts +++ b/projects/src/project_07/12_stack_test.ts @@ -53,6 +53,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates StackTest.vm on the VM simulator. load StackTest.vm, +compare-to StackTest.cmp, set RAM[0] 256, // initializes the stack pointer @@ -75,6 +76,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests StackTest.asm on the CPU emulator. +load StackTest.asm, +compare-to StackTest.cmp, + set RAM[0] 256, // initializes the stack pointer repeat 1000 { // enough cycles to complete the execution diff --git a/projects/src/project_07/21_basic_test.ts b/projects/src/project_07/21_basic_test.ts index dae1ce756..b2fb37048 100644 --- a/projects/src/project_07/21_basic_test.ts +++ b/projects/src/project_07/21_basic_test.ts @@ -42,6 +42,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // of relevant memory segments to selected RAM addresses. load BasicTest.vm, +compare-to BasicTest.cmp, set sp 256, // stack pointer set local 300, // base address of the local segment @@ -67,6 +68,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests BasicTest.asm on the CPU emulator. +load BasicTest.asm, +compare-to BasicTest.cmp, + set RAM[0] 256, // stack pointer set RAM[1] 300, // base address of the local segment set RAM[2] 400, // base address of the argument segment diff --git a/projects/src/project_07/22_pointer_test.ts b/projects/src/project_07/22_pointer_test.ts index a00a944fa..34ba86301 100644 --- a/projects/src/project_07/22_pointer_test.ts +++ b/projects/src/project_07/22_pointer_test.ts @@ -31,6 +31,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates PointerTest.vm on the VM simulator. load PointerTest.vm, +compare-to PointerTest.cmp, set RAM[0] 256, // initializes the stack pointer @@ -52,6 +53,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests PointerTest.asm on the CPU emulator. +load PointerTest.asm, +compare-to PointerTest.cmp, + set RAM[0] 256, // initializes the stack pointer repeat 450 { // enough cycles to complete the execution diff --git a/projects/src/project_07/23_static_test.ts b/projects/src/project_07/23_static_test.ts index c97de3fc6..dbb7c342b 100644 --- a/projects/src/project_07/23_static_test.ts +++ b/projects/src/project_07/23_static_test.ts @@ -26,6 +26,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates StaticTest.vm on the VM simulator. load StaticTest.vm, +compare-to StaticTest.cmp, set sp 256, // initializes the stack pointer @@ -45,6 +46,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests StaticTest.asm on the CPU emulator. +load StaticTest.asm, +compare-to StaticTest.cmp, + set RAM[0] 256, // initializes the stack pointer repeat 200 { // enough cycles to complete the execution diff --git a/projects/src/project_08/11_basic_loop.ts b/projects/src/project_08/11_basic_loop.ts index 05b1d5db3..bea8b84b7 100644 --- a/projects/src/project_08/11_basic_loop.ts +++ b/projects/src/project_08/11_basic_loop.ts @@ -34,6 +34,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // and sets argument[0]. load BasicLoop.vm, +compare-to BasicLoop.cmp, set sp 256, set local 300, @@ -59,6 +60,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // and the base addresses of the local and argument segments, // and sets argument[0]. +load BasicLoop.asm, +compare-to BasicLoop.cmp, + set RAM[0] 256, // SP set RAM[1] 300, // LCL set RAM[2] 400, // ARG diff --git a/projects/src/project_08/12_fibonacci_series.ts b/projects/src/project_08/12_fibonacci_series.ts index d11a8be47..ad9d50f22 100644 --- a/projects/src/project_08/12_fibonacci_series.ts +++ b/projects/src/project_08/12_fibonacci_series.ts @@ -56,6 +56,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // of the generated series. load FibonacciSeries.vm, +compare-to FibonacciSeries.cmp, set sp 256, set local 300, @@ -83,6 +84,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // and the base addresses of the local and argument segments, // and sets argument[0] and argument [1]. +load FibonacciSeries.asm, +compare-to FibonacciSeries.cmp, + set RAM[0] 256, // SP set RAM[1] 300, // LCL set RAM[2] 400, // ARG diff --git a/projects/src/project_08/20_simple_function.ts b/projects/src/project_08/20_simple_function.ts index eb51209fe..0bdaedc00 100644 --- a/projects/src/project_08/20_simple_function.ts +++ b/projects/src/project_08/20_simple_function.ts @@ -29,6 +29,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // and sets some values in the argument segment. load SimpleFunction.vm, +compare-to SimpleFunction.cmp, set sp 317, set local 317, @@ -65,6 +66,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Before executing the code, initializes the stack pointer and the pointers of some // of the memory segments, and sets some values in the argument segment. +Load SimpleFunction.asm, +compare-to SimpleFunction.cmp, + set RAM[0] 317, // SP set RAM[1] 317, // LCL set RAM[2] 310, // ARG diff --git a/projects/src/project_08/21_nested_call.ts b/projects/src/project_08/21_nested_call.ts index 39d981e0e..78fd0dfe3 100644 --- a/projects/src/project_08/21_nested_call.ts +++ b/projects/src/project_08/21_nested_call.ts @@ -62,6 +62,7 @@ export const vm_tst = `// Tests and illustrates how the VM implementation handle // In particular, loads and runs the functions in Sys.vm. load Sys.vm, +compare-to NestedCall.cmp, output-list RAM[0]%D1.6.1 RAM[1]%D1.6.1 RAM[2]%D1.6.1 RAM[3]%D1.6.1 RAM[4]%D1.6.1 RAM[5]%D1.6.1 RAM[6]%D1.6.1; set RAM[0] 261, @@ -135,6 +136,9 @@ export const hdl_tst = `// Tests how the VM implementation handles function-call // the VM translator is applied to the NestedCall folder, which // includes only one VM file: Sys.vm. +load NestedCall.asm, +compare-to NestedCall.cmp, + set RAM[0] 261, set RAM[1] 261, set RAM[2] 256, diff --git a/projects/src/project_08/22_fibonacci_element.ts b/projects/src/project_08/22_fibonacci_element.ts index ea3c27fe4..bd7381767 100644 --- a/projects/src/project_08/22_fibonacci_element.ts +++ b/projects/src/project_08/22_fibonacci_element.ts @@ -58,6 +58,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates the given Fibonacci element program on the VM emulator. load, +compare-to FibonacciElement.cmp, set sp 261, @@ -80,6 +81,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // FibonacciElement.asm results from translating Main.vm and Sys.vm into // a single assembly program, stored in the file FibonacciElement.asm. +load FibonacciElement.asm, +compare-to FibonacciElement.cmp, + repeat 6000 { ticktock; } diff --git a/projects/src/project_08/23_statics_test.ts b/projects/src/project_08/23_statics_test.ts index 26991720a..25eecbc36 100644 --- a/projects/src/project_08/23_statics_test.ts +++ b/projects/src/project_08/23_statics_test.ts @@ -70,6 +70,7 @@ export const vm_tst = `// This file is part of www.nand2tetris.org // Tests and illustrates the statics test on the VM emulator. load, +compare-to StaticsTest.cmp, set sp 261, @@ -89,6 +90,9 @@ export const hdl_tst = `// This file is part of www.nand2tetris.org // Tests StaticTest.asm in the CPU emulator. // This assembly file results from translating the staticsTest folder. +load StaticsTest.asm, +compare-to StaticsTest.cmp, + set RAM[0] 256, repeat 2500 {