Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://github.com/mathewmariani/MARIE-Examples. Please feel free to email me if you have any questions.
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
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
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 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
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
/ #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
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
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 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
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
@Leslie29

This comment has been minimized.

Show comment
Hide comment
@Leslie29

Leslie29 Apr 7, 2017

guys i need help..what is the final value in ADD I D??

HEX Address LABEL INSTRUCTION

100 Start LOAD A

101 ADD B

102 STORE D

103 CLEAR

104 OUTPUT

105 ADD I D

106 STORE B

107 HALT

108 A, HEX 00FC

109 B, DEC 14

10A C, HEX 0108

10B D, HEX 0000

Leslie29 commented Apr 7, 2017

guys i need help..what is the final value in ADD I D??

HEX Address LABEL INSTRUCTION

100 Start LOAD A

101 ADD B

102 STORE D

103 CLEAR

104 OUTPUT

105 ADD I D

106 STORE B

107 HALT

108 A, HEX 00FC

109 B, DEC 14

10A C, HEX 0108

10B D, HEX 0000

@Marli95

This comment has been minimized.

Show comment
Hide comment
@Marli95

Marli95 Apr 9, 2017

How do you code a subroutine to convert uppercase to lowercase?
Regards,
Marli

Marli95 commented Apr 9, 2017

How do you code a subroutine to convert uppercase to lowercase?
Regards,
Marli

@Wisso81

This comment has been minimized.

Show comment
Hide comment
@Wisso81

Wisso81 Apr 26, 2017

Please if you know how to solve this question in marie simulator:
if ( x < y+z )
{
x=x-y;
z=z+1;
}
else
y=y-1;

Wisso81 commented Apr 26, 2017

Please if you know how to solve this question in marie simulator:
if ( x < y+z )
{
x=x-y;
z=z+1;
}
else
y=y-1;

@mathewmariani

This comment has been minimized.

Show comment
Hide comment
@mathewmariani

mathewmariani Oct 14, 2017

Feel free to email me if you have any questions.

Owner

mathewmariani commented Oct 14, 2017

Feel free to email me if you have any questions.

@Rahim89

This comment has been minimized.

Show comment
Hide comment
@Rahim89

Rahim89 Nov 8, 2017

hi my problem is that,
I'm trying to multiply to numbers in assembly language with Marie by using the addition method. but i can't stop the loop.
can you help me?

store y
add x
skipcond y
jump y
output y
x, dec 4
y, dec 3

Rahim89 commented Nov 8, 2017

hi my problem is that,
I'm trying to multiply to numbers in assembly language with Marie by using the addition method. but i can't stop the loop.
can you help me?

store y
add x
skipcond y
jump y
output y
x, dec 4
y, dec 3

@dina789

This comment has been minimized.

Show comment
Hide comment
@dina789

dina789 Dec 4, 2017

Can you please show me how to write a program to print an odd number in marie?

dina789 commented Dec 4, 2017

Can you please show me how to write a program to print an odd number in marie?

@fenderrex

This comment has been minimized.

Show comment
Hide comment
@fenderrex

fenderrex Dec 12, 2017

anyone know how to get the 10s place of a dec?
I'm trying to print a 2 digit number in ascii so I can include spaces
i have tried building converting this from JS to marie...
https://stackoverflow.com/questions/24226324/getting-place-values-of-a-number-w-modulus
this is the result.. i think my devide works


printNumber,	HEX 000//2 diget print

	//set ones
	load numToPrint
	store numerator
	load ten
	store denominator
	JnS	devide
	load count
	store ones
	//ones=num%10
	
	//set tens
	load numToPrint
	store numerator
	load ten
	store denominator
	JnS	devide
	//count=num/10
	
	load count
	store numerator
	load ten
	store denominator
	JnS	devide
	load remainder
	store tens
	//tens=count%10
	

	
	load tens
	add offset
	output
	
	load ones
	add offset
	output
	

	jumpI printNumber

devide,	HEX 000//JnS	devide// denominator, numerator  >> remainder, count
	load numerator
	//store tt
	test,	load numerator
	subt denominator
	store numerator
	
	//count it
	load count
	add one
	store count
	
	//if we have some more numerator do again
	load numerator
	
	Skipcond 000//if we have some more numerator do again
	jump test
	
	Skipcond 800//if we are negative rewind and get the diffrence
	jump getRemainder
	
	jumpI devide//return
	//numerator
	getRemainder,	load count
	subt one
	store count//remove one from count
	load numerator
	add denominator//add the denominator back to pre last test
	store remainder
	jumpI devide//return
	

fenderrex commented Dec 12, 2017

anyone know how to get the 10s place of a dec?
I'm trying to print a 2 digit number in ascii so I can include spaces
i have tried building converting this from JS to marie...
https://stackoverflow.com/questions/24226324/getting-place-values-of-a-number-w-modulus
this is the result.. i think my devide works


printNumber,	HEX 000//2 diget print

	//set ones
	load numToPrint
	store numerator
	load ten
	store denominator
	JnS	devide
	load count
	store ones
	//ones=num%10
	
	//set tens
	load numToPrint
	store numerator
	load ten
	store denominator
	JnS	devide
	//count=num/10
	
	load count
	store numerator
	load ten
	store denominator
	JnS	devide
	load remainder
	store tens
	//tens=count%10
	

	
	load tens
	add offset
	output
	
	load ones
	add offset
	output
	

	jumpI printNumber

devide,	HEX 000//JnS	devide// denominator, numerator  >> remainder, count
	load numerator
	//store tt
	test,	load numerator
	subt denominator
	store numerator
	
	//count it
	load count
	add one
	store count
	
	//if we have some more numerator do again
	load numerator
	
	Skipcond 000//if we have some more numerator do again
	jump test
	
	Skipcond 800//if we are negative rewind and get the diffrence
	jump getRemainder
	
	jumpI devide//return
	//numerator
	getRemainder,	load count
	subt one
	store count//remove one from count
	load numerator
	add denominator//add the denominator back to pre last test
	store remainder
	jumpI devide//return
	
@fenderrex

This comment has been minimized.

Show comment
Hide comment
@fenderrex

fenderrex Dec 12, 2017

but i am 21 instead of 13...

fenderrex commented Dec 12, 2017

but i am 21 instead of 13...

@louis00009

This comment has been minimized.

Show comment
Hide comment
@louis00009

louis00009 Sep 5, 2018

would you like to give some help on clear up all the spaces in the user input

louis00009 commented Sep 5, 2018

would you like to give some help on clear up all the spaces in the user input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment