Chapter 2 Using the PC

Table of Contents
2.1 Microsoft Windows / DOS
2.2 Assembling and Linking Files

Before a program can be successfully written, one must have a good understanding of the functions and operations of the PC in general. This chapter will describe the operation of the PC as it applies to the creation of programs for this course.

2.1 Microsoft Windows / DOS

Microsoft Windows is the program that controls other running programs, supervises and executes the I/O operations (receiving characters from the keyboard or displaying characters on the screen, for instance), and manages the files on the diskettes. When the computer is first powered up ("boot" or "bootstrap"), you commence executing in the Windows system. By means of a dialogue of commands between the system and the user, conducted via the keyboard, mouse, and display, a program may be edited, assembled, and run. You may also create, rename, and delete files on disks or diskettes.

Microsoft DOS was the first Disk Operating System used for IBM and IBM-compatible PCs. Unlike Windows, it ran in text mode and only one program could be open at a time. Commands were entered at the DOS prompt using a keyboard. An extended DOS-compatible prompt is still available under Windows, and it will be used extensively in ECE 291 for assembling and running the MPs written in class. In Windows 2000, this DOS-compatible prompt is sometimes called the Command Prompt.

2.1.1 Entering Commands

DOS displays a prompt to indicate that it is waiting for you to enter a command. The prompt shows the current disk drive and directory name. For example,

W:\MyFiles>_

The underscore ("_"), called the cursor, indicates the location on the screen that text typed on the keyboard will appear. For example, the following command may now be entered:

W:\MyFiles>gvim example.asm

This command tells DOS to edit the file EXAMPLE.ASM using the VI editor. gvim is the command name, and the filename example.asm is an argument to the command. (Not all DOS commands take arguments).

2.1.2 Files and Filenames

DOS manages the files stored on your diskettes and the hard disk. This includes system files as well as your own program files. You can manage your files using the same types of functions you use when editing text--add, delete, etc. As your disks fill up, it's necessary to delete the older files that are no longer needed to free up space. As the network drives accessible from the lab machines have many gigabytes of space available, it should not be necessary to delete any class-related files.

Each file is identified by a file specification filespec, which consists of these four parts:

filespec = [disk drive name:][path]filename[.extension]

For example:

W:\MyFiles\example.asm

The disk drive name (W:) gives the name of the disk drive containing the file. This can be a hard drive, a network drive, or a diskette drive. If you do not supply a disk drive name, the current one (shown in the DOS prompt) is used. For much of your work, the disk drive need not be specified. The path is a series of directory names which gives the specific directory where your file is contained. For example, if the path was "\MyFiles\MP0\", that would mean the directory MyFiles contains the directory MP0, which in turn contains the file. You may decide not to use directories at all, in which case the path can be omitted. However, if you are using directories and you omit the path, DOS will use the current path (shown in the DOS prompt). The filename is the identifier for the file, and the extension gives the type of the file. While Windows allows the filename and extension to be any length, some older DOS programs only allow a filename to be a maximum of eight characters in length, and an extension to be a maximum of three characters in length. The Glossary lists some standard extensions. In many contexts (e.g., DOS commands for program assembly, linking, or execution), the extension need not be specified if it is a standard extension.

2.1.3 Wildcards

Wildcards are special characters which can be used in a file specification to simplify the specification of several related files. DOS allows the use of two special characters "*" and "?" in place of specific characters as illustrated below:

W:*.COM

any file on Disk W having extension "COM". Hence, "*" stands for any sequence of characters.

W:ABC.?OM

any file on Disk A with name "ABC" and extension ending in "OM". Hence, "?" stands for any single character.

These can be used in combinations, as in:

W:A??C*.*

any file whose filename starts with an A, then two more characters, then a C.

The "?" character may be used anywhere in the filename and extension, but the "*" character causes any characters following it in the same field to be ignored (i.e.,"A:AUT*C.BAT" is equivalent to "A:AUT*.BAT").

2.1.4 Useful DOS Commands

Following is a brief list of some useful DOS commands and their meanings. In some instances, examples are given in order to clarify their usage. [..] indicates optional elements in the command.


type {filespec}

Display the named file on the display.


type {filespec} | more

Cause output to pause at page breaks. Any command can be followed by | more to cause its output to pause at page breaks. However, more cannot be used as a command itself.


dir [filespec]

List the files in the current directory matching filespec (which may contain wildcards as described in Section 2.1.3), or all the files if filespec is not specified.


cd {path}

Change the current directory to path.


mkdir {name}

Create a new directory in the current directory called name.


rmdir {name}

Remove the named directory (must be empty).


del {filespec}

Delete the files matching filespec (may contain wildcards).


copy {fromfile} {tofile}

Copy fromfile to make tofile. If the filename.ext portion of tofile is not specified, the new copy has the same name as the old one.


ren {fromfile} {tofile}

Rename a file from fromfile to tofile.


[drive:][path]filename

Execute the named file (assumed to be in assembled and linked form).

2.1.5 Batch files

DOS batch files are a very useful way of automating common actions. A batch file is a file with an extension of ".BAT". It contains DOS commands and can be executed just like an .EXE file (by typing the filename without the extension). As a simple example, create a file called GO.BAT which contains the following two lines:

nasm -g -f obj mp0.asm
tlink /c /v mp0, , , lib291

Now type GO at the DOS prompt. DOS will execute the batch file, assembling and linking your program in the process. You can also specify input arguments to your batch files. An argument is represented within a batch file by the term "%n", where n is a decimal digit. "%1" represents the first argument, "%2" represents the second, and so on. Using this feature, you could customize the batch file so it takes the MP number as an argument:

nasm -g -f obj mp%1.asm
tlink /c /v mp%1, , , lib291

This batch file could be called with GO 0 to assemble and link MP0, or GO 1 to assemble and link MP1, and so on. Arguments can be any string of text, not just numbers, so you could also input the library name with the following batch file:

nasm -g -f obj mp%1.asm
tlink /c /v mp%1, , , %2

This could be called with GO 1 LIB291, for example.

A better way to automate the assembling and linking is by using a tool called Make that conditionally runs programs based on the last modified date of the source and output files. All of the machine problems in ECE 291 will be distributed with a Makefile to make the build process easier.