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 (MARIE Assembly language) and MEX (MARIE EXecutable) files in the drop box. Put them in the drop box separately; don't zip them up.

# Homework:

1. Input two numbers and output their sum. In class.
2. Input three numbers from the keyboard and output their sum.
3. 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)

1. 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:

big = a

if b> big:

big = b

if c > big:

big = c

print(big)

1. 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:

if n == 0:

break

sum = sum + n

print(sum)

1. 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:

big = 0

for i =1 to size:

if n > big:

big = n

print(big)

1. 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:

result = 0

for i = 1 to a:

result = result + b

print(result)

1. 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.

// 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)