ERROR DETECTION AND CORRECTION DEVICE AND METHOD THEREOF

An error detection and correction device and a method thereof are provided. The method for error detection and correction includes the following steps. Converting an operation program into a two's complement inverse operation program. Converting the variables of the operation program into a two's complement variables. Executing the operation program to obtain a first operation result according to variables. Executing the operation program to obtain a second operation result according to the two's complement variables. Calculating the checksum result corresponding to the variables, and calculating the checksum result corresponding to the two's complement variables. Performing at least one of comparing the first operation result with the second operation result, comparing the checksum result corresponding to the variables, and comparing the checksum result corresponding to the two's complement variables. Outputting the first operation result, the second operation result or an error message according to the above comparison results.

This application claims the benefit of Taiwan application Serial No. 110145674, filed Dec. 7, 2021, the disclosure of which is incorporated by reference herein in its entirety.

TECHNICAL FIELD

The disclosure relates to an error detection device and an error detection method, and relates to a device for detecting and/or correcting erroneous execution of the operation program and a method thereof.

BACKGROUND

Due to the environmental factors, the memory or register of a system platform may be interfered with or even may be damaged, and the numeric content stored in the memory or register may be changed which leads to erroneous operation result of the operation program executed on the system platform. In the space outside the atmosphere, environmental factors such as particle collision or electromagnetic interference are even worse and may easily result in single-event upset (SEU). For example, single particle in the outer space may collide with a satellite equipment operating in the outer space and change the state of the memory or register of the satellite equipment and reverse the bit data stored in the memory or register, causing execution error to the operation program of the satellite equipment and generating an erroneous operation result. Even more, the operation program may crash, and the overall task may fail.

For of the operation of the satellite equipment, due to the factors of cost, environment and distance, if errors occur to the software operation program, it is difficult to re-start the satellite equipment or re-execute the system to correct the errors of the operation program. Although the numeric errors caused by single-event upset may be resolved by upgrading hardware specification of the equipment, the cost for upgrading the specification of satellite equipment is extremely high.

Therefore, skilled ones in related industries of this technical field are devoted to resolve, using software algorithm, the technical problems caused by numeric errors arising from single-event upset among the environmental factors.

SUMMARY

According to one embodiment, an error detection and correction device for detecting and/or correcting error(s) of an operation program is provided. The error detection and correction device includes a conversion unit, a program execution unit, a checksum operation unit, a comparison unit, and an output unit. A conversion unit is for converting the operation program into a two's complement inverse operation program, and converting a plurality of variables of the operation program into a plurality of two's complement variables. A program execution unit is for executing the operation program to obtain a first operation result according to the variables, and executing the two's complement inverse operation program to obtain a second operation result according to the two's complement variables. A checksum operation unit is for calculating a checksum result corresponding to the variables according to the operation program, and calculating a checksum result corresponding to the two's complement variables according to the two's complement inverse operation program. A comparison unit is for performing at least one of the following: comparing the first operation result with the second operation result, comparing the checksum result of the variables, or comparing the checksum result of the two's complement variables. An output unit is for outputting the first operation result, the second operation result or an error message according to a comparison result of the first operation result and the second operation result, the checksum result corresponding to the variables and/or the checksum result corresponding to the two's complement variables.

According to another embodiment, an error detection and correction method for detecting and/or correcting error(s) of an operation program is provided. The error detection and correction method includes the following steps. Converting the operation program into a two's complement inverse operation program. Converting a plurality of variables of the operation program into a plurality of two's complement variables. Executing the operation program to obtain a first operation result according to the variables. Executing the two's complement inverse operation program to obtain a second operation result according to the two's complement variables. Calculating a checksum result corresponding to the variables according to the operation program. Calculating a checksum result corresponding to the two's complement variables according to the two's complement inverse operation program. Comparing the first operation result with the second operation result, comparing the checksum result of the variables, or comparing the checksum result of the two's complement variables. Outputting the first operation result, the second operation result or an error message according to a comparison result of the first operation result and the second operation result, the checksum result corresponding to the variables and/or the checksum result corresponding to the two's complement variables.

DETAILED DESCRIPTION

Technical terms are used in the specification with reference to the prior art used in the technology field. For any terms described or defined in the specification, the descriptions and definitions in the specification shall prevail. Each embodiment of the present disclosure has one or more technical features. Given that each embodiment is implementable, a person ordinarily skilled in the art may selectively implement or combine some or all technical features of any embodiment of the present disclosure.

