-
Notifications
You must be signed in to change notification settings - Fork 44
A Simple Adder
In this demonstration we are going to do write a piece of code which assembles a simple addition calculator
So we want to do is get user input and store into two variable. For this we are going to use: X and Y. A simple way to do this is:
INPUT
Store X
INPUT
Store Y
This will store the user input into two variables: X and Y. For the purposes we recommend you set the input and output value types to DEC (Decimal) mode. Now, declare these variables into 'temporary' values, note that declaration is usually at the end of the code.
X, DEC 0
Y, DEC 0
Now for the next step we are going to load a variable into the AC and Add the other value, output it and then halt the program, so:
Load X
Add Y
Output
Halt
There we have it. The code should something like
INPUT
Store X
INPUT
Store Y
Load X
Add Y
Output
Halt
X, DEC 0
Y, DEC 0
In RTL this will look like:
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 5 as input
IN ← 1
AC ← IN
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 2 as store
MAR ← IR & FFF
MBR ← AC
M[MAR] ← MBR
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 5 as input
IN ← 2
AC ← IN
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 2 as store
MAR ← IR & FFF
MBR ← AC
M[MAR] ← MBR
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 1 as load
MAR ← IR & FFF
MBR ← M[MAR]
AC ← MBR
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 3 as add
MAR ← IR & FFF
MBR ← M[MAR]
AC ← AC + MBR
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 6 as output
OUT ← AC
MAR ← PC
IR ← M[MAR]
PC ← PC + 1
Decoded opcode 7 as halt
----- halted -----
Copyright © 2018 Jason Nguyen, Saurabh Joshi, Eric Jiang, Felix Salim, Guido Tack, Monash University
Documentation
MARIE Instructions Set with Opcode
Register Transfer Language (RTL)
More Reading
The Essentials of Computer Organization and Architecture-Chapter 4.2
Tutorials
MARIE.js Documentation