Tools: Updated OS Memory.vm and Memory.class files

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Tools: Updated OS Memory.vm and Memory.class files

cadet1620
Administrator
Contributed by Mark Armbrust
27 Sept 2015
Copy this file to your  nand2tetris/tools/OS  directory.
  Memory.vm
Copy this file to your  nand2tetris/tools/builtInVMCode  directory.
  Memory.class

These files correct a bug in Memory.alloc() that causes ERR5 in some Jack programs.

ERR5 is documented as "Allocated memory size must be positive". The problem is that the VM code written by JackCompiler calls Memory.alloc(0) when a class with no field variables is constructed.

This fix allows zero length memory blocks to be allocated. The meaning of ERR5 is changed to "Allocated memory size must be non-negative".

See this forum thread for details about the bug and the code change.