FIG.1is a block diagram of an error detection and correction device1000according to an embodiment of the disclosure. Referring toFIG.1. The error detection and correction device1000is used to execute an operation program100. Furthermore, the error detection and correction device1000may obtain a two's complement inverse operation program100C through two's complement conversion, in which the two's complement inverse operation program100C corresponds to the operation program100. Moreover, the error detection and correction device1000performs error detection and/or error correction on the operation program100according to respective operation result of the operation program100and the two's complement inverse operation program100C. The error detection and correction device1000includes a conversion unit200, a program execution unit250, a checksum operation unit300, a comparison unit400and an output unit500. Moreover, the storage unit600may be disposed in the error detection and correction device1000or disposed outside the error detection and correction device1000. The error detection and correction device1000may perform error detection and/or error correction on the operation program100to operate the above-mentioned conversion unit200, program execution unit250, checksum operation unit300, comparison unit400, output unit500and storage unit600.

The operation program100has one or more variables120. The error detection and correction device1000may access values of the variables120from the storage unit600. Furthermore, the conversion unit200may perform two's complement conversion to obtain the two's complement variables120C of the two's complement inverse operation program100C according to the variables120. Correspondingly, values of the two's complement variables120C may be accessed from the storage unit600. Moreover, the operation program100includes one or more functions130. The conversion unit200may perform two's complement conversion to obtain the inverse operation functions130C of the two's complement inverse operation program100C according to the functions130.

The program execution unit250may execute the functions130to obtain a first operation result140of the operation program100according to the variables120. Correspondingly, the program execution unit250may execute the inverse operation functions130C to obtain a second operation result140C of the two's complement inverse operation program100C according to the two's complement variables120C.

The comparison unit400may compare the first operation result140with the second operation result140C. If the second operation result140C is equal to the two's complement of the first operation result140, it is determined that the program execution unit250correctly executes the functions130of the operation program100, and no numeric errors occur when the values of the variables120are accessed from the storage unit600. Furthermore, it is determined that the program execution unit250correctly executes the inverse operation functions130C of the two's complement inverse operation program100C, and no numeric errors occur when the values of the two's complement variables120C are accessed from the storage unit600.

The checksum operation unit300may perform checksum operation on the variables120to assist determining whether the operation program100is executed correctly. Correspondingly, the checksum operation unit300may perform checksum operation on the two's complement variables120C to assist determining whether two's complement inverse operation program100C is executed correctly.

The output unit500may output the first operation result140, the second operation result140C or the error message150according to the comparison result of the comparison unit400and the checksum operation result of the checksum operation unit300. If the comparison results and the checksum operation results indicate that the operation program100is executed correctly, the output unit500outputs the first operation result140. On the other hand, if the comparison results and the checksum operation results indicate that the operation program100and the two's complement inverse operation program100C are both erroneously-executed, the output unit500outputs the error message150.

FIG.2is a schematic diagram of an error detection and correction device1000operating on a system platform2000according to an embodiment of the disclosure. Referring toFIG.2. The error detection and correction device1000may operate on the system platform2000to detect and/or correct error(s) of the operation program100. The system platform2000may be, for example, a system platform of a personal computer, a server, an industrial computer, a military computer or satellite equipment. The operation program100may refer to, for example, a software application program executed on the system platform2000. The storage unit600is also disposed on the system platform2000(i.e., the storage unit600may not necessary to be included in the error detection and correction device1000). The storage unit600may refer to, for example, a register or a memory through which values of the variables120of the operation program100and the two's complement variables120C of the two's complement inverse operation program100C may be accessed.

Taking the system platform2000of the satellite equipment as an example. When the satellite equipment operates in the outer space, the state of the storage unit600of the system platform2000may easily be changed due to particle collision or electromagnetic interference, hence reversing the bit data stored in the storage unit600(e.g., reversing from bit “1” to bit “0”) and leading to numeric errors in values of the variables120of the operation program100. The error detection and correction device1000of the disclosure performs error detection and/or error correction on the operation program100executed on the system platform2000, for the system platform2000of the satellite equipment. The error detection and correction device1000may generate a first execution area2100and a second execution area2200on the system platform2000.

The first execution area2100is an area where a normal software or normal processes are executed. The operation program100is executed in the first execution area2100. Moreover, the error detection and correction device1000performs two's complement conversion to obtain a corresponding two's complement inverse operation program100C according to the operation program100. The two's complement inverse operation program100C is executed in the second execution area2200. The second execution area2200is the execution area of the two's complement inverse operation process.

