• Keine Ergebnisse gefunden

ADVANCED PROGRAMMING

Im Dokument CONTROL ENGINEERING (Seite 155-198)

Edgar VViIli3m~

ADVANCED PROGRAMMING

6-1. Introduction

The previous chapter was concerned with the details of programming and coding at the instruction level. The four-, three-, two-, and one-address instruction formats were described and compared. The octal-coded binary and decimal-octal-coded binary systems were compared. The steps in preparing a flow chart, symbolic code, and finally the code itself written in the actual machine language were described. Decision branches, instruction modification, and recursion codes were discussed and examples given. Coding was found to be detailed and laborious, and the one-address system particularly aggravated these qualities.

Advanced programming techniques attempt to lighten the load of the programmer and coder. Its purpose is to try to make the computer itself help prepare the program or code, minimizing the amount of writing a programmer need do. The means used to accomplish this is to prepare or precode the computer with an intermediate, or automatic, program which is always available in the computer memory. This inter-mediate or automatic code encompasses certain aspects of coding that are common to many programs and of general applicability. Then, when the programmer is coding any specific problem, his work can be shortened by taking advantage of already precoded items of the automatic program that are already in the computer. Such automatic programming can greatly simplify the coding of computers otherwise difficult to code. Hence, in the design of some computers, little attention is paid to ease of coding, and such advanced programming techniques are heavily relied upon to compensate for this. Unfortunately, however, the coder must then learn how to use not only the computer but also the automatic programming schemes. Evidently a balance must be sought in computer design between the amount of automatic program-ming envisioned and the difficulty of coding. It is clear that automatic-programming concepts are of great importance to the computer engineer.

Rarely is a program written that is found to be absolutely correct the first time it is run on the computer. Hence in this chapter we first consider automatic aids for analyzing an already coded program for errors. Having discussed automatic programs to aid the coder to correct his code, we turn to such programs that aid the computer engineer to

130

SEC. 5-2] ADVANCED PROGRAMMING 131 maintain the computer. Next automatic programs designed to lighten the load of the programmer are considered. These can be roughly classed in two categories-the interpretive routines and the compiling routines. Various examples are discussed as illustrative of the methods and techniques of formulating and using such automatic programs. The specific examples given are intended to illustrate the principles involved, and their particular form as chosen for this chapter was dictated by pedagogical considerations only. As will become clear during the course of the chapter, there are many other ways to solve the problems posed, and in actual practice the final choice depends on the primary purpose of the code and the detailed characteristics of the computer to be used.

5-2. Program Debugging Methods and Routines

The Problem of Program Debugging. The first time a program is tried on a computer, it usually does not run correctly. If the start button is pushed and the program allowed to run, one of four results can occur: First, the computer might run up to a point and then just stop, or "hang up." Second, the computer could continue to run for an excessively long time, neither stopping nor producing any results. Third, the computer could run and, as expected, print out results, but wrong results. And finally the program could run correctly. In the first three cases an error is indicated in the program, and the problem is to detect where-at what instruction or instructions-the error occurs and then to correct it. This procedure is often referred to as "debugging" a program.

It is hard to describe in general how to debug a particular program;

ingenuity on the part of the programmer, systematic and neat flow charts, coding sheets with detailed remarks, and a thorough knowledge of the code are, of course, all essential. When a program just stops, this usually indicates that the computer has been asked to do an illegal instruction; for instance, the instruction might have an operation code not corresponding to any operation or might contain an address that the computer does not have, etc. Illegal instructions are often the result of an error in instruction modification. When a program never stops, the program usually has a loop with a faulty exit. The exit may not have been properly set up, or else a nonconverging iteration may be in process, etc. The printing out of wrong results requires examination of these results in the light of the problem: Is the scaling wrong? Are the con-stants correct? Has any phase of the calculation been skipped, etc.?

However, certain techniques can be discussed that are often used to aid the debugging process. These can be generally classified into dynamic debugging and post-mortem debugging. Dynamic techniques try to check the program while it is actually running on the computer; post-mortem techniques examine the computer memory after the program has stopped, or "hung up."

Dynamic Program Debugging. Let us first consider dynamic program debugging. There are two generally used methods: the first is called the

break-point (or check-point) method; the second is called the automonitor method. The break-point method consists in writing into the program, at critical intermediate points, instructions that either will stop the computer so that important intermediate results can be observed or will make the computer print out such intermediate results automatically.

The sign bit on an instruction word is often used to facilitate such a

process~ For example, some computers are designed so that after executing an instruction with a negative sign the computer will stop.

Usually such computers also have the following additional feature: A manual switch on the control panel can be thrown so that in one position the computer will not stop after a negative instruction-this being called the normal switch position-and so that in the other position the com-puter will stop-this being called the break-point switch position. The advantage of this control-panel switch is clear: in debugging a program, the negative instruction stops are used, and the switch is set accordingly;

when the program has been corrected, these negative stops are no longer desired and hence the switch is thrown to normal.

