• Aucun résultat trouvé

Installing Turbo

Dans le document Turbo AssemblefID (Page 16-0)

Assembler on your system.

Chapter 2: Getting started In Turbo Assembler provides you with an introduction to programming in assembly language, and a few sample programs to make you comfortable using the command-line switches.

Chapter 3: Command-line reference details all the command-line options, plus tells you about using the configuration file and command files.

Chapter 4: The nature of assembly language leads you through a discussion of computers in general and the 8088 processor in particular.

Chapter 5: The elements of an assembler program describes the basic components of assembler, with some good solid information about directives, instructions, accessing memory, segments, and more.

Chapter 6: More about programming In Turbo Assembler goes one step further than Chapter 5, discussing some advanced aspects of Turbo Assembler-more about directives, string instructions, and so on. This chapter also covers some common pitfalls you may encounter as an assembly progralnmer.

Chapter 7: Interfacing Turbo Assembler with Turbo C describes how to use Turbo C, a high-level language, with assembly language. We detail how to link assembler modules to Turbo C and how to call Turbo Assembler functions from Turbo C.

Chapter 8: Interfacing Turbo Assembler with Turbo Pascal tells you how to interface your assembler code with your Turbo Pascal code; sample programs are also provided.

Chapter 9: Advanced programming In Turbo Assembler provides you with more details about everything we've touched on in earlier chapters, such as segment override prefixes, macros, segment directives, and so on.

Chapter 10: The 80386 and other processors covers programming with the 80386.

Chapter 11: Turbo Assembler Ideal mode tells you all about Ideal mode and why you'll want to use it.

References lists several useful books about assembly programming.

Notational conventions

Introduction

When we talk about IBM PCs or compatibles, we're referring to any computer that uses the 8088, 8086, 80186, 80286, and 80386 chips (all of these chips are commonly referred to as 80x86). When discussing PC-OOS, DOS, or MS-DOS, we're referring to version 2.0 or greater of the operating system.

3

All typefaces were produced by Borland's Sprint: The Professional Word Processor, output on a PostScript printer. The different typefaces displayed are used for the following purposes:

Italics In text, italics represent labels, placeholders, variables, and arrays. In syntax expressions, placeholders are set in italics to indicate that they are user-defined.

Boldface Boldface is used in text for directives, instructions, symbols, and operators, as well as for command-line options.

CAPITALS In text, capital letters are used to represent instructions, directives, registers, and operators.

Monospace Monospace type is used to display any sample code, text or code that appears on your screen, and any text that you must actually type to assemble, link, and run a program.

Keycaps In text, keycaps are used to indicate a key on your keyboard. It is often used when describing a key you must press to perform a particular function;

for example, "Press Enter after typing your program name at the prompt."

How to contact Borland

If, after reading this manual and using Turbo Assembler, you would like to contact Borland with comments, questions, or suggestions, we suggest the following procedures:

• The best way is to log on to Borland's forum on CompuServe:

Type GO BPROGB at the main CompuServe menu and follow the menus to Turbo Assembler. Leave your questions or comments here for the support staff to process .

• If you prefer, write a letter detailing your problem and send it to

Technical Support Department Borland International

P.O. Box 660001 1700 Green Hills Drive Scotts Valley, CA 95066 U.S.A.

Introduction

• You can also telephone our Technical Support department at (408) 438-5300. To help us handle your problem as quickly as possible, have these items handy before you call:

• product name and version number

• product serial number

• computer make and model number

• operating system and version number

If you're not familiar with Borland's No-Nonsense License

statement, now's the time to read the agreement at the front of this manual and mail in your completed product registration card.

5

c

H

Files on disk

A p T E R

1

Installing Turbo Assembler

