43 lines
1.3 KiB
Plaintext
43 lines
1.3 KiB
Plaintext
// 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(4107, 333); // RAM[4107] = 333
|
|
let temp = Memory.peek(4107);
|
|
do Memory.poke(4108, temp + 1); // RAM[4108] = 334
|
|
|
|
let a = Array.new(3); // uses Memory.alloc
|
|
let a[2] = 222;
|
|
do Memory.poke(4109, a[2]); // RAM[4109] = 222
|
|
|
|
let b = Array.new(3);
|
|
let b[1] = a[2] - 100;
|
|
do Memory.poke(4110, b[1]); // RAM[4110] = 122
|
|
|
|
let c = Array.new(500);
|
|
let c[499] = a[2] - b[1];
|
|
do Memory.poke(4111, c[499]); // RAM[4111] = 100
|
|
|
|
do a.dispose(); // uses Memory.deAlloc
|
|
do b.dispose();
|
|
|
|
let b = Array.new(3);
|
|
let b[0] = c[499] - 90;
|
|
do Memory.poke(4107, b[0]); // RAM[4107] = 10
|
|
|
|
do c.dispose();
|
|
do b.dispose();
|
|
|
|
return;
|
|
}
|
|
}
|