## Week 10 Homework

Due Mar 25

## Assembly Language Programs

### Problem 1

Write an assembly language program that has two variables (n1 and n2). If
n1 is greater than n2, then the program swaps the values of the two
variables (so the smaller value always ends up in n1). Use constants (c1 and
c2) to initialize the values of n1 and n2. Here is the basic logic:

final int C1 = 10;
final int C2 = 20;
int n1, n2;
n1 = C1;
n2 = C2;
if (n1 > n2)
{
swap n1 and n2;
}

I should be able to modify your program by entering different values for
c1 and c2 and your program should still work correctly. Submit your program
as "H10P1.JAS".

### Problem 2

Write a program that has two methods named quotient and remainder. The
quotient function has two non-negative parameters and returns the integer
quotient found by dividing the first parameter by the second. The remainder
function has two non-negative parameters and returns the remainder that
would be left after dividing the first parameter by the second.

To find the quotient, subtract the second parameter (the divisor) from
the first (the dividend) until the result is less than the divisor. The
number of subtractions performed is the quotient and the final difference
(the one that is less than the divisor) is the remainder. Consider 10
divided by 3; 3 can be subtracted 3 times before the result (1) is less than
the divisor (3). The quotient is 3 and the remainder is 1:

10 - 3 = 7
7 - 3 = 4
4 - 3 = 1

Don't forget that the quotient is 0 if the dividend is less than the
divisor in the first place. In that case, the remainder is the dividend. For
example 3 divided by 10 has a quotient of 0 and a remainder of 3.

Declare the divisor and dividend as constants. Declare variables to store
the quotient and remainder. Here is the basic logic of main:

final int DIVIDEND = 10;
final int DIVISOR = 3;
int q, r;
q = quotient(DIVIDEND, DIVISOR);
r = remainder(DIVIDEND, DIVISOR);

I should be able to modify the values of the dividend and divisor and get
the correct quotient and remainder. Submit your program as "H10P2.JAS".