Basic operations of the error detection and correction device1000are briefly disclosed in above paragraphs. Detailed operations of the error detection and correction device1000are disclosed below in detail with reference to steps and flows of the error detection and correction method illustrated inFIGS.3A,3B,4A and4B.

FIG.3Ais a flowchart of an error detection and correction method according to an embodiment of the disclosure. In the present embodiment, the operation program100may be a program which is compiled in advance. Referring toFIG.3A(by reference toFIGS.1and2). Firstly, at step S110, the operation program100is pre-processed by the error detection and correction device1000, for example, to confirm the compatibility between the operation program100and the execution environment of the system platform2000. Next, at step S120, the operation program100is duplicated by the conversion unit200to obtain a duplicated operation program100(for simplicity, the duplicated program is not illustrated inFIGS.1and2). The duplicated program includes all functions130of the operation program100.

Next, at step S130, the duplicated program is translated and converted by the conversion unit200to obtain a two's complement inverse operation program100C. The functions130of the duplicated program are respectively converted into the inverse operation functions130C by the conversion unit200, wherein the two's complement inverse operation program100C is composed of the inverse operation functions130C. Next, at step S140, the operation program100and the two's complement inverse operation program100C are compiled. Next, at step S150, the compiled operation program100and the compiled two's complement inverse operation program100C are linked, so as to obtain an exe file that may be executed on the system platform2000. Next, at step S160, the operation program100and the two's complement inverse operation program100C are executed on the system platform2000, either concurrently or consecutively, according to the linked exe file, and subsequent error detection and/or error correction are performed.

FIG.3Bis a flowchart of an error detection and correction method according to another embodiment of the disclosure. In the present embodiment, the operation program100may refer to a directly-interpreted program with no necessity to be compiled. Steps S210to S230ofFIG.3Bare identical to steps S110to S130ofFIG.3A. Furthermore, Step S240ofFIG.3Bis similar to step S160ofFIG.3A, but is different in that, at step S240ofFIG.3Bthe operation program100and the two's complement inverse operation program100C are directly executed, either concurrently or consecutively, by the interpreter of the system platform2000, and no necessity to perform compilation and linking.

Detailed implementation for step S130ofFIG.3Aand step S230ofFIG.3Bare described below by reference toFIG.1and Table 1. Two's complement conversion may be performed by the conversion unit200of the error detection and correction device1000to obtain the two's complement variables120C of the two's complement inverse operation program100C according to the variables120of the operation program100. The two's complement variables120C may be two's complement of the variables120. If the variables120are signed numbers, their sign is opposite to the sign of the two's complement variables120C and the variables120. If the variables120are unsigned numbers, the two's complement variables120C are identical to the variables120. Moreover, the conversion unit200may perform two's complement conversion to obtain inverse operation functions130C according to the functions130of the operation program100. The two's complement inverse operation program100C is composed of the two's complement variables120C and the inverse operation functions130C. Table 1 lists some examples of the functions130and the inverse operation functions130C:

Referring to Table 1, taking the functions130of “arithmetic operation” as “+”, “−”, “*”, “l”, and “%”. If the operand of the functions130is a variable “x”, the inverse operation functions130C are completely identical to the functions130. That is, the inverse operation functions130C are “+”, “−”, “*”, “/”, and “%”. On the other hand, if the functions130are “+”, “−”, “*”, “/”, and “%” and the operand of the functions130is a fixed value “m”, the inverse operation functions130C are “−,” “+”, “*”, “/”, and “%”. If the functions130are “+” and “−”, the inverse operation functions130C are two's complement inverse operations, that is, the inverse operation functions130C are “−” and “+”; if the functions130are “*”, “/”, and “%”, the inverse operation functions130C are completely identical to the functions130. Thus, if the operand of the functions130is a variable “x”, the inverse operation functions130C are completely identical to the functions130. If the operand of the functions130is a fixed value “m”, the inverse operation functions130C could be identical to the functions130or the inverse operation functions130C are the two's complement inverse operations of the functions130.

Besides, let the functions130of “assign operation” be “=”, “+=”, “−=”, “*=”, “/=”, and “%=”. If the operand of the functions130is a variable “x”, the inverse operation functions130C are still “=”, “+=”, “−=”, “*=”, “/=”, and “%=”, and the inverse operation functions130C are completely identical to the functions130. If the operand of the functions130is a fixed value “m”, the inverse operation functions130C of “+=” and “−=” respectively are the two's complement inverse operations of the functions130of “−=” and “+=”.

