CSCI 150, Spring 2003

Home | | Course Schedule | | Assignments | | Lecture Notes

Homework 8 solution

Problem 1.
Consider the following assembly language program:

a) What is the output of the above program if the input is 4?

b) What is the output of the above program if the input is 0?

c) Briefly describe how the program works.

Problem 2.
Write an assembly language program that reads two integers and prints their product.

Problem 3.
P88 Instructions to enter 2 numbers and print out the larger of the two:

There are many possible solutions. Here is one:

        IN      AX           {Enter 1st number}
        COPY    X, AX        {Copy 1st number into X}
        IN      AX           {Enter 2nd number}
        COPY    Y, AX        {Copy 2nd number into Y (optional)}
        CMP     AX, X        {if AX < X set CF = B, else CF = NB}
        JNB     PRINT        {if AX >= X print it out}
        COPY    AX, X        {copy 1st number back into AX, since it's biggest}
PRINT   OUT     AX           {Print out number that's in accumulator}
        END