Skip to content

Commit

Permalink
Add load and compare-to commands to all test scripts (#418)
Browse files Browse the repository at this point in the history
* Add load and compare-to commands to all test scripts
  • Loading branch information
netalondon authored Jul 31, 2024
1 parent c5c42cf commit a5eb9dd
Show file tree
Hide file tree
Showing 45 changed files with 122 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/src/stores/chip.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand All @@ -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,
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/01_not.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/02_and.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/03_or.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/04_xor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/05_mux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/06_dmux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/07_not16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/08_and16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/09_or16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/10_mux16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/11_mux4way16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/12_mux8way16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/13_dmux4way.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/14_dmux8way.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_01/15_or8way.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_02/01_half_adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_02/02_full_adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_02/03_add16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_02/04_inc16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_02/06_alu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/01_bit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/02_register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/03_pc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/04_ram8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/05_ram64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/06_ram512.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/07_ram4k.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_03/08_ram16k.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_04/01_mult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions projects/src/project_04/02_fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions projects/src/project_05/01_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions projects/src/project_05/02_cpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions projects/src/project_05/03_computer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions projects/src/project_07/11_simple_add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions projects/src/project_07/12_stack_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit a5eb9dd

Please sign in to comment.