Skip to content

Commit

Permalink
Merge pull request #5 from MARIE-js/master
Browse files Browse the repository at this point in the history
Update my fork so that I can update Google APIs credentials
  • Loading branch information
auroranil authored Aug 25, 2020
2 parents c02f218 + 49bfc7e commit 84d28ad
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/MARIE-js/MARIE.js.svg?branch=master)](https://travis-ci.org/MARIE-js/MARIE.js) [![Gitter chat](https://badges.gitter.im/MARIE-js/gitter.png)](https://gitter.im/MARIE-js/Lobby) [![npm version](https://badge.fury.io/js/npm.svg)](https://badge.fury.io/js/npm)
==============
Current version: `1.2.0`
Current version: `1.3.0`

MARIE.js is an implementation of a simulator for a 'Machine Architecture that is Really Intuitive and Easy'
from [The Essentials of Computer Organization and Architecture](https://books.google.com.au/books/about/The_Essentials_of_Computer_Organization.html?id=3kQoAwAAQBAJ&redir_esc=y) (Linda Null, Julia Lobur) in JavaScript.
Expand Down
4 changes: 2 additions & 2 deletions build/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<main>
<div id="about" class="container">
<h1 class="center">MARIE.js <span class="version">v1.2.0</span></h1>
<h1 class="center">MARIE.js <span class="version">v1.3.0</span></h1>
<h2>About MARIE</h2>
<p>MARIE ('Machine Architecture that is Really Intuitive and Easy') is a machine architecture and assembly language from <a href="https://books.google.com.au/books/about/The_Essentials_of_Computer_Organization.html?id=3kQoAwAAQBAJ&redir_esc=y" target="_blank">The Essentials of Computer Organization and Architecture</a> (Linda Null, Julia Lobur). The publisher provides a set of <a href="http://computerscience.jbpub.com/ecoa/3e/simulators.aspx">simulators for the machine</a>, written in Java. However, since using simulators can be rather difficult, we have implemented a web-based version, so that students are able to access it readily and easily. Since beginning the project we have added many features such as importing and exporting of Marie Assembly Source files (*.mas) to provide compatibility with the existing simulators.</p>
<br>
Expand Down Expand Up @@ -133,7 +133,7 @@ <h2>License</h2>
<h4 class="modal-title"> MARIE.js | <i class="fa fa-hashtag"></i> Current Version</h4>
</div>
<div class="modal-body">
<p>This version of <strong>MARIE.js</strong> is: v1.2.0</p>
<p>This version of <strong>MARIE.js</strong> is: v1.3.0</p>
</div>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<li><a href="./?addition"><span class="fa fa-plus"></span> Addition</a></li>
<li><a href="./?multiply"><span class="fa fa-times"></span> Multiply</a></li>
<li><a href="./?quicksort"><span class="fa fa-sort"></span> Quicksort</a></li>
<li><a href="./?unicode"><span class="fa fa-font"></span> Unicode</a></li>
</ul>
</li>
<li class="dropdown">
Expand Down Expand Up @@ -216,7 +217,7 @@
<select id="output-select" class="output-type">
<option>HEX</option>
<option>DEC</option>
<option>UNICODE</option>
<option>UNICODE (UTF-16BE)</option>
<option>BIN</option>
</select>
<hr>
Expand All @@ -242,7 +243,7 @@
<select id="input-list-select" class="output-type">
<option>HEX</option>
<option>DEC</option>
<option>UNICODE</option>
<option>UNICODE (UTF-16BE)</option>
<option>BIN</option>
</select>
</div>
Expand Down Expand Up @@ -335,7 +336,7 @@ <h4>Input Value</h4>
<h4 class="modal-title">MARIE.js | <i class="fa fa-hashtag"></i> Current Version</h4>
</div>
<div class="modal-body">
<p>This version of <strong>MARIE.js</strong> is: v1.2.0</p>
<p>This version of <strong>MARIE.js</strong> is: v1.3.0</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MARIE.js",
"version": "1.2.0",
"version": "1.3.0",
"description": "MARIE.js is an implementation of a simulator for a 'Machine Architecture that is Really Intuitive and Easy' from The Essentials of Computer Organization and Architecture (Linda Null, Julia Lobur) in JavaScript.",
"main": "main.js",
"scripts": {
Expand Down
55 changes: 46 additions & 9 deletions src/code/multiply.mas
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,67 @@
/ Copyright (C) 2016. Licensed under the MIT License

/ Prompt user to type in integers
INPUT
Clear
Store result
Input
Store X
INPUT
Input
Store Y

/ check if Y is negative, if -ve negate Y and set negative flag
Load Y
Skipcond 000
Jump nonneg

Subt Y
Subt Y
Store Y
Clear
Add one
Store negflag
Clear
Jump loop

nonneg, Clear
Store negflag
/ check if Y is zero, if it is, then we jump to halt
Load Y
Skipcond 400
Jump loop / false
Jump halt / true

/ Loop for performing iterative addition
loop, Load num
loop, Load result
Add X
Store num
Store result

Load Y
Subt one
Store Y

Skipcond 400 / have we completed the multiplication?
Jump loop / no; repeat loop
/ yes, so exit the loop

/ check for negative flag, if it is set, negate the result
Load negflag
Skipcond 800
Jump halt

/ negate result
Load result
Subt result
Subt result
Store result
/ run the next three instructions, which halts the program

/ Output result to user then halt program
Load num
Output
Halt
halt, Load result
Output
Halt

X, DEC 0
Y, DEC 0
num, DEC 0
one, DEC 1
negflag, DEC 0
result, DEC 0
63 changes: 63 additions & 0 deletions src/code/unicode.mas
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/ Unicode (UTF-16BE) Demo
/ by the MARIE.js Team
/ Copyright (C) 2020. Licensed under the MIT License

LOOP, Load PTR
/ output word
LoadI PTR
Output

/ increment pointer
Load PTR
Add ONE
Store PTR

/ increment counter
Load CTR
Add ONE
Store CTR

/ check whether all words have been processed and halt if so
Subt WORDS
Skipcond 400
Jump LOOP
Halt

ONE, DEC 1
CTR, DEC 0
WORDS, DEC 19

/ initialize pointer to words
PTR, ADR S

/ ouput data
/ "Hello World!"
S, HEX 48
HEX 45
HEX 4C
HEX 4C
HEX 4F
HEX 20
HEX 57
HEX 4F
HEX 52
HEX 4C
HEX 44
HEX 21

/ Smiley (outside of the Basic Multilingual Plane)
HEX D83D
HEX DE42

/ Byte Order Mark, big-endian (ignored)
HEX FEFF

/ Byte Order Mark, little-endian (ignored)
HEX FFFE

/ Inverted Smiley (outside of the BMP)
HEX D83D
HEX DE43

/ Copyright Sign (inside the BMP)
HEX A9
1 change: 0 additions & 1 deletion src/css/styleDark.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ button[disabled=disabled], button:disabled {
}

.output-type {
width:100px;
text-align: right;
color: inherit;
bottom:100%;
Expand Down
1 change: 0 additions & 1 deletion src/css/styleLight.css
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ codeblock {
}

.output-type {
width:100px;
text-align: right;
background-color: inherit;
color: inherit;
Expand Down
68 changes: 62 additions & 6 deletions src/js/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ window.addEventListener("load", function() {
}

function convertOutput(value) {
// Unicode UTF-16BE characters outside the Basic Multilingual Plane
// are encoded using a 2-word sequence called a surrogate pair.
// Assuming network byte order, i.e. a big-endian encoding,
// the high surrogate comes first in the output stream,
// and then comes the low surrogate.
// Since we assume network byte order, we can legally ignore Byte Order
// Markers according to the Unicode standard.
if( convertOutput.highSurrogate === undefined ) {
convertOutput.highSurrogate = 0;
}
switch(outputType) {
case HEX:
return document.createTextNode(Utility.hex(value));
Expand All @@ -455,12 +465,53 @@ window.addEventListener("load", function() {
case UNICODE:
if (value===10) {
return document.createElement("br");
} else {
return document.createTextNode(String.fromCharCode(value));
}
if(value >= -10240 && value <= -9217) {
// start of a valid UTF-16BE surrogate pair
// high surrogates are in the range of 0xD800 - 0xDBFF
// converted to 16-bit two's complement integers,
// this yields the negative number range from
// -10240 to -9217
convertOutput.highSurrogate = value;
return null;
}
if (convertOutput.highSurrogate === 0 &&
value >= -9216 && value <= -8193) {
// low surrogate without high surrogate
// invalid UTF-16BE sequence
// low surrogates are in the range of 0xDC00 - 0xDFFF
// converted to 16-bit two's complement integers,
// this yields the negative number range from
// -9216 to -8193
return null;
}
if (convertOutput.highSurrogate != 0 &&
value >= -9216 && value <= -8193) {
// valid UTF-16BE surrogate pair
var output = String.fromCharCode(convertOutput.highSurrogate, value);
convertOutput.highSurrogate = 0;
return document.createTextNode(output);
}
if (convertOutput.highSurrogate != 0 &&
!(value >= -9216 && value <= -8193)) {
// high surrogate without low surrogate
// invalid UTF-16BE sequence
convertOutput.highSurrogate = 0;
return null;
}
if (value === -2 || value === -257) {
// Byte Order Mark (0xFFFE or 0xFEFF), ignore
// 0xFFFE converted to 16-bit two's complement integer
// is -2,
// 0xFEFF converted to 16-bit two's complement integer
// is -257
return null;
}
// character is in the Basic Multilingual Plane
return document.createTextNode(String.fromCharCode(value));
break;
case BIN:
return document.createTextNode(Utility.uintToBinGroup(value, 16, prefs.binaryStringGroupLength));
return document.createTextNode(Utility.intToBinGroup(value, 16, prefs.binaryStringGroupLength));
default:
return document.createTextNode("Invalid output type.");
}
Expand All @@ -472,7 +523,10 @@ window.addEventListener("load", function() {
}

for(var i = 0; i < outputList.length; i++) {
outputLog.appendChild(convertOutput(outputList[i]));
var element = convertOutput(outputList[i]);
if (element != null) {
outputLog.appendChild(element);
}
if (outputType!==UNICODE) {
outputLog.appendChild(document.createElement("br"));
}
Expand Down Expand Up @@ -788,8 +842,10 @@ window.addEventListener("load", function() {
var shouldScrollToBottomOutputLog = outputLog.getAttribute("data-stick-to-bottom") == "true";

outputList.push(value);

outputLog.appendChild(convertOutput(value));
var element = convertOutput(value);
if (element != null) {
outputLog.appendChild(element);
}
if (outputType!==UNICODE) {
outputLog.appendChild(document.createElement("br"));
}
Expand Down
45 changes: 45 additions & 0 deletions src/js/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ var Utility = {};
return binArray;
};

/**
* Converts a signed integer in *size*-bit two's-complement format
* into an array of binary numbers.
* @memberof Utility
*
* @param {Number} num - the signed integer to be converted.
* @param {Number} size - size of the signed integer.
* @returns {Array} the binary array representation of signed integer.
*/
Utility.intToBinArray = function(num, size) {
var binArray = [];
for(var i=0; i<size; i++){
binArray.push(num & 1);
num >>= 1;
}

binArray.reverse();

return binArray;
};

/**
* Converts an unsigned integer into an array of
Expand Down Expand Up @@ -61,6 +81,31 @@ var Utility = {};
return binString;
};

/**
* Converts a signed integer in *size*-bit two's complement format
* into an array of binary numbers, and then converts into a bit string
* with even spacing between each group of binary digits.
* @memberof Utility
*
* @param {Number} num - The unsigned integer to be converted.
* @param {Number} size - Size of the signed integer.
* @param {Number} bitSize - The length of each bit group.
* @returns {String} The binary array representation of signed integer.
*/
Utility.intToBinGroup = function(num, size, bitSize) {
var binArray = Utility.intToBinArray(num, size);
var binString = "";

for (var i = 0; i < size; i++) {
binString += binArray[i];

if(i % bitSize == bitSize - 1){
binString += " ";
}
}

return binString;
};

/**
* Converts signed integer into unsigned integer.
Expand Down
Loading

0 comments on commit 84d28ad

Please sign in to comment.