Before we get you up to speed on programming in assembler, you'll need to get one thing out of the way. Take the Turbo Assembler disks and make copies (via DOS) of each one to create your "working" copies. Once you've done that, put the original disks away. (There's a fee to replace disks that you damage, so only use the originals to make backups and work copies.) If you are going to use Turbo Assembler as a replacement for MASM, read Appendix B in the Reference Manual to see in which areas Turbo Assembler behaves differently from MASM.

Note: Be sure to read the README file before working with Turbo Assembler. This file contains the latest information about the program, as well as corrections and/or additions to the manuals.

• TASM.EXE: Turbo Assembler

• TLINK.EXE: Turbo Linker

• MAKE.EXE: Command-line MAKE utility

• TLIB.EXE: Turbo Librarian

• README.COM: Program to display README file

• README: Any last minute information about the software and documentation

Chapter 7, Installing Turbo Assembler 7

• TCREF.EXE: A source file cross-reference utility

• OBJXREF.COM: Object file cross-reference utility

• GREP.COM: Grep utility

• TOUCH.COM: A file-update utility

• INSTALL.EXE: Installation program

• MMACROS.ARC: An archived file of MASM mode macros

Installing Turbo Assembler

The INSTALL disk contains a program called INST ALL.EXE that will assist you with the installation of Turbo Assembler 1.0. There are two options for installation:

1. Hard Disk Users: This option allows you to pick the subdirectories where the files will be loaded.

2. Floppy Disk Users: This option will install the files necessary to use Turbo Assembler on a two-drive system. Be sure to have four fonnatted disks ready before you start.

To start the installation, change your current drive to the one that has the INSTALL program on it and type INSTALL. You will be given instructions for each prompt in a box at the bottom of the screen. For example, if you will be installing from drive A, type

INSTALL

Before you install Turbo Assembler, be sure to read the README file to get further infonnation about this release.

Note: If you will be running INSTALL on a laptop or any other system that uses an LCD display, you should set your system to black-and-white mode before running INSTALL. You can do this from DOS with the following command line:

mode bw80

You can also force INSTALL to come up in black-and-white mode by using the Ib switch:

INSTALL /b

c

H A p T E R

2

Getting staried with Turbo Assembler

If you've never programmed in assembly language before, this is the place to begin. You might have heard that assembly language programming is a black art suited only to hackers and wizards.

Don't believe it! Assembly language is nothing more than a human form of the language of the computer itself and, as you'd expect, the computer's own language is highly logical. As you might also expect, assembly language is very powerful-in fact, assembly language is the only way to tap the full power of the Intel80x86 family, the processors at the heart of the IBM PC family and compatibles.

You can write whole programs in nothing but assembly language or you can, if you want, mix assembly language into programs written in Turbo C, Turbo Pascal, Turbo Prolog, Turbo Basic, and other languages. Either way, with assembly language, you can write small and blindingly fast programs. As important as speed is the assembly language code's ability to control every aspect of your computer's operation, down to the last tick of the system dock.

In this chapter, we'll introduce you to assembly language and explore the unique qualities of assembly language programming.

You'll enter and run several working assembly language programs, both to get a feel for the language and to get used to working with the assembler.

Chapter 5, "The elements of an assembler program," picks up where this chapter leaves off, covering the structure of ~n

Chapter 2, Getting started with Turbo Assembler 9

assembly language program and fundamental program elements and summing up everything you've learned with a full-fledged example program.

Chapter 6, "More about programming in Turbo Assembler,"

continues to explore assembly language programming, and Chapter 9 , "Advanced programming in Turbo Assembler,"

progresses to memory models, macros, and other advanced topics.

Naturally, we can't make you expert assembly language programmers in the course of a few chapters; we're simply introducing you to assembly language and getting you started on the road to writing your own programs. We strongly suggest that you get one of the many excellent books devoted entirely to assembly language programming and PC architecture (see the references at the end of this book). In addition, you may find IBM's DOS Technical Reference, BIOS Interface Technical Reference, and Personal Computer XT Technical Reference manuals to be useful reference material; these manuals document the assembly

language programming interface to the systems software and hardware of IBM's personal computers.

Before you read further, you might want to read Chapter 3,

"Command-line reference," to familiarize yourself with the command-line options. You should also install Turbo Assembler (make working copies of your Turbo Assembler disks or copy the files from your Turbo Assembler disks onto your hard disk) as described in Chapter 1, ''Installing Turbo Assembler," if you haven't already done so.

One final point: Assembly language is a complex topic, and there are many things you will need to know in order to write even a relatively simple assembly language program. Sometimes we'll have to use features in our examples that we haven't discussed yet, simply because we have to start somewhere. Bear with us; we'll explain everything in due course. If, at any time, you're curious about a specific feature, just look in Chapter 3, "Directives," in the Reference Guide.

With that out of the way, and with Chapter 3 of the second volume close at hand, it's time to create your first assembly language program.

You can follow this tutorial step by step, typing in all the code examples as you go, or you can unpack the example file on disk (when you install Turbo Assembler) and have all the programs at

your fingertips. (Whatever your decision, the file names are provided at the beginning of each example for your convenience.

Writing your first Turbo Assembler program

Assembling your first program

In the world of programming, the first program is traditionally a program that displays the message, "Hello, world" and that's as good a place as any for us to start.

Get into your text editor of choice (one that outputs ASCII files), and type in the following lines that make up the program HELLO.ASM:

.MODEL small .STACK 100h

• DATA

HelloMessage DB 'Hello, world' ,13,10,'$' .CODE

mov ax,@data

mov ds,ax iset OS to point to the data segment

mov ah,9 iDOS print string function

mov dx,OFFSET HelloMessage ipoint to "Hello, world"

int 21h idisplay "Hello, world"

mov ah,4ch iDOS terminate program function

int 21h iterminate the program

END

As soon as you've entered HELLO.ASM, save it to disk.

If you're familiar with C or Pascal, you might be thinking that the assembler version of "Hello, world" seems a bit long. Well, yes, assembler programs do tend to be long because each assembler instruction by itself does less than a C or Pascal instruction. On the other hand, you've got complete freedom in combining those assembler instructions in any way you want. That means that, unlike C and Pascal, assembler lets you program the computer to do anything it's capable of-and that's often worth typing a few extra lines.

Now that you've saved HELLO.ASM, you'll want to run it. Before you can run the program, though, you'll have to convert it into an executable (able to be run or executed) form. This requires two additional steps, assembling and linking, as shown in Figure 2.1,

Chapter 2, Getting started with Turbo Assembler 11

Figure 2.1 The edit, assemble, link, and

run cycle

which depicts the complete edit, assemble, link, and run program development cycle.

Create a New Program

Assembler Source File HELLO.ASM

Assemble

!

Object File HELLO.OBJ

Link

I l

Executable File HELLO.EXE

Run I

!

(If changes are needed)

~

The assembly step turns your source code into an intermediate form called an object module, and the linking step combines one or

Linking your first program

more object modules into an executable program. You can do your assembling and linking from the command line.

To assemble HELLO.ASM, type TASM hello

Unless you specify another file name, HELLO.ASM will be assembled to HELLO.OBJ. (Note that you don't need to type in the file extension name; Turbo Assembler assumes .ASM in this case.) This is what you'll see onscreen:

Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 by Borland International, Inc.

Assembling file: HELLO.ASM Error messages: None Warning messages: None Passes: 1

Remaining memory: 266K

You won't receive any warnings or errors if you typed HELLO.ASM exactly as shown. If you get warnings or errors, they'll appear onscreen, along with the line numbers to indicate where they occurred. If you get errors, check your code and make sure it's precisely the same as the code we've shown you, then assemble the program again.

After you've successfully assembled HELLO.ASM, you're only one step away from running your first assembler program. Once you've linked the just-assembled object code into an executable form, you can run the program.

To link the program, you'll use TLINK, the linker accompanying Turbo Assembler. At the command line, type

TLINK hello

Again, there's no need to enter the extension name; TLINK assumes it's .OBJ. When linking completes (again, after a few seconds at most), the linker automatically gives the .EXE file the same name as your object file, unless you've specified otherwise.

When linking is successful, this message appears onscreen:

Turbo Link Version 3.0 Copyright (c) 1987, 1990 by Borland International, Inc.

Chapter 2, Getting started with Turbo Assembler 13

Running your first

Errors can occur during the linking process, although that's unlikely with this example program. If you do receive any link errors (they'll appear onscreen), modify your code to exactly rna tch the code shown here, then assemble and link again.

program

Now you're ready to run your program. Type hello at the DOS prompt. The message

Hello, world

will be displayed onscreen. And that's all there is to it-you've just created and run your first Turbo Assembler program!

What happened?

Now that you've gotten HELLO.ASM up and running, let's go back and figure out exactly what happened along the path from entering text to running the program.

When you first entered the assembler source code, the text was stored by your text editor in memory. If the computer had been turned off at this point, for whatever reason, the source code would have been lost; consequently, we suggest you save your source code early and often in order to avert possible tragedy.

When you saved the source code to disk, a permanent copy of the text was stored in the file HELLO.ASM, where it would survive even if you shut off your computer. (HELLO.ASM might not survive a disk crash, however, so we also suggest that you back up your disks regularly.) HELLO.ASM is a standard ASCII text file; you can display it at the DOS prompt by typing

type hello.asm

and you can edit it with any text editor.

When you assembled HELLO.ASM, Turbo Assembler turned the text instructions in HELLO.ASM into their binary equivalents in the object file HELLO.OBI. HELLO.OBI is an intermediate file, partway between source code and an executable file. HELLO.OBI contains all the information needed to make executable code out of the instructions that started out in HELLO.ASM, but it's in a form that can readily be combined with other object files into a single program. In Chapter 6, "More about programming in Turbo Assembler," you'll see how useful this can be when you're developing large programs.

Next, when you linked HELLO.OB], TLINK converted it into the executable file HELLO.EXE. Finally, you ran HELLO.EXE when you typed hello at the prompt.

Now type

dir hello.*

to list the various HELLO files on your disk. You'll find HELLO.ASM, HELLO.OB], HELLO.EXE, and HELLO.MAP.

Modifying your first Turbo Assembler program

Now go back to your editor and modify your program to accept a bit of input from the outside world. (The outside world is you, typing at your keyboard.) Change the code to the following:

.MODEL small .STACK 100h

• DATA

TimePrompt DB 'Is it after 12 noon (Y/N)?$' GoodMorningMessage LABEL BYTE

DB 13,10,'Good morning, world!',13,10,'$' GoodAfternoonMessage LABEL BYTE

DB 13,10,'Good afternoon, world!' ,13,10,'$'

• CODE

;get a single-character response ityped lowercase y for after noon? mov dx,OFFSET GoodAfternoonMessage ;point to the afternoon

; greeting jmp DisplayGreeting

IsMorning:

mov dx,OFFSET GoodMorningMessage ;point to the before noon

i greeting DisplayGreeting:

mov ah,9 int 21h

Chapter 2, Getting started with Turbo Assembler

iDOS print string function #

;display the appropriate greeting

15

mov ah,4ch int 21h

END

;005 terminate program function t

;terminate the program

You've added two important new capabilities to your program:

input and decision-making. This program asks you whether it's after noon, then accepts a single-character response from the keyboard. If the character typed is an uppercase or lowercase Y, the program displays a greeting appropriate for the afternoon;

otherwise, it gives a morning greeting. All the essential elements of a useful program-input from the outside world, data

processing and decision-making, and output to the outside world-are present in this code.

Save the modified program to disk. (This replaces your original version of HELLO.ASM with the modified code, so the original version will be lost.) Then reassemble and relink the program just as you did in the previous examples. Run the program again by typing hello at. the DOS prompt. The message

Is it after 12 noon (YIN)?

is displayed, with the cursor blinking after the question mark, waiting for your response. Press Y. The program responds

Good afternoon, world!

HELLO.ASM is now an interactive, decision-making program.

In the course of your assembler programming, you will surely make a wide variety of mistakes in typing and in program syntax.

Turbo Assembler ca tches many mistakes for you as it assembles your code, reporting all such errors. The mistakes reported fall into two categories: warnings and errors. Turbo Assembler displays a warning message if it detects something suspicious, but not necessarily wrong, in your code; sometimes warnings can be

Turbo Assembler ca tches many mistakes for you as it assembles your code, reporting all such errors. The mistakes reported fall into two categories: warnings and errors. Turbo Assembler displays a warning message if it detects something suspicious, but not necessarily wrong, in your code; sometimes warnings can be

Dans le document Turbo AssemblefID (Page 16-0)

Documents relatifs