MARIE Programming Problems

Updated 2020.09.04

For all programs, __put comments with your name and a
brief description__ of the problem at the top of the program.

For all programs, __get a printout of the LST file__
and hand it in.

For all programs, put the MAS (**M**ARIE **As**sembly language)
and MEX (**M**ARIE** EX**ecutable) files in the drop box. Put them in the drop box
separately; don't zip them up.

- Input
two numbers and output their sum.
*In class*. - Input
three numbers from the keyboard and output their sum.
- Display
(output) the odd numbers from 1 to 99. You
__must__use a loop. In Python, this would look like this:

For n in range(1, 100, 2):

print(n)

- Input three positive numbers from the
keyboard and output the largest of the three. To verify that your program
works, test all 6 possibilities: 1-2-3, 1-3-2, 2-1-3, 2-3-1, 3-1-2, 3-2-1.
You do not need to worry about the possibility of two numbers being equal.
In Python:

read(a)

read(b)

read(c)

big = a

if b> big:

big = b

if c > big:

big = c

print(big)

- Input a list of numbers from the
keyboard and output their sum. The size of the list is unknown, but the
last number in the list is 0. The numbers may be positive or negative. In
Python:

sum = 0

while True:

read(n)

if n == 0:

break

sum = sum + n

print(sum)

- Input
a list of numbers from the keyboard and output the largest. The first
number input will be an integer telling how many numbers follow in the
list. You may assume that there will be at least 1 number input (the size
of the list will not be 0). The numbers that are in the list will only be
positive. Here is the program/algorithm in (almost) Python:

read(size)

big = 0

for i =1 to size:

read(n)

if n >
big:

big = n

print(big)

- Input
two positive numbers from the keyboard and output their product. Since
there is no multiply instruction on MARIE, use repeated addition. Here is
the program/algorithm in (almost) Python:

read(a)

read(b)

result = 0

for i = 1 to a:

result =
result + b

print(result)

- Input
three numbers from the keyboard and output them in ascending order. Again,
test all 6 possibilities (see above). The bubble-sort algorithm may be
helpful here. You do not have to implement the entire bubble-sort
algorithm, but I think you may want to model your solution on the
bubble-sort algorithm.

read(a)

read(b)

read(c)

// compare b and c

if c<b:

swap c and b

// compare the new b with a

if b < a:

swap a and b

// compare the current b and c

if c < b:

swap c and b

print(a)

print(b)

print(c)