Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






The basic principles of programming






(continued)

 

1. The Use of Temporaries. Memory space in a computer should be conserved. From this point of view there are two kinds of numbers contained in addresses: permanent or constant numbers, such as 2 and g, and temporary numbers, i.e., numbers that appear only in intermediate stages of the computation. These temporary numbers can share their address with other temporary numbers that appear at some other time. Hence we call such memory locations temporaries.

2. Flow Chart. A flow chart is a diagram, or picture, of a code that is often helpful for visualizing interrelationship between various parts of a code. Such diagram is almost always made before the specific instructions are written. There are essentially three kinds of symbols used in a flow chart (see Fig. 5). The first represents function calculations, the second represents decisions and the various associated alternatives, the third, called a variable connector, and is simply a way to eliminate too many crossing lines in the picture or to indicate which lines to follow when one has to continue the diagram on another page.

3. Symbolic Coding Aids. It is another intermediate aid between the statement of the problem and the final code. Symbolic coding consists in writing a code not in terms of specific numerical addresses, but rather in terms of some name description or other symbolism to represent the addresses. Then, at a later time, specific addresses can be assigned for these symbols or names to produce the actual code. The intermediate code in terms of symbols is called the symbolic code.

 

Figure 5. Flow Chart Symbols

 

This technique is extremely useful particularly in those cases where one must write instructions involving addresses of constants or of other instructions that have not yet been specially assigned.

4. The Use of a Subroutine. A subroutine is a subcode that may be used many times during the computation of a program but written only once in the whole code. As the computer proceeds down the main program, the control will occasionally jump to this subroutine and then, after doing the subroutine, will jump back to the main program where it left off. The term " jump" or " branch" is commonly used in the sense of " take the next instruction from". Thus the expression " jump to a subroutine" means " take the next instruction from the address where the first instruction of the subroutine is located".

5. The detour from the main program through the subroutine may occur several times during the computation of the program. Hence a subroutine must have an entrance, a way of getting into it, and an exit, a way of getting out of it. Each time when an entrance is made to a subroutine, some initial conditions must be set up that are characteristic of the place in the main program from which the entrance was made. For instance, if the subroutine calculates some function, the initial values of the independent variables at that point in the main program must be given to the subroutine. In addition, as an entrance to a subroutine is made, the exit must be set up; i.e., the subroutine must be told where to transfer control back to the main program.

6. Hence, in order to use a subroutine, the coder must know (1) the entrance, i.e., the address of the first instruction; (2) the addresses of the temporaries in which the initial conditions are to be set up; (3) the addresses of the temporaries whose contents will be the results of the subroutine computation; (4) the exit, i.e., the address of some jump /branch) instruction that is to be present (when entering the subroutine) so that when the computation of the subroutine has been completed, the computer will transfer control back to the proper address of the main program.

7. Consider, for instance, the flow chart in Fig. 6, which illustrates the setting up of the initial conditions and different exits of the subroutine. The A in the circle is a connector and of course means that the program jumps to the subroutine at that point. The В connector is called a variable connector, i.e., it indicates that the program jumps either to B1 or to B2, depending on how the " variable" connector is set. When we say that B=

B1 we mean that the В connector is set so that it will go from В to B1; and when we say that B=B2, then the В connector is set to go from В to В2. The rest of the flow diagram is self-explanatory but should be studied carefully by the student.

8. Library of Subroutines. Several subroutines may be used in one program. In fact it is found that many common subroutines are used quite often. Hence it often becomes profitable to have a library of subroutines available to the programmer stored at all times in some part of the computer memory. There would also be some catalogue kept outside the computer that the programmer can consult when he wants to use a subroutine. This catalogue would tell where each subroutine is located and all data about how to use it, such as where to put the initial values of independent variables, where the computed values of the dependent variables are found, etc.

 

 

Notes:

symbolic coding aids – средства символического кодирования

initial conditions – начальные (исходные) условия

independent variables – независимые переменные

the proper address – правильный (соответствующий) адрес

self-explanatory – ясный, не требующий разъяснения

dependent variables – зависимые переменные

 






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.