Method for carrying out a boolean operation between any two bits of any two registers

Abstract: A method for performing logic operations between any two bits belonging respectively to any two distinct registers belonging to a register file and/or to other physical data storing resources of a microprocessor or of internal and/or external pheripherals associated with the microprocessor, employs procedures which permit the utilization of the entire register addressing space. The method permits to the microprocessor to perform as a real boolean processor for simulating complex logic networks in an efficient and fast manner.

Description: BACKGROUND OF THE INVENTION The present invention relates to a novel method for carrying out logic (boolean) operations between two bits stored respectively in any two registers belonging to a certain set of registers or to other physical data storage device of a microprocessor or of peripherals associated thereto. US Patent No. 4,212,076 discloses a digital computer capable of providing arithmetic and boolean logic operations. The basic digital computer system is equipped with a logic processor to where an operand is transferred for performing a boolean operation on it, before writing back the result in the memory location from where the operand had been originally gathered. Commonly, microprocessors are capable of performing logic operations among bits belonging to a certain limited portion of the overall physical data storage resources which are associated to the microprocessor, by utilizing for the purpose a fixed register otherwise known as the "accumulator", to which the resulting bit is returned and wherein the operand bits are temporarily transferred by reading them from the respective registers where they reside (are permanently stored). A drawback of these microprocessor systems is due to the necessity of effecting a large number of data transfers to and from the physical data storage resources of the microprocessor and this fact strongly limits the possibility of simulating complex logic networks in an efficient and fast manner. SUMMARY OF THE INVENTION It has now been found a new method which overcomes these difficulties and permits to perform logic operations between any two bits stored in any two registers of the microprocessor, which method permits to exploit the whole register addressing space and therefore to operate on a Register File as well as on available data storage resources of peripheral units which are associated with the microprocessor, whether these are physically integrated in the microprocessor chip, such as for example the registers of input/output (I/O) management macrocells, the registers of special, dedicated circuit blocks for the management of external peripheral units, etc. or not, such as for example registers of external peripherals. The method of the present invention expands the flexibility of the microprocessor so as to be able to consider it as a true boolean processor capable of simulating complex logic networks in an efficient and fast way. The method of the invention is implemented by means of a defined number of steps which may be controlled through a set of standard instructions (in Assembler language) having a perfect orthogonality in the "address space" of all the physical data storage resources belonging to and/or associated with the microprocessor. DESCRIPTION OF A PREFERRED EMBODIMENT OF THE INVENTION A preferred embodiment of the instant invention is characterized by comprising at least one of the following steps or any combination thereof: 1. selecting a first bit (j), in a first source register (r s ) and a second bit (i) in a second, destination register (r d ); placing said first bit in a logic XOR with said second bit and writing the resulting bit into the position occupied by said second bit in said second, destination register, without altering the other bits present in said destination register. This step may be performed by means of the following instruction: BXOR r d ·i,r s ·j 2. Selecting a first bit (j) in a first, source register (r s ); generating the complementary bit of said first bit; placing said complementary bit of said first bit in a logic XOR with a second bit (i) selected from the bits stored in a second, destination register (r d ) and writing the resulting bit in the position occupied by said second bit in said second destination register, without altering the other bits stored in said destination register. This step may be performed by means of the following instruction: BXOR r d ·i,!r s ·j 3. Selecting a first bit (j) in a first, source register (r s ) and a second bit (i) in a second, destination register (r d ), placing said first bit in a logic AND with said second bit and writing the resulting bit in the position occupied by said second bit in said second destination register, without altering the other bits stored in said destination register. This step may be performed by means of the following instruction: BAND r d ·i,r s ·j 4. Selecting a first bit (j) in a first, source register (r s ) and a second bit (i) in a second, destination register (r d ), generating a complementary bit of said first bit and placing said complementary bit in a logic AND with said second bit and writing the resulting bit in the position occupied by said second bit in said second destination register, without altering the other bits stored in said destination register. This step may be performed by means of the following instruction: BAND r d ·i,!r s ·j 5. Selecting a first bit (j) in a first, source register (r s ) and a second bit (i) in a second, destination register (r d ), placing said first bit in a logic OR with said second bit and writing the resulting bit in the position occupied by said second bit in said second destination register, without altering the other bits stored in said destination register. This operation may be performed by means of the following instruction: BOR r d ·i,r s ·j 6. Selecting a first bit (j) in a first, source register (r s ) and a seocnd bit (i) in a second, destination register (r d ), generating a complementary bit of said first bit and placing said complementary bit in a logic OR with said second bit and writing the resulting bit in the position occupied by said second bit in said second destination register, without altering the other bits stored in said destination register. This step may be performed by means of the following instruction: BOR r d ·i,!r s ·j 7. Selecting a first bit (j) in a first, source register (r s ), and writing said first bit in the position occupied by a second bit (i) selected in a second, destination register (r d ), without altering the other bits stored in said second destination register. This operation may be performed by means of the following instruction: BLD r d ·i,r s ·j 8. Selecting a first bit (j) in a first, source register (r s ), generating a complementary bit of said first selected bit and writing said complementary bit in the position occupied by a second selected bit (i) in a second, destination register (r d ), without altering the other bits stored in said destination register. This step may be performed by means of the following instruction: BLD r d ·i,!r s ·j Basically the permitted logic operations of the above collection are the following: Of course the register pointing techniques used for addressing the source and the destination registers may be any known techniques which is customarily used for this purpose in state-of-the-art microprocessors. The method of the invention can be carried out with the hardware present in any state-of-the-art microprocessor, which is normally provided with the hardware for carrying out Set/Reset operations of any selected bit (BSET and BRES). In practice, the method of the invention is implemented by carrying out Set/Reset operations on a selected bit of a destination register in function of the type of logic operator (OR, AND or XOR) and of the value of a selected bit of a source register. In other words, the above-described logic operations between any two bits belonging respectively to a source register and to a destination register are performed by manipulating the selected bit in the destination register in function of certain parameters which are determined by the type of logic operator and by the value of the selected bit of the source register. BIT OPERATION In accordance with the method of the invention, the basic six standard instructions: BSET, BRES, BCPL, BOR, BAND and BXOR, are all carried out by following a somewhat similar flow, notwithstanding the fact the last three instructions imply the performance of a boolean operation between two operands as compared to the first three instructions which concern a single operand. The first three instructions: BSET, BRES and BCPL, can be discriminated from the other three instructions because the fourth bit of the second byte of the relative OPCODE is equal to "⊘". These first three operations (BSET, BRES and BCPL) are performed through a commonly used parametric technique by which a logic OR, AND or XOR operation between the byte containing the bit to be modified and an appropriate constant is carried out. The constant is automatically generated by decoding the bits 5, 6, and 7 of the second byte of the instruction's OPCODE. The selected constant is always constituted by seven "1" and one "⊘" and is loaded in a direct form or in a complementary form depending on the type of operation to be performed, e.g. in its direct form if a Reset is performed or in its complementary form if a Set is performed. This method of executing the first three instructions is customary and does not imply any particular difficulty. By contrast, the known methods for performing the other three boolean operations (BOR, BAND and BXOR) between selected bits, as well as the so-called Bit Load operation (BLD), have drawbacks as mentioned in the preamble of this specification. The instructions for executing the above mentioned three boolean operations between any two selected bits (two operands) are easily recognized because the fourth bit of the second byte of these instructions, expressed in the same OPCODE, is equal to "1", while for the first three operations was equal "⊘". In accordance with the method of the present invention, for carrying out a generic operation involving an operator chosen among OR, AND and XOR logic operators, between any selected bit of any source register and any selected bit of any destination register, the following procedure is followed. Firstly, by following a flow similar to the flow followed for executing the above-identified first three basic instructions: BSET, BRES and BCPL, a certain Set/Reset operation on the bit which has been selected as the destination bit is performed and the resulting modified data is saved to a temporary storage register, according to the following scheme: a Set operation for an OR operation; a Reset operation for an AND operation; and a complement generation operation for an XOR operation. Subsequently, the bit which has been selected as the source bit in the source register is tested by means of a pair of standard instructions: FORCE TEST and SET ALU C, which permit to the ALU to perform an AND operation with a constant formed by seven "⊘" and one "1" and to carry out a ZERO TEST on the result. The result of this test is elaborated by the parametric evaluation circuitry of the microprocessor and is utilized by the CPU for selecting one of two possible flow paths. One path stores the modified data in the destination register and the other path leads to a nonaction. The method of the invention will be illustrated now through a series of specific examples. BOR: between the third bit of the data F0h (destination byte) and the first bit of the data 0Fh (source byte); carrying out a Set operation on the third bit of the destination data F0h and storing the resulting data in a temporary storage register, as F8h; performing a ZERO TEST on the source bit 1 of the source data 0Fh; if the result of the ZERO TEST on the source bit is equal to "1", then the modified data F8h is saved to the destination register, thus completing the BOR operation. BAND: between the third bit of the data FFh (destination byte) and the first bit of the data 00h (source byte); carrying out a Reset operation on the third bit of the destination data FFh and storing the resulting data in a temporary storage register, as F7h; performing a ZERO TEST on the source bit 1 of the source data 00h; if the result of the ZERO TEST on the source bit is equal to "⊘", then the modified data F7h is saved to the destination register, thus completing the BAND operation. BXOR: between the third bit of the data F0h (destination byte) and the first bit of the data 0Fh (source byte); generating the complement of the third bit of the destination data F0h and storing the resulting data in a temporary storage register, as F8h; performing a ZERO TEST on the source bit 1 of the source data 0Fh; if the result of the ZERO TEST on the source bit is equal to "1", then the temporarily stored modified data F8h is saved to the destination register, thus completing the BXOR operation. From the above examples one notes that the saving to the destination register of the modified data placed in the temporary storage register must occur in different instances; i.e. for test bit 1 = "1" in execution of a BOR operation and of a BXOR operation and for test bit 1 = "⊘" in execution of a BAND operation. In order to avoid a flow duplication, a consequent complication of the execution of the instruction and an increase of the time of execution, the result of the ZERO TEST on the source bit, may be "reversed" in function of the fourth bit of the third byte of the instruction's OPCODE. Therefore in execution of a BOR or BXOR instruction the third byte will have the fourth bit equal to "⊘", while in execution of a BAND instruction the fourth bit of the third byte of the OPCODE will be equal to "1". The fourth bit of the third byte of the OPCODE is sampled every time the instruction SET ALU C is given. The peculiar construction of this standard command greatly facilitates the possibility of executing it with the source bit complemented, it will be sufficient in fact to generate the complement of the fourth bit of the third byte of the code. BIT LOAD In accordance with the method of the invention, this operation between a source bit and a destination bit may be performed advantageously through an approach different from the approach followed for the other three operations between bits, in so far the ZERO TEST on the source bit is executed first and is followed by the performance of the Set and Reset operations on the destination bit before finally saving the result in function of the result of the ZERO TEST previously carried out on the source bit. The test is carried out on the source bit by means of the usual pair of standard instructions: FORCE TEST and SET ALU C. The test is carried out first because two microinstructions are necessary before being able to utilize the result for conditioning the flow. This modified parametric technique allows to perform directly the Set operation on the destination bit which is actually performed immediately after the ZERO TEST. The result of the Set operation is saved to a temporary storage register. In case the ZERO TEST on the source bit has given a result equal to "1", the performance of a Reset operation on the destination bit is not required and thereafter the modified data contained in the temporary storage register is saved to the destination register. In the opposite case, a Reset operation must be performed on the destination bit followed by the execution of an AND operation with an appropriate constant. The selection of the constant and the parametric prearrangement may be effected conveniently through the usual two instructions: FORCE TEST and SET ALU C, which perform the ZERO TEST, i.e. by performing an AND operation with a purposely inverted constant (seven "⊘" and one "1"). In this way, it will be sufficient to invert the constant before carrying out the Reset on the destination bit, which may be effected by means of the pair of standard instructions: FORCE TEST and FORCE ALU SUB, which, if given simultaneously, permit to use the constant in its straightforward form (noninverted). The resulting data is eventually saved to the destination register to complete the Bit Load operation.

