Marie HW 1-1
Marie HW 1-1
MAR or Memory Access Register: stores or fetches the ‘data’ at the given
address
MBR or Memory Buffer Register: stores the data when being transferred
to or from memory
Getting Started
MARIE is an open source project on github and can be accessed by
https://marie.js.org. Agree to the terms and conditions and you are good to
go. Innitially you will see the Coding Panel on the left and the output panel
on the right. Click ASSEMBLE to see a visualized version of the available
memory locations in MARIE. Notice the values in memory and the registers
are all set to Hexadecimal, 0000 which shows that neither assembly code or
data are stored in it.
https://marie.js.org
The bottom bar contains the 6 important tools.
Assemble: Converts the written Assembly Code into Machine code. This
makes the code ready for execution.
Restart: Does not reassemble the code but reruns the assembled code.
Step: Executes one line of the code. Click it one more time to execute the
next and so on.
Step Back: Changes the state of the program to before executing the final
line of code.
Delay Gauge: Set a delay to visualise the program being executed line by
line.
What we are gonna do is print the sum of two numbers x and y. But before
that, there are a couple of fundamental syntax required.
Assemble the code. Note that the input prompt gives us the option to enter
decimal, Hexadecimal, Unicode or Binary. For this program lets add two
decimal numbers. Choose Decimal and click Accept . Do the same for the
next input and voila the addition will be printed on the output log. *Be
mindful that the output log also has the ability to print the output in several
formats. Make sure its set to ‘DEC’.
Congrats 🥳!!!! You have successfully coded your first MARIE Assembly
code.
🦘Jump 🦘
One of the most important instruction in MARIE is the Jump Instruction.
This is used to Jump from one line to another line of code. We can directly
instruct the program to Jump 8 , which will jump to the 8th line of code. This
is a bad approach in the long run. *Since if line number changes we will be
jumping to a different Instruction.
Instead we use the Jump Instruction with a variable so that it would jump to
that specific instruction even if the line number changes. The code below
will demonstrate the use of the Jump instruction. *This is not a complete
program.
Jump End
Load X
Output
End, HALT
This program will not execute Load X or Output . It will directly jump into
END (This is a variable). Once it reaches END it will HALT the program. This
would be very helpful when we go through Conditions.
Note that the above statements can only check a value relative to 0. Yet we
can subtract a values by itself an check whether its equal to 0 or not. This
might not be clear through my explanation. Yet it will be much clearer when
we code.
Activity 2: Our goal is to write Assembly code that will ADD x and y if z=1 or
Subtract Y from X is z=0. Lets try it out!!!
End, HALT
/Perform the Subtraction
Subtract, Load X
Subt Y
Output
Jump End /Quit after Output
/Variable decleration
Z, HEX 0
X, HEX 0
Y, HEX 0
How can we end the blog without talking about Loops. Well it isn’t easy as
adding a For Loop in Python. Yet its quite easy to build it up using
conditions and the Jump statement.
Well if the idea hasn’t clicked yet the basic structure is:
If the condition has been met, then Jump out of the loop.
Wrapping up ✅
Just like we used conditions and Jump statements to create loops. Many
more features found in high level programming languages can be created in
MARIE.
Personally learning MARIE I have realised that the possibilities are limitless
yet it isnt straightforward at all. Thank you & Stay Safe!!!