This commit is contained in:
QkoSad
2025-07-16 13:00:37 +03:00
commit 7894b48931
806 changed files with 162532 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
function Array.new 0
push argument 0
push constant 0
gt
not
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 2
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
call Memory.alloc 1
return
function Array.dispose 0
push argument 0
pop pointer 0
push pointer 0
call Memory.deAlloc 1
pop temp 0
push constant 0
return
+102
View File
@@ -0,0 +1,102 @@
function Keyboard.init 0
push constant 0
return
function Keyboard.keyPressed 0
push constant 24576
call Memory.peek 1
return
function Keyboard.readChar 2
push constant 0
call Output.printChar 1
pop temp 0
label WHILE_EXP0
push local 1
push constant 0
eq
push local 0
push constant 0
gt
or
not
if-goto WHILE_END0
call Keyboard.keyPressed 0
pop local 0
push local 0
push constant 0
gt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push local 0
pop local 1
label IF_FALSE0
goto WHILE_EXP0
label WHILE_END0
call String.backSpace 0
call Output.printChar 1
pop temp 0
push local 1
call Output.printChar 1
pop temp 0
push local 1
return
function Keyboard.readLine 5
push constant 80
call String.new 1
pop local 3
push argument 0
call Output.printString 1
pop temp 0
call String.newLine 0
pop local 1
call String.backSpace 0
pop local 2
label WHILE_EXP0
push local 4
not
not
if-goto WHILE_END0
call Keyboard.readChar 0
pop local 0
push local 0
push local 1
eq
pop local 4
push local 4
not
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push local 0
push local 2
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 3
call String.eraseLastChar 1
pop temp 0
goto IF_END1
label IF_FALSE1
push local 3
push local 0
call String.appendChar 2
pop local 3
label IF_END1
label IF_FALSE0
goto WHILE_EXP0
label WHILE_END0
push local 3
return
function Keyboard.readInt 2
push argument 0
call Keyboard.readLine 1
pop local 0
push local 0
call String.intValue 1
pop local 1
push local 0
call String.dispose 1
pop temp 0
push local 1
return
+53
View File
@@ -0,0 +1,53 @@
// 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, err;
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 err = 0;
let b = Array.new(3);
let b[1] = a[2] - 100;
if (b = a) { // Fail compare if b = a
let err = 1; }
do Memory.poke(8003, b[1] + err); // RAM[8003] = 122
let err = 0;
let c = Array.new(500);
let c[499] = a[2] - b[1];
if (c = a) { // Fail compare if c = a
let err = 1; }
if (c = b) { // Fail compare if c = b
let err = err + 10; }
do Memory.poke(8004, c[499]+err); // RAM[8004] = 100
do a.dispose(); // uses Memory.deAlloc
do b.dispose();
let err = 0;
let b = Array.new(3);
let b[0] = c[499] - 90;
if (b = c) { // Fail compare if b = c
let err = 1; }
do Memory.poke(8005, b[0] + err); // RAM[8005] = 10
do c.dispose();
do b.dispose();
return;
}
}
+180
View File
@@ -0,0 +1,180 @@
function Main.main 5
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 2
push local 2
push constant 2
push constant 222
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 8002
push local 2
push constant 2
add
pop pointer 1
push that 0
call Memory.poke 2
pop temp 0
push constant 0
pop local 1
push constant 3
call Array.new 1
pop local 3
push local 3
push constant 1
push local 2
push constant 2
add
pop pointer 1
push that 0
push constant 100
sub
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
push local 2
eq
not
if-goto L0
push constant 1
pop local 1
goto L1
label L0
label L1
push constant 8003
push local 3
push constant 1
add
pop pointer 1
push that 0
push local 1
add
call Memory.poke 2
pop temp 0
push constant 0
pop local 1
push constant 500
call Array.new 1
pop local 4
push local 4
push constant 499
push local 2
push constant 2
add
pop pointer 1
push that 0
push local 3
push constant 1
add
pop pointer 1
push that 0
sub
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push local 2
eq
not
if-goto L2
push constant 1
pop local 1
goto L3
label L2
label L3
push local 4
push local 3
eq
not
if-goto L4
push local 1
push constant 10
add
pop local 1
goto L5
label L4
label L5
push constant 8004
push local 4
push constant 499
add
pop pointer 1
push that 0
push local 1
add
call Memory.poke 2
pop temp 0
push local 2
call Array.dispose 1
pop temp 0
push local 3
call Array.dispose 1
pop temp 0
push constant 0
pop local 1
push constant 3
call Array.new 1
pop local 3
push local 3
push constant 0
push local 4
push constant 499
add
pop pointer 1
push that 0
push constant 90
sub
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
push local 4
eq
not
if-goto L6
push constant 1
pop local 1
goto L7
label L6
label L7
push constant 8005
push local 3
push constant 0
add
pop pointer 1
push that 0
push local 1
add
call Memory.poke 2
pop temp 0
push local 4
call Array.dispose 1
pop temp 0
push local 3
call Array.dispose 1
pop temp 0
push constant 0
return
+408
View File
@@ -0,0 +1,408 @@
function Math.init 1
push constant 16
call Array.new 1
pop static 1
push constant 16
call Array.new 1
pop static 0
push constant 0
push static 0
add
push constant 1
pop temp 0
pop pointer 1
push temp 0
pop that 0
label WHILE_EXP0
push local 0
push constant 15
lt
not
if-goto WHILE_END0
push local 0
push constant 1
add
pop local 0
push local 0
push static 0
add
push local 0
push constant 1
sub
push static 0
add
pop pointer 1
push that 0
push local 0
push constant 1
sub
push static 0
add
pop pointer 1
push that 0
add
pop temp 0
pop pointer 1
push temp 0
pop that 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Math.abs 0
push argument 0
push constant 0
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 0
neg
pop argument 0
label IF_FALSE0
push argument 0
return
function Math.multiply 5
push argument 0
push constant 0
lt
push argument 1
push constant 0
gt
and
push argument 0
push constant 0
gt
push argument 1
push constant 0
lt
and
or
pop local 4
push argument 0
call Math.abs 1
pop argument 0
push argument 1
call Math.abs 1
pop argument 1
push argument 0
push argument 1
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 0
pop local 1
push argument 1
pop argument 0
push local 1
pop argument 1
label IF_FALSE0
label WHILE_EXP0
push local 2
push constant 1
sub
push argument 1
push constant 1
sub
lt
not
if-goto WHILE_END0
push local 3
push static 0
add
pop pointer 1
push that 0
push argument 1
and
push constant 0
eq
not
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
push argument 0
add
pop local 0
push local 2
push local 3
push static 0
add
pop pointer 1
push that 0
add
pop local 2
label IF_FALSE1
push argument 0
push argument 0
add
pop argument 0
push local 3
push constant 1
add
pop local 3
goto WHILE_EXP0
label WHILE_END0
push local 4
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 0
neg
pop local 0
label IF_FALSE2
push local 0
return
function Math.divide 4
push argument 1
push constant 0
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 3
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
push constant 0
lt
push argument 1
push constant 0
gt
and
push argument 0
push constant 0
gt
push argument 1
push constant 0
lt
and
or
pop local 2
push constant 0
push static 1
add
push argument 1
call Math.abs 1
pop temp 0
pop pointer 1
push temp 0
pop that 0
push argument 0
call Math.abs 1
pop argument 0
label WHILE_EXP0
push local 0
push constant 15
lt
push local 3
not
and
not
if-goto WHILE_END0
push constant 32767
push local 0
push static 1
add
pop pointer 1
push that 0
push constant 1
sub
sub
push local 0
push static 1
add
pop pointer 1
push that 0
push constant 1
sub
lt
pop local 3
push local 3
not
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
push constant 1
add
push static 1
add
push local 0
push static 1
add
pop pointer 1
push that 0
push local 0
push static 1
add
pop pointer 1
push that 0
add
pop temp 0
pop pointer 1
push temp 0
pop that 0
push local 0
push constant 1
add
push static 1
add
pop pointer 1
push that 0
push constant 1
sub
push argument 0
push constant 1
sub
gt
pop local 3
push local 3
not
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 0
push constant 1
add
pop local 0
label IF_FALSE2
label IF_FALSE1
goto WHILE_EXP0
label WHILE_END0
label WHILE_EXP1
push local 0
push constant 1
neg
gt
not
if-goto WHILE_END1
push local 0
push static 1
add
pop pointer 1
push that 0
push constant 1
sub
push argument 0
push constant 1
sub
gt
not
if-goto IF_TRUE3
goto IF_FALSE3
label IF_TRUE3
push local 1
push local 0
push static 0
add
pop pointer 1
push that 0
add
pop local 1
push argument 0
push local 0
push static 1
add
pop pointer 1
push that 0
sub
pop argument 0
label IF_FALSE3
push local 0
push constant 1
sub
pop local 0
goto WHILE_EXP1
label WHILE_END1
push local 2
if-goto IF_TRUE4
goto IF_FALSE4
label IF_TRUE4
push local 1
neg
pop local 1
label IF_FALSE4
push local 1
return
function Math.sqrt 4
push argument 0
push constant 0
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 4
call Sys.error 1
pop temp 0
label IF_FALSE0
push constant 7
pop local 0
label WHILE_EXP0
push local 0
push constant 1
neg
gt
not
if-goto WHILE_END0
push local 3
push local 0
push static 0
add
pop pointer 1
push that 0
add
pop local 1
push local 1
push local 1
call Math.multiply 2
pop local 2
push local 2
push argument 0
gt
not
push local 2
push constant 0
lt
not
and
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 1
pop local 3
label IF_FALSE1
push local 0
push constant 1
sub
pop local 0
goto WHILE_EXP0
label WHILE_END0
push local 3
return
function Math.max 0
push argument 0
push argument 1
gt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 0
pop argument 1
label IF_FALSE0
push argument 1
return
function Math.min 0
push argument 0
push argument 1
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 0
pop argument 1
label IF_FALSE0
push argument 1
return
+63
View File
@@ -0,0 +1,63 @@
// 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 mem;
/** Initializes the class. */
function void init() {
let mem = 0;
let mem[2048] = 14334;
let mem[2049] = -1;
return;
}
/** Returns the RAM value at the given address. */
function int peek(int address) {
return mem[address];
}
/** Sets the RAM value at the given address to the given value. */
function void poke(int address, int value) {
let mem[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 Array current_block;
var int tmp;
let current_block = 2048;
if (size < 0){
do Sys.error(5);
}
if (size = 0){
let size = 1;
}
while (current_block[0] < (size + 2)) {
let current_block = current_block[1];
}
let current_block[0] = current_block[0] - size - 2;
let current_block = current_block + current_block[0] + 2;
let current_block[0] = size;
return current_block + 2;
}
/** De-allocates the given object (cast as an array) by making
* it available for future allocations. */
function void deAlloc(Array o) {
var Array current_block;
let current_block = 2048;
let o[1]= current_block[1];
let current_block[1] = o;
return;
}
}
+147
View File
@@ -0,0 +1,147 @@
function Memory.init 0
push constant 0
pop static 0
push static 0
push constant 2048
push constant 14334
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push static 0
push constant 2049
push constant 1
neg
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 0
return
function Memory.peek 0
push static 0
push argument 0
add
pop pointer 1
push that 0
return
function Memory.poke 0
push static 0
push argument 0
push argument 1
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 0
return
function Memory.alloc 2
push constant 2048
pop local 0
push argument 0
push constant 0
lt
not
if-goto L0
push constant 5
call Sys.error 1
pop temp 0
goto L1
label L0
label L1
push argument 0
push constant 0
eq
not
if-goto L2
push constant 1
pop argument 0
goto L3
label L2
label L3
label L4
push local 0
push constant 0
add
pop pointer 1
push that 0
push argument 0
push constant 2
add
lt
not
if-goto L5
push local 0
push constant 1
add
pop pointer 1
push that 0
pop local 0
goto L4
label L5
push local 0
push constant 0
push local 0
push constant 0
add
pop pointer 1
push that 0
push argument 0
sub
push constant 2
sub
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 0
push local 0
push constant 0
add
pop pointer 1
push that 0
add
push constant 2
add
pop local 0
push local 0
push constant 0
push argument 0
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 0
push constant 2
add
return
function Memory.deAlloc 1
push constant 2048
pop local 0
push argument 0
push constant 1
push local 0
push constant 1
add
pop pointer 1
push that 0
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 0
push constant 1
push argument 0
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 0
return
+183
View File
@@ -0,0 +1,183 @@
// 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 {
/** Test Memory.peek(), poke(), alloc() and deAlloc().
*
* This test is also a diagnostic. RAM[17000] is incremented before and
* after every call so that the failure point can be accurately determined
* when using command line testing. Return values from all alloc() calls
* are also stored in the test results to aid debugging.
*/
function void main() {
var int temp;
var Array a, b, c, out;
let out = 17000; // Address where test results will be stored.
// Test poke() and peek().
let out[0] = 10; // poke test
do Memory.poke(out + 1, 333); // RAM[17001] = 333
let out[0] = 11; // peek test
let temp = Memory.peek(out + 1);
let out[2] = temp + 1; // RAM[17002] = 334
let out[0] = 12; // peek/poke test complete
// Allocate a memory block.
// Validate that the returned block is entirely within the heap,
// Test aborts if the block is not valid.
let out[0] = 20;
let a = Memory.alloc(20);
let out[3] = a; // RAM[17003] = block address
let out[0] = 21;
do Main.checkRange(a, 20);
let out[0] = 22;
// Allocate a SMALLER memory block.
// Validate that the returned block is entirely within the heap,
// and that it does not overlap block 'a'.
// Test aborts if the block is not valid or overlaps.
//
// Common failure: first block was not removed from free list so space
// for this block was found within the first block.
let out[0] = 30;
let b = Memory.alloc(3);
let out[4] = b; // RAM[17004] = block address
let out[0] = 31;
do Main.checkRange(b, 3);
let out[0] = 32;
do Main.checkOverlap(b, 3, a, 3);
let out[0] = 33;
// Allocate a memory block.
// Validate that the returned block is entirely within the heap,
// and that it does not overlap blocks 'a' or 'b'.
// Test aborts if the block is not valid or overlaps.
let out[0] = 40;
let c = Memory.alloc(500);
let out[5] = c; // RAM[17005] = block address
let out[0] = 41;
do Main.checkRange(c, 500);
let out[0] = 42;
do Main.checkOverlap(c, 500, a, 3);
let out[0] = 43;
do Main.checkOverlap(c, 500, b, 3);
let out[0] = 44;
// Deallocate blocks 'a' and 'b', retaining 'c'.
//
// Common failure: free list corrupted by deAlloc().
let out[0] = 50;
do Memory.deAlloc(a);
let out[0] = 51;
do Memory.deAlloc(b);
let out[0] = 52;
// Allocate a memory block.
// Validate that the returned block is entirely within the heap,
// and that it does not overlap blocks 'c'.
// Test aborts if the block is not valid or overlaps.
//
// Common failure: free list corrupted by deAlloc().
let out[0] = 60;
let b = Memory.alloc(3);
let out[6] = b; // RAM[17006] = block address
let out[0] = 61;
do Main.checkRange(b, 3);
let out[0] = 62;
do Main.checkOverlap(b, 3, c, 500);
let out[0] = 63;
// Deallocate blocks 'b' and 'c'.
let out[0] = 70;
do Memory.deAlloc(c);
let out[0] = 71;
do Memory.deAlloc(b);
let out[0] = 72;
// Test that deallocated blocks are placed on the free list and can
// be reused.
let out[0] = 70;
let a = Memory.alloc(8000);
let out[7] = a; // RAM[17007] = block address
let out[0] = 71;
do Main.checkRange(a, 8000);
let out[0] = 72;
do Memory.deAlloc(a);
let out[0] = 73;
let a = Memory.alloc(7000);
let out[0] = 74;
do Main.checkRange(a, 7000);
let out[0] = 75;
do Memory.deAlloc(a);
let out[8] = a; // RAM[17008] = block address
// Test complete.
let out[0] = 100;
// At this point all allocated blocks have been deallocated.
//
// You can inspect the free list and confirm that all of the heap is
// contained in the free segments.
//
// If you implemented defragmentation in dealloc(), the free list
// should contain only one segment, consisting of the entire heap.
return;
}
/** Check that block a(a_len) is in the heap.
*
* If the block begins or ends outside of the heap, calls Sys.halt()
*/
function void checkRange(int a, int a_len) {
var int a_high;
let a_high = (a + a_len)-1;
if ((a < 2048) | ((a_high) > 16383)) {
// Block is not entirely within heap.
do Sys.halt();
}
return;
}
/** Check that block a(a_len) does not overlap block b(b_len).
* Assumes that both blocks have been range checked.
*
* If the blocks overlap, calls Sys.halt()
*/
function void checkOverlap(int a, int a_len, int b, int b_len) {
var int a_high, b_high;
let a_high = (a + a_len)-1;
let b_high = (b + b_len)-1;
if ( ~ ((a > b_high) | (a_high < b))) {
// Block overlaps excluded range.
do Sys.halt();
}
return;
}
}
+467
View File
@@ -0,0 +1,467 @@
function Main.main 5
push constant 17000
pop local 4
push local 4
push constant 0
push constant 10
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 1
add
push constant 333
call Memory.poke 2
pop temp 0
push local 4
push constant 0
push constant 11
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 1
add
call Memory.peek 1
pop local 0
push local 4
push constant 2
push local 0
push constant 1
add
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 12
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 20
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 20
call Memory.alloc 1
pop local 1
push local 4
push constant 3
push local 1
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 21
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
push constant 20
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 22
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 30
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 3
call Memory.alloc 1
pop local 2
push local 4
push constant 4
push local 2
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 31
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
push constant 3
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 32
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
push constant 3
push local 1
push constant 3
call Main.checkOverlap 4
pop temp 0
push local 4
push constant 0
push constant 33
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 40
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 500
call Memory.alloc 1
pop local 3
push local 4
push constant 5
push local 3
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 41
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
push constant 500
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 42
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
push constant 500
push local 1
push constant 3
call Main.checkOverlap 4
pop temp 0
push local 4
push constant 0
push constant 43
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
push constant 500
push local 2
push constant 3
call Main.checkOverlap 4
pop temp 0
push local 4
push constant 0
push constant 44
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 50
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 0
push constant 51
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 0
push constant 52
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 60
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 3
call Memory.alloc 1
pop local 2
push local 4
push constant 6
push local 2
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 61
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
push constant 3
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 62
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
push constant 3
push local 3
push constant 500
call Main.checkOverlap 4
pop temp 0
push local 4
push constant 0
push constant 63
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 70
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 3
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 0
push constant 71
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 2
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 0
push constant 72
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 70
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 8000
call Memory.alloc 1
pop local 1
push local 4
push constant 7
push local 1
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 71
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
push constant 8000
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 72
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 0
push constant 73
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 7000
call Memory.alloc 1
pop local 1
push local 4
push constant 0
push constant 74
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
push constant 7000
call Main.checkRange 2
pop temp 0
push local 4
push constant 0
push constant 75
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 1
call Memory.deAlloc 1
pop temp 0
push local 4
push constant 8
push local 1
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push local 4
push constant 0
push constant 100
pop temp 1
add
pop pointer 1
push temp 1
pop that 0
push constant 0
return
function Main.checkRange 1
push argument 0
push argument 1
add
push constant 1
sub
pop local 0
push argument 0
push constant 2048
lt
push local 0
push constant 16383
gt
or
not
if-goto L0
call Sys.halt 0
pop temp 0
goto L1
label L0
label L1
push constant 0
return
function Main.checkOverlap 2
push argument 0
push argument 1
add
push constant 1
sub
pop local 0
push argument 2
push argument 3
add
push constant 1
sub
pop local 1
push argument 0
push local 1
gt
push local 0
push argument 2
lt
or
not
not
if-goto L2
call Sys.halt 0
pop temp 0
goto L3
label L2
label L3
push constant 0
return
+2
View File
@@ -0,0 +1,2 @@
|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
| 100 | 333 | 334 |*********|*********|*********|*********|*********|*********|
+18
View File
@@ -0,0 +1,18 @@
// 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/MemoryDiag/MemoryDiag.tst
echo "At the end of this test it is normal to see some pixels set on the screen";
load,
output-file MemoryDiag.out,
compare-to MemoryDiag.cmp,
output-list RAM[17000]%D2.6.1 RAM[17001]%D2.6.1 RAM[17002]%D2.6.1
RAM[17003]%D2.6.1 RAM[17004]%D2.6.1 RAM[17005]%D2.6.1 RAM[17006]%D2.6.1
RAM[17007]%D2.6.1 RAM[17008]%D2.6.1;
repeat 1000000 {
vmstep;
}
output;
+55
View File
@@ -0,0 +1,55 @@
<html>
<h4>MemoryDiag is both a pass/fail test and a diagnostic.</h4>
<p>
MemoryDiag tests the following:
<ol>
<li>Memory.peek() and Memory.poke() read from and write to the specified memory address.</li>
<li>Memory.alloc() returns RAM blocks that are fully contained within the heap address range 2048-16383.</li>
<li>Memory.alloc() does not return RAM blocks that overlap each other.</li>
<li>RAM blocks deallocated by Memory.deAlloc() are made available for Memory.alloc() to reuse.</li>
</ol>
The block reuse test allocates and deallocates an 8000 word block. It then tries to allocates a 7000 word block which must be allocated from the deallocated 8000 word block. If the 8000 word block is not available for reuse, there will only be about 6300 words available in the heap so you will get an ERR6.
<p>
<i>At the end of this test it is normal to see some pixels set on the screen.</i> This is because the results of the test are written to RAM[17000]&nbsp;&ndash; RAM[17008] which is in the Screen memory. MemoryDiag does not put its results in the first 16K of RAM because it must not interfere with the Memory.jack that is being tested.
<h4>Using MemoryDiag as a diagnostic</h4>
RAM[17000] is set to a unique value before every system call and address validation. This allows the exact failure location in the test to be identified when automated testing is used. At the end of the test, RAM[17000] is set to 100.
<p>
When the test fails to compare, look at the MemoryDiag.out file and note the RAM[17000] value. This is the test <i>step</i> that failed. Look through the Main.jack code and find the corresponding<br>
&emsp;&emsp;<tt>let out[0] = <i>step</i>;</tt><br>
statement. The function immediately following this statement is where the failure occurred.
<p>
For example, if RAM[17000] is 51, the<br>
&emsp;&emsp;<tt>do Memory.deAlloc(b);</tt><br>
call did not return. Either there was a simulation error like a bad address or deAlloc() got stuck in a loop.
<h4>Sample MemoryDiag output files</h4>
<i>Note that RAM[17003]&nbsp;&ndash; RAM[17008] are "don't care" values in the MemoryDiag.cmp file.</i>
<p>
Supplied Memory.vm passes:
<pre style="padding-left:2em;">
|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
| 100 | 333 | 334 | 2050 | 2072 | 2077 | 2050 | 2050 | 2050 |
</pre>
Memory.Jack using the Coursera implementation passes:
<pre style="padding-left:2em;">
|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
| 100 | 333 | 334 | 16364 | 16359 | 15857 | 15852 | 7850 | 8850 |
</pre>
Broken Memory.jack fails (alloc() returns duplicate block address):
<pre style="padding-left:2em;">
|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
| 32 | 333 | 334 | 2050 | 2050 | 0 | 0 | 0 | 0 |
</pre>
Broken Memory.jack fails (deAlloc() does not recycle memory blocks):
<pre style="padding-left:2em;">
|RAM[17000|RAM[17001|RAM[17002|RAM[17003|RAM[17004|RAM[17005|RAM[17006|RAM[17007|RAM[17008|
| 73 | 333 | 334 | 16364 | 16359 | 15857 | 15852 | 7850 | 0 |
</pre>
</html>
<p>
+2
View File
@@ -0,0 +1,2 @@
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|
| 333 | 334 | 222 | 122 | 100 | 10 |
+2
View File
@@ -0,0 +1,2 @@
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|
| 333 | 334 | 222 | 122 | 100 | 10 |
+15
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/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;
+1852
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
There are some specific wrong values that indicate that your Memory.jack
returned identical pointers to allocated segments. Look at Main.jack to
see where the pointers a, b and c are used.
RAM[8003] = 123 b = a
RAM[8004] = 101 c = a
RAM[8004] = 110 c = b
RAM[8004] = 111 c = a and c = b
RAM[8005] = 11 new b = c
+806
View File
@@ -0,0 +1,806 @@
function Screen.init 1
push constant 16384
pop static 1
push constant 0
not
pop static 2
push constant 17
call Array.new 1
pop static 0
push constant 0
push static 0
add
push constant 1
pop temp 0
pop pointer 1
push temp 0
pop that 0
label WHILE_EXP0
push local 0
push constant 16
lt
not
if-goto WHILE_END0
push local 0
push constant 1
add
pop local 0
push local 0
push static 0
add
push local 0
push constant 1
sub
push static 0
add
pop pointer 1
push that 0
push local 0
push constant 1
sub
push static 0
add
pop pointer 1
push that 0
add
pop temp 0
pop pointer 1
push temp 0
pop that 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Screen.clearScreen 1
label WHILE_EXP0
push local 0
push constant 8192
lt
not
if-goto WHILE_END0
push local 0
push static 1
add
push constant 0
pop temp 0
pop pointer 1
push temp 0
pop that 0
push local 0
push constant 1
add
pop local 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Screen.updateLocation 0
push static 2
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 0
push static 1
add
push argument 0
push static 1
add
pop pointer 1
push that 0
push argument 1
or
pop temp 0
pop pointer 1
push temp 0
pop that 0
goto IF_END0
label IF_FALSE0
push argument 0
push static 1
add
push argument 0
push static 1
add
pop pointer 1
push that 0
push argument 1
not
and
pop temp 0
pop pointer 1
push temp 0
pop that 0
label IF_END0
push constant 0
return
function Screen.setColor 0
push argument 0
pop static 2
push constant 0
return
function Screen.drawPixel 3
push argument 0
push constant 0
lt
push argument 0
push constant 511
gt
or
push argument 1
push constant 0
lt
or
push argument 1
push constant 255
gt
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 7
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
push constant 16
call Math.divide 2
pop local 0
push argument 0
push local 0
push constant 16
call Math.multiply 2
sub
pop local 1
push argument 1
push constant 32
call Math.multiply 2
push local 0
add
pop local 2
push local 2
push local 1
push static 0
add
pop pointer 1
push that 0
call Screen.updateLocation 2
pop temp 0
push constant 0
return
function Screen.drawConditional 0
push argument 2
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push argument 1
push argument 0
call Screen.drawPixel 2
pop temp 0
goto IF_END0
label IF_FALSE0
push argument 0
push argument 1
call Screen.drawPixel 2
pop temp 0
label IF_END0
push constant 0
return
function Screen.drawLine 11
push argument 0
push constant 0
lt
push argument 2
push constant 511
gt
or
push argument 1
push constant 0
lt
or
push argument 3
push constant 255
gt
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 8
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 2
push argument 0
sub
call Math.abs 1
pop local 3
push argument 3
push argument 1
sub
call Math.abs 1
pop local 2
push local 3
push local 2
lt
pop local 6
push local 6
push argument 3
push argument 1
lt
and
push local 6
not
push argument 2
push argument 0
lt
and
or
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push argument 0
pop local 4
push argument 2
pop argument 0
push local 4
pop argument 2
push argument 1
pop local 4
push argument 3
pop argument 1
push local 4
pop argument 3
label IF_FALSE1
push local 6
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 3
pop local 4
push local 2
pop local 3
push local 4
pop local 2
push argument 1
pop local 1
push argument 0
pop local 0
push argument 3
pop local 8
push argument 0
push argument 2
gt
pop local 7
goto IF_END2
label IF_FALSE2
push argument 0
pop local 1
push argument 1
pop local 0
push argument 2
pop local 8
push argument 1
push argument 3
gt
pop local 7
label IF_END2
push constant 2
push local 2
call Math.multiply 2
push local 3
sub
pop local 5
push constant 2
push local 2
call Math.multiply 2
pop local 9
push constant 2
push local 2
push local 3
sub
call Math.multiply 2
pop local 10
push local 1
push local 0
push local 6
call Screen.drawConditional 3
pop temp 0
label WHILE_EXP0
push local 1
push local 8
lt
not
if-goto WHILE_END0
push local 5
push constant 0
lt
if-goto IF_TRUE3
goto IF_FALSE3
label IF_TRUE3
push local 5
push local 9
add
pop local 5
goto IF_END3
label IF_FALSE3
push local 5
push local 10
add
pop local 5
push local 7
if-goto IF_TRUE4
goto IF_FALSE4
label IF_TRUE4
push local 0
push constant 1
sub
pop local 0
goto IF_END4
label IF_FALSE4
push local 0
push constant 1
add
pop local 0
label IF_END4
label IF_END3
push local 1
push constant 1
add
pop local 1
push local 1
push local 0
push local 6
call Screen.drawConditional 3
pop temp 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Screen.drawRectangle 9
push argument 0
push argument 2
gt
push argument 1
push argument 3
gt
or
push argument 0
push constant 0
lt
or
push argument 2
push constant 511
gt
or
push argument 1
push constant 0
lt
or
push argument 3
push constant 255
gt
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 9
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
push constant 16
call Math.divide 2
pop local 3
push argument 0
push local 3
push constant 16
call Math.multiply 2
sub
pop local 7
push argument 2
push constant 16
call Math.divide 2
pop local 4
push argument 2
push local 4
push constant 16
call Math.multiply 2
sub
pop local 8
push local 7
push static 0
add
pop pointer 1
push that 0
push constant 1
sub
not
pop local 6
push local 8
push constant 1
add
push static 0
add
pop pointer 1
push that 0
push constant 1
sub
pop local 5
push argument 1
push constant 32
call Math.multiply 2
push local 3
add
pop local 0
push local 4
push local 3
sub
pop local 2
label WHILE_EXP0
push argument 1
push argument 3
gt
not
not
if-goto WHILE_END0
push local 0
push local 2
add
pop local 1
push local 2
push constant 0
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
push local 5
push local 6
and
call Screen.updateLocation 2
pop temp 0
goto IF_END1
label IF_FALSE1
push local 0
push local 6
call Screen.updateLocation 2
pop temp 0
push local 0
push constant 1
add
pop local 0
label WHILE_EXP1
push local 0
push local 1
lt
not
if-goto WHILE_END1
push local 0
push constant 1
neg
call Screen.updateLocation 2
pop temp 0
push local 0
push constant 1
add
pop local 0
goto WHILE_EXP1
label WHILE_END1
push local 1
push local 5
call Screen.updateLocation 2
pop temp 0
label IF_END1
push argument 1
push constant 1
add
pop argument 1
push local 1
push constant 32
add
push local 2
sub
pop local 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Screen.drawHorizontal 11
push argument 1
push argument 2
call Math.min 2
pop local 7
push argument 1
push argument 2
call Math.max 2
pop local 8
push argument 0
push constant 1
neg
gt
push argument 0
push constant 256
lt
and
push local 7
push constant 512
lt
and
push local 8
push constant 1
neg
gt
and
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push local 7
push constant 0
call Math.max 2
pop local 7
push local 8
push constant 511
call Math.min 2
pop local 8
push local 7
push constant 16
call Math.divide 2
pop local 1
push local 7
push local 1
push constant 16
call Math.multiply 2
sub
pop local 9
push local 8
push constant 16
call Math.divide 2
pop local 2
push local 8
push local 2
push constant 16
call Math.multiply 2
sub
pop local 10
push local 9
push static 0
add
pop pointer 1
push that 0
push constant 1
sub
not
pop local 5
push local 10
push constant 1
add
push static 0
add
pop pointer 1
push that 0
push constant 1
sub
pop local 4
push argument 0
push constant 32
call Math.multiply 2
push local 1
add
pop local 0
push local 2
push local 1
sub
pop local 6
push local 0
push local 6
add
pop local 3
push local 6
push constant 0
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
push local 4
push local 5
and
call Screen.updateLocation 2
pop temp 0
goto IF_END1
label IF_FALSE1
push local 0
push local 5
call Screen.updateLocation 2
pop temp 0
push local 0
push constant 1
add
pop local 0
label WHILE_EXP0
push local 0
push local 3
lt
not
if-goto WHILE_END0
push local 0
push constant 1
neg
call Screen.updateLocation 2
pop temp 0
push local 0
push constant 1
add
pop local 0
goto WHILE_EXP0
label WHILE_END0
push local 3
push local 4
call Screen.updateLocation 2
pop temp 0
label IF_END1
label IF_FALSE0
push constant 0
return
function Screen.drawSymetric 0
push argument 1
push argument 3
sub
push argument 0
push argument 2
add
push argument 0
push argument 2
sub
call Screen.drawHorizontal 3
pop temp 0
push argument 1
push argument 3
add
push argument 0
push argument 2
add
push argument 0
push argument 2
sub
call Screen.drawHorizontal 3
pop temp 0
push argument 1
push argument 2
sub
push argument 0
push argument 3
sub
push argument 0
push argument 3
add
call Screen.drawHorizontal 3
pop temp 0
push argument 1
push argument 2
add
push argument 0
push argument 3
sub
push argument 0
push argument 3
add
call Screen.drawHorizontal 3
pop temp 0
push constant 0
return
function Screen.drawCircle 3
push argument 0
push constant 0
lt
push argument 0
push constant 511
gt
or
push argument 1
push constant 0
lt
or
push argument 1
push constant 255
gt
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 12
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
push argument 2
sub
push constant 0
lt
push argument 0
push argument 2
add
push constant 511
gt
or
push argument 1
push argument 2
sub
push constant 0
lt
or
push argument 1
push argument 2
add
push constant 255
gt
or
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push constant 13
call Sys.error 1
pop temp 0
label IF_FALSE1
push argument 2
pop local 1
push constant 1
push argument 2
sub
pop local 2
push argument 0
push argument 1
push local 0
push local 1
call Screen.drawSymetric 4
pop temp 0
label WHILE_EXP0
push local 1
push local 0
gt
not
if-goto WHILE_END0
push local 2
push constant 0
lt
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 2
push constant 2
push local 0
call Math.multiply 2
add
push constant 3
add
pop local 2
goto IF_END2
label IF_FALSE2
push local 2
push constant 2
push local 0
push local 1
sub
call Math.multiply 2
add
push constant 5
add
pop local 2
push local 1
push constant 1
sub
pop local 1
label IF_END2
push local 0
push constant 1
add
pop local 0
push argument 0
push argument 1
push local 0
push local 1
call Screen.drawSymetric 4
pop temp 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
+393
View File
@@ -0,0 +1,393 @@
function String.new 0
push constant 3
call Memory.alloc 1
pop pointer 0
push argument 0
push constant 0
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 14
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 0
push constant 0
gt
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push argument 0
call Array.new 1
pop this 1
label IF_FALSE1
push argument 0
pop this 0
push constant 0
pop this 2
push pointer 0
return
function String.dispose 0
push argument 0
pop pointer 0
push this 0
push constant 0
gt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push this 1
call Array.dispose 1
pop temp 0
label IF_FALSE0
push pointer 0
call Memory.deAlloc 1
pop temp 0
push constant 0
return
function String.length 0
push argument 0
pop pointer 0
push this 2
return
function String.charAt 0
push argument 0
pop pointer 0
push argument 1
push constant 0
lt
push argument 1
push this 2
gt
or
push argument 1
push this 2
eq
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 15
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 1
push this 1
add
pop pointer 1
push that 0
return
function String.setCharAt 0
push argument 0
pop pointer 0
push argument 1
push constant 0
lt
push argument 1
push this 2
gt
or
push argument 1
push this 2
eq
or
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 16
call Sys.error 1
pop temp 0
label IF_FALSE0
push argument 1
push this 1
add
push argument 2
pop temp 0
pop pointer 1
push temp 0
pop that 0
push constant 0
return
function String.appendChar 0
push argument 0
pop pointer 0
push this 2
push this 0
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 17
call Sys.error 1
pop temp 0
label IF_FALSE0
push this 2
push this 1
add
push argument 1
pop temp 0
pop pointer 1
push temp 0
pop that 0
push this 2
push constant 1
add
pop this 2
push pointer 0
return
function String.eraseLastChar 0
push argument 0
pop pointer 0
push this 2
push constant 0
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 18
call Sys.error 1
pop temp 0
label IF_FALSE0
push this 2
push constant 1
sub
pop this 2
push constant 0
return
function String.intValue 5
push argument 0
pop pointer 0
push this 2
push constant 0
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 0
return
label IF_FALSE0
push constant 0
not
pop local 3
push constant 0
push this 1
add
pop pointer 1
push that 0
push constant 45
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push constant 0
not
pop local 4
push constant 1
pop local 0
label IF_FALSE1
label WHILE_EXP0
push local 0
push this 2
lt
push local 3
and
not
if-goto WHILE_END0
push local 0
push this 1
add
pop pointer 1
push that 0
push constant 48
sub
pop local 2
push local 2
push constant 0
lt
push local 2
push constant 9
gt
or
not
pop local 3
push local 3
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 1
push constant 10
call Math.multiply 2
push local 2
add
pop local 1
push local 0
push constant 1
add
pop local 0
label IF_FALSE2
goto WHILE_EXP0
label WHILE_END0
push local 4
if-goto IF_TRUE3
goto IF_FALSE3
label IF_TRUE3
push local 1
neg
pop local 1
label IF_FALSE3
push local 1
return
function String.setInt 4
push argument 0
pop pointer 0
push this 0
push constant 0
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 19
call Sys.error 1
pop temp 0
label IF_FALSE0
push constant 6
call Array.new 1
pop local 2
push argument 1
push constant 0
lt
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push constant 0
not
pop local 3
push argument 1
neg
pop argument 1
label IF_FALSE1
push argument 1
pop local 1
label WHILE_EXP0
push local 1
push constant 0
gt
not
if-goto WHILE_END0
push argument 1
push constant 10
call Math.divide 2
pop local 1
push local 0
push local 2
add
push constant 48
push argument 1
push local 1
push constant 10
call Math.multiply 2
sub
add
pop temp 0
pop pointer 1
push temp 0
pop that 0
push local 0
push constant 1
add
pop local 0
push local 1
pop argument 1
goto WHILE_EXP0
label WHILE_END0
push local 3
if-goto IF_TRUE2
goto IF_FALSE2
label IF_TRUE2
push local 0
push local 2
add
push constant 45
pop temp 0
pop pointer 1
push temp 0
pop that 0
push local 0
push constant 1
add
pop local 0
label IF_FALSE2
push this 0
push local 0
lt
if-goto IF_TRUE3
goto IF_FALSE3
label IF_TRUE3
push constant 19
call Sys.error 1
pop temp 0
label IF_FALSE3
push local 0
push constant 0
eq
if-goto IF_TRUE4
goto IF_FALSE4
label IF_TRUE4
push constant 0
push this 1
add
push constant 48
pop temp 0
pop pointer 1
push temp 0
pop that 0
push constant 1
pop this 2
goto IF_END4
label IF_FALSE4
push constant 0
pop this 2
label WHILE_EXP1
push this 2
push local 0
lt
not
if-goto WHILE_END1
push this 2
push this 1
add
push local 0
push this 2
push constant 1
add
sub
push local 2
add
pop pointer 1
push that 0
pop temp 0
pop pointer 1
push temp 0
pop that 0
push this 2
push constant 1
add
pop this 2
goto WHILE_EXP1
label WHILE_END1
label IF_END4
push local 2
call Array.dispose 1
pop temp 0
push constant 0
return
function String.newLine 0
push constant 128
return
function String.backSpace 0
push constant 129
return
function String.doubleQuote 0
push constant 34
return
+83
View File
@@ -0,0 +1,83 @@
function Sys.init 0
call Memory.init 0
pop temp 0
call Math.init 0
pop temp 0
call Screen.init 0
pop temp 0
call Output.init 0
pop temp 0
call Keyboard.init 0
pop temp 0
call Main.main 0
pop temp 0
call Sys.halt 0
pop temp 0
push constant 0
return
function Sys.halt 0
label WHILE_EXP0
push constant 0
not
not
if-goto WHILE_END0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Sys.wait 1
push argument 0
push constant 0
lt
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push constant 1
call Sys.error 1
pop temp 0
label IF_FALSE0
label WHILE_EXP0
push argument 0
push constant 0
gt
not
if-goto WHILE_END0
push constant 50
pop local 0
label WHILE_EXP1
push local 0
push constant 0
gt
not
if-goto WHILE_END1
push local 0
push constant 1
sub
pop local 0
goto WHILE_EXP1
label WHILE_END1
push argument 0
push constant 1
sub
pop argument 0
goto WHILE_EXP0
label WHILE_END0
push constant 0
return
function Sys.error 0
push constant 69
call Output.printChar 1
pop temp 0
push constant 82
call Output.printChar 1
pop temp 0
push constant 82
call Output.printChar 1
pop temp 0
push argument 0
call Output.printInt 1
pop temp 0
call Sys.halt 0
pop temp 0
push constant 0
return
Binary file not shown.
Binary file not shown.
Binary file not shown.