From d3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 20 Jan 2018 15:41:49 +0100 Subject: rearranged the dir for github - removed tools and pdfs - rearranged the projects dirs - added md files - other minor changes --- projects/12/MemoryTest/Main.jack | 42 ------ projects/12/MemoryTest/Main.vm | 126 ----------------- projects/12/MemoryTest/Memory.jack | 72 ---------- projects/12/MemoryTest/Memory.vm | 258 ---------------------------------- projects/12/MemoryTest/MemoryTest.cmp | 2 - projects/12/MemoryTest/MemoryTest.out | 0 projects/12/MemoryTest/MemoryTest.tst | 15 -- 7 files changed, 515 deletions(-) delete mode 100644 projects/12/MemoryTest/Main.jack delete mode 100644 projects/12/MemoryTest/Main.vm delete mode 100644 projects/12/MemoryTest/Memory.jack delete mode 100644 projects/12/MemoryTest/Memory.vm delete mode 100644 projects/12/MemoryTest/MemoryTest.cmp delete mode 100644 projects/12/MemoryTest/MemoryTest.out delete mode 100644 projects/12/MemoryTest/MemoryTest.tst (limited to 'projects/12/MemoryTest') diff --git a/projects/12/MemoryTest/Main.jack b/projects/12/MemoryTest/Main.jack deleted file mode 100644 index 77a53a9..0000000 --- a/projects/12/MemoryTest/Main.jack +++ /dev/null @@ -1,42 +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/12/MemoryTest/Main.jack - -/** Test program for the OS Memory class. */ -class Main { - - /** Performs various memory manipulations. */ - function void main() { - var int temp; - var Array a, b, c; - - do Memory.poke(8000, 333); // RAM[8000] = 333 - let temp = Memory.peek(8000); - do Memory.poke(8001, temp + 1); // RAM[8001] = 334 - - let a = Array.new(3); // uses Memory.alloc - let a[2] = 222; - do Memory.poke(8002, a[2]); // RAM[8002] = 222 - - let b = Array.new(3); - let b[1] = a[2] - 100; - do Memory.poke(8003, b[1]); // RAM[8003] = 122 - - let c = Array.new(500); - let c[499] = a[2] - b[1]; - do Memory.poke(8004, c[499]); // RAM[8004] = 100 - - do a.dispose(); // uses Memory.deAlloc - do b.dispose(); - - let b = Array.new(3); - let b[0] = c[499] - 90; - do Memory.poke(8005, b[0]); // RAM[8005] = 10 - - do c.dispose(); - do b.dispose(); - - return; - } -} diff --git a/projects/12/MemoryTest/Main.vm b/projects/12/MemoryTest/Main.vm deleted file mode 100644 index a3a9e81..0000000 --- a/projects/12/MemoryTest/Main.vm +++ /dev/null @@ -1,126 +0,0 @@ -function Main.main 4 -push constant 8000 -push constant 333 -call Memory.poke 2 -pop temp 0 -push constant 8000 -call Memory.peek 1 -pop local 0 -push constant 8001 -push local 0 -push constant 1 -add -call Memory.poke 2 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 1 -push constant 2 -push local 1 -add -push constant 222 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8002 -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 1 -push local 2 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 100 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8003 -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push constant 500 -call Array.new 1 -pop local 3 -push constant 499 -push local 3 -add -push constant 2 -push local 1 -add -pop pointer 1 -push that 0 -push constant 1 -push local 2 -add -pop pointer 1 -push that 0 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8004 -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push local 1 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 3 -call Array.new 1 -pop local 2 -push constant 0 -push local 2 -add -push constant 499 -push local 3 -add -pop pointer 1 -push that 0 -push constant 90 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 8005 -push constant 0 -push local 2 -add -pop pointer 1 -push that 0 -call Memory.poke 2 -pop temp 0 -push local 3 -call Array.dispose 1 -pop temp 0 -push local 2 -call Array.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/12/MemoryTest/Memory.jack b/projects/12/MemoryTest/Memory.jack deleted file mode 100644 index 54e04aa..0000000 --- a/projects/12/MemoryTest/Memory.jack +++ /dev/null @@ -1,72 +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/12/Memory.jack - -/** - * This library provides two services: direct access to the computer's main - * memory (RAM), and allocation and recycling of memory blocks. The Hack RAM - * consists of 32,768 words, each holding a 16-bit binary number. - */ -class Memory { - static Array memory; - static Array heap; - static int last; - - /** Initializes the class. */ - function void init() { - let memory = 0; - let heap = 2048; - let heap[0] = -1; - let heap[1] = 14334; - let last = 0; - return; - } - - /** Returns the RAM value at the given address. */ - function int peek(int address) { - return memory[address]; - } - - /** Sets the RAM value at the given address to the given value. */ - function void poke(int address, int value) { - let memory[address] = value; - return; - } - - /** Finds an available RAM block of the given size and returns - * a reference to its base address. */ - function int alloc(int size) { - var int current; - var int size2; - var int newLast; - let current = 0; - let size2 = size + 2; - while ((current > -1) & (heap[current + 1] < size2)) { - let current = heap[current]; - } - if (current = -1) { - do String.println("Insufficient space for allocation!"); - do Sys.error(1); - return -1; - } else { - let heap[current + 1] = heap[current + 1] - size2; - let newLast = current + heap[current + 1] + 2; - let heap[newLast] = heap[current]; - let heap[current] = newLast; - let heap[newLast + 1] = size; - return heap + newLast + 2; - } - } - - /** De-allocates the given object (cast as an array) by making - * it available for future allocations. */ - function void deAlloc(Array o) { - var int oBase; - let oBase = o - heap - 2; - let heap[oBase] = -1; - let heap[last] = oBase; - let last = oBase; - return; - } -} diff --git a/projects/12/MemoryTest/Memory.vm b/projects/12/MemoryTest/Memory.vm deleted file mode 100644 index 0570b46..0000000 --- a/projects/12/MemoryTest/Memory.vm +++ /dev/null @@ -1,258 +0,0 @@ -function Memory.init 0 -push constant 0 -pop static 0 -push constant 2048 -pop static 1 -push constant 0 -push static 1 -add -push constant 1 -neg -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push static 1 -add -push constant 14334 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -pop static 2 -push constant 0 -return -function Memory.peek 0 -push argument 0 -push static 0 -add -pop pointer 1 -push that 0 -return -function Memory.poke 0 -push argument 0 -push static 0 -add -push argument 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -return -function Memory.alloc 3 -push constant 0 -pop local 0 -push argument 0 -push constant 2 -add -pop local 1 -label WHILE_EXP0 -push local 0 -push constant 1 -neg -gt -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -push local 1 -lt -and -not -if-goto WHILE_END0 -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -push constant 1 -neg -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 34 -call String.new 1 -push constant 73 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 112 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 102 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call String.println 1 -pop temp 0 -push constant 1 -call Sys.error 1 -pop temp 0 -push constant 1 -neg -return -goto IF_END0 -label IF_FALSE0 -push local 0 -push constant 1 -add -push static 1 -add -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -push local 1 -sub -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -push local 0 -push constant 1 -add -push static 1 -add -pop pointer 1 -push that 0 -add -push constant 2 -add -pop local 2 -push local 2 -push static 1 -add -push local 0 -push static 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -push static 1 -add -push local 2 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 2 -push constant 1 -add -push static 1 -add -push argument 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push static 1 -push local 2 -add -push constant 2 -add -return -label IF_END0 -function Memory.deAlloc 1 -push argument 0 -push static 1 -sub -push constant 2 -sub -pop local 0 -push local 0 -push static 1 -add -push constant 1 -neg -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push static 2 -push static 1 -add -push local 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -pop static 2 -push constant 0 -return diff --git a/projects/12/MemoryTest/MemoryTest.cmp b/projects/12/MemoryTest/MemoryTest.cmp deleted file mode 100644 index 057958b..0000000 --- a/projects/12/MemoryTest/MemoryTest.cmp +++ /dev/null @@ -1,2 +0,0 @@ -|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]| -| 333 | 334 | 222 | 122 | 100 | 10 | diff --git a/projects/12/MemoryTest/MemoryTest.out b/projects/12/MemoryTest/MemoryTest.out deleted file mode 100644 index e69de29..0000000 diff --git a/projects/12/MemoryTest/MemoryTest.tst b/projects/12/MemoryTest/MemoryTest.tst deleted file mode 100644 index 1da34fd..0000000 --- a/projects/12/MemoryTest/MemoryTest.tst +++ /dev/null @@ -1,15 +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/12/MemoryTest/MemoryTest.tst - -load, -output-file MemoryTest.out, -compare-to MemoryTest.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; - -repeat 1000000 { - vmstep; -} - -output; -- cgit v1.2.3