Project 1 Programmer Manual S. Laufer CS221-02 - Fall, 2010 1. Problem Description The purpose of this project is to read 10 integers from the console. Upon input of 10 integers (between -32768 and 32768 due to the limitations of a 16-bit system), these integers will be sorted, and displayed along side the original, unsorted values. 2. Data Types or Classes This project uses signed integers, arrays and null-terminated strings. a. Arrays arr1 - An array of two-byte signed integers, used to store and sort user input. arr2 - An array of two-byte signed integers, used to store user input. b. Integers count - an unsigned two-byte integer, containing the size of arr1 and arr2. WriteIntBase - an unsigned two-byte integer, containing the "base" to convert to when writing an integer to the console. Used for div. ReadIntNeg - an unsigned one-byte integer, used to denote whether or not the number read is negative. c. Strings prompt1, prompt2 - static parts of the string used to prompt the user to enter an integer. table1, table2, table3 - static parts of the table containing the program output. crlf - a Character Return/Line Feed. WriteIntField - Used to store the output of WriteInt. ReadIntField - Used to store the input to ReadInt. 3. Procedures a. Sort (short * arr, short size) This procedure takes its arguments from the stack in reverse order. The first argument pushed should be a two-byte unsigned integer representing the size of the array to be sorted. The second argument pushed should be the DS offset of the first element of an array of two-byte signed integers. These values will be sorted using the bubble sort algorithm, and control will then be returned to the calling procedure. b. WriteStr (char * str) This procedure takes its argument from the stack. The first and only argument pushed should be a two-byte unsigned integer representing the DS offset of a null-terminated string. This procedure will begin at the passed DS offset and print every character until it reaches a null terminator (0x00, NULL) c. ReadStr (char * ptr, short size) This procedure takes its arguments from the stack. The first argument pushed should be a two-byte unsigned integer representing the maximum size of the string to be read. The second argument should be a two-byte unsigned integer representing a DS offset at which to store the values read. This procedure will begin reading from the console, and continue reading until it receives a Carriage Return (0x0D, CR). If more than (size - 1) characters are read before a Carriage Return is received, subsequent characters will be discarded. d. WriteInt (short val) This procedure takes its argument from the stack. The first and only argument pushed should be a two-byte signed integer to be printed to the console. This procedure will print the passed integer to the console, then return control to the calling procedure. e. ReadInt (short * val) This procedure takes its argument from the stack. The first and only argument pushed should be a two-byte unsigned integer representing the DS offset where the value read should be stored. This procedure will prompt the user for to enter an integer value. If the value entered is invalid, the procedure will continue to prompt the user until a valid value is entered. When a valid value is entered, it will be stored at the passed location and control will be returned to the calling procedure. f. Greet () This procedure prints a simple greeting message. 4. High Level Program Design Prompt user for 10 integers, storing copies in two separate arrays Pass one array to sort procedure Print sorted and unsorted arrays side-by-side 5. Design Diagram /----------\ | WriteInt |-----------\ \----------/ | ^ | | v /--------------\ /----------\ | ProgramStart |-->| WriteStr | \--------------/ \----------/ | | | /-------\ v v \--------------------->| Greet | /------\ /---------\ /---------\ \-------/ | Sort | | ReadInt |-->| ReadStr | \------/ \---------/ \---------/ 6. Design Limitations and Suggestions This program is limited by the range of two-byte integers, and is also vulnerable to roll-over issues related to excessively large or small integers.