Method for executing a program

Abstract: In a method for executing a program for sequentially reading step information registered in an execution queue in the order of registration in order to permit the modification of a branch-to address with ease and without error when the modification of the branch-to address is instructed during the debugging of the program, the step information which is no longer the branch-to address due to the modification is searched in response to the branch-to address modification instruction, the retrieved step information is erased from the execution queue, and step information which is a new branch-to address is registered at the position of the erased step.

Description: BACKGROUND OF THE INVENTION Field of the Invention The present invention relates to a method for executing a program by sequentially executing instructions in the program. Related Background Art In a prior art method for executing a program, when a flow of the program is to be branched to a different direction from a normal direction during the debugging of the program having a branch point, the execution of the program is temporarily interrupted before the branch point and a variable is changed at the branch point to change a branch condition which determines the direction of the branch from a predetermined one to indirectly change the direction of the branch. In executing the program branching of this type, that is, when the direction of the branch of the program is to be changed, an operator must analyze the branch condition of the program and manually change the content of the variable so that the program is correctly branched to the desired direction. In this method, where the branch condition of the program is complex, the analysis of the branch condition is difficult to attain and the decision for the variable (the number of variables to be changed is not necessarily one) and the content of the change of the variable to attain the branch in the desired direction must be manually determined. Accordingly, the burden to the operator increases and a probability of misoperation rises. Further, it may happen that the program makes an unexpected operation at a different point because of the change of the content of the variable, and if it is a control program for an equipment, a significant damage may be imparted to the overall system. An example of such a system is disclosed in Electro, Vol. 11, No. 22/4, 1986, Los Angeles US pages 1-7, Ronald E. Kole "Software Development and Debugging in Embedded Systems: Maintaining the High-Level View". The present invention provides a method for executing a program including a plurality of steps to be executed, wherein a flow of the program is branched at a branch point and the direction of branching can be modified during the execution of the program, said method being characterised by comprising the steps of: sequentially registering in a queue information of steps to be executed in an order of execution at positions designated by a write pointer while incrementing the write pointer; searching, in response to an instruction for modifying a branch-to direction from a first direction to a second direction, for information of a step belonging to the first direction in the queue by sequentially checking information of a step designated by a search pointer while incrementing the search pointer, and holding the search pointer if the information of the step belonging to the first direction is found; registering in place of the information of the step designated by the held search pointer information of a step belonging to the second direction at the position in the queue designated by the held search pointer; sequentially reading information of a step designated by a read pointer in the queue while incrementing the read pointer in the order of registration; and executing steps corresponding to the read step information. The present invention further provides an apparatus as set out in claim 4. An embodiment of the present invention provides a method for executing a program which permits the change of a branch-to-address with ease and without error when the change of the branch-to address is instructed during the debugging of the program. Other advantages besides those discussed above shall be apparent to those skilled in the art from the description of the preferred embodiments of the invention which follows. In the description, reference is made to the accompanying drawings, which form a part hereof, and which illustrate examples of the invention. Such examples, however, are not exhaustive of various embodiments of the invention, and therefore reference is made to the claims which follow the description for determining the scope of the invention. Fig. 1 shows a block diagram of a configuration of an information processing apparatus for realising the present invention; Fig. 2 shows a chart of a format of a step which is a unit of process; Fig. 3 shows a structure of a command execution queue; Fig. 4 shows a flow chart of a program execution management process; Fig. 5 shows a flow chart of a branch-to address modification process; and Fig. 6 shows a shift of a process by the branch-to address modification. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT An embodiment of the present invention will now be explained with reference to the drawings. Fig. 1 shows a block diagram of a configuration of an information processing system for realizing a method for executing a program of the present invention. Numeral 20 denotes a register for temporarily storing data or an operation result and numeral 21 denotes a memory for storing programs or data. A user program and a monitor program are stored as the programs. The program stored in the memory 21 is sent to an instruction decoder 22 through a bus 24 and decoded thereby, and the decoded result is sent to an instruction execution unit 23 and executed thereby. In the present embodiment, a step represents a minimum division unit for processing the program and the program comprises an aggregation of steps. In the information processing apparatus thus constructed, when a branch-to address modification based on a debug program is instructed by the instruction execution unit 23 while a plurality of numbers of steps to be executed are registered in the queue (an execution queue of a step number registration unit 10), the instruction execution unit 23 erases the step number which has been registered in the queue but is not to be executed, and re-register the modified step at the same position as that at which the erased step has been registered to correctly modify the branch-to address of the program to a desired direction. Fig. 2 shows a schematic diagram of a format of the step processed by the information processing apparatus shown in Fig. 1. In Fig. 2, numeral 30 denotes an operation code field which defines a type of instruction to be executed. Numeral 31 denotes an operand field which defines detail of the instruction to be executed. Numeral 32 denotes an end field which defines a step number to be executed next. In the information processing apparatus of the present embodiment, since the step is defined by the format shown in Fig. 2, the monitor program refers to the operation code field 30 to determine the type of instruction to be executed. Then, the monitor program refers to the operand field 31 to detect the detail of the instruction to be executed and determine the type of instruction to be executed as well as a job to be done by a CPU and issues a group of instructions to the CPU. The end field 32 contains the step number to be executed next, and the monitor program refers to the end field 32 to determine the step to be executed next. Fig. 3 shows a structure of the instruction queue in the instruction execution unit 23 shown in Fig. 1. In Fig. 3, numeral 10 denotes a step number registration unit in which currently queuing step number is registered. Numeral 11 denotes a read queue pointer pointing the currently executed step. Numeral 12 denotes a write queue pointer pointing a location of registration of the step number to be registered next. Numeral 13 denotes a search queue pointer for searching the step number whose execution is to be cancelled by the modification of the branch-to address of the program and holding that location in the execution queue until a replacement step number is registered, and numeral 14 denotes a search queue pointer home position. An instruction execution operation in the information processing apparatus of the present invention is now explained with reference to Fig. 4. Fig. 4 shows a flow chart of an example of a program execution management process in the information processing apparatus of the present invention. It is assumed that a step has already been registered in the execution queue (the read pointer and the write pointer shown in Fig. 3 do not match). First, the monitor program checks in a step S41 whether there is a step waiting for the execution in the queue, and if there is such a step, the monitor program checks in a step S42 whether the read queue pointer 11 matches to the search queue pointer 13. If it matches, the process waits until mismatching occurs, and in a step S43, the monitor program reads the step number from the position pointed by the read queue pointer 11. In a step S44, the monitor program causes the step corresponding to the read step to be executed by the CPU, not shown. When the execution of that step has been completed, the monitor program refers the end field 32 shown in Fig. 2 in a step S45 to determine the step number to be executed next in the program and writes it at the position pointed by the write queue pointer 12. In a step S46, the write queue pointer 12 is incremented by one. If the write queue pointer 12 exceeds the final stage of the execution queue, a head address of the execution queue is placed in the write queue pointer 12 so that it returns to the head of the execution queue. In a step S47, the read queue pointer 11 is incremented by one. If the read queue pointer 11 exceeds the final stage of the execution queue, the head address of the execution queue is placed in the read queue pointer so that it returns to the head of the execution queue. Then, the process returns to the step S41 to determine whether there is a step waiting for the execution or not, and if there is such a step, the steps S42 - S47 are repeated. If there is no such step in the step S41, the process is terminated. Fig. 5 shows a flow chart of an example of a branch-to address modification process in the present invention. This process is separate from the program execution management process shown in Fig. 4 and both processes are executed in parallel. When the branch-to address modification is instructed by the debugger, the monitor program starts the branch-to address modification process. First, the monitor program determines in a step S51 whether the branch-to address modification has been instructed or not, and if the decision is YES, it shifts the search queue pointer 13 from the search queue pointer home position 14 to the head of the execution queue in a step S52, and searches the step before the modification from the execution queue while it increments the search queue pointer 13. When it finds the step before the modification, it retains the search queue pointer 13 at that position in a step S53 and erases the step before the modification. Then, in a step S54, the step after the modification is registered at the position pointed by the search queue pointer 13, and the process return to the step S51. In the step S51, whether there is another branch-to address modification instruction or not is checked, and if there is, the steps S52 - S54 are repeated, and if there is not, the search queue pointer 13 is returned to the search queue pointer home position 14 in a step S55 and the process is terminated. Fig. 6 shows a diagram of a shift of the branch-to address modification of the program in the information processing apparatus of the present invention. In the Figure, numerals 60 - 68 show a sequence of process orders. It is assumed that the process starts from a process order 60 and normally proceeds in the sequence of process orders 61 - 65, that is, along an arrow A. In this case, a step 1 shown in the process order 61 is executed, a branch node shown in the process order 62 is execute, a branch condition is determined, and a step 2 shown in the process order 63 is registered in the execution queue. If the branch-to address modification is instructed before the step 2 shown in the process order 63 is executed and the execution of the step 3 shown in the process order 66 instead of the step 2 shown in the process order 63 is instructed, the branch-to address modification process shown in Fig. 5 is started. In the example of Fig. 6, the branch-to address modification process searches the step 2 shown in the process order 63 from the execution queue while it increments the search queue pointer 13. If it finds the step 2 in the execution queue, it retains the search queue pointer 13 at that position in the execution queue and erases the step 2 from the execution queue. Then, it registers the step 3 shown in the process order 66 to the position in the execution queue pointed by the search queue pointer 13, returns the search queue pointer 13 to the search queue pointer home position, and terminates the branch-to address modification process. Thereafter, the program execution management process reads the step number pointed by the read queue pointer 11 from the execution queue and executes it, in a conventional manner. When the step 3 in the process order 66 is executed, the step 5 shown in the process order 67 is registered in the execution queue by the end field of the step 3 and it is registered. Through the above process, the direction of the flow of program is modified from the arrow A to an arrow B in Fig. 6. In the above embodiment, a plurality of locations to register the steps to be next executed are provided in the queue to permit a quasi-parallel processing in which a plurality of programs are executed in the CPU. In the above embodiment, it is assumed that the program comprises steps which are minimum units of processing although it is not essential to the present invention. The present invention is readily applicable to a program having a hierarchy structure in which the program is an aggregation of sub-programs which are aggregations of steps. In the above embodiment, a so-called interpreter system in which the step is structured as shown in Fig. 2 and the monitor program decodes the content thereof to issue a group of instructions of the CPU is adopted although it is not essential to the present invention. The present invention is readily applicable to a so-called compiler system by registering the step to be executed next in the execution queue after the execution of the steps by embedding information of the step to be executed next at portions of the respective steps. In accordance with the present invention, if the branch-to address modification is instructed by the debug program while one or more steps to be executed are registered, the step which is no longer executed as a result of the branch-to address modification is erased from the registered steps, and the step to be executed as a result of the modification is relisted at the same position as that at which the erased step has been registered. Accordingly, the branch-to address of the program can be modified to a desired direction without error. Accordingly, the troublesome work required in the prior art method to manually modify the content of the variable in the branch condition of the program is eliminated and the burden to the operator is significantly reduced. Further, since it is not necessary to change the content of the variable, the introduction of a new bug due to the modification of the content of the variable is avoided and the program having a branch point can be efficiently debugged. Although the present invention has been described in its preferred form with a certain degree of particularity, many apparently widely different embodiments of the invention can be made without departing from the scope thereof. It is to be understood that the invention is not limited to the specific embodiments thereof except as defined in the appended claims.

