CS-220, Lab 6 Due Date: 4-6-06 In this assignment you will be working with indirect addressing and arrays. Specifically you are to write an IBM-PC assembly language program and a C program, each of which is do the following: Prompt the user to enter the sex (m or f) of a student and the grade (A, B, C, D, or F) that student obtained on an exam. These data are to be stored in memory. After all the data have been entered (when the user enters an x for the grade) the programs should construct and display a table of frequencies of grades and sex (see below). Each program should then prompt the user to enter a student number (00, 01, 02, 03, ..., etc.), after they the grade and the sex of that student will be displayed. The programs should terminate when the user enters a 99 for the student number. The frequency table will contain the number of students of each sex who received A's, B's, C's, D's, and F's. In the assembly language program the entries in this table are to be stored in consecutive bytes of memory in row major order. In the C version they are to be stored in a two dimensional array. The programs should also compute and store the number of males and females, the numbers of A's, B's C's, D's, F's, as well as the total number of students. The following is an example of a program run (what would appear on the screen): Enter the grade and sex of each person who took an exam Possible grades are: A, B, C, D, F Possible sexes are: m, f Terminate with an x for the grade Grade: B <The user entered the 'B'> Sex: f <The user entered the 'f'> Grade: C <etc.> Sex: m Grade: D Sex: m Grade: A Sex: f Grade: A Sex: m Grade: C Sex: f Grade: F Sex: m Grade: B Sex: m Grade: C Sex: f Grade: A Sex: m Grade: B Sex: m Grade: C Sex: f Grade: x The following is the frequency table Grade: 0=A 1=B 2=C 3=D 4=F Totals ------------------------------------------------------------ Sex: 0=Female 01 01 03 00 00 05 1=Male 02 02 01 01 01 07 ------------------------------------------------------------ Totals: 03 03 04 01 01 12 To see a student's grade and sex, please enter a student number (00 to 11). Enter a 99 to terminate the program. 02 The grade of student 02 was D Student 02 was a male To see a student's grade and sex, please enter a student number (00 to 11). Enter a 99 to terminate the program. 11 The grade of student 11 was C Student 11 was a female To see a student's grade and sex, please enter a student number (00 to 11). Enter a 99 to terminate the program. 99 DONE! The following shows how the first part of the data segment of the assembly language program might be organized. .DATA N db ? ;number of people in sample, computed by program org 16 SEX db 32 dup(?) ;will hold the sex (m or f) of up to 32 people GRADE db 32 dup(?) ;will hold the letter grade of up to 32 people org 80 TABLE db 10 dup (?) ;this is the required frequency table org 96 STOTALS db 2 dup(?) ;this is a table for the sex totals GTOTALS db 5 dup(?) ;this is a table for the grade totals ... The following shows how this part of the data segment of the assembly language program would look before and after you run your program. A DEBUG-style memory dump (-d) of the first several bytes in the data segment is shown, but, for clarity, all numbers are expressed in decimal (and the data entered are expressed as ASCII characters--what would really be stored, of course, would be the ASCII codes). The first number on each line is the offset of the start address (again expressed in decimal) of that row of 16 bytes. XX represents an uninitialized byte. Before running the program: 00 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 16 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 32 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 48 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 64 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 80 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 96 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX After running the program with the data given above: 00 12 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 16 f m m f m f m m f m m f XX XX XX XX 32 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 48 B C D A A C F B C A B C x XX XX XX 64 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX 80 01 01 03 00 00 02 02 01 01 01 XX XX XX XX XX XX 96 05 07 03 03 04 01 01 XX XX XX XX XX XX XX XX XX Note that in the first row (offset 00), the first entry is 12 which is the total number of students in this particular data set. This number was determined by the program. The next row gives the sex (m or f) of each student, and the third row (offset 48) the grade. Notice also that with this organization the grade and sex of a given student can be obtained by using the student number as an index. In other words if, for example, you set SI to the student number (entered by the user), the grade of that student will be GRADE[SI] and the sex will be SEX[SI]. The sixth row (offset 80) is the required table containing the number of students of each sex receiving each letter grade, stored in row major order. Obviously the numbers stored in the table have been calculated by the program. The first two bytes in the last row (offset 96) are the totals for each sex--in this case 5 females and 7 males, and the next five bytes are the totals for each letter grade--in this case 3 A's, 3 B's, 4 C's, 1 D, and 1 F. These numbers have also been computed by the program. The results shown in this table are to be output to the screen. The result should be similar to the table given in the sample run above. ASSEMBLY LANGUAGE PROGRAM HINTS: Use an index for sex (s=0--female, s=1--male) and another index for grade (g=0--A, g=1--B, g=2--C, g=3--D, g=4--F). Then you should be able to convince yourself that the position in the TABLE that needs to be incremented will be s*5+g.) It is suggested that you store the data to be displayed as individual lines of ASCII codes in your data segment. For example, the first two lines of the table above could be set up as follows in your data segment: L1 db 'grade: 0=A 1=B 2=C 3=D 4=F Totals', 0dh,0ah L2 db '-----------------------------------------------------------', 0dh,0ah The other lines will be similar, with the exception that the ASCII codes for each digit of each numerical result will have to be determined and placed in the line. Once the lines of the table have been set up in memory, it will be a simple task for your program to index through each line and send the characters to your screen display procedure. C LANGUAGE PROGRAM HINTS: Use a one-dimensional array to store the grades and another one-dimensional array to store the sexes. Use a two-dimensional array to store the frequencies. For example: freq[grade][sex] where grade varies from 0 to 4 (0=A,1=B,2=C,3=D,4=F) and sex varies from 0 to 1 (0=female, 1=male). Then whenever a new grade and sex are entered by the user, the specified element of the array should be increased by 1. ITEMS TO BE SUBMITTED: You should run your programs several times with different data, including one run of each program with the data given above. As usual, you are to submit a well-organized, well-documented, readable, error-free, assembled/compiled program listings (.LST files); a hierarchy chart; a flow chart for each procedure; printed copies of the output from each program run; and a diskette or CD-ROM with the source and executable files for the program.