Also, let the functions130of “pointer operation” be “&” and “*”. If the operand of the functions130is an integer “N” whose value is fixed, the inverse operation functions130C are completely identical to the functions130. If the operand of the functions130is a variable, such as “xPtr” and “yOffset”, the inverse operation function130C of “*(xPtr−yOffset)” is the two's complement inverse operation of the function130of “*(xPtr+yOffset)”.

Furthermore, let the functions130of “increment/decrement operation” and “operation relation” be “++”, “−−”, “>” “<”, “<=”. If the operand of the functions130of “increment/decrement operation” and “operation relation” is a fixed value “m”, the inverse operation functions130are the two's complement inverse operation of the functions130, that is, the inverse operation functions130are “−−”, “++”, “<”, “<=”, “>”, “>=”. Also, in the example of the functions130of “relation operation”, if the functions130are “==” and “!=”, the inverse operation functions130C are still “==” and “!=”, that is, the inverse operation functions130C are identical to the functions130.

As disclosed above, when the conversion unit200of the error detection and correction device1000performs two's complement conversion on the functions130and obtains the inverse operation functions130C, most of the inverse operation functions130C are identical to the original functions130. When the operand of a part of the functions130is a fixed value, the inverse operation functions130C may be obtained by reversing the sign of the functions130or adjusting the comparison relation of value size (for example, adjusting “>” to “<”).

Detailed implementations of step S160ofFIG.3Aand step S240ofFIG.3Bare disclosed below withFIG.1and Table 2. The program execution unit250of the error detection and correction device1000may concurrently or consecutively execute the operation program100and the two's complement inverse operation program100C to obtain a first operation result140and a second operation result140respectively. Table 2 lists examples of the program code of operation program100, the corresponding first operation result140, the program code of the two's complement inverse operation program100C, and the corresponding second operation result140C:

As indicated in Table 2, in the operation program100, the operand of the functions130is a variable120, which may be an input variable inputted from the outside of the program or a local variable of the program. In the present embodiment, the variables120of the functions130of “=”, “<=”, “++”, “+=” are local variables “x” and “i”. Refer to the “program code” column in Table 2. In the example where the value of the variable “i” is accumulated from “1” to “10”, the operation program100declares that the initial values of variables “x” and “i” both are integer “0”.

When executing the functions130of “=”, “<=”, “++”, and “+=”, the program execution unit250uses variable “i” as recursion index. When recursion is performed, the value of variable “i” is progressively increased from “1” to “10”. When the function130of “+=” is executed within the recursion, the value of variable “i” is accumulated to variable “x”. After 10 times of recursion, the last value of variable “x” obtained by the operation program100is a numeric value “55”. Meanwhile, the first operation result140generated by the operation program100is a numeric value “55”.

Moreover, the conversion unit200performs two's complement conversion to convert variables “x” and “i” (the variables120of the operation program100) respectively into a two's complement variable “(x″)” and a two's complement variable “(i″)” (the two's complement variables120C of the two's complement inverse operation program100C), the two's complement inverse operation program100C declares that the two's complement variable “(x″)” and the two's complement variable are “(i″)” and “−0” respectively. Also, the conversion unit200converts the function130of increment operation, that is, “++”, into the inverse operation function130C of decrement operation, that is, “−−”, and when the two's complement inverse operation program100C performs recursion, the value of the two's complement variable “(i″)” progressively decreases from “−1” to “−10”. Thus, after 10 times of recursion, the last value of two's complement variable “(x″)” obtained by the two's complement inverse operation program100C is a numeric value “−55”. Meanwhile, the second operation result140C generated by the two's complement inverse operation program100C is a numeric value “−55”.

Then, the comparison unit400compares the first operation result140with the second operation result140C. The comparison result is: the numeric value “−55” of the second operation result140C and the numeric value “55” of the first operation result140have identical absolute value but have opposite sings. In other words, the numeric value “−55” of the second operation result140C is the two's complement of the numeric value “55” of the first operation result140.

