0% found this document useful (0 votes)
24 views9 pages

Marie HW 1-1

Uploaded by

mdtahmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

Marie HW 1-1

Uploaded by

mdtahmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MARIE HW 1

Why care about Assembly Language in 2023?


Can you refer to a memory location in Python? Ever thought about the
underlying processes behind a loop in Java? Assembly language would most
probably never be a mandatory requirement for a Computer Scientist or a
Software Engineer, yet knowing the real deal under the hood of any high
level language will make you look at programming in a whole different light.

“Real programmers can write assembly code in any


language” ~ Larry Wall

Meet MARIE Assembly Language!


MARIE (‘Machine Architecture that is Really Intuitive and Easy’) is a
machine architecture and assembly language. In a nutshell, MARIE
assembly language is a simple implementation of the von Neumann
architecture. MARIE consists of 5 registers (some books mention 7). A simple
idea of which register does what is required to proceed.

AC or Accumulator: intermediate data is stored within the AC

PC or Program Counter: as the name suggests it stores the current


position of the instruction, with each instruction having its own address

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

IR or Instruction Register: holds the current instruction

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.

Run: Executes the already assembled code.

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.

MARIE’S version of “Hello World!”


Unlike many programming languages printing “Hello World” is not where we
are going to start off from. Since it isn’t easy as it sounds in Assembly
Language.

This is your go to website when it comes to MARIE instructions.


https://github.com/MARIE-js/MARIE.js/wiki/MARIE-Instruction-Set-(with-
Opcodes)

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.

INPUT : Takes the users input and stores it in the AC.


STORE X : Stores the value stored in the AC to variable, X.

LOAD X : Loads the value stored in X to the AC.

HALT : Ends the execution of the program.

ADD X : Adds the number stored in X to the number stored in AC and


stores the resulting value at AC.

X, HEX/DEC 0 : X is equal to Hexadecimal/Decimal 0. *It should be one of


them, either HEX OR DEC.

Subt X : Subtracts the number stored in X to the number stored in AC


and stores the resulting value at AC.

Activity 1: Type out the following code in the MARIE simulator:

Input /Takes user input


Store X /Stores user input to X
Input /Takes user input
Store Y /Stores user input to Y
Load X /Load X to AC
Add Y /Add Y to X
Store Z /Store addition to Z
Output /Print Z
HALT /End program
/Variable decleration
Z, HEX 0
X, HEX 0
Y, HEX 0

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.

Conditions…. Do this? Or that?


Unlike High level languages a simple IF statement wouldn't do the job. We
will be looking at a new command:

Skipcond 000 : Skips the next instruction if value in AC<0

Skipcond 400 : Skips the next instruction if value in AC=0

Skipcond 800 : Skips the next instruction if value in AC>0

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!!!

Input /Takes user input


Store X /Stores user input to X
Input /Takes user input
Store Y /Stores user input to Y
Input /Takes user input
Store Z /Stores user input to Y
skipcond 400 /Skips nxt line if equal to 0
Jump Subtract

/Perform the addition


Adder, Load X
ADD Y
Output

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

Loops… Again and Again ♾

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:

Have the content to be repeated written.


At the end use the Jump statement to move to the beginning of the code.

Meanwhile check if the required condition has been met through


Skipcond

If the condition has been met, then Jump out of the loop.

Activity 3: Let's look at a program that prints numbers from 0 to 9.

Begin, Load X /Load value at X


Output /Print X
Add one /Increment X by 1
Store X /Store the incremented value at X
Subt ten /Subtract 10 to compare of X equal to 10
Skipcond 400 /Skip next line of equal to 10
Jump Begin /Not yet 10
Halt. /End because X=10
/Variable declaration
X, DEC 0
ten, DEC 10
one, DEC 1

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.

Expanding your Knowledge: Look into creating a Calculator. That does


addition, subtraction and finding the exponent. *Can be created using the
content of this blog.

Personally learning MARIE I have realised that the possibilities are limitless
yet it isnt straightforward at all. Thank you & Stay Safe!!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy