Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Assembly Language Step by Step Programming with DOS and Linux 2nd Ed 2000.pdf
Скачиваний:
156
Добавлен:
17.08.2013
Размер:
4.44 Mб
Скачать

Chapter 5: NASM-IDE: A Place to Stand Give me a lever long enough, and a place to stand, and I will move the Earth.

-ARCHIMEDES

Access to Tools

The old guy was speaking literally about the mechanical advantage of the lever here, but behind his words there is a larger truth about work in general: To get something done, you need a place to work, with access to tools. My radio bench in the garage is set up that way: a large, flat space to lay ailing transmitters down, and a shelf above where my oscilloscope, VTVM, frequency counter, signal generator, and dip meter are within easy reach.

Much of the astonishing early success of Turbo Pascal was grounded in that truth. For the first time, a compiler vendor gathered up the most important tools of software development and put them together in an intuitive fashion so that the various tasks involved in creating software flowed easily from one step to the next. From a menu that was your place to stand, you pressed one key, and your Pascal program was compiled. You pressed another one, and the program was run. It was simple, fast, and easy to learn. Turbo Pascal literally took Pascal from a backwater language favored by academics to the most popular compiled language in history at that time.

What Borland so boldly introduced in 1983 was adopted (reluctantly at times) by its major competitor, Microsoft. Today, Microsoft's Visual Studio (including Visual C++ and Visual Basic) and Borland's Delphi are the best examples of what we call integrated development environments (IDEs). They provide well-designed menus to give you that place to stand and a multitude of tools that are only one or two keystrokes away.

A little remarkably, there is no true equivalent to Turbo Pascal in the assembly language field. Neither MASM nor Borland's Turbo Assembler (TASM) has that same comfortable place to stand. The reasons for this may seem peculiar to you, the beginner: Seasoned assembly language programmers either create their own development environments (they are, after all, the programming elite) or they simply work from the naked operating system command prompt. The appeal of a Turbo Pascal-type environment is not so strong to them as it is to you.

NASM-IDE

Robert Anderton of the United Kingdom had a slightly radical idea some time back that challenges that notion: He wanted to create an IDE for assembly language work, one that would be simple enough for beginners to use. Out of this radical idea came NASM-IDE, which was written-most appropriately-in Borland Pascal, the mature successor to Turbo Pascal, which made the idea of a built-in programming IDE mainstream. NASM-IDE is a DOS-based utility, and there is no version for Linux. (When we get to Linux we're going to do it the way the big boys do: from the command line.) Robert is working on a more advanced IDE, in Java, that will function for both DOS and Linux, but that's for another time, and perhaps the next edition of this book. For now, we're learning under DOS and starting from square one. NASM-IDE is just the thing.

I've arranged with Robert to distribute NASM-IDE on the CD-ROM in this book. If for some reason your copy of the book lacks a CD-ROM (as used computer books often do) or has a damaged and unreadable CD-ROM, you can download NASM-IDE free of charge from Robert's home page at www.inglenook.co.uk/nasmide/index.html.

NASM-IDE has the advantage for us that it was created specifically for use with the NASM assembler, which we'll begin using shortly. NASM has the power to assemble directly to a DOS .COM executable file, making the separate link step (as I describe in Chapter 4) unnecessary for simple programs that you write in only one source code file. NASM-IDE takes advantage of this power and allows you to edit, assemble, and test simple assembly language programs very quickly. (We explore modular assembly and linking in a later chapter, as it remains a very important topic for intermediate and advanced

assembly work.)

NASM-IDE's Place to Stand

Like Turbo Pascal and the other integrated development environments from both Borland and Microsoft, NASM-IDE's most visible part is a text editor. If you look back once again to Figure 4.5, you'll see that all roads seem to lead back to the text editor in good time. In general, you do most of your thinking while staring at the text editor screen, so it seems a logical location to put your place to stand.

So, one way to think of NASM-IDE is as a text editor from which you can do additional, assembly- language-related things. You invoke NASM-IDE like a text editor, in fact. If you're working from DOS, the first time you want to work on a particular source code file, you type the name NASMIDE followed by the name of the source code file:

