ECE291 Computer Engineering II Lockwood, Spring 1997

Machine Problem 1: Events Calendar

Assigned Thursday 1/30/97
Due Date Tuesday 2/11/97
Purpose Learn to write assembler code. Use looping and branching. Perform simple math operations.
Points50

Introduction

Life is full of events. Between assignments, meetings, birthdays, and anniversaries, it is easy to forget about an important event. A single semester of ECE291, for example, has over a dozen deadlines just for homeworks and machine problems. To remember events, it helps to be warned of those that have deadlines approaching in the near future.

Problem Description

For this machine problem, you are to complete an assembly program which scans a list of events and reports those that have deadlines within a given number of days in the future.

For this machine problem, you are given:

Your program is required to:

Format of an event

A structure (abbreviated STRUC) describes to the computer how your data is represented. For MP1, each event is described as a message and a date. The message is represented as an ASCII string and the month and day are represented as byte-sized integers. The deadline for this machine problem, for example, can be described as "MP1 due" on 2/11.

The format of the 32-byte Event structure is summarized below. In this table 'B' represents a 1-byte unsigned integer, 'A' represents an ASCII character, and '$' represents the ASCII character used to mark the end of a string. By default, message is initialized as a 29-byte array of blank characters. The endmark field is always filled with the '$' character so that message can be easily printed with the DSPMSG routine of LIB291. The offset refers to the starting location of each field in the structure.

Field month day message endmark
Data B B AAAAAAAAAAAAAAAAAAAAAAAAAAAAA $
Offset 01231

An array of event structures is defined by a variable called events. The number of events in this array is given by a word-sized integer called numrec.

Sample Output

Procedure

Final Steps

  1. Demonstrate MP1.EXE to a TA or to the instructor. You will be asked to recompile and demonstrate MP1 using a different EVENTS.INC file. This file will specify a modified database of events and a different lookahead value. Successful completion of your program with different inputs will ensure that you followed directions and that your program has no hard-coded operations.
  2. Be sure that your name and date appears in the first line of MP1.ASM.
  3. Copy your programs to a floppy using the following command:
    xcopy /s F:\mp1 a:\mp1
  4. Print MP1.ASM
  5. Take your printout and disk with MP1 to the same TA which approved your demonstration.

MP1.ASM

PAGE 75, 132 TITLE ECE291:MP1:Events - Your Name - Date COMMENT * This program checks a calendar to remind you of events that will occur in the near future. The data for this program are read from the file events.inc when the program is assembled. Dates are specified in a month/day format. ECE291 Machine Problem 1 Prof. John W. Lockwood Unversity of Illinois, Dept. of Electrical & Computer Engineering Spring 1997 * ;====== SECTION 1: Define constants ======================================= CR EQU 0Dh LF EQU 0Ah ;====== SECTION 2: Declare external procedures ============================ ; -- Functions in LIB291.LIB -- extrn binasc:near, dspmsg:near, dosxit:near, dspout:near; ; Please read your lab manual for a full description of the ; LIB291 functions. You will want to use these functions for ; displaying output on the screen. ; -- Functions in LIBMP1.LIB -- ; You may use these procedures freely. extrn getdate:near ;Purpose: Read current date ; Inputs: None ;Outputs: DH = month ; DL = day ; CX = year ;Registers: All others preserved extrn printdate:near ; Purpose: Print a 5-character date string as "MM/DD" ; Inputs: DH=month (MM) ; DL=day (DD) ; Output: None (Prints to screen) ;Registers: All others preserved extrn calcdate:near ; Purpose: Calculates a day number from a given month and day. ; Inputs: DH=month ; DL=day ; O utput: AX=Day number (0..365) ;Registers: All others preserved ; Note: Always assumes that Feb has 29 days (leap year) ;====== 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 =================== Event STRUC ; -- Format of Events Database -- month BYTE ? ; Month Number (1..12) day BYTE ? ; Day Number (1..31) message BYTE 29 dup(' ') ; Message to Print endmark BYTE '$' Event ENDS INCLUDE events.inc ; Read the file called 'events.inc'. ; 'Events' defined as an array of event structures ; 'numrec' : 16-bit word which stores the number of records ; 'lookahead' : 16-bit word which indicates how many days to look ahead todaymsg db 'Today is: ','$'; First Message Printed hdr db '-Date- ----------Event------------- -Days-',CR,LF,'$' ; Column Header pbuf db 7 dup(?) ; Temporary storage used by BINASC lib291 call crlf db CR,LF,'$' ; String to generate a new line today dw ? ; Stores the day number ;====== SECTION 6: Procedures ========================================= main proc far mov ax, cseg ; Initialize DS register mov ds, ax ; --- Free code to get you started --- mov dx, offset todaymsg ; Print 'Today is: ' call dspmsg call getdate ; Read the date call printdate ; Print the date call calcdate ; Calculate the day number mov today,ax ; save the result in the variable 'today' mov dx,offset crlf ; Print two carriage returns call dspmsg call dspmsg ; ================================================ ; YOUR CODE GOES HERE ; ================================================ call dosxit main endp cseg ends end main