Last active
February 18, 2024 17:59
-
-
Save mathewmariani/91f471422c4ac0b5ee37 to your computer and use it in GitHub Desktop.
https://github.com/mathewmariani/MARIE-Examples. Please feel free to email me if you have any questions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 | |
LOAD X / LOAD X into AC | |
ADD Y / ADD Y to AC | |
STORE Z / STORE AC in Z | |
LOAD Z / LOAD Z into AC | |
OUTPUT / OUTPUT AC | |
X, DEC 1 / variable declaration | |
Y, DEC 2 / variable declaration | |
Z, DEC 0 / variable declaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 | |
Cond, LOAD COUNT / LOAD count into AC | |
SUBT ARRAY / SUBTRACT array[0] from AC | |
SKIPCOND 000 / Skipcond 000 if AC < 0 | |
JUMP End / JUMP to End | |
Loop, LOAD COUNT / LOAD Count into AC | |
ADD ONE / ADD ONE to AC | |
STORE COUNT / STORE AC into COUNT | |
LOADI INDEX / LOAD MEM[index] into AC | |
OUTPUT / OUTPUT value at index | |
LOAD INDEX | |
ADD ONE | |
STORE INDEX | |
JUMP Cond / JUMP to Cond | |
End, LOAD START / LOAD start into AC | |
STORE INDEX / STORE AC into index | |
HALT / HALT process | |
INDEX, HEX 013 / Our current memory location | |
START, HEX 013 / The memory location of our first value (in hex) | |
ARRAY, DEC 5 / The first index of our array (used for size) | |
DEC 0 / index 0 | |
DEC 2 / index 1 | |
DEC 4 / index 2 | |
DEC 8 / index 3 | |
DEC 16 / index 4 | |
COUNT, DEC 0 | |
/ constant values | |
ZERO, DEC 0 | |
ONE, DEC 1 | |
TWO, DEC 2 | |
THREE, DEC 3 | |
FOUR, DEC 4 | |
FIVE, DEC 5 | |
SIX, DEC 6 | |
SEVEN, DEC 7 | |
EIGHT, DEC 8 | |
NINE, DEC 9 | |
TEN, DEC 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 | |
Cond, LOAD COUNT / Load count into AC | |
SUBT TEN / Remove 10 from count | |
SKIPCOND 000 / Skipcond 000 if AC < 0 | |
JUMP End / End Loop | |
Loop, LOAD COUNT / Load count into AC | |
ADD ONE / Increment Count by 1 | |
STORE COUNT / Store AC in count | |
JNS Fibb | |
JUMP Cond / Check loop conditions | |
Fibb, HEX 000 / Store value for JNS | |
CLEAR / AC = 0 | |
/ Fi = F1 + F2 | |
ADD F1 / AC + F1 | |
ADD F2 / AC + F2 | |
STORE Fi / Fi = AC | |
/ F1 = F2 | |
LOAD F2 / AC = F2 | |
STORE F1 / F1 = AC | |
/ F2 = Fi | |
LOAD Fi / AC = Fi | |
STORE F2 / F2 = AC | |
/ Quick Output | |
LOAD Fi / AC = FI | |
OUTPUT / Output AC | |
JUMPI Fibb | |
End, HALT / Halt process | |
/ variables | |
COUNT, DEC 0 / count for loop | |
Fi, DEC 0 | |
F1, DEC 0 | |
F2, DEC 1 | |
/ constant values | |
ZERO, DEC 0 | |
ONE, DEC 1 | |
TWO, DEC 2 | |
THREE, DEC 3 | |
FOUR, DEC 4 | |
FIVE, DEC 5 | |
SIX, DEC 6 | |
SEVEN, DEC 7 | |
EIGHT, DEC 8 | |
NINE, DEC 9 | |
TEN, DEC 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ This program presents a simple add(a, b) function. | |
/ #L8-9 Sets the argument `add_a` for the add function. | |
/ #L10-11 Sets the argument `add_b` for the add function. | |
/ #L12 Calls the add function using JNS which stores the current PC to be used as a callback | |
/ #L21 Indirectly jumps back to where the function was called from. | |
ORG 0 | |
LOAD X | |
STORE add_a | |
LOAD Y | |
STORE add_b | |
JNS add | |
OUTPUT | |
HALT | |
add_a, DEC 0 | |
add_b, DEC 0 | |
add, HEX 0 | |
LOAD add_a | |
ADD add_b | |
JUMPI add | |
/ variables | |
X, DEC 1 | |
Y, DEC 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 / implemented using "do while" loop | |
WHILE, LOAD STR_BASE / load str_base into ac | |
ADD ITR / add index to str_base | |
STORE INDEX / store (str_base + index) into ac | |
CLEAR / set ac to zero | |
ADDI INDEX / get the value at ADDR | |
SKIPCOND 400 / SKIP if ADDR = 0 (or null char) | |
JUMP DO / jump to DO | |
JUMP END / JUMP to END | |
DO, OUTPUT / output value at ADDR | |
LOAD ITR / load iterator into ac | |
ADD ONE / increment iterator by one | |
STORE ITR / store ac in iterator | |
JUMP WHILE / jump to while | |
END, HALT | |
ONE, DEC 1 | |
ITR, DEC 0 | |
INDEX, HEX 0 | |
STR_BASE, HEX 12 / memory location of str | |
STR, HEX 48 / H | |
HEX 65 / E | |
HEX 6C / L | |
HEX 6C / L | |
HEX 6F / O | |
HEX D / carriage return | |
HEX 57 / W | |
HEX 6F / O | |
HEX 72 / R | |
HEX 6C / L | |
HEX 64 / D | |
HEX 0 / NULL char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ #L10 Is beginning of an if control block, where an the value of an expression is determined. | |
/ In this case were comparing `EXP` to 0. | |
/ #L14 Is the body of the if statement, we output `IVALUE` and `JUMP` to `end`. | |
/ We `JUMP` to avoid running code from `else`. | |
/ #L18 Is the body of the else statement, we output `EVALUE` and continue running the program. | |
/ Unlike the body of the if statment we don't need to `JUMP`; instead we can continue. | |
/ #L11 If `EXP` is not 0 then then SKIPCOND will not skip over #L12 forcing a `JUMP`. | |
ORG 0 | |
if, LOAD EXP / LOAD EXP into AC | |
SKIPCOND 400 / SKIPCOND 400 (if AC = 0) | |
JUMP else / JUMP to `else` | |
LOAD IVALUE / LOAD IVALUE into AC | |
OUTPUT / OUTPUT value IVALUE | |
JUMP end / JUMP to `end` | |
else, LOAD EVALUE / LOAD IVALUE into AC | |
OUTPUT / OUTPUT value IVALUE | |
end, HALT / HALT | |
/ variables | |
EXP, DEC 1 | |
IVALUE, DEC 2 | |
EVALUE, DEC 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 / implemented using a "for" loop | |
Cond, LOAD COUNT / LOAD count into AC | |
SUBT TEN / SUBTRACT 10 from AC | |
SKIPCOND 000 / Skipcond 000 if AC < 0 | |
JUMP End / JUMP to End | |
Loop, LOAD COUNT / LOAD Count into AC | |
ADD ONE / ADD ONE to AC | |
STORE COUNT / STORE AC into COUNT | |
LOAD COUNT / LOAD count into AC | |
OUTPUT / OUTPUT AC | |
JUMP Cond / JUMP to Cond | |
End, HALT / HALT process | |
COUNT, DEC 0 | |
/ constant values | |
ZERO, DEC 0 | |
ONE, DEC 1 | |
TWO, DEC 2 | |
THREE, DEC 3 | |
FOUR, DEC 4 | |
FIVE, DEC 5 | |
SIX, DEC 6 | |
SEVEN, DEC 7 | |
EIGHT, DEC 8 | |
NINE, DEC 9 | |
TEN, DEC 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 | |
LOAD X / LOAD X into AC | |
SUBT Y / SUBTRACT Y from AC | |
STORE Z / STORE AC in Z | |
LOADZ / LOAD Z into AC | |
OUTPUT / OUTPUT AC | |
X, DEC 2 / variable declaration | |
Y, DEC 1 / variable declaration | |
Z, DEC 0 / variable declaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ This program presents a simple tolower(ptr) function. | |
/ #L8-9 Sets the argument `str_ptr` for the tolower function. | |
/ #L10 Calls the tolower function. | |
/ #L27 Adds the offset between upper and lower case letters on ascii table. | |
/ 0x41 ('A') 0x61 ('a') --> 0x20 | |
ORG 0 | |
LOAD str_ptr | |
STORE tolower_ptr | |
JNS tolower | |
HALT | |
tolower_itr, DEC 0 | |
tolower_ptr, HEX 0 | |
tolower_idx, HEX 0 | |
tolower_offset, HEX 20 | |
tolower, HEX 0 | |
tolower_while, LOAD tolower_ptr | |
ADD tolower_itr | |
STORE tolower_idx | |
CLEAR | |
ADDI tolower_idx | |
SKIPCOND 400 | |
JUMP tolower_do | |
JUMPI tolower | |
tolower_do, ADD tolower_offset | |
OUTPUT | |
LOAD tolower_itr | |
ADD ONE | |
STORE tolower_itr | |
JUMP tolower_while | |
str_ptr, HEX 18 / memory location of str | |
str, HEX 48 / H | |
HEX 45 / E | |
HEX 4C / L | |
HEX 4C / L | |
HEX 4F / O | |
HEX D / carriage return | |
HEX 57 / W | |
HEX 4F / O | |
HEX 52 / R | |
HEX 4C / L | |
HEX 44 / D | |
HEX 0 / NULL char | |
/ constants | |
ONE, DEC 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORG 0 / implemented using a "for" loop | |
INPUT / INPUT into AC | |
STORE MAX / STORE AC into MAX | |
Cond, LOAD COUNT / LOAD count into AC | |
SUBT USR / SUBT MAX from AC | |
SKIPCOND 000 / Skipcond 000 if AC < 0 | |
JUMP End / JUMP to End | |
Loop, LOAD COUNT / LOAD Count into AC | |
ADD ONE / ADD ONE to AC | |
STORE COUNT / STORE AC into COUNT | |
LOAD COUNT / LOAD count into AC | |
OUTPUT / OUTPUT AC | |
JUMP Cond / JUMP to Cond | |
End, HALT / HALT process | |
/ variables | |
COUNT, DEC 0 | |
MAX, DEC 0 | |
/ constants | |
ZERO, DEC 0 | |
ONE, DEC 1 | |
TWO, DEC 2 | |
THREE, DEC 3 | |
FOUR, DEC 4 | |
FIVE, DEC 5 | |
SIX, DEC 6 | |
SEVEN, DEC 7 | |
EIGHT, DEC 8 | |
NINE, DEC 9 | |
TEN, DEC 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mathewmariani Please check my email!