Claims: A method for executing a program including a plurality of steps to be executed, wherein a flow of the program is branched at a branch point and the direction of branching can be modified during the execution of the program, said method being characterised by comprising the steps of: sequentially registering in a queue (10) information of steps to be executed in an order of execution at positions designated by a write pointer (12) while incrementing the write pointer (S45, S46); searching, in response to an instruction for modifying a branch-to direction from a first direction to a second direction, for information of a step belonging to the first direction in the queue by sequentially checking information of a step designated by a search pointer (13) while incrementing the search pointer, and holding the search pointer if the information of the step belonging to the first direction is found (S51, S52); registering in place of the information of the step designated by the held search pointer information of a step belonging to the second direction at the position in the queue designated by the held search pointer (S53, S54); sequentially reading information of a step designated by a read pointer (11) in the queue while incrementing the read pointer in the order of registration (S43, S47); and executing steps corresponding to the read step information (S44). A method for executing a program according to claim 1 wherein the reading of the step is inhibited when the read pointer and the search pointer match (S42). A method according to claim 1 or 2 wherein the queue registers only one step which is the step to be executed next. An apparatus for executing a program including a plurality of steps to be executed, wherein a flow of the program is branched at a branch point and the direction of branching can be modified during the execution of the program, said apparatus being characterised by comprising: storage means (10) for storing a queue; first registering means for sequentially registering in a queue information of steps to be executed in an order of execution at positions designated by a write pointer (12) while incrementing the write pointer; search means for searching, in response to an instruction for modifying a branch-to direction from a first direction to a second direction, for information of a step belonging to the first direction in the queue by sequentially checking information of a step designated by a search pointer (13) while incrementing the search pointer and holding the search pointer if the information of the step belonging to the first direction is found; second registering means (23) for registering in place of the information of the step designated by the held search pointer information of a step belonging to the second direction at the position in the queue designated by the held search pointer; reading means for sequentially reading information of a step designated by a read pointer (11) in the queue while incrementing the read pointer in the order of registration; and execution means for executing steps corresponding to the read step information. An apparatus according to claim 4 in which the reading means is operable to inhibit the reading of the step when the read pointer and the search pointer match (S42). An apparatus according to claim 4 or 5 in which only one step which is to be executed next is registered in the queue.

Inventors: ASADA SATOSHI, KADOSAWA TSUNEAKI, KOGA EIJI, NAKAMURA TAKASHI, WATANABE HITOSHI, ASADA, SATOSHI, KADOSAWA, TSUNEAKI, KOGA, EIJI, NAKAMURA, TAKASHI, WATANABE, HITOSHI, Asada, Satoshi, c/o Canon K.K., Kadosawa, Tsuneaki, c/o Canon K.K., Koga, Eiji, c/o Canon K.K., Nakamura, Takashi, c/o Canon K.K., Watanabe, Hitoshi, c/o Canon K.K.
Applicants: CANON KK, CANON KABUSHIKI KAISHA
Application year: 1993
Main classification: G06F11
IPC codes: G06F11