As disclosed above, the comparison result of the comparison unit400shows that: the first operation result140of the operation program100is equal to the two's complement of the second operation result140C of the two's complement inverse operation program100C. Thus, the error detection and correction device1000may determine that: when the program execution unit250executes the operation program100and the two's complement inverse operation program100C, the operation program100and the two's complement inverse operation program100C both are executed correctly, and during the execution of the programs, no numeric errors occur when the values of the variables120of “x”, “i” and the two's complement variables1200“(x″)” and “(i″)” are accessed from the storage unit600.

After step S160ofFIG.3Aand step S240ofFIG.3Bare executed, steps S310to S350ofFIGS.4A and4Bwill be performed.FIGS.4A and4Bare detailed flowcharts of an error detection and correction method for detecting and/or detecting errors according to the comparison result of the operation program100and the two's complement inverse operation program100C and the checksum result according to an embodiment of the disclosure. Referring toFIG.4A(also by reference toFIGS.1and2). At step S310, two's complement conversion is performed on the variables120of the operation program100by the conversion unit200to obtain corresponding two's complement variables120C. Then, at step S312, the values of the variables120and the values of the two's complement variables120C are accessed from the storage unit600by the operation program100. Then, at step S314, when the operation program100is executed by the program execution unit250, operations of the functions130are performed by the program execution unit250to obtain a first operation result140according to the variables120. Then, at step S316, checksum operation is performed on all variables120(such as variables “i” and “x”) of the operation program100by the checksum operation unit300to obtain a checksum result corresponding to all variables120of the operation program100.

Then, at step S318, when the two's complement inverse operation program100C is executed by the program execution unit250, operations of the inverse operation functions130C are performed by the program execution unit250to obtain a second operation result140C according to the two's complement variables120. Then, at step S320, checksum operation is performed on all two's complement variables120C (such as variables “(i″)” and “(x″)”) of the two's complement inverse operation program100C by the checksum operation unit300to obtain a checksum result corresponding to all two's complement variables120of the two's complement inverse operation program100C.

Then, at step S322, the first operation result140and the second operation result140C are compared by the comparison unit400to determine whether the first operation result140is equal to the two's complement of the second operation result140C and accordingly determine whether the operation program100and the two's complement inverse operation program100C are executed correctly. At step S322, if the first operation result140is equal to the two's complement of the second operation result140C, the determination is as follows: the program execution unit250correctly executes the operation program100, the program execution unit250also correctly executes the two's complement inverse operation program100C, and no numeric errors occur when the values of the variables120of the operation program100and the two's complement variables120C of the two's complement inverse operation program100C are accessed from the storage unit600by the program execution unit250when executing the operation program100and the two's complement inverse operation program100C. Thus, it may be determined that both the first operation result140and the second operation result140C are correct. Then, at step S324, the first operation result140is outputted and returned to the system platform2000by the output unit500.

