header

Week 15 Homework

Due Monday, Apr 29

Problem 1

Write an Intel 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;
}

Remember that there is no mechanism in the Intel instruction set to enforce the rule that a constant cannot be modified after it has been initialized. Consequently, in assembly language, a constant is just like any other variable and it is up to the programmer to make sure that no instructions are written that would modify the value of the initialized "constant".

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 H15P1.asm.

Problem 2

Write an Intel assembly language program that has three 16-bit integer variables; b, e, and result. Your program should find the absolute value of b, raise it to the e power, and store the result in result. You may assume that e is a positive integer but b could be either positive or negative. When I test your program, I will choose values of b and e that will not result in overflow (a value greater than 65,535).

I should be able to modify the initial values of b and e and your program should still work. Submit your program as H15P2.asm.