ECE291 Computer Engineering II Lockwood, Spring 1999

Machine Problem 0

Assigned Thursday 1/21/99
Due Date Thursday 1/28/99
Purpose Introduction
Points 25

Introduction

This machine problem will introduce you to the computers, network, and software in the ECE291 laboratory. For this machine problem, you will learn how to edit, assemble, debug, and execute an existing, simple assembly language program. A full listing of the program and a Makefile are given at the end of this assignment. Electronic copies of the program are available in the lab or on-line as mp0.zip.

Preliminary Procedure

  1. Visit the ECE291 laboratory in room 238 Everitt Lab. You will need an activated key card to open the door.

  2. Have a seat at any available computer in the laboratory. The machine should boot into Windows 98.

  3. Enter your login and password. You can obtain your login information from the TAs in the lab in exchange for having your photo taken. You can change your windows password from the settings - control panel - windows password menu.

  4. Start a DOS shell. This can be done by clicking on the start button, navigating to Programs, then releasing the mouse button on MS-DOS Prompt.

  5. For the machines in the ECE291 lab, you will be using the following drive letters:

    DriveDescriptionPurpose
    C: Hard Drive (local) Holds Windows98, MASM, and other applications
    Do not store files here!
    V: Class Drive (network) Class material, libraries, example code
    (Read Only)
    W: Your personal home directory (network) This drive will be mounted each time you log in,
    and is accessible from any machine in the lab.
    (Store your MPs here!)

  6. Copy the MP0 directory on the class drive to your private directory by typing:
    xcopy /s V:\ece291\mp0 W:\mp0
    When prompted, respond with D to copy the entire directory.

  7. Go into your private directory

  8. From the start menu, run Windows Explorer. Navigate to your W: drive, open the mp0 folder

  9. Double-click on the MP0 ASM file to edit the program. (If you are working at home, you'll need to install your own text editor. Avoid Notepad and QuickEdit like the Plague). Scroll through the program, but don't make any changes yet.

    The code is broken into several sections to illustrate the various components in an assembly program. This is certainly not the only way to organize an assembly program, but it gives a good starting point. Again, you do not need to understand precisely what the statements are doing at this point, but notice the overall structure of the program. This will be a good reference for future machine problems.

  10. From the DOS window, Assemble and link MP0 by typing NMAKE. This command will read Makefile and invoke the following commands:
    MASM /Zi MP0,,;
    LINK /co MP0,,,lib291/map;
    At this point, you should have just created the executable program called MP0.EXE.

  11. Run the program by just typing its name, MP0
    Try giving the program different input. Remember: this program is looking for upper-case letters!

  12. Now examine your program by running the debugging tool CodeView (CV).
    CV /50 MP0
    Codeview will read your MP0.EXE program and allow you to step and trace through the program as it executes. The /50 provides you with a large (50-line) window to work in.

  13. Now return to your text editor (WinEdit) to modify MP0.ASM. You need to make the following changes:

    1. Put your name and the current date at the beginning of the program
    2. Add a feature to the program that prints a message of your choice when the grade C is selected.
    3. Assemble and test your program with all possible inputs. Debug with CodeView as necessary until the program works as expected.

  14. Now return to your text editor and add a line to MP0.ASM.

    1. Add a new variable to your program called mystery that is initialized with the hex values of 0FEh,0C0h. (This is MASM's method of entering hex values). Declare this variable at the location in your code immediately after the input is read using the lib291 kbdine function.
    2. Re-Assemble your code and run CodeView.
    3. Run your program a few more times and observe what happens. Try Switching between DisplayMode=Source and DisplayMode=Assembly.
    4. Browse the source window in assembly mode and record what addresses the mystery bytes were stored in.
      Address= ______ : ______
    5. In the space below, explain how the program behaves differently and why.
    6. Finally, Move this variable declaration to where it belongs in the code.

Final Steps

  1. Print a copy of the MP0 Grading report (mp0gr) from the MP section of the ECE291 web pages.

  2. Demonstrate your updated MP0.EXE to a TA or to the instructor. Review your solutions to the question with the TA. Be prepared to be quizzed by the TA with additional questions about your codeview debugging experiences. The TA will not allow you to submit your MP until he or she is satisified that you have mastered Codeview.

  3. Once approved, make a printout of MP0. This can be done in the ECE291 lab by dragging the mp0.asm file to the printer icon. This will use a program called GreenPrint32. This allows printing of multiple pages per sheet. All MP's MUST be printed using GreenPrint32 or they will not be accepted. Make sure that your name appears on the printout.

  4. Staple the MP0 grading report to the front of your modified MPO.ASM program. Give this to the same TA which approved your demonstration.

  5. Have the TA run the electronic handin program from the floppy.

  6. Log off by clicking on the start button and navigating to Shutdown.

  7. You are now finished!

MP0.ASM

TITLE MP0 Your_Name Todays_Date COMMENT * This program illustrates a (very) basic assembly program and the use of LIB291 input and output routines. By working on this code, you will have the opportunity to exercise the tools for this class, namely the editor (WinEdit), the Assembler (MASM), and the debugger (CodeView). Be sure to put your name in the places where it says 'Your Name' and also change the date where it says 'current date'. The changes that you need to make to this program are described in the MP0 assignment page. * ;====== SECTION 1: Define constants ======================================= CR EQU 0Dh LF EQU 0Ah BEL EQU 07h ;====== SECTION 2: Declare external procedures ============================ EXTRN kbdine:near, dspout:near, dspmsg:near, dosxit:near ;====== 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' ; *** CODE SEGMENT *** ASSUME cs:cseg, ds:cseg, ss:stkseg, es:nothing ;====== SECTION 5: Declare variables for main procedure =================== mygrade db ? question db 'What grade would you like in ECE291? ','$' Exitmsg db CR,LF,'Good Luck!',CR,LF,'$' invalid db CR,LF,'Not a valid choice! ',CR,LF,'$' Amsg db CR,LF,'Learn all material and Submit MPs early.',CR,LF,'$' Bmsg db CR,LF,'Keep up in class and submit MPs on time.',CR,LF,'$' Dmsg db CR,LF,'Skip a few machine problems.',CR,LF,'$' Fmsg db CR,LF,'Sleep through exams.',CR,LF,'$' ;====== SECTION 6: Main procedure ========================================= MAIN PROC FAR mov ax, cseg ; Initialize Default Segment register mov ds, ax mov dx, offset question ; Prompt user with the grade question call dspmsg call kbdine mov mygrade,AL ; Save result CheckGrade: cmp mygrade, 'A' ; Check if A student jne NotGradeA mov dx, offset Amsg ; Print message for A students call dspmsg jmp mpExit NotGradeA: cmp mygrade, 'B' ; Check if B student jne NotGradeB mov dx, offset Bmsg ; Print message for B students call dspmsg jmp mpExit NotGradeB: cmp mygrade, 'D' ; Check if D student jne NotGradeD mov dx, offset Dmsg ; Print message for D students call dspmsg jmp mpExit NotGradeD: cmp mygrade, 'F' ; Check if F student jne NotGradeF mov dx, offset Fmsg ; Print message for F students call dspmsg jmp mpExit NotGradeF: mov dl, BEL ; Ring the bell if other character call dspout mov dx, offset invalid ; Print invalid message call dspmsg jmp FinalExit mpExit: mov dx, offset Exitmsg ; Type out exit message call dspmsg FinalExit: call dosxit ; Exit to DOS MAIN ENDP CSEG ENDS END MAIN

Makefile

all: mp0.exe mp0.exe: mp0.obj link /co mp0,,,lib291/map; mp0.obj: mp0.asm masm /Zi mp0,,; clean: del mp0.exe del *.obj del *.map del *.lst