Вы находитесь на странице: 1из 4

5 Assembly language

programming

This chapter aims to provide readers with an overview of assembly language


programming techniques, and explores the architecture and instruction set of
the x86 microprocessor family used in the PC and compatible equipment.
Rather than providing a complete guide to assembly language programming
(which, in any event, would require a complete book in its own right!), the
aim has been that of providing readers with sufficient information to decide
whether assembly language is appropriate for a particular application, to out-
line the advantages and disadvantages of assembly language programming,
and to introduce techniques used for the development of assembly language
Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376
programs.
Readers wishing to develop their own assembly language programs will not
only require complete documentation for the x86 family of processors (includ-
ing a comprehensive explanation of the microprocessor’s instruction set) but will
also require development software comprising, as minimum, a macro assem-
bler, a linker, and a debugger. Furthermore, despite the fact that one of the
most powerful 32-bit assemblers, MASM32, is currently available as ‘free-
ware’; readers should not underestimate the investment required (in terms of
time) required to successfully follow this route.

Advantages of Assembly language programs offer a number of advantages when compared


assembly language with higher-level alternatives. The principal advantages are that the executable
code produced by an assembler (and linker) will:
• invariably be more compact than an equivalent program written in a higher-
level language;
• invariably run faster than an equivalent program written in a higher-level
language;
• not require the services of a resident interpreter or a compiler run-time
system;
• be able to offer the programmer unprecedented control over the hardware in
the system.
It is this last advantage, in particular, that makes assembly language a prime
contender for use in control applications. No other programming language
can hope to compete with assembly language where control of hardware is
concerned. Indeed, an important requirement of high-level languages used in
control applications is that they can be interfaced with machine code modules
designed to cope with problems arising from limitations of the language where
input/output (I/O) control is concerned.

Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376


168 PC Based Instrumentation and Control

Disadvantages of Unfortunately, when compared with higher-level languages, assembly language


assembly language has a number of drawbacks; most notable of which are the following:
• Programs require considerably more development time (including writing,
assembling, linking or loading, and debugging) than their equivalent written
in a high-level language.
• Programs are not readily transportable between microprocessors from differ-
ent families. Different microprocessors have different internal architectures
and, in particular, the provision of registers accessible to the programmer
will vary from one microprocessor to another. Differences in internal archi-
tecture is reflected in corresponding differences in the type and function of
the software instructions provided for the programmer.
• The situation is further compounded by the fact that microprocessor manu-
facturers frequently adopt different terminology to refer to the same thing.
The variety of names used to describe the register used to indicate the out-
come of the last arithmetic logic unit (ALU) operation (and the internal
status of the microprocessor) is a case in point. This is variously referred to
as a Flag Register, Status Register, Condition Code Register, and Processor
Status Word.
Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376
• In practice this means that the system designer is constrained to select one
particular microprocessor type or family, and develop code exclusively for
this particular device. This, of course, is not a particular problem in the case
of the PC and compatible equipment which are all based on the standard x86
and Pentium families.
• Unless liberally commented, the action of an assembly language program is
not obvious from merely reading the source text. Programs written in high-
level language are usually easy to comprehend and their structure is usually
self-evident.
• The production of efficient assembly language programs requires a relatively
high degree of proficiency on the part of the programmer. Such expertise
can usually only be acquired as a result of practical experience aided by
appropriate training.

Developing assembly The process of developing an assembly language program depends on a number
language programs of factors including the hardware configuration available for software develop-
ment and the range of software tools available to the developer. As a minimum,
the task normally involves the following steps:
1 Analysing the problem and producing a specification for both hardware and
software (see Chapter 4).
2 Developing the overall structure of the program, defining the individual ele-
ments and modules within it, and identifying those which already exist (or
can be easily modified or extended) within the programmer’s existing library.
3 Coding each new module required using assembly language mnemonics,
entering the text using an editor, and saving each source code module to disk
using an appropriate filename.
4 Assembling each source code module (using an assembler) to produce an
intermediate relocatable object code file.

Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376


Assembly language programming 169

5 Linking modules (including those taken from the user’s library) in order to
produce a complete executable program.
6 Testing, debugging, and documenting the final program prior to evaluation
and/or acceptance testing by the end-user (see Chapter 4).
In practice, the development process is largely iterative and there may also
be some considerable overlap between phases. In order to ensure that the tar-
get specification is met within the constraints of time and budget, an ongoing
appraisal is necessary in order to maximize resources in the areas for which
there is much need.

Software tools

The following items of utility software (software tools) are normally required
in the development process:
• an ASCII text editor (e.g. Microsoft’s M);
• a macro assembler (e.g. Microsoft’s MASM);
• a linker (e.g. Microsoft’s LINK).
Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376
In addition, three further software tools may be found to be invaluable.
These are:
• a cross-referencing utility (e.g. Microsoft’s CREF);
• a library manager (e.g. Microsoft’s LIB);
• a utility which can help automate the program development cycle (e.g.
Microsoft’s MAKE).
Note that, in order to assist the programmer and to help automate the produc-
tion of executable code, an Integrated Development Environment (IDE) is often
used. This acts as a ‘shell’ which launches the various software tools, passing
any required parameters without requiring the user to be aware of the necessary
command syntax. However, for the benefit of the newcomer to assembly lan-
guage programming, we shall briefly explain the function of each of the basic
tools and their role in the production of assembly language programs.

Editors

Editors allow users to create and manipulate text files. Such files can be thought
of as a sequence of keystrokes saved to disk. An assembly language source
code file is simply a text file written using assembly language mnemonics and
containing appropriate assembler directives.
The Microsoft Editor (M) is invoked using a command line of the form:
M <options><file list>

The options include that of allowing the user to load a previously saved con-
figuration file (TOOLS.INI). This file contains settings which will be used to
initialize the editor and thus the user may easily customize the software to
his/her own particular requirements. The file list is simply a list of files that will
be loaded into the editor. The first file in the list will be the first to be edited.
Then, when the user selects the exit option (F8), the next file in the list, ready
for editing, is loaded.

Buy this file from http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376


Chapter extract

To buy the full chapter, and for copyright


information, click here
http://www.download-it.org/learning-resources.php?promoCode=&partnerID=&content=story&storyID=1376

The publisher detailed in the title page holds the copyright for this document

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form or by any means, electronic, mechanical, photocopying, recorded or otherwise, without the written
permission of Spenford IT Ltd who are licensed to reproduce this document by the
publisher

All requests should by sent in the first instance to

rights@download-it.org

Please ensure you have book-marked our website.

www.download-it.org

Вам также может понравиться