Another break-point procedure depends on the programmer inserting into the program at intermediate critical points manual-switch jump instructions. In debugging the program, the switches are positioned so that the computer will jump when it encounters such an instruction;

usually special print-out routines are included in the program, and the jump instructions transfer the computer to these routines. When the program has been corrected, the switches are turned off and the computer simply ignores the jump instructions.

Use of the A utomonitor Program. The automonitor method for dynamic debugging does not require any additions or special considera-tions in the program itself, as does the check-point method. Instead the automonitor method requires the use of a special automonitor pro-gram which is read into the computer in addition to the propro-gram to be debugged. The automonitor program is general and once written can be used for every program to be debugged. Occasionally the computer has the properties of the automatic automonitor program already wired in, so that the automonitor process can be carried out simply by throw-ing a switch on the computer console. An automonitorthrow-ing program makes the computer print out-while each instruction of the program being debugged is being executed-the instruction itself, the contents of each of the operand addresses, and the computed result. For example, suppose the program to be debugged is as follows:

Address Instruction

00 Operation ao ~o 'Yo 01 01 Operation al ~1 'Yl 02 02 Operation a2 ~2 'Y2 Os

SEC. 5-2] ADVANCED PROGRAMMING 133 Then the automonitor program would have the computer print out the following:

Address Instruction 1st operand 2d operand Result

