Homework Assignments for CSC 325

Spring 2004

 

 

 

Homework 1: See document CSC325-Homework1.doc

See document poly.htm for solution to poly.asm and another equation (quad.asm) to complete.

See document QUAD.txt for a template to do quad.asm.

 

Homework 2:

1.      The CPU contains registers and what other basic elements?

2.      Why does memory access take more machine cycles than register access?

3.      What are the three basic steps in the instruction execution cycle?

4.      During which stage of the instruction execution cycle is the program counter incremented?

5.      In a 5-stage single-pipeline processor, how many clock cycles would it take to execute 8 instructions?

6.      Which flag is set when an arithmetic or logical operation generates a negative result?

7.      Which part of the CPU performs floating-point arithmetic?

8.      Describe external cache memory.

9.      Of the three levels of input/output in a computer system, which is the most universal and portable?

10.  At which level(s) can an assembly language program manipulate input/output?

 

Homework 3:

Write a program that defines a variables string and prints out the variable string.

 

Homework 4:

Write a program that defines five variables as follows:

            Num1 dw 9

            Num2 dw 8

            Num3 dw 7

            Num4 dw 6

            Num5 dw “a”

Display the five values on the screen, add the five variables, and display the results on the screen.


Homework 5:

Write a program that inputs three numbers and two character strings from the keyboard and displays the three numbers and the two character strings on the screen.

 

Homework 6:

Write a program that displays a request to enter a five numbers, accepts the five numbers entered from the keyboard, add the five numbers, displays the results to the screen, subtracts the fifth from the first, and displays the results on the screen.

 

Homework 7:

Write a program that displays a request to enter ten numbers, accepts the ten numbers from the keyboard, add the first five numbers, displays the results with an appropriate message indicating that the numbers were added, subtract 1000d from the sum of the second five, display the results with an appropriate message, multiply the 9th and 10th numbers, and display the results with an appropriate message.

 

Homework 8:

Copy a String Backwards: Write a program using the LOOP instruction with indirect addressing that reads a string of 10 characters input from the keyboard, stores the characters in a variable called source,  copies the string from source to target, reversing the character order in the process.

 

Homework 9:

Integer Array Input: Write a program that uses a loop to input ten signed 16-bit integers from the user, stores the integers in an array, and redisplays the integers.  Add the fifth and seventh elements of the array and display the results.

 

Homework 10:

Write a program that clears the screen, locates the cursor near the middle of the screen, prompts the user for an integer, stores that integer, locates the cursor in the middle of the screen one line below the first prompt, inputs a second digit, adds the first integer to the second, and displays their sum in the middle of the screen just one line below the prompt for the second integer.

 

Homework 11:

Sort Routine: Prompt the user for a random string of ten characters (characters can be lower case letters of the alphabet, upper case letters of the alphabet, and the numbers 0 to 9).  Arrange the letters in alphabetical orders with numbers first then letters of the alphabet.  If an upper case and lower case of the same letter occurs, the upper case should appear first then the lower case.  For example, the string “yuUa05Ab8Y” would be rearranged and output as “058AabUuYy”.  If two of the same character appears (for example, AA or 11 or bb) produce an error message indicating the problem.  If the input string is not exactly 10 characters produce an error message.

 

Homework 12:

Fast Multiplication: Write a procedure named FastMultiply that multiplies any unsigned 16-bit integer by AX, using only shifting and addition.  Pass the integer to the procedure in the BX register, and return the product in the AX register.  Write a short test program that calls the procedure and displays the product.  Assume that the product is never larger than 16 bits.

 

Homework 13:

Greatest Common Divisor (GCD): The greatest common divisor of two integers is the largest integer that will evenly divide both integers.  The GCD algorithm involves integer division in a loop, described by the following C++ code:

 

Int GCD (int x, int y)

{

            y = abs(x);

            x = abs (y);

            do {

                        int n = x % y;

                        x = y;

            y = n;

            } while y > 0;

            return y;

}

Implement this function in assembly language, and write a test program that calls the function several times, passing it different values.  Display all results oj the screen.

 

Homework 14:

Prime Number Program: Write a procedure that sets the Zero flag if the 16-bit integer passed in the AX register is prime.  (A prime number is evenly divisible by only itself and 1.)  Optimize the program’s loop to run as efficiently as possible.  Your program should prompt the user for a number and then display a message indicating whether or not the number is prime.  The program should then ask for another number from the user.  Continue the loop in this fashion until the user enters the value –1.