CS/ECE354: Pentium Section

Writing Your Programs: A Little Guide

Fall 98


Advice

Many of you have used Visual C++ before, in writing programs for 302. So, it will be familiar to you. That is good. However, for 354, we will be using the Visual C++ tool for writing and executing assembly language programs. So, things will be a little bit different. Try hard to follow the directions given, even if you are familiar with the tools.

Keep all your programs and homeworks in your private directory (folder). This will help to ensure that classmates cannot access your files. If you are being organized, (within your private directory) create one directory (folder) for each assignment. This will reduce the number of files per directory, making it easier for you to find what you want. It will also reduce the incidence of overwriting old files that you want to keep.

Make backup copies of your programs-in-progress. There is nothing worse than accidentally losing your entire program after spending many hours, or even days, working on it. Each hour, or so, copy your assembly language source code (.asm extension) to a new file name.


Executing Your First SASM Program

Since we're using the Visual C++ tool in a slightly unusual way, I will give you your first SASM program. To run the program, and see that it works, do the following.

  1. Copy three files to somewhere within your private directory. One of the files to copy is
    /p/course/cs354-smoler/public/p0.asm
    The second file to copy is
    /p/course/cs354-smoler/public/p0.mak
    The third file to copy is
    /p/course/cs354-smoler/public/sasmacros.inc
    Do not change the names of these files.
  2. Start running the program Microsoft Visual C++ 5.0.
  3. Once running Visual C++, you want to OPEN the file p0.mak. You'll need to find the directory (folder) where you put the files. Inside the dialog box, if you press the mouse button over where it says bin, you'll see several things listed. Your home directory is under U:, so bring up that one, and double click from there to get to the right directory. In the right directory, list files of type All Files, and open as type AUTO (the default). You will get a dialog box that says something to the point that this make file was not generated by the Developer's Studio, and continuing will "wrap" the makefile. You want to "wrap" this make file, so click on YES. You will get another dialog box that assigns the Win32 platform. Click on OK.
  4. You are now ready to work on the assembly language program. If you want, OPEN the file p0.asm as type AUTO (the default), to see what is in it. For this first program, you will not need to change or save anything, but you may want to be able to see the program.
  5. Before you can execute (run) a program, you need to assemble and link the program. (This is similar to when you compiled a C++ program.) Your makefile together with the Visual C++ tool will do this for you. To do this, under BUILD, do either BUILD ALL or BUILD p0.exe. You will see a window pop up that tells you what is being built, and if there were errors, you would see them here. If you've done everything right, there should be no errors with this first program.
  6. If there were errors (there are none in p0.asm), then you would iterate on the steps of modifying your source code (the file with the .asm extension), save the file, and again BUILD, until your program makes it through the build with no errors and no warnings.
  7. At this point, you can execute the program. Do this by choosing EXECUTE p0.exe under the BUILD menu.

Executing Subsequent SASM Programs

Once you have your first SASM program set, you can create and work on other SASM programs. Here is what to do.

  1. For each program, you will need to start out with the make file (.mak extension), the source code (.asm extension), and the SASM macros (called sasmacros.inc). The source code and make file will need a name. Make one up. Make copies of the three necessary files to somewhere within your private directory. Copy the .mak file from an existing make file, and copy the .asm file from an existing source code file.
  2. Edit the make file (within Visual C++), because you need the make file to assemble and link the correct source code. Open the make file (.mak extension) as type TEXT. Find and change the 3 places where the name of the files are wrong. For example, for the second program, you will have copied p0.asm and p0.mak to another name, like p1.asm and p1.mak. Inside p1.mak, find and change the 3 places where it says 'p0' to 'p1'. Save the file. Close the file.
  3. To work on the new program, re-open the make file, this time as type AUTO. Like the first program, a dialog box with ask if you want to "wrap" the file. Answer these as before, because you do want your make file wrapped up for you.
  4. To edit your assembly language source code, open the .asm file. Edit it. Save it.
  5. Build the program. Fix any build errors by editing the source code. Don't forget to save after each change!
  6. When you have built the executable without any errors or warnings, then Execute the program.
  7. Iterate on steps 5-6 until the program works.

Executing Pentium Programs

For Pentium programs, we use exactly the same tools as we did for SASM programs. The makefile (.mak extension) is exactly the same for Pentium programs. The source code changes in 2 ways:

The debugging interface for SASM programs was nonexistent. We have something much better for Pentium programs. The Visual C++ environment can give us instruction-level debugging, as well as details about the state of the processor at any point within a program's execution. You can have Visual C++ display a window containing the contents of the registers when a program is executed. To display this window, look under the View menu for Debug Windows. Choose the one that says Registers. Other windows can help you see the contents of memory.

To use the single step features of the environment, you will need to use the debugging features of Visual C++. Getting to executing the code within your program is the first step, after your program has been built (without errors). From the Build menu, choose Start debug. You will then get to choose options from there. Try out the different options to see how they work.

There is quite a bit of system level code that is executed before the first instruction within your program to do things like setting up a window for input and output. So, if you look at the Disassembly window (your source code, essentially), you'll actually see the instructions executed, and their location in memory.

To make execution stop at some specific point within your program, you will need to set a breakpoint. The cleanest way I've found to do this is to use a macro (it will be indistinguishable from an instruction) that I wrote for you called at_my_code. Place this call at an appropriate place within your code. Hit the button for "Run to Cursor" and away you go. As this call is reached, you'll get a dialog box that pops up with the message that a breakpoint was reached. You will see that the values within the registers are updated at this point. From a breakpoint, you can single step through your program or run to the end or run to the next breakpoint.

Best advice when first starting out is to play around with the tool a bit. You cannot ruin your source code by playing around with the debugging support.