Claims: A method for performing logic operations between a first bit stored in a first destination register location and a second bit stored in a second source register location; characterised by comprising at least one of the logic operations OR, AND or XOR or any form of combination thereof; and a) comprising in the case of a logic OR-operation the steps of: a1) performing a logic OR-operation between said first bit and a logic " I " for the selected bit position ( Set-Operation) and writing the result to the corresponding bit location of a temporary register; a2) comparing said second bit to logic " I "; and a3) if the content of said second bit is equal to "1" writing the value of the corresponding bit location of the temporary register to the first destination register location, otherwise not changing the content of the first destination register location. b) in the case of a logic AND-operation comprising the steps of: b1) performing a logic AND-operation between said first bit and a logic " 0 " for the selected bit position ( Reset-Operation) and writing the result to the corresponding bit location of a temporary register; b2) comparing said second bit to logic " 0 "; and b3) if the content of said second bit is equal to "0" writing the value of the corresponding bit location of the temporary register to the first destination register location, otherwise not changing the content of the first destination register location; and c) in the case of a logic XOR-operation comprising the steps of: c1) performing a logic XOR-operation between said first bit and a logic " I " for the selected bit position ( Complement generation operation ) and writing the result to the corresponding bit location of a temporary register; c2) comparing said second bit to logic "l"; and c3) if the content of said second bit is equal to " I " writing the value of the corresponding bit location of the temporary register to the first destination register location, otherwise not changing the content of the first destination register location. The method of claim 1, wherein at least one logical bit operation is performed on the complement of the first bit. A method for loading a bit value from a first, selected bit position of a first register into a second, selected bit position of a second register, wherein all the locations of the first and second registers have a certain number of bit positions and each bit position has either a first logical value or a second logical value complementary to the first logical value, wherein the logical states of the bit positions of each register defines a location value, the method characterized by comprising the steps of: comparing the value of the first selected bit position of the first register to zero; storing the location value corresponding to the destination location into a temporary register having a certain number of bit positions and simultaneously setting the second bit position of the temporary register to the first logical value; if the result of said comparing step is "0", setting the value of the second bit position stored in the temporary register to the second logical value; and writing the location value in the temporary register into the addressable destination location. A method for copying a bit of data from a cell of a source register to a cell of a destination register, wherein the source and destination registers each comprise a plurality of cells for storing a corresponding plurality of bits of data, the method characterized by comprising the steps of: a) selecting a cell of the source register as a source cell; b) selecting a cell of the destination register as a destination cell; c) comparing the content of the source cell to zero; d) loading the contents of the destination register into a temporary register having the same number of cells as the destination register; e) setting to one the content of the cell in the temporary register that corresponds to the destination cell of the destination register; f) if the content of the source cell is equal to zero, resetting to zero the content of the cell of the temporary register that corresponds to the destination cell of the destination register, otherwise not changing the content of the temporary register; and g) transferring the contents of the temporary register into the destination register.

Inventors: SCARRA FLAVIO, SCARRA', FLAVIO
Applicants: ST MICROELECTRONICS SRL, STMICROELECTRONICS S.R.L.
Application year: 1991
Main classification: G06F9
IPC codes: G06F7, G06F9