CSE306 Processing Systems and StructuresII Lockwood, Spring 2003

Machine Problem 0

Assigned Monday 1/27/03
Due Date Monday 2/3/03
Purpose Introduction
Points 25

Introduction

This machine problem will introduce you to the computers, network, and software in the CSE306 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 CSE306 laboratory in the Urbauer 115 lab during any laboratory period [times shown in yellow]

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

  3. Enter your login and password. You should log in as the user 'cs306' and use the password given in class. Once in, you should next provide your personalized CEC login and password in order to access your own files.

  4. Start a command shell. This can be done by clicking on the start button, navigating to Run, then type 'CMD' .

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

    DriveDescriptionPurpose
    C: Hard Drive (local) Holds Windows XP, MASM, and other applications
    Do not store files here!
    H: 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. Download MP0.ZIP and extract the files to your H:\CSE306\MP0 directory.

  7. Go into your private directory

  8. From the desktop, click on My Computer. Navigate to your home drive (H:), open the cse306 directory, then browse to 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. The Irvine book includes the textpad editor, which offers context-aware text highlighting. Avoid using editors like Notepad and QuickEdit, as they are not designed for editing code. 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 command window, Assemble and link MP0 by typing NMAKE. This command will read Makefile and invoke the following commands:
    MASM /Zi MP0,,;
    LINK /co MP0,,,lib306/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 lib306 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. Submit your MP0 Grading report (mp0gr) from the MP section of the CSE306 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. Have the TA run the electronic handin program

  4. Log off by clicking on the start button and navigating to Shutdown then Log Off.

  5. 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 LIB306 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 CSE306? ','$' 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,,,lib306/map; mp0.obj: mp0.asm masm /Zi mp0,,; clean: del mp0.exe del *.obj del *.map del *.lst