00 (150) (ao) ({30) ( 1'0)

ch (151 ) (al) ({3J) (-YI)

02 (15 2) (a2) ((32) (1'2)

In other words, the autoinonitor program gives a complete record for the program being debugged of just which instructions are being done by the computer and what the results were. With this information it becomes easy to spot any error in the program being debugged. Note that the automonitor program is a program that operates on another program-more about this point will be said in the succeeding sections.

Of course certain instructions of the program being debugged are handled somewhat differently. For example, in a compare instruction, (y) need not be printed, but just 0, (0), (a), ({3), for the address of the next instruction tells which way the comparison went. Common sense clearly dictates what an automonitor program should print out.

An automonitor program for a three-address computer would be similar to that just described for a four-address system. For a two-or one-address system the contents of the accumulattwo-or two-or other registers becomes of importance, and hence the contents of the accumulator is printed out. For instance, in a one-address system, the print-out would look like this:

(acc) (acc) (ace)

The A utomonitor Program Itself. In order to grasp more fully the general concept behind an automonitor program, let us examine in a cursory way how such an automonitor program itself might be written for a one-address system. The flow chart is given in Fig. 5-1. This automonitor program is in one part of the memory, and the program to be debugged is in another part of the memory. The automonitor program must be given the address of the first instruction of the program to be debugged. Then the automonitor program prints out the desired record and also executes the instructions of the program to be debugged. First the automonitor program prints the address of this first instruction, 00;

then it copies (00) into a special temporary located in the automonitor program's part of the memory. This instruction is printed, and (ao) is printed. Next the automonitor program directs the computer to execute the first instruction in its location within the automonitor program.

Then (ace) is printed, and the automonitor program goes on to the next instruction, etc. There are a few important details that must be attended

to. When the program to be debugged is being exe'cuted, the contents of the accumulator from instruction to instruction is, of course, important.

But when the automonitor program executes one instruction at a time and inserts print routines, etc., between these instructions, the contents

Start

Reset accumulator and registers, and execute the instruction in the temporary

In order to correct this situation, the contents of the accumulator (and other registers) must be recorded after the execution of each instruc-tion of the program being debugged.

Then, before the next such instruc-tion is to be executed, the registers ob-serve the results. From a knowledge of the program and the erroneous results an error can often be located.

For example, if the magnitude of the results is off, the scaling is checked for error, etc. The second method is to print out the entire memory of the computer after the program has been run. If the program got into were correctly modified, etc. A third method is to have another program that examines the program to be de-bugged after it has run. This

pro-FIG. 5-1. Flow chart of automonitor gram compares the program to be

program. debugged with itself before and after

it has been run and tells the programmer where they differ. In this way the programmer can determine if any instructions were inadvertently destroyed, if all differences that should appear actually do appear, etc.

Of course the programmer uses combinations of the techniques that are at his disposal. What we have briefly outlined here is in no way

com-t Also, provision is made in the automonitor code so that jump instructions are not performed directly but rather operate on the automonitor o-address reading instruction.

SEC. 5-3] ADVANCED PROGRAMMING 135 plete but rather indicates some of the directions from which aids to programming may arise.

EXERCISES

(a) Write out precisely what an automonitor program would print if applied to the code of Example 3-lc.

(b) Suppose that a code contains a negative jump instruction. How can the automonitor program handle such an instruction? After the automonitor program executes the negative jump, how can it regain control again?

(c) Write a simple post-mortem debugging program as required for the third method.

5-3. Computer Maintenance Routines

Maintenance. If a computer circuit is malfunctioning, then the com-puter will not always produce the correct results. Evidently these incorrect results must in some way reflect the course of the malfunction-ing. Hence it seems possible that specific routines can be designed especially for determining a malfunctioning circuit. Such programs are called maintenance routines. Of course one must be able to read into the computer, read out of the computer, and perform some opera-tions in order that a maintenance routine be capable of application at all.

Then there is the fact that even though a programmer using a computer may swear that it is malfunctioning, it may often be in perfect operating condition. Hence a maintenance routine must check to see whether or not the computer is indeed malfunctioning. However, if the user of the computer can demonstrate that it gives two different results to the same program, then the computer must be malfunctioning no matter what the maintenance routines determine. Finally observe that a maintenance routine often cannot detect a particular malfunctioning circuit but can determine only that one of several circuits is not operating correctly.

Then, of course, the computer maintenance engineer must make electronic tests on these circuits themselves inside the computer.

Actually maintenance routines are composed after a detailed knowledge of the computer logical circuitry has been mastered. However, we have placed this discussion in Part 1, rather than at the end of Part 4, to illustrate for the prospective computer engineer the necessity of a thorough understanding of coding.

Locating Malfunctioning Parts. Maintenance routines usually are designed to determine whether or not some particular part of the com-puter is working correctly. For example, a routine may test the input-output equipment, another may test different parts of the memory, another may test the add operation, another the multiply operation, etc.

The logic most often used in interpreting the meaning of a maintenance routine test is: if the part of the computer tested by the routine is operat-ing correctly, then the malfunctionoperat-ing circuit must be located in some other part of the computer. In this way the possible malfunctioning

circuit is located by the elimination of correctly operating circuits. The fact that a maintenance routine test fails does not necessarily mean that the malfunctioning circuit is located in the part tested by this routine, whereas the fact that a maintenance routine test passes does mean that the circuits in the part tested are in operating order. The reason for this is that it is extremely difficult to distinguish by means of a maintenance routine between a malfunctioning circuit in the control unit and some malfunctioning circuit in the arithmetic unit.

As an example of a maintenance routine, suppose it has already been determined that the first sixteen memory cells are operating correctly, in addition to the accumulator and the add, subtract, transfer, and jump instructions. The problem is to test the rest of the memory. To see whether or not a memory location is dropping a bit, a word of all units is read into an address and, after a time, read out again. If the word read out is not all units, i.e., has at least one zero, then it can be concluded that this address is malfunctioning. Hence the entire memory from 020 on is filled with words of all units; and the program of Table 5-1 will test

TABLE 5-1. MAINTENANCE ROUTINE

Instruction

Address Remarks

Operation a (preload accumulator with 77 777) 000

001 Subtract 020 Subtract contents of a memory address from accu-mulator, and put result into accumulator

002 Add 012 Add a word of all units to accumulator; if there is an overflow, we are assuming that computer will stop 003 Subtract 012 Clear accumulator

004 Add 001

} Modify subtract instruction found as (001) to consider

005 Add 013

006 Transfer 001 the next successive memory address 007 Subtract 001 Clear accumulator

010 Add 012 } Set up initial conditions for next loop; take next 011 Jump 001 instruction from 001

012 77 777 Constant: a word of all units 013 00 001 Constant: 00 001

whether or not any bits are being dropped, where it is assumed that the computer is designed so that an overflow will cause a stop and that an illegal a will also cause a stop. For this code (accumulator) must initially be a word of all units-i.e., initially (ace) = 77777. N ow, if a memory address being tested does not drop a bit, then the result ·of the subtraction will be all zeros and hence, after (012) is added to the accumu-lator, the initial conditions are once more set up and the next memory address can be tested. On the other hand, if a memory address did drop a bit; then some unit would be a zero and the result of the subtraction

SEC. 5-3] ADVANCED PROGRAMMING 137 would contain a unit in the position where the memory address had a zero. Hence, when this result is added to a word of all units, overflow will occur and the computer will stop. (It was, of course, assumed that the computer in question had this property.) Then the a address of the instruction stored in address 001 is the malfunctioning address; and the position where the units of the accumulator turn to zero is the position where the bit is being dropped, i.e.:

Dropped bit

(. 111 111) - (. 110 111)

1

(. 001 000) whence

( . . . 001 000)

+ ( ...

111 111) = ( . . . 000 111) Position of dropped bit

i

When a bit is dropped, this can often be due to either the control circuitry or the memory itself. Then these must be checked electronically.

A - - - r - - /

And gate

gate

FIG. 5-2. Comparison (or equalizer) circuit.

I - - - C

As another example, suppose that the add, compare, and transfer instructions and the memory were operating; the problem is to check the shift-left instruction. Since shifting (a) left n positions is the same as forming 2n . x [where (a) = x], we can perform the equivalent of shifting by adding a number to itself, and the result to itself, etc., repeated n times. Hence we perform the shift and also perform the add interpreta-tion of a shift, and then see if we have gotten the same answer. Note that two things need to be checked: first that the bits do shift from each position to the next successive position to the left; also that the number of positions shifted is the number called for in the instruction.

Locating Malfunctioning Gates. Up to now we have discussed

Locating Malfunctioning Gates. Up to now we have discussed

Im Dokument CONTROL ENGINEERING (Seite 155-198)