You are on page 1of 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 sufcient information to decide whether assembly language is appropriate for a particular application, to outline 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 (including a comprehensive explanation of the microprocessors instruction set) but will also require development software comprising, as minimum, a macro assembler, a linker, and a debugger. Furthermore, despite the fact that one of the most powerful 32-bit assemblers, MASM32, is currently available as freeware; 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 invariably run faster than an equivalent program written in a higher-level not require the services of a resident interpreter or a compiler run-time 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. system; language; level language;

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 assembly language

Unfortunately, when compared with higher-level languages, 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 different 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 architecture is reected 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 manufacturers frequently adopt different terminology to refer to the same thing. The variety of names used to describe the register used to indicate the outcome 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 highlevel language are usually easy to comprehend and their structure is usually self-evident. The production of efcient assembly language programs requires a relatively high degree of prociency 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 conguration available for software development 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 specication for both hardware and software (see Chapter 4). 2 Developing the overall structure of the program, dening the individual elements and modules within it, and identifying those which already exist (or can be easily modied or extended) within the programmers 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 lename. 4 Assembling each source code module (using an assembler) to produce an intermediate relocatable object code le.

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 users library) in order to produce a complete executable program. 6 Testing, debugging, and documenting the nal 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 target specication 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. Microsofts M); a macro assembler (e.g. Microsofts MASM); a linker (e.g. Microsofts 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. Microsofts CREF); a library manager (e.g. Microsofts LIB); a utility which can help automate the program development cycle (e.g.
Microsofts MAKE). Note that, in order to assist the programmer and to help automate the production 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 benet of the newcomer to assembly language programming, we shall briey 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 les. Such les can be thought of as a sequence of keystrokes saved to disk. An assembly language source code le is simply a text le 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 conguration le (TOOLS.INI). This le 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 le list is simply a list of les that will be loaded into the editor. The rst le in the list will be the rst to be edited. Then, when the user selects the exit option (F8), the next le 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

You might also like