ebook img

Computer Programming. A Mixed Language Approach PDF

465 Pages·1964·20.616 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computer Programming. A Mixed Language Approach

COMPUTER PROGRAMMING: Λ Λ/Ι/xed Language Approach by Marvin L. Stein and William D. Munro Division of Mathematics, Numerical Analysis Center University of Minnesota, Minneapolis, Minnesota ACADEMIC PRESS, New York and London COPYRIGHT © 1964, BY ACADEMIC PRESS INC. ALL RIGHTS RESERVED. NO PART OP THIS BOOK MAY BE REPRODUCED IN ANY FORM, BY PHOTOSTAT, MICROFILM, OR ANY OTHER MEANS, WITHOUT WRITTEN PERMISSION FROM THE PUBLISHERS. ACADEMIC PRESS INC. Ill Fifth Avenue, New York, New York 10003 United Kingdom Edition published by ACADEMIC PRESS INC. (LONDON) LTD. Berkeley Square House, London W.l LIBRARY OF CONGRESS CATALOG CARD NUMBER: 64-20324 First Printing, 1964 Second Printing, 1965 Third Printing, 1966 PRINTED IN THE UNITED STATES OF AMERICA. For Ruth and Anne Preface The purpose of this book is to help in providing the training of two classes of computer users. For the professional programmer-to-be, it aims to furnish a solid foundation for the more complex and subtle programs with which he will ultimately deal. For the nonprofessional, who neverthe- less is required to make consistent use of the computer, it represents an attempt to give him an adequate training with which the additional practice of use will suffice. For this reason we treat three kinds of pro- gramming languages, the absolute machine language required by the com- puter "hardware," the symbolic machine language, and the problem- oriented language provided by the "software" of symbolic assembly programs and compilers. For the occasional user of a computer with perhaps a differential equation to solve, a minimum of one of the problem-oriented languages and the help of a professional will be adequate. It is our belief, however, that a consistent user of a computer must delve deeper. An in- telligent and efficient use of the convenience furnished by the software languages can only be attained with a thorough understanding of how the computer itself functions and of machine language. A thorough mastery of the subject of programming includes the versatility to make effective use of the hardware and software aspects of the total system provided. In particular, this can be achieved through the utilization of the mixed languages which are neither the absolute machine languages nor the more facile problem-oriented languages alone, but a composite of both. In this book we attempt the task of drawing together this material into a unified whole to illustrate the basic way in which the computer operates and how this is related to a convenient mixed language in current use. In the earlier days of digital computers the transition from the original problem to an acceptable version for the computer was usually accomplished vii viii PREFACE by a staff of trained personnel who could do the necessary programming and coding. The increased speeds and capacities of modern computers and the increased demand for their use, however, have made it impossible to maintain a sufficiently large body of professional programmers to meet all needs. For this reason, an ever growing numbefr of persons who are not primarily interested in digital computers as such have, nevertheless, found it necessary to learn enough to do the major part of the programming for their own problems. This raises the two questions which this book attempts to answer. How are these people to be trained to use a computer with a minimum of help, and how are additional professional programmers to be educated at the same time? The fact that the ordering of the topics follows a historical pattern is incidental. We believe that this is both the logical order and the order which is pedagogically most sound. It is easy for a person well grounded in absolute machine language who has written at least a few programs in this form to make the transition to the more convenient symbolic languages of the assemblers, and from these to the problem-oriented language. Furthermore, he will better understand what is involved in the translation from the symbolic language to the objective program, and can make a more intelligent and efficient use of the software. It is our experience that the inversion of this order makes it much more difficult to attain the same level of programming proficiency. Some people, however, will disagree with this point of view and will prefer to start with a symbolic language. This objective can still be achieved by reordering the chapters of the book. For those who wish to start with a compiler, Chapters 7 and 9 give a reasonably complete and self-contained version of Fortran, after which the other chapters can be considered in any desired order. We recommend, however, that early attention be given to Chapter 2, at least to the extent that the student becomes sufficiently familiar with machine organization to understand why we can identify symbolic addresses and variable names. For those who wish to start with a symbolic form of machine language, Chapter 8 can be treated earlier. Whatever the order of its use, the book tries to give a complete fundamental description of each of the three languages, alone and intermixed, and presents numerous examples for illustration. We have also provided a variety of exercises for each of the topics covered, together with answers to selected ones of these where a single answer is meaningful. We have chosen Fortran as the compiler language of this book because it is a widely used language available in some form at most installations, and serves, with the Fortran Symbolic Assembly Program, to give a good illustration of mixed language programming. PREFACE ix In the basic description of the organization of a computer and the use of machine language, we have attempted to present the topics with as great a generality as possible. For purposes of explicit illustration, however, it is necessary to introduce a specific machine, real or hypothetical. We feel that the use of a real machine which is widely employed has advantages over the use of a hypothetical one, provided that the salient generalities are not obscured by the painful detail of a manufacturer's manual. At the same time, the direct introduction of some of the typical hardware and software idiosyncrasies associated with any real computing system will guard against a complete idealization and give the student a feel for the actualities he will encounter in practice. We have chosen for illustration the Control Data Corporation Model 1604 (which we will hereafter refer to as the CDC 1604). In terms of instruction repertoire this is representa- tive of most large scale modern computers. It is also completely compatible with a subset of the instruction repertoires of the Control Data 3400* and 3600* systems, and all discussions in the book are directly applicable to these. Furthermore, the format of its instruction words is such as to teach something of a feel for both single address and double address computers. It is true that once machine language is learned for a particular machine, the transition to another machine is relatively simple. This is so to the ex- tent that many of our students have done the laboratory problems on other kinds of computers available to them, even though the text illustrates programming concepts with the CDC 1604. Except for Chapter 3 in which the specific programs all relate to it, those sections which deal specifically with the CDC 1604 are so labeled. Although the practice of external scaling is much less prevalent in current usage than it was formerly, we have treated the topic in considerable detail. This was done with a twofold purpose in mind. First, to understand floating point operation, which is merely scaling handled by the computer, a programmer needs to know what scaling is all about. Moreover, in some oroblems he will have to use it. Second, we felt that the literature lacked a detailed exposition of the topic which could be used as a reference. This aspect is of more interest if we note that an increase in the use of external scaling is likely to result from the development of the modern hybrid digital and analog systems. The material in the complete book is suitable for a course of three quarters or two semesters, although in a course of such length we usually include some additional material on topics such as circuit logic and Algol. For a one-quarter or one-semester course, the book can be used in various ways. It can be used for training in Fortran alone. Alternatively, as we use it, * Registered. χ PREFACE it is suitable for a brief introduction to machine language, floating point operation, and elementary Fortran. The material is designed for the junior, senior, and early graduate level. No specific background of mathematical knowledge is required, although the maturity acquired by, say, a first course in differential equations is valuable. Students in almost all fields including physical sciences, behavioral sciences, biological sciences, educa- tion, and agriculture have successfully mastered the material. The book should be used, if possible, in conjunction with a laboratory program which permits the students at the earliest possible moment to write and run programs on a computer. In starting with machine language we have found that students can write successful programs of the sort sug- gested in the exercises within a week of starting Chapter 3. The writing of programs of increasing complexity and diversity should run concurrently with the material covered in class during the entire course. We have found it useful for students to write simple assembly programs before using the more sophisticated ones. The joint experience of the authors in the use and teaching of a variety of computers and a variety of topics in the computing field totals more than twenty-five years. This book reflects our judgment of the topics and presentation which will best guide the novice along the road to becoming a well-rounded programmer. We find it impossible to mention all of the associates or authors who have contributed invaluably to our present way of thinking, nevertheless, we thank them all. We also thank James Carlson, Richard Hotchkiss, and Lawrence Liddiard for invaluable criti- cisms and contributions, and Mrs. Janet Schuffenhauer for care and pa- tience in typing the manuscript. We also express our appreciation to Control Data Corporation for their permission to use the CDC 1604 as the illustrative model of a computer. Finally, we would like to express our appreciation to Academic Press for their competence and skill in producing the book. Minneapolis, Minnesota MARVIN L. STEIN WILLIAM D. MUNRO Introduction 0-0. General Description of a Modem Digital Computer We will use the terminology modem digital computer to describe a high- speed, internally programmed, general-purpose, automatic, digital com- puting machine. In what follows we will deal with three basic questions regarding the modern digital computer: What is it? What does it do? How do we get it to do whatever it is that it does do? As a specific model for illustration we shall use the CDC 1604; however, the general ideas carry- over to other modern computing systems since they are all similar in their main operating features, although they differ somewhat in the design of these features. To say that a computer is digital is to say that it operates on numbers represented by sequences of digits. This is in contrast to the class of com- puting machines called analog computers that operate on continuous input data represented in terms of some physical quantity (such as voltage or an- gular displacement of a wheel) which varies in proportion to the actual data which it represents. The digital computer, on the other hand, deals with discrete sets of digits in much the same way as a human being in carrying out the operations of addition, subtraction, multiplication, and division It can also distinguish between a sequence of digits representing a number greater than or equal to zero and one representing a number less than zero; however, this is about as far as its ability in arithmetic will ordinarily extend. Very few modern digital calculators come from the assembly line with the builtin ability to evaluate such functions as the logarithm to the base e or the Bessel function of order zero. Any one of these machines can be used to turn out a table of logarithms or Bessel functions, but it must be 1 2 INTRODUCTION made to carry out such complex operations by a proper sequence of the elementary operations which are built into it. The fact that the digital computer performs only very simple operations upon digits is compensated for by the extremely high speeds at which it performs them. It carries out literally thousands of operations each second. Speed alone, however, is not enough. The ingenuity and skill displayed by the human operator in expressing his problems in terms of mathematical models that lend themselves to solution by means of sequences of the simple operations available, and in actually creating the correct sequences of such operations, is also of prime importance. The modern high-speed digital calculator is automatic only in the sense that, after being presented with its input, it can operate upon that input to produce the desired output without further intervention by any human operator. It operates in this manner by means of its program. By the pro- gram of a machine we mean its way of selecting the sequence in which the operations will actually be carried out in order to solve a specific problem. A special-purpose computer will have a fixed program built in to solve its specific problem. Such a computer is a useful and economical device if we wish only to solve the same problem for different input values a large number of times. The modern digital calculator, however, is a general- purpose type of machine. It aims at versatility. With it the user can attempt any particular problem he has in mind; and once his programs are prepared, he can switch from one program to another in a few seconds. If its repertoire of operations is suitably versatile, a machine may be judged to be general-purpose by the degree of ease with which its program can be changed. There are a variety of ways in which a change of program can be facilitated. A common technique is to provide easily accessible external switches or an external plugboard. This technique can be made more effective by making the plugboards removable, thus enabling one to set up any number of programs in advance. Another common method for changing the program is to feed into the machine a sequence of punched cards or, what is logically the same, a punched paper tape. The holes in the tape are used to change internal switch settings. Even greater flexibility in the changing of programs can be provided by a combination of removable plugboards and punched paper tape. Automatic computing machines which employ any of the above or similar means for changing their programs are referred to as externally programmed machines. The programs of these machines are external in the sense that the machines must accept them as given by their operators and can do little, if anything at all, to change or modify them by means of their own operations. In the modern digital calculator, however, this is not the case. The program of a modern digital 0-1. FUNCTIONAL DESCRIPTION 3 calculator is stored within the calculator in the same form as its data. As a consequence, the modern digital calculator can operate upon its program just as it can operate upon its data and can change and modify the program during the course of the operation. For this reason the modern digital calculating machine is referred to as an internally programmed machine. Internal programming and high speed of operation are what make a general-purpose, automatic, digital calculator truly versatile. It is clear that these two features must go hand-in-hand. In order for a machine that can perform thousands of operations each second to be economically in balance, it must receive its instruction as to which of its operations it is to perform next just as quickly as it can perform that operation. The machine cannot afford to wait for a relatively slow moving tape; no plugboard would contain enough hubs to set up the thousands of operations necessary to keep it going even a few seconds unless a small set of operations is used repetitively. Similarly, unless a small set of operations is used repetitively, the machine's internal storage capacity would have to be unaffordably large before a sequence of internally stored operations could be set up which was long enough to keep the machine going for a length of time sufficient for the operator even to remove his finger from the start button. The solution is for the machine to have the ability to manufacture its instructions internally on the basis of a set of initial instructions to be loaded in with the data. Thus, to solve a problem we do not write a complete sequence which includes one operation for each computation that is to be made. Rather, we prepare a relatively small set of instructions (small in relation to the eventual number of operations that are to be executed) which will cause the computing machine to create internally, as it needs it, the program that is necessary to the solution of the given problem. It is obvious that a departure from older methods of problem preparation is called for if such a machine is to be put into effective use. 0-1. Functional Description of a Modern Digital Computer In solving a given problem a modern digital computer performs the functions of input of information, storage of information, control, arithmetic, logic, and, finally, output of information. These are all indicated in the figure below, the traditional block diagram of a calculator. The parallel with a human being who is doing hand computation on a desk calculator is straightforward. The human being is replaced by the control; his desk calculator is replaced by the arithmetic-logic unit; and his pencil and paper, books of tables, and human memory are replaced by the input-output and storage units.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.