ECE291 Computer Engineering II Lockwood, Fall 1996

Machine Problem 1

Assigned Tuesday 9/17/96
Due Date Friday 9/27/96
Purpose Learn to write assembler code. Use looping and branching. Perform simple math operations.
Points50

Introduction

As mentioned in the Course Syllabus, an ECE291 grade is determined by the following components: machine problems (40%), homeworks (10%), examination 1 (15%), examination 2 (15%), and the final examination (20%).

The computation of ECE291 scores are based on a 1000-point system. A student's total score is computed as the sum of the raw points earned on the machine problems, exams, and final plus one-fourth (1/4) of the sum of the raw points earned on the homework.

The breakdown of points for each assignment is shown in the table below. MP6 refers to the final group project at the end of the semester.

Homework Machine
Problem
Exam Final
02425
17550150200
27550150
37550
47550
57675
6 100
Subtotal400400300200
HW/4 100400300200
Total
1000 points

Problem Description

For this machine problem, you will write a program which converts a list of raw scores from ECE291 homeworks, machine problems, exams, and final exam into a sorted list of class standings.

The list of raw scores will be given to you in the form of a database. For ECE291, our database is collection of records that each hold a student ID and individual raw scores. The ID is an alpha-numeric string stored as 5 ASCII characters and terminated with a '$' symbol. Each of the 16 individual raw scores is stored as a 1-byte unsigned integer. The total score is represented as a 2-byte unsigned integer. In total, each ECE291 record occupies 24 bytes.

Record Format

The record format of the ECE291 database is summarized below. In this table 'A' represents an ASCII character, '$' represents the ASCII character used to mark the end of a string, 'B' represents a 1-byte unsigned integer, and 'WW' represents a 2-byte unsigned integer. The offset refers to the starting location of each field in each 24-byte array.

 
Field ID Homework Machine Problems Exams Final Total
Data AAAAA$ BBBBBB BBBBBBB BB B WW
Offset 06789 101112131415 16171819202122

For this machine problem, you will use the INCLUDE directive to read a database of fictitious ECE291 scores into your program. This directive will insert the contents of the file called gbk.dta into your .ASM program at the time you run MASM. The gbk.dta file defines a variable called gbk which holds the entire database as well as a variable called numrec which stores the number of records in the database. The contents of gbk.dta is shown below:

gbk db 'PERFT','$',24,75,75,75,75,76, 25,50,50,50,50,75,100, 150,150, 200,0,0
    db '12345','$',24,75,70,65,70,65, 25,50,40,45,40,75, 80, 125,125, 133,0,0
    db 'MEETO','$',20,60,75,70,65,76, 25,45,45,50,45,70, 90, 110,140, 140,0,0
    db 'YOUTO','$', 0,75,65,75,75,72,  0,50,45,50,45,75, 95, 130,135, 150,0,0
    db 'HLPME','$', 2, 4, 4, 8, 6, 8,  5,10,10,15,10, 5, 10,  50, 50,  75,0,0

numrec dw 5 ; Number of records (5 in this case)

Notice that the record with id=MEETO begins at a byte offset of 24x2=48 in the array. The homework zero score for this record is located at offset 24x2+6=54. The total score (which you will need to compute) for this record is defined at offset 24x2+22=70.

Sample Output

-ID-- hw0 hw1 hw2 hw3 hw4 hw5 mp0 mp1 mp2 mp3 mp4 mp5 mp6 Ex1 Ex2 Fin Total
PERFT  24  75  75  75  75  76  25  50  50  50  50  75 100 150 150 200  1000
YOUTO   0  75  65  75  75  72   0  50  45  50  45  75  95 130 135 150   865
MEETO  20  60  75  70  65  76  25  45  45  50  45  70  90 110 140 140   851
12345  24  75  70  65  70  65  25  50  40  45  40  75  80 125 125 133   830
HLPME   2   4   4   8   6   8   5  10  10  15  10   5  10  50  50  75   248


DOSXIT: Exit to DOS 

Preliminary Procedure

Program Assignment

  1. Calculate the total score for each record in the database.
  2. Write another loop which prints out each record, sorted in order of decreasing scores.

Final Steps

  1. Demonstrate MP1.EXE to a TA or to the instructor. You will then be asked to recompile and demonstrate MP1 with a different database file. Once approved, you are ready to turn in your program.
  2. Copy your programs to a floppy:
    xcopy /s F:\mp1 a:\mp1
  3. Print MP1.ASM
  4. Take your printout and disk with MP1 to the same TA which approved your demonstration. Be sure that your name is on the disk and on the printout.

MP1.ASM

        PAGE 75, 132
        TITLE   MP1    your name       current date

COMMENT *
        This program computes class standings (grades) based on
        the raw scores for homeworks, machine problems, exams,
        and the final.  
	*

;====== SECTION 1: Define constants =======================================

	CR	EQU	0Dh
	LF	EQU	0Ah

;====== SECTION 2: Declare external procedures ============================

        extrn   binasc:near, dspmsg:near, dosxit:near  ; From lib291.lib
        extrn   printrec:near                          ; From libmp1.lib

;====== SECTION 3: Define stack segment ===================================

stkseg  segment stack                   ; *** STACK SEGMENT ***
        db      64 dup ('STACK   ')
stkseg  ends

;====== SECTION 4: Define code segment ====================================

cseg    segment public                  ; *** CODE SEGMENT ***
        assume  cs:cseg, ds:cseg, ss:stkseg, es:nothing

;====== SECTION 5: Declare variables for main procedure ===================
; Format of the gradebook database:
;   [Note that each record is 24 bytes long]
;
;            ID: 5 ASCII letters or numbers
;    hw0..final: 1-byte unsigned integers (array of 16 elements)
;           tot: 2-byte unsigned integer (calculated as per instructions)
;
;   ID,'$',hw0,hw1,hw2,hw3,hw4,hw5,mp0,mp1,mp2,mp4,mp5,mp6,e1,e1,final,tot

INCLUDE gbk.dta

; This directive inserts the contents of the file gbk.dta here.
; In this file, two variables are defined: gbk and numrec
;
; gbk is an array of 24-byte records holding raw scores
; numrec is defined as a 16-bit integer which stores the number of records

; This header should be the first line printed 
hdr db '-ID-- '
    db 'hw0 hw1 hw2 hw3 hw4 hw5 '
    db 'mp0 mp1 mp2 mp3 mp4 mp5 mp6 '
    db 'Ex1 Ex2 Fin Total',CR,LF,'$'

;====== SECTION 6: Main procedure =========================================

main    proc    far
        mov     ax, cseg                ; Initialize DS register
        mov     ds, ax

        ; Your code

        call    dosxit
main    endp


cseg    ends
        end     main