Fixing Bugs with MARIE.js Explained - MARIE-js/MARIE.js GitHub Wiki
Synopsis
This page talks about how to go about solving multiple important and critical issues found in MARIE.js
Bug 148 - Memory Cell Overflow Bug
This bug occurs when the user tries to jump to an address beyond the address range of 0 to 4096.
For example, the following code would break the simulator, and crash the webpage.
LoadI X
X, DEC 4097
All we did was check if the values passed to PC
is beyond the address range or not:
if(target == "pc"){
if(this[target] < 0 || this[target] >= 4096){
throw new MarieSimError("RuntimeError", ...);
}
}
from marie.js: RegSet
Bug 169 - Overflow Bug
Well, the second biggest bug solved was the calculation overflow bug, this occurs when the number goes beyond the range. So to determine the range you have to do the following:
- Calculate the amount of numbers between the range (0 to HEX FFFF), there are
16^4
possibilities which give 65536 numbers - Find the 'middle point', this gives us
65536/2
which is32768
- We know that MARIE uses 2nd-Complement, which means that between -32768 to 0 and 0 to 32767 are calculable. Using the concept from bug #148, we can apply it here to
if(this[target] < -32768 || this[target] > 32767){
throw new MarieSimError("RuntimeError", ...);
}
from marie.js: RegSet