added v2.0

This commit is contained in:
Michael Schröder
2023-01-11 11:13:09 +01:00
parent 2a5a64ca91
commit 971b323822
584 changed files with 159319 additions and 0 deletions

View File

@@ -0,0 +1 @@
../Array.jack

View File

@@ -0,0 +1 @@
../GPIO.jack

View File

@@ -0,0 +1,35 @@
// 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/12/MathTest/Main.jack
/** Test program for the OS Math class. */
class Main {
/** Performs various mathematical operations, using calls to the Math class methods. */
function void main() {
var Array r; // stores the test results;
let r = 4107;
let r[0] = 2 * 3; // 6
let r[1] = r[0] * (-30); // 6 * (-30) = -180
let r[2] = r[1] * 100; // (-180) * 100 = -18000
let r[3] = 1 * r[2]; // 1 * (-18000) = -18000
let r[4] = r[3] * 0; // 0
let r[0] = 9 / 3; // 3
let r[1] = (-18000) / 6; // -3000
let r[2] = 32766 / (-32767); // 0
let r[3] = Math.sqrt(9); // 3
let r[4] = Math.sqrt(32767); // 181
let r[0] = Math.min(345, 123); // 123
let r[1] = Math.max(123, -345); // 123
let r[2] = Math.abs(27); // 27
let r[3] = Math.abs(-32767); // 32767
return;
}
}

View File

@@ -0,0 +1,18 @@
all: jack vm asm bin sim
jack:
../../tools/JackCompiler/JackCompiler.pyc ./
vm:
../../tools/VMTranslator/VMTranslator.pyc ./
asm:
../../tools/Assembler/assembler.pyc out.asm
bin:
../../tools/AsciiToBin.py out.hack
sim:
cp out.hack ../00_HACK/ROM.hack
upload:
iceprogduino -o 64k -w out.bin
clean:
rm -f *.vm *.asm *.hack *.bin *~
.PHONY: all clean

View File

@@ -0,0 +1 @@
../Math.jack

View File

@@ -0,0 +1,2 @@
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|RAM[8006]|RAM[8007]|RAM[8008]|RAM[8009]|RAM[8010]|RAM[8011]|RAM[8012]|RAM[8013]|
| 6 | -180 | -18000 | -18000 | 0 | 3 | -3000 | 0 | 3 | 181 | 123 | 123 | 27 | 32767 |

View File

@@ -0,0 +1,15 @@
// 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/12/MathTest/MathTest.tst
load,
output-file MathTest.out,
compare-to MathTest.cmp,
output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1 RAM[8006]%D2.6.1 RAM[8007]%D2.6.1 RAM[8008]%D2.6.1 RAM[8009]%D2.6.1 RAM[8010]%D2.6.1 RAM[8011]%D2.6.1 RAM[8012]%D2.6.1 RAM[8013]%D2.6.1;
repeat 1000000 {
vmstep;
}
output;

View File

@@ -0,0 +1 @@
../Memory.jack

View File

@@ -0,0 +1,24 @@
## Math_Test
A library of commonly used mathematical functions.
**Note:** Jack compilers implement multiplication and division using OS method calls.
***
### Project
* Implement `Math.jack`
* Test in simulation:
```
$ cd 00_Math_Test
$ make
$ cd ../00_HACK
$ apio clean
$ apio sim
```
* Compare the content of special function register DEBUG0--DEBUG4.
![](math.png)

View File

@@ -0,0 +1,33 @@
## Math_Test
A library of commonly used mathematical functions.
**Note:** Jack compilers implement multiplication and division using OS method calls.
### function void init() {
Initializes the library.
### function int abs(int x)
Returns the absolute value of x.
### function int multiply(int x, int y)
Returns the product of x and y. When a Jack compiler detects the multiplication operator `"*"` in the program's code, it handles it by invoking this method. In other words, the Jack expressions x*y and multiply(x,y) return the same value.
### function int divide(int x, int y)
Returns the integer part of x/y. When a Jack compiler detects the multiplication operator `"/"` in the program's code, it handles it by invoking this method. In other words, the Jack expressions x/y and divide(x,y) return the same value.
### function int sqrt(int x)
Returns the integer part of the square root of x.
### function int max(int a, int b)
Returns the greater number.
### function int min(int a, int b)
Returns the smaller number.
***
## Project
* Implement `Math.jack`
* Test in simulation:
```
$ cd 00_Math_Test
$ make
$ cd ../00_HACK
$ apio clean
$ apio sim
```
* Compare the content of special function register DEBUG0--DEBUG4.
![](math.png)

View File

@@ -0,0 +1 @@
../Sys.jack

View File

@@ -0,0 +1 @@
../UART.jack

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB