Homework Assignments for CSC 225

Spring 2006

 

 

 

Homework 1: See document CSC225-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:

The CPU contains registers and what other basic elements?

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

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

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

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

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

Which part of the CPU performs floating-point arithmetic?

Describe external cache memory.

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

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 1

            Num2 dw 2

            Num3 dw 3

            Num4 dw 4

            Num5 dw 5

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


Homework 5:

Write a program that inputs five numbers from the keyboard and displays the five numbers on the screen.

 

Homework 6:

Write a program that displays a request to enter a three numbers, accepts the three numbers entered from the keyboard, add the three numbers, displays the results to the screen, subtracts the first and second for third, 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 copies a 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.

 

Homework 10:

Simple Addition: Write a program that clears the screen, locates the cursor near the middle of the screen, prompts the user for two integers, adds the integers, and displays their sum.

 

Homework 11:

Test Score Evaluation: Using the following table as a guide, write a program that asks the user to enter an integer test score between 0 and 100.  The program should display the appropriate letter grade.

 

Score Range

Letter Grade

90 to 100

A

80 to 89

B

70 to 79

C

60 to 69

D

0 to 59

F

 

Homework 12:

Fast Multiplication: Write a procedure named FastMultiply that multiplies any unsigned 16-bit integer by EAX, using only shifting and addition.  Pass the integer to the procedure in the EBX register, and return the product in the EAX 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:

Nonrecursive Factorial: Write a nonrecursive version of Factorial procedure in Section 8.5.2 that uses a loop.  Write a short program that interactively tests your Factorial procedure.  Let the user ea value of n.  Display the calculated factorial.

 

Homework 14:

Sieve of Eratosthenes: The Sieve of Eratosthenes, invented by the Greek mathematician having the same name, provides a way to find all the prime numbers within a given range.  The algorithm involves creating an array of bytes in which positions are “marked” by inserting 1’s in the following manner:  Beginning with position 2 (which is a prime number), insert a 1 in each array position that is a multiple of 2.  Then do the same thing for multiples of 3, the next rime number.  Find the next prime number after 3, which is 5, and mark all positions that are multiples of 5.  Proceed in the same manner until all multiples of primes have been found.  The remaining positions of the array that are unmarked indicate which number s are prime.  For this program, crate a 31,000-element array and display all primes between 2 and 31,000.