In: Computer Science
Exercise #1: Write MARIE assembly language code to input 3 values into variables x, y, and z, calculate x + y -z, and outputs the result. Run your code in the simulator and submit a screen shot of your program run and the code.
//x + y -z
ORG 100
INPUT
STORE X
INPUT
STORE Y
INPUT
STORE Z
LOAD X
ADD Y
SUBT Z
OUTPUT
Halt
X, Dec 0
Y, DEC 0
Z, DEC 0
Exercise #2: Write MARIE assembly language code to implement the following algorithm:
Y = 0;
X = 1;
While X < 10 do
Y = Y + X;
X = X + 1;
Endwhile;
So this code calculates the sum of integers between 1 and 9, and
stores the result in Y. So after executing the code, the value
stored in Y should be decimal 45 i.e. Hexacimal 2D.
ORG 100
Load X
Store One
Test, Subt Ten
Skipcond 400
Jump Loop
Jump Done
Loop, Load Y
ADD X
STORE Y
Load X
Add One
Store X
Jump Test
Done, Halt
X, DEC 1
Y, DEC 0
Ten, DEC 10
One, DEC 1
Output:
Input is X = 10, Y = 15, Z = 13
ITS PROGRAMMING
Greetings!!
1.
Code:
INPUT
STORE X
INPUT
STORE Y
INPUT
STORE Z
LOAD X
ADD Y
SUBT Z
OUTPUT
Halt
X, Dec 0
Y, DEC 0
Z, DEC 0
Output screenshot:
2.
Code:
LOOP, LOAD COUNT
ADD Y
STORE Y
LOAD COUNT
SUBT ONE
STORE COUNT
SKIPCOND 400
JUMP LOOP
LOAD Y
OUTPUT
HALT
Y, DEC 0
COUNT, DEC 9
ONE, DEC 1
Output screenshot:
Hope this helps