C:\ASM>NASMIDE EAT2.ASM

(Here, "EAT2.ASM" is the name of an assembly language source code file that we'll be working on later in this book.)

I recommend that you place the directory containing NASM-IDE on your DOS path. That way, no matter where you are on your hard drive, you can type "NASMIDE" and NASM-IDE will come up, ready for work.

When you bring up NASM-IDE using the preceding command line, what you'll see should look a lot like Figure 5.1.

Figure 5.1: The NASM-IDE environment.

NASM-IDE consists of an empty space (with a texture to fill it, indicating that it's empty) in which you can open windows containing information. At the top of the screen is a menu bar. At the bottom of the screen is a prompt bar. The menu bar provides several menus of options that you can pull down (either from the keyboard or with the mouse) to accomplish the various things that NASM-IDE can do. The prompt bar gives you terse reminders of the most important commands that you can issue via the function keys and various hot keys. Square in the middle of the screen is an edit window containing the file you opened when you invoked NASM-IDE.

Telling NASM-IDE Where NASM Is

There isn't a lot of installing or configuring to be done with either NASMIDE or NASM itself. I've arranged a directory on this book's CD-ROM called ASM with all the various tools in it in the right places. However, you need to copy that directory to a place on your hard drive, because you cannot write files to the CD-ROM. You can drag the ASM directory from the CD-ROM to one of your hard drive units using Windows Explorer, and all of the subdirectories under ASM will come along. However, if you're working purely from DOS, you need to use XCOPY to do the copying.

Once you get NASM-IDE running, you need to do one essential piece of configuration before you can use it: You must tell it the exact path where the NASM executable file resides. This cannot be the path of the CD-ROM! I recommend making ASM a subdirectory on the root of one of your hard drives; for example, C:\ASM rather than C:\programming\ ASM. The drive unit doesn't have to be C:, especially in these days of multigigabyte hard drives where a typical Windows 95 PC has units C:, D:, E:, and possibly even F:, all with 2 gigabytes of storage or more. (A Windows 95 hard drive unit cannot contain

more than 2 gigabytes.)

Choose one and copy the ASM directory from your CD-ROM to your hard drive. Then bring up NASMIDE and pull down the Options menu. Select the Options|Assembler item by either highlighting it and pressing Enter, or double-clicking on it with your mouse. A dialog box will appear. You shouldn't change anything in this box except for one item: the edit line labeled NASM Location. When the dialog box appears, this line will be blank. You need to enter the full path of the NASM executable file where it was copied to your hard drive.

If you copied the ASM directory to the root of your D: drive (probably better than putting it on C: since everybody wants to be on C: and C: is often a little crowded), the path to NASM will be this:

D:\ASM\nasm16.exe

Obviously, if you copied the ASM directory to C: or E:, the initial letter will not be D:. Think it through. But this is the line you should type into the field marked NASM Location. Then click on the button labeled OK. NASM-IDE now knows where the assembler lives and will be able to invoke it for you behind the scenes.

With that accomplished, you're ready to rock. So let's see what NASM-IDE and NASM can do.

The Edit Window

The edit window is the part of NASM-IDE that you'll be seeing most often. It contains the assembly language source code file you're working on at any given time. Within the edit window you can type text, delete text, change text, and search for sequences of characters (strings) in your text. This is where you'll write new code and change code that doesn't work correctly. The cursor moves in response to the mouse, and you can move it from the keyboard as well.

The edit window works a great deal like the edit window present in the last generation of DOS-based Borland language products, Borland Pascal and Borland C++. If you have any experience in those DOS-based products, you'll feel right at home. The various hot keys and function keys all do pretty much the same things as they did in those products.

When you first bring up a file in the edit window (as you did with EAT2.ASM just now), the file will be in an edit window centered in the middle of the screen. There will be a line of empty space on all four sides. If all you're doing is editing that one file, there's no need to waste the empty space all around the edit window. At the top edge of the edit window are two controls: a small square on the left, and an upward-pointing arrow on the right. The upward-pointing arrow expands (or zooms) your edit window to occupy the full screen. The small square closes the edit window, which then vanishes.

Text screens are small enough as it is. I always zoom my edit windows so that they become as large as possible. One click on the arrow control on the top edge of the edit window is all it takes.

At the top edge of the edit window is the full path of the file currently loaded and being edited in that window.

The Menu Bar

All along the top edge of the NASM-IDE screen is the menu bar. Each word in the menu bar is the name of a separate menu. If you click on one of these menu names with the mouse, the menu proper (containing a number of menu items) will drop down beneath the name, and the top item on the menu will be highlighted with a green bar. Each item in a menu represents a command of some sort. You can move the highlight bar up and down by pressing the up/down arrow keys on the keyboard. To execute the menu command represented by the highlighted item, you press Enter. You can click on a menu option with the mouse, and the command it represents will be executed right then.

Sometimes a menu item's name is followed by three dots or periods. This indicates that this menu item, when selected, brings up a dialog box that you must fill out with some additional information in order to execute the command. I describe these dialog boxes a little later in this chapter.

At the right edge of the menu bar is a time display. The time is taken from your machine's system clock.

Although nearly all PC systems these days are equipped with a mouse, it's possible to use NASM-IDE without a mouse. (The mouse makes many things quicker and easier, however.) Note that the menu names in the menu bar have the first letters of their names highlighted in a separate color. (This will be red unless you change it.) The distinctive color on the first characters of the menu names reminds you of the hot keys associated with the menus. You can pull down any of the menus by pressing Alt followed by the highlighted letter.

For example, the E in "Edit" in the menu bar is in red. If you press Alt-E, you'll pull down the Edit menu. Then you can use the up/down arrow keys on the keyboard to move the item highlight bar up and down. When the highlight bar is over the option that you want, you simply press Enter to select that item and issue the command that it represents.

Note that the items in some of the menus are divided into groups by single horizontal lines. These lines are there only to help you recall that certain menu items are related to one another. The dividing lines cannot be selected and have no command-related function themselves.

I go through most of NASM-IDE's menu items in detail later in this chapter.

The Prompt Bar

At the bottom of the screen is another horizontal bar. This one, called the prompt bar, contains little reminders of certain hot keys that are functional at various times in NASM-IDE, depending on what you have open on the screen and what you're doing with it.

However, the most useful function of the prompt bar is to enlarge upon NASM-IDE's menu items a little. When you have a menu pulled down, the prompt bar will show you a short description of what the highlighted menu item is for. This will help you a lot while you're learning NASM-IDE and will make it a lot less necessary to be constantly flipping through this book looking for an explanation of a particular menu item that you haven't quite committed to memory.

Keep in mind that the prompt bar is not interactive; that is, there's nothing you can select in it, and nothing you can click on. It's there to give you little mental noodges, especially while you're learning the NASM-IDE system.

Other Windows

Files under edit aren't the only things that appear in windows in NASM-IDE. In fact, anything that isn't on the menu bar or the prompt bar must be in a window. Most of the time, it'll be assembly source code text files in the window. But you will see other information in windows as well.

The most significant of these is probably the help window. If you press F1 from almost anywhere in NASM-IDE, the help window will appear, and you can navigate around in it to read up on many of NASM-IDE's features. I have more to say about the help window later in this chapter.

When NASM-IDE invokes NASM to assemble a source code file for you, it will create a window for any error or warning messages that NASM generates while translating your source code file. This window will appear even when it's empty, to indicate that the assembly process went through completely and correctly.

There are error message boxes that will appear if certain things (such as loading a file from disk) don't go quite right. These are windows, too. Finally, several of the menu items bring up small windows called dialog boxes that must be filled in (by you) with additional information to complete the job the menu item was intended to accomplish. I discuss these dialog box windows in connection with the menu items that bring them up.

NASM-IDE windows have a few things in common. All windows have some sort of title at the center of their top edges, to indicate what they're for. Windows containing source code files will have the full path of the file shown in the window. All windows in NASM-IDE have the close control on their top edge. This is the small square toward the left side of the top edge of the window. Dialog box windows, however, lack the zoom control on the right edge. You can close any window, but it only makes sense to zoom certain types of windows, primarily the help window and the edit windows containing your source code

files.