.
This commit is contained in:
Executable
+97
@@ -0,0 +1,97 @@
|
||||
@END //check if button is pressed
|
||||
0;JMP
|
||||
|
||||
(BLACK)
|
||||
//start= 16384 the start of the screen memory
|
||||
@SCREEN
|
||||
D=A
|
||||
@start
|
||||
M=D
|
||||
|
||||
//n=8,192 this is the memory for the display =addreass of the keyboard - address of the screen
|
||||
@8192
|
||||
D=A
|
||||
@n
|
||||
M=D
|
||||
|
||||
//i=0 this is the index for each group of pixels
|
||||
@i
|
||||
M=0
|
||||
|
||||
(LOOP1)
|
||||
//if i==n goto end
|
||||
@i
|
||||
D=M
|
||||
@n
|
||||
D=D-M
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
//start+1=-1 set each group of pixels to -1 which is = 111111111111
|
||||
@start
|
||||
D=M
|
||||
@i
|
||||
A=D+M
|
||||
M=-1
|
||||
|
||||
// increment i by 1
|
||||
@i
|
||||
M=M+1
|
||||
|
||||
// go back to the start of the loop
|
||||
@LOOP1
|
||||
0;JMP
|
||||
|
||||
(WHITE)
|
||||
//start= 16384 the start of the screen memory
|
||||
@SCREEN
|
||||
D=A
|
||||
@start
|
||||
M=D
|
||||
|
||||
//n=8,192 this is the memory for the display =addreass of the keyboard - address of the screen
|
||||
@8192
|
||||
D=A
|
||||
@n
|
||||
M=D
|
||||
|
||||
//i=0 this is the index for each group of pixels
|
||||
@i
|
||||
M=0
|
||||
|
||||
(LOOP2)
|
||||
//if i==n goto end
|
||||
@i
|
||||
D=M
|
||||
@n
|
||||
D=D-M
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
//start+1=-1 set each group of pixels to 0 which is = 00000000
|
||||
@start
|
||||
D=M
|
||||
@i
|
||||
A=D+M
|
||||
M=0
|
||||
|
||||
// increment i by 1
|
||||
@i
|
||||
M=M+1
|
||||
|
||||
// go back to the start of the loop
|
||||
@LOOP2
|
||||
0;JMP
|
||||
|
||||
//check if button is pressed
|
||||
(END)
|
||||
@KBD
|
||||
D=M
|
||||
@WHITE
|
||||
D;JEQ
|
||||
@KBD
|
||||
D=M
|
||||
@BLACK
|
||||
D;JNE
|
||||
@END
|
||||
0;JMP
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
@R2
|
||||
M=0
|
||||
@sum
|
||||
M=0
|
||||
(LOOP)
|
||||
@1
|
||||
D=M
|
||||
@END
|
||||
D;JEQ // if R1==0 goto end
|
||||
@R0
|
||||
D=M // D=R0
|
||||
@sum
|
||||
M=M+D // sum=sum+R0
|
||||
@R1
|
||||
M=M-1 //R1=R1-1
|
||||
@sum
|
||||
D=M
|
||||
@R2
|
||||
M=D
|
||||
@LOOP
|
||||
0;JMP
|
||||
(END)
|
||||
@END
|
||||
0;JMP
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
@END //check if button is pressed
|
||||
0;JMP
|
||||
|
||||
(BLACK)
|
||||
//start= 16384 the start of the screen memory
|
||||
@SCREEN
|
||||
D=A
|
||||
@start
|
||||
M=D
|
||||
|
||||
//n=8,192 this is the memory for the display =addreass of the keyboard - address of the screen
|
||||
@8192
|
||||
D=A
|
||||
@n
|
||||
M=D
|
||||
|
||||
//i=0 this is the index for each group of pixels
|
||||
@i
|
||||
M=0
|
||||
|
||||
(LOOP1)
|
||||
//if i==n goto end
|
||||
@i
|
||||
D=M
|
||||
@n
|
||||
D=D-M
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
//start+1=-1 set each group of pixels to -1 which is = 111111111111
|
||||
@start
|
||||
D=M
|
||||
@i
|
||||
A=D+M
|
||||
M=-1
|
||||
|
||||
// increment i by 1
|
||||
@i
|
||||
M=M+1
|
||||
|
||||
// go back to the start of the loop
|
||||
@LOOP1
|
||||
0;JMP
|
||||
|
||||
(WHITE)
|
||||
//start= 16384 the start of the screen memory
|
||||
@SCREEN
|
||||
D=A
|
||||
@start
|
||||
M=D
|
||||
|
||||
//n=8,192 this is the memory for the display =addreass of the keyboard - address of the screen
|
||||
@8192
|
||||
D=A
|
||||
@n
|
||||
M=D
|
||||
|
||||
//i=0 this is the index for each group of pixels
|
||||
@i
|
||||
M=0
|
||||
|
||||
(LOOP2)
|
||||
//if i==n goto end
|
||||
@i
|
||||
D=M
|
||||
@n
|
||||
D=D-M
|
||||
@END
|
||||
D;JEQ
|
||||
|
||||
//start+1=-1 set each group of pixels to 0 which is = 00000000
|
||||
@start
|
||||
D=M
|
||||
@i
|
||||
A=D+M
|
||||
M=0
|
||||
|
||||
// increment i by 1
|
||||
@i
|
||||
M=M+1
|
||||
|
||||
// go back to the start of the loop
|
||||
@LOOP2
|
||||
0;JMP
|
||||
|
||||
//check if button is pressed
|
||||
(END)
|
||||
@KBD
|
||||
D=M
|
||||
@WHITE
|
||||
D;JEQ
|
||||
@KBD
|
||||
D=M
|
||||
@BLACK
|
||||
D;JNE
|
||||
@END
|
||||
0;JMP
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
// 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/04/fill/Fill.tst
|
||||
|
||||
load Fill.asm;
|
||||
echo "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen.";
|
||||
|
||||
repeat {
|
||||
ticktock;
|
||||
}
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
|
||||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
|
||||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
// 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/04/fill/FillAutomatic
|
||||
|
||||
// This script can be used to test the Fill program automatically,
|
||||
// rather than interactively. Specifically, the script sets the keyboard
|
||||
// memory map (RAM[24576]) to 0, 1, and then again to 0. This simulates the
|
||||
// acts of leaving the keyboard untouched, pressing some key, and then releasing
|
||||
// the key. After each on of these simulated events, the script outputs the values
|
||||
// of some selected registers from the screen memory map (RAM[16384]-RAM[24576]).
|
||||
// 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,
|
||||
output-file FillAutomatic.out,
|
||||
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
|
||||
repeat 1000000 {
|
||||
ticktock;
|
||||
}
|
||||
output; // test that the screen is white
|
||||
|
||||
set RAM[24576] 1, // a keyboard key is pressed
|
||||
repeat 1000000 {
|
||||
ticktock;
|
||||
}
|
||||
output; // test that the screen is black
|
||||
|
||||
set RAM[24576] 0, // they keyboard in untouched
|
||||
repeat 1000000 {
|
||||
ticktock;
|
||||
}
|
||||
output; // test that the screen is white
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
@R2
|
||||
M=0
|
||||
@sum
|
||||
M=0
|
||||
(LOOP)
|
||||
@1
|
||||
D=M
|
||||
@END
|
||||
D;JEQ // if R1==0 goto end
|
||||
@R0
|
||||
D=M // D=R0
|
||||
@sum
|
||||
M=M+D // sum=sum+R0
|
||||
@R1
|
||||
M=M-1 //R1=R1-1
|
||||
@sum
|
||||
D=M
|
||||
@R2
|
||||
M=D
|
||||
@LOOP
|
||||
0;JMP
|
||||
(END)
|
||||
@END
|
||||
0;JMP
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
| RAM[0] | RAM[1] | RAM[2] |
|
||||
| 0 | 0 | 0 |
|
||||
| 1 | 0 | 0 |
|
||||
| 0 | 2 | 0 |
|
||||
| 3 | 1 | 3 |
|
||||
| 2 | 4 | 8 |
|
||||
| 6 | 7 | 42 |
|
||||
Executable
Executable
+74
@@ -0,0 +1,74 @@
|
||||
// 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/04/mult/Mult.tst
|
||||
|
||||
load Mult.asm,
|
||||
output-file Mult.out,
|
||||
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, // Set test arguments
|
||||
set RAM[1] 0,
|
||||
set RAM[2] -1; // Test that program initialized product to 0
|
||||
repeat 20 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 0, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 0,
|
||||
output;
|
||||
|
||||
set PC 0,
|
||||
set RAM[0] 1, // Set test arguments
|
||||
set RAM[1] 0,
|
||||
set RAM[2] -1; // Ensure that program initialized product to 0
|
||||
repeat 50 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 1, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 0,
|
||||
output;
|
||||
|
||||
set PC 0,
|
||||
set RAM[0] 0, // Set test arguments
|
||||
set RAM[1] 2,
|
||||
set RAM[2] -1; // Ensure that program initialized product to 0
|
||||
repeat 80 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 0, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 2,
|
||||
output;
|
||||
|
||||
set PC 0,
|
||||
set RAM[0] 3, // Set test arguments
|
||||
set RAM[1] 1,
|
||||
set RAM[2] -1; // Ensure that program initialized product to 0
|
||||
repeat 120 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 3, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 1,
|
||||
output;
|
||||
|
||||
set PC 0,
|
||||
set RAM[0] 2, // Set test arguments
|
||||
set RAM[1] 4,
|
||||
set RAM[2] -1; // Ensure that program initialized product to 0
|
||||
repeat 150 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 2, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 4,
|
||||
output;
|
||||
|
||||
set PC 0,
|
||||
set RAM[0] 6, // Set test arguments
|
||||
set RAM[1] 7,
|
||||
set RAM[2] -1; // Ensure that program initialized product to 0
|
||||
repeat 210 {
|
||||
ticktock;
|
||||
}
|
||||
set RAM[0] 6, // Restore arguments in case program used them as loop counter
|
||||
set RAM[1] 7,
|
||||
output;
|
||||
Reference in New Issue
Block a user