On the other hand, at step S322, if the comparison result of the comparison unit400shows that the first operation result140is not equal to the two's complement of the second operation result140C, the determination is as follows: the program execution unit250erroneously executes the operation program100and/or the program execution unit250erroneously executes the two's complement inverse operation program100C (that is, at least one of the operation program100and the two's complement inverse operation program100C is executed erroneously). Meanwhile, steps S330and S340ofFIG.4Bare performed concurrently or consecutively.

Referring toFIG.4B, at step S330, the checksum result corresponding to all variables120of the operation program100are analyzed by the checksum operation unit300. Then, at step S332, whether the mutual checksum result corresponding to all variables120of the operation program100is equal to the mutual checksum result corresponding to the variables between the “first variable” and the “last variable” of the operation program100. If the determination at step S332shows that the above checksum results are equal, this indicates that the operation program100is executed correctly, and at step S334, the first operation result140of the operation program100is outputted and returned to the system platform2000. If the determination in step S332shows that the above checksum results are not equal, this indicates that the operation program100is executed erroneously, and at step S350, an error message150is outputted to the system platform2000.

On the other hand, at step S340to step S344, the checksum result is analyzed in the two's complement inverse operation program100C to determine whether the two's complement inverse operation program100C is executed correctly. At step S340, the checksum result corresponding to all two's complement variables120C of the two's complement inverse operation program100C is analyzed by the checksum operation unit300. Then, at step S342, whether the checksum result corresponding to all two's complement variables120C of the two's complement inverse operation program100C is equal to the mutual checksum result corresponding to the variables between the “first variable” and the “last variable” of the two's complement inverse operation program100C is determined. If the determination in step S342shows that the above checksum results are equal, this indicates that the two's complement inverse operation program100C is executed correctly, and at step S344, the second operation result140C of the operation program100is outputted and returned to the system platform2000. If the determination in step S342shows that the above checksum results are not equal, this indicates that the two's complement inverse operation program100C is executed erroneously, and at step S350, an error message150is outputted to the system platform2000.

Detailed implementation of step S316and step S320ofFIG.4Aand steps S330, S332, S340and S342ofFIG.4Bfor performing checksum operation and analyzing the checksum operation result are described below by reference toFIG.1, Table 3, Table 4 and Table 5.

Refer to Table 3. When operation is performed on any of the variables “x” and “y” of the operation program100and changes the value of the variable, checksum operation must be immediately performed on the variable with value change to update the checksum operation result. Let the variable “x” and the variable “y” be taken for example. After the program code of “x=1,” is performed, the value of the variable “x” changes to “1”. After the program code of “y=2;” is performed, the value of the variable “y” changes to “2”. Thus, checksum operation must be performed on the variable “x” and the variable “y” to obtain an updated checksum result: “1{circumflex over ( )}2=3”, wherein the operation symbol “{circumflex over ( )}” represents a mutually exclusive or (XOR) operation. Then, after the program code of “y=3;” is performed, the value of the variable “y” changes to “3”. Thus, checksum operation must be performed on the variable “x” and the variable “y” to obtain an updated checksum result: “1{circumflex over ( )}3=2”.

During the execution of the operation program, the “first variable” is defined as the value of the first appearing variable among the variables of the operation program100. According to the execution of the program code as illustrated in Table 3, the “first variable” is the numeric value “1” of the variable “x”. On the other hand, the “last variable” is defined as the value of the last appearing variable among the variables of the operation program100. According to the execution of the program code as illustrated in Table 3, the “last variable” is the numeric value “3” of the variable “y”. The checksum result obtained by performing mutual checksum operation on the variables between the first variable value “1” and the last variable value “3” is: “1{circumflex over ( )}3=2”.

Next, referring to Table 4, checksum operations are performed on all variables “x” and “i” of the operation program100to obtain a checksum results corresponding to all variables “x” and “i” according to the sub-functions of “checksum{circumflex over ( )}=x” and “checksum{circumflex over ( )}=i”. For example, after the variable “x” is declared, the checksum operation of “checksum{circumflex over ( )}=x” is performed on the variable “x”, both before and after the variable “i” is accumulated to the variable “x”. Similarly, after the variable “i” is declared, the checksum operation of “checksum{circumflex over ( )}=i” is performed on the variable “i”, both before and after increment operation is performed on the variable “i”.

Additionally, the “first variable” and the “last variable” are analyzed. In the operation program100, the “first variable” is the value of the variable which firstly appears among all variables (here, is the value of variable “i”), and the “last variable” is the value of the variable which last appears among all variables (here, is the value of variable “x”). When the execution of the operation program100is completed, mutual checksum operation of “checksum=i{circumflex over ( )}x” corresponding to the variable between the “first variable” (the value of the firstly appearing variable “i”) and the “last variable” (the value of the last appearing variable “x”) is performed to obtain a mutual checksum result corresponding to the variable between the “first variable” and the “last variable”.

Refer to Table 5. Checksum operation is performed on all variables “x″” and “i″” to obtain a checksum result corresponding to all variable “x″” and “i″” of the two's complement inverse operation program100C according to the sub-functions of “checksum{circumflex over ( )}=x″” and “checksum{circumflex over ( )}=i″”. Mutual checksum operation of “checksum=i″{circumflex over ( )}x″” is performed on the variables between the “first variable” and the “last variable”.

As disclosed in above embodiments, the error detection and correction device1000of the disclosure converts an operation program100into a two's complement inverse operation program100C, executes the operation program100and the two's complement inverse operation program100C, compares the operation results of the operation program100with the two's complement inverse operation program100C (the first operation result140and the second operation result140C) and checks whether the first operation result140is two's complement of the second operation result140C to determine whether the operation program100and the two's complement inverse operation program100C are executed correctly, and determine whether numeric errors occur to the values of the variables120and the values of the accessed two's complement variables120C. Furthermore, the error detection and correction device1000may be assisted with checksum operation to enhance the accuracy of the values of the variables120and the two's complement variables120C when operation program100and the two's complement inverse operation program100C are executed. Thus, the disclosure is capable of detecting and/or correcting erroneous execution of the operation program100by using software algorithms only and resolving single-event upset with a lower cost.