US20100191934A1
2010-07-29
12/726,694
2010-03-18
Herein disclosed is a microcomputer MCU adopting the general purpose register method. The microcomputer is enabled to have a small program capacity or a high program memory using efficiency and a low system cost, while enjoying the advantage of simplification of the instruction decoding as in the RISC machine having a fixed length instruction format of the prior art, by adopting a fixed length instruction format having a power of 2 but a smaller bit number than that of the maximum data word length fed to instruction execution means. And, the control of the coded division is executed by noting the code bits.
Get notified when new applications in this technology area are published.
G06F7/535 » CPC main
Methods or arrangements for processing data by operating upon the order or content of the data handled; Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices; Multiplying; Dividing Dividing only
G06F9/3001 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Arrangements for executing specific machine instructions to perform operations on data operands Arithmetic instructions
G06F9/30112 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Register arrangements; Register structure for variable length data, e.g. single or double registers
G06F9/3013 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Register arrangements; Organisation of register space, e.g. banked or distributed register file according to data content, e.g. floating-point registers, address registers
G06F9/30145 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode Instruction analysis, e.g. decoding, instruction word fields
G06F9/30149 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Instruction analysis, e.g. decoding, instruction word fields of variable length instructions
G06F9/3016 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Instruction analysis, e.g. decoding, instruction word fields Decoding the operand specifier, e.g. specifier format
G06F9/30163 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Instruction analysis, e.g. decoding, instruction word fields; Decoding the operand specifier, e.g. specifier format with implied specifier, e.g. top of stack
G06F9/30167 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Instruction analysis, e.g. decoding, instruction word fields; Decoding the operand specifier, e.g. specifier format of immediate specifier, e.g. constants
G06F9/30181 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode Instruction operation extension or modification
G06F9/30189 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Instruction operation extension or modification according to execution mode, e.g. mode flag
G06F9/322 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Address formation of the next instruction, e.g. by incrementing the instruction counter for non-sequential address
G06F9/324 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Address formation of the next instruction, e.g. by incrementing the instruction counter for non-sequential address using program counter relative addressing
G06F9/3557 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Addressing or accessing the instruction operand or the result ; Formation of operand address; Addressing modes; Indexed addressing, i.e. using more than one address operand using program counter as base address
G06F9/3802 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead Instruction prefetching
G06F9/3814 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead; Instruction prefetching Implementation provisions of instruction buffers, e.g. prefetch buffer; banks
G06F9/3836 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead Instruction issuing, e.g. dynamic instruction scheduling, out of order instruction execution
G06F9/3857 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead; Instruction issuing, e.g. dynamic instruction scheduling, out of order instruction execution Result writeback, i.e. updating the architectural state
G06F9/3859 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead; Instruction issuing, e.g. dynamic instruction scheduling, out of order instruction execution; Result writeback, i.e. updating the architectural state with result invalidation, e.g. nullification
G06F9/3867 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode; Concurrent instruction execution, e.g. pipeline, look ahead using instruction pipelines
G06F2207/5352 » CPC further
Indexing scheme relating to methods or arrangements for processing data by operating upon the order or content of the data handled; Indexing scheme relating to groups - Non-restoring division not covered by
G06F9/38 IPC
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs; Arrangements for executing machine instructions, e.g. instruction decode Concurrent instruction execution, e.g. pipeline, look ahead
G06F12/08 IPC
Accessing, addressing or allocating within memory systems or architectures; Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
G06F9/30 » CPC further
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs Arrangements for executing machine instructions, e.g. instruction decode
G06F15/76 IPC
Digital computers in general ; Data processing equipment in general Architectures of general purpose stored program computers
G06F9/06 IPC
Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
This application is a continuation application of U.S. application Ser. No. 12/195,856, filed Aug. 21, 2008, which is a continuation application of U.S. application Ser. No. 11/120,105, filed May 3, 2005, now abandoned, which is a continuation application of U.S. Ser. No. 10/011,807, filed Dec. 11, 2001, now U.S. Pat. No. 6,996,700, which is a continuation of U.S. Ser. No. 09/632,332 filed Aug. 3, 2000, now U.S. Pat. No. 6,343,357, which is a continuation application of U.S. Ser. No. 09/053,638 filed Apr. 2, 1998, now U.S. Pat. No. 6,253,308, which is a continuation application of U.S. Ser. No. 08/478,730 filed Jun. 7, 1995, now U.S. Pat. No. 5,991,545, which is a continuation application of U.S. Ser. No. 07/897,457 filed Jun. 10, 1992, now abandoned.
The present invention relates to an architecture of a microcomputer, particularly a RISC (Reduced Instruction Set Computer) type microcomputer and, more particularly, to a technology effective if applied to a microcomputer to be packaged in a device for controlling it.
Moreover, the present invention relates to a circuit for coded division such as a dividing circuit for a coded binary number of arbitrary length and multi-precision and, more particularly, to a technology effective if applied to a step division of the RISC type microcomputer.
The most serious bottleneck for reducing the number of machine cycles necessary for executing one instruction is known to be the decoding of the instruction. In order to speed up this decoding, it is know effective to adopt an instruction format of fixed length so that where the boundary of the instruction resides may be informed before a preceding instruction has been interpreted. In the so-called βRISC type computerβ, most instructions are executed for one cycle by adopting the instruction format of fixed length and a pipe line of multiple steps. The conventional RISC computer has used a 32-bit instruction format without exception. This 32-bit fixed length instruction format is advantageous in that what register is to be read can be determined without decoding the operation code by fixing fields in the instruction formats of a source register and a destination register, and in that no alignment is required when an immediate value is decoded. On the contrary, the 32-bit fixed length instruction format requires 32 bits even no matter simple content of an instruction might be described. As a result, the number of bytes occupied by the instruction code is increased to raise a problem that the ratio of the memory area to be occupied by a program is accordingly increased. If the memory area occupied by the program is increased, a memory having a larger capacity has to be packaged to raise the cost of the microcomputer system, thus making it difficult to construct a system having an excellent performance ratio to the cost. Since the RISC processor is given an architecture for speeding up the executions of instructions by reducing the number of instructions, there arises a tendency that the undefined operation codes grow more for the instruction set. The multiplicity of the undefined operation codes deteriorates the code efficiency of the object program and degrades the memory using efficiency the worse.
The preceding patent application for improving such memory using efficiency or code efficiency is exemplified by Japanese Patent Application No. 222203/1990 (corresponding to U.S. patent application having Ser. No. 07/748,779 filed on Aug. 22, 1991). This application discloses a concept that the instruction format has a shorter bit number than that of the data word length. In this case, however, we have found that the various problems have to be solved by adopting the fixed length instruction format having a shorter bit number than the data word length. For example, new measures for the data processing have to be examined on the case, in which immediate data having a bit number equivalent to the data word length are necessary, or on the manner for assigning a branch destination address such as an absolute address as to the enlarged program or system structure. On the other hand, the above-specified application has failed to take any consideration into a relation of a power of 2 between the data word length and the instruction word length. Thus, the application has failed to positively prevent such a misalignment, in which one instruction is present across one word boundary of the memory, to leave new items such as the memory using efficiency, the software program simplification or the processing rate unexamined.
As a dividing technology to be executed in the microcomputer or the like, on the other hand, there is well known a division method, in which the codes of the quotient and the remainder are determined from the code of a dividend and the code of a divisor to execute the division with the absolute value of the dividend by a recovering method or a recovered method until the codes of the quotient and the remainder are finally corrected. In recent years, there are disclosed in the coded division several circuits and methods for executing the divisions in the coded state without taking the absolute values of the dividend and the divisor. In case the division is to be executed with the coded dividend and divisor, either method basically adopts the following procedures. Specifically, in case the code of the dividend or partial remainder and the code of the divisor are equal, the result of subtraction of the divisor from the dividend or partial remainder is used as a new partial remainder. In case, on the other hand, the code of the dividend or partial remainder and the code of the divisor are different, the result of an addition of the divisor to the dividend or partial remainder is used as a new partial remainder. Thus, the quotient is determined by repeating the subtractions or additions sequentially. At this time, in case the dividend is positive or in case the dividend is not contained by the divisor, a correct answer can be achieved by executing some quotient or remainder corrections on the basis of those procedures. In case, however, the dividend is negative and in case the dividend is contained by the divisor, the quotient thus determined is smaller than the correct quotient by the value β1β having an LSB weight toward the smaller absolute value. This error is caused by deeming the code of the partial remainder as correct in case the negative dividend or the partial remainder is subjected to the aforementioned addition or subtraction so that the partial remainder takes a zero.
In order to eliminate this error, there have been devised several dividing circuits which are equipped with means for detecting that the partial remainder is zero to correct the quotient. In Japanese Patent Laid-Open No. 165326/1990, for example, there is disclosed a technique, in which the irrecoverable dividing means is equipped with a register, which is set when the arithmetic result (i.e., the partial remainder) on each line is zero and reset when the value 1 enters the least significant bit on each line of the dividend, so that the quotient and remainder are corrected by using the result of the register. According to this disclosure, a correct coded division is realized by detecting and correcting the case, in which the partial remainder is zero, by using the aforementioned set and reset register. In Japanese Patent Laid-Open No. 171828/1990, on the other hand, there is disclosed another technique for preventing an erroneous quotient bit from being outputted in case the dividend is negative, by detecting whether or not the partial remainder is zero at each step of determining the quotient bit. In Japanese Patent Laid-Open No. 160235/1984, moreover, there is disclosed a technique which is equipped with a hardware for detecting the case, in which the partial remainder is zero, so that the most significant bit of the partial remainder may be deemed as 1 if the dividend is negative and if the partial remainder becomes zero in the course of the division.
Thus, in the prior art for the division with the coded dividend and divisor, the quotient bit is corrected by detecting that the partial remainder is zero. According to this technique, whether or not the partial remainder is zero has to be decided each time it is determined, and these decisions have to be accomplished n-times if the divisor has n bits. Moreover, whether or not the partial remainder is zero is not determined until all bits are examined. Therefore, the necessity for a special purpose hardware is anticipated if one decision is to be speeded up.
An object of the present invention is to solve the various problems accompanying the adoption of a fixed length instruction format having a smaller bit number than that of a data word length. A more specific object of the present invention is to provide a microcomputer which can achieve one or plural items selected from: that neither the use of immediate data nor the assignment of an absolute address is restricted even if the bit number of the fixed length instruction format is less than that of the data word length; that a description such as a necessary displacement can be executed in the fixed length instruction format having a limited bit number; that a contribution is made to the prevention of a misalignment of the program arrangement on a memory; and that the code efficiency or memory using efficiency is improved better from the standpoint of the content of a supporting instruction.
Another object of the present invention is to provide a division circuit which can determine a correct quotient easily without detecting whether or not a partial remainder is 0 at each dividing step of determining a quotient bit even in case a dividend is negative. Still another object of the present invention is to provide a division circuit which can develop a division program without considering whether the dividend is positive or negative. A further object of the present invention is to provide a division circuit which can improve the dividing efficiency with a simple circuit structure.
The foregoing and other objects and novel features of the present invention will become apparent from the following description to be made with reference to the accompanying drawings.
The representatives of the invention to be disclosed herein will be briefly summarized in the following.
(1) In a microcomputer adopting the general purpose register method, there is adopted a fixed length instruction format which has a smaller bit number than that of the maximum data word length fed to instruction execution means.
(2) In order that the bit number set in the fixed length instruction format may prevent a misalignment of a program on a memory, the fixed length instruction format and the maximum data word length may be set to a bit number of a power of 2. If the maximum data word length is 32 bits, for example, the instruction format is fixed to 16 bits.
(3) In case the aforementioned relation holds between the maximum word length of data and the bit number of the instruction format, a plurality of instruction may be prefetched in a common cycle so as to fetch the instructions efficiently by making use of an internal bus of a bit number equal to that of the maximum data word length or to reduce the bus access number for the instruction fetch.
(4) In case the internal bus is shared between the data transfer and the instruction fetch, the pipe control may be executed to prefer the data fetch thereby to delay the whole instruction execution schedule including an instruction fetch conflicting with that data fetch, so as to simplify either a processing when the data fetch and the instruction fetch conflict or a post-processing caused by the former.
(5) In order to simply cope with the state, in which the uses of the general purpose registers in response to the instructions before and after the pipe-line execution, the pipe-line control may be executed, because the general purpose register method is adopted, by detecting the state, in which the uses of the general purpose registers in response to the plurality of instructions to be executed in the pipe-line manner conflicts, on the basis of the information of a register assigned area contained in the instruction format, thereby to delay the execution of an instruction after the register conflicting state on the basis of the register conflicting state detected and the execution cycle number of the instruction to be preferentially executed.
(6) In order that the restriction on the bit number of the fixed length instruction format may not limit the use of immediate data, it is advisable to support the instruction containing a description for assigning the immediate data in a data relation for offsetting the value of a displacement relative to the value of a predetermined register.
(7) Even in the fixed length instruction format having a restricted bit number, the displacement necessary for the data processing or the bit number of the immediate data may be maximized to support an instruction for implicitly assigning a predetermined general purpose register which is fixed as an operand despite of no register assigning field in the instruction.
(8) Even in the fixed length instruction format having a restricted bit number, likewise, the displacement necessary for the processing or the bit number of the immediate data may be maximized to support an instruction containing a description for reflecting the truth or false of the arithmetic result for a specified condition upon a predetermined status flag.
(9) A proper branch destination assigning displacement length is fixedly assigned in accordance with the kinds of branching instructions. For a 16 bit fixed length instruction format, the displacement of a condition branching instruction is fixed at 8 bits, and the displacements of a subroutine branching instruction and an unconditional branching instruction are fixed to 12 bits.
(10) In case a dividend is negative in a coded division, a preliminary processing is executed by subtracting the value β1β having a weight of the LSB of the dividend from the dividend. This dividend is an integer if its LSB weight is 1. In case the dividend is a number having a fixed point, no substantial influence will arise even if the division is executed by assuming it to be an integer. This is because the point may be later adjusted. Hence, there arises no actual harm even if the intermediate calculations are executed while deeming the dividend as an integer by assuming the weight of the LSB of the dividend to be 1. In the following description, the dividend will be deemed as an integer unless otherwise especially specified so.
(11) Noting that the code bit is 1 for a negative dividend and 0 for a positive or zero dividend, the subtraction of a code bit (i.e., the MSB) is subtracted from the dividend is the subtraction of 1 from a negative dividend. This calculation can be deemed as a transformation from a negative integer in a complement expression of 2 to a complement expression of 1. In this way, the preliminary processing for the dividend can be executed without considering whether the dividend is positive or negative. FIG. 35 shows a trans-formation state, in which the number 1 is subtracted from a negative integer of 4 bits, for example. Since an extra 1 bit is necessary for transforming the minimum value of a complement of 2 of a finite bit number into a complement of 1, an extension of 1 bit is executed, if necessary. Since a partial remainder may be positive, the aforementioned transformation for a negative integer is extended all over integers to introduce a new integer expression. For example, an expression shown in FIG. 36 is adopted within a range of coded integers of 4 bits. If an arbitrary integer is expressed by a number ZZ which is calculated by subtracting 1 from that integer, the expression of the ZZ, which has been transformed by subtracting 1 from an integer using a complement of 2, can be deemed equal to a complement of 1 in an integer no more than 0 and can be expressed in an integer no less than 0 by a number which is smaller by 1 than the intrinsic value. At this time, the code bit of 0 is 1 as for a negative number.
(12) In order to hold the quotient and the partial remainder (or rest) in the procedure of the coded division, the quotient (or quotient bit) and the rest (or partial remainder) may be latched in single storage means such as one register so that the number of processing steps for transferring the quotient bit or partial remainder to be calculated or used for the calculations to the register or the like may be reduced.
(1) According to the means described above, the adoption of a 16 bit fixed length instruction format for a 32 bit data word length makes it possible to grasp the decision of where an instruction boundary resides, before a preceding instruction is completed, like the RISC machine of the prior art having the 32 bit fixed length instruction format in the point that the instruction format has the fixed length, thereby to warrant an advantage such as a simplification of the instruction decoding.
(2) The program capacity is smaller than that of the case, in which the 32 bit fixed length instruction format is adopted. Specifically, in the RISC architecture for speeding up the executions of instructions by reducing the kinds of them, there is a tendency that many undefined operation codes are in the instruction set. If the instruction length is halved at this time from that of the prior art, the using efficiency of the program memory is improved.
(3) The various problems intrinsic to the adoption of a fixed length instruction format having a smaller bit number than that of a data word length are solved by the facts: that neither the use of immediate data nor the assignment of an absolute address is restricted even if the bit number of the fixed length instruction format is less than that of the data word length; that a description such as a necessary displacement can be executed in the fixed length instruction format having a limited bit number; that a contribution is made to the prevention of a misalignment of the program arrangement on a memory; and that the code efficiency or memory using efficiency is improved better from the standpoint of the content of a supporting instruction.
(4) According to the means for the aforementioned coded division, the quotient is determined by: subtracting the value 1 having the weight of the LSB of a dividend from the dividend in case the dividend is negative; predicting the code of a quotient; adding and subtracting a divisor to and from the dividend or partial remainder while depending upon whether the exclusive OR between the code of the dividend or partial remainder and the code of the divisor is 0 or 1 to exemplify the quotient bit by the exclusive OR between the code of the partial remainder and the code of the divisor; and correcting the quotient of the complement of 1 into a complement of 2 in case the quotient is negative.
(5) In case the aforementioned dividend is negative, the subtraction of the value 1 having the weight of the LSB of the dividend from the dividend is equivalent to the preliminary processing for expressing the value 0 such that all the bits and the code bits are expressed by 1. This preliminary processing makes it unnecessary to detect that the partial remainder is 0 in case the dividend is negative. As a result, the divisions including the overflow check or the correction of the remainder can be controlled on the basis of information such as the code bit of the first dividend, the code bit of the partial remainder, the code bit of the divisor and the code bit of the quotient. This can simplify the hardware and software of the divisions and can effect an application to the coded divisions of arbitrary length and arbitrary accuracy. In addition, the register for latching the partial remainder can be shifted to a more significant side by 1 bit, and the processing for applying means for shifting in the quotient bit can be speeded up.
FIG. 1 is a block diagram showing one example of a system making use of a microcomputer MCU according to one embodiment of the present invention;
FIG. 2 is a block diagram showing a microcomputer according to one embodiment of the present invention;
FIG. 3 is a diagram for conceptionally explaining a pin arrangement for a package of a microcomputer according to the present embodiment;
FIG. 4 is an explanatory diagram showing one example of the relation between the data word length and the instruction word length to the bus width in the microcomputer according to the present embodiment;
FIG. 5 is a block diagram showing one example an internal block of a central processing unit, especially its instruction control system included in the microcomputer of the present embodiment;
FIG. 6 is a block diagram showing the structure of one half of an execution unit of the central processing unit;
FIG. 7 is a block diagram showing the structure of the remaining half of the execution unit of the central processing unit;
FIG. 8 is a diagram for explaining one example of a stage of a pipe-line processing by the central processing unit;
FIG. 9 is a diagram for explaining one example of a pipe-line sequence in a register conflicting state;
FIG. 10 is a diagram for explaining another example of a pipe-line sequence in a register conflicting state;
FIG. 11 is a diagram for explaining one example of a pipe control sequence in case a data fetch and an instruction fetch conflict;
FIG. 12 is an operation timing chart showing one example when a plurality of cycle instructions are executed;
FIG. 13 is an explanatory diagram showing a table of one half of data transfer instructions to be executed in the microcomputer of the present embodiment;
FIG. 14 is an explanatory diagram showing a table of the remaining half of data transfer instructions to be executed in the microcomputer of the present embodiment;
FIG. 15 is an explanatory diagram showing a table of logical operation instructions to be executed by the microcomputer of the present embodiment;
FIG. 16 is an explanatory diagram showing a table of one half of arithmetic operation instructions to be executed by the microcomputer of the present embodiment;
FIG. 17 is an explanatory diagram showing a table of the remaining half of arithmetic operation instructions to be executed by the microcomputer of the present embodiment;
FIG. 18 is an explanatory diagram showing a table of instructions to be executed by the microcomputer of the present embodiment:
FIG. 19 is an explanatory diagram showing a table of branching instructions to be executed by the microcomputer of the present embodiment;
FIG. 20 is an explanatory diagram showing a table of one half of system control instructions to be executed by the microcomputer of the present embodiment;
FIG. 21 is an explanatory diagram showing a table of the remaining half of system control instructions to be executed by the microcomputer of the present embodiment;
FIG. 22 is a diagram for explaining the description types of FIGS. 13 to 21;
FIG. 23 is an explanatory diagram showing a table of addressing modes in the mnemonic designations shown in FIGS. 13 to 21;
FIG. 24 is an explanatory diagram showing one example of the relations between the displacement lengths of branch instructions and the appearance frequency of instructions having the displacement lengths;
FIG. 25 is an explanatory diagram showing one example of the relations between the displacement lengths of branch always instructions and the appearance frequency of instructions having the displacement lengths;
FIG. 26 is an explanatory diagram showing one example of the relations between the displacement lengths of subroutine call instructions and the appearance frequency of instructions having the displacement lengths;
FIG. 27 is an explanatory diagram showing one example of the relations between the displacement lengths of jump instructions or jump subroutine instructions and the appearance frequency of instructions having the displacement lengths;
FIG. 28 is a diagram for explaining the structure of a register of an example as a programmer's model;
FIG. 29 is a conceptional diagram showing the principle of a preliminary processing for a dividend in a coded division according to the present invention;
FIG. 30 is a diagram for explaining one principle example of the coded division processing in case of negativeΓ·negative;
FIG. 31 is a diagram for explaining one principle example of the coded division processing in case of negativeΓ·positive;
FIG. 32 is a diagram for explaining one principle example of the coded division processing in case of positiveΓ·positive;
FIG. 33 is an explanatory view showing in a general form the entirety of the basic promises or processing procedures of the coded division according to the present invention;
FIG. 34(A) is a diagram for explaining the manner of a pre-correction of a dividend, and FIG. 34(B) is a diagram for explaining a prediction of the code of a quotient;
FIG. 35 is a diagram for explaining one example of the pre-correction of a negative dividend;
FIG. 36 is a diagram for explaining an example of the expression of a partial remainder after the pre-correction of subtracting 1 from the negative dividend;
FIG. 37(A) is a diagram for explaining one example how to extract an addition/subtraction command in the coded dividing procedure, and FIG. 37(B) is a diagram for explaining one example how to extract a quotient bit;
FIG. 38 is a diagram for explaining one example how to correct the quotient and the remainder;
FIG. 39 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of β8Γ·β3;
FIG. 40 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 39;
FIG. 41 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of β8Γ·3:
FIG. 42 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 41;
FIG. 43 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of β9Γ·β3;
FIG. 44 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 43;
FIG. 45 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of β9Γ·3;
FIG. 46 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 45;
FIG. 47 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of 8Γ·3;
FIG. 48 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 47;
FIG. 49 is a diagram for explaining a specific processing procedure for the pre-correction and the dividing processing in a coded division of 8Γ·β3;
FIG. 50 is a diagram for explaining a specific processing procedure of a post-processing continued from the processing of FIG. 49;
FIG. 51 is a block diagram showing one embodiment of an operation unit for a coded division;
FIG. 52 is a logical circuit diagram showing one example of an arithmetic logical operation circuit, an operation circuit and an operation control circuit shown in FIG. 51;
FIG. 53 is a detailed diagram for explaining one example of an instruction description for the coded division;
FIG. 54 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction EOR R0,R0 of FIG. 53;
FIG. 55 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction SL16 R1 of FIG. 53;
FIG. 56 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIVOS R0,R2 of FIG. 53;
FIG. 57 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction MOVT R3 of FIG. 53;
FIG. 58 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction SUBC R0,R2 of FIG. 53;
FIG. 59 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIVOS R1,R2 of FIG. 53;
FIG. 60 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIV1 R1,R2 of FIG. 53;
FIG. 61 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction MOV R2,R4 of FIG. 53;
FIG. 62 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction EXTS.W R2,R2 of FIG. 53;
FIG. 63 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction ROTCL R2 of FIG. 53;
FIG. 64 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction ABDC R0,R2 of FIG. 53;
FIG. 65 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIVOS R0,R4 of FIG. 53;
FIG. 66 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction MOVT R0 of FIG. 53;
FIG. 67 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction EOR R3,R0 of FIG. 53;
FIG. 68 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction ROTCR R0 of FIG. 53;
FIG. 69 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIVAS R1,R4 of FIG. 53;
FIG. 70 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction ROTCR R4 of FIG. 53;
FIG. 71 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction DIV1 R1,R4 of FIG. 53;
FIG. 72 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction SR16 R4 of FIG. 53;
FIG. 73 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction ADD R3,R4 of FIG. 53;
FIG. 74 is a diagram for explaining the operations of the circuits of FIG. 51 for executing the instruction EXTS.W R4,R4 of FIG. 53;
FIG. 75(A) is a diagram for explaining the state of a register corresponding to the operations of FIG. 54, FIG. 75(B) is a diagram for explaining the state of a register corresponding to the operations of FIG. 55, and FIG. 75(C) is a diagram for explaining the state of a register corresponding to the operations of FIG. 56;
FIG. 76(D) is a diagram for explaining the state of a register corresponding to the operations of FIG. 57, FIG. 76(E) is a diagram for explaining the state of a register corresponding to the operations of FIG. 58, and FIG. 76(F) is a diagram for explaining the state of a register corresponding to the operations of FIG. 59;
FIG. 77(G) is a diagram for explaining the state of a register corresponding to the operations of FIG. 60, and FIG. 77(H) is a diagram for explaining the state of a register corresponding to the operations of FIG. 62;
FIG. 78(I) is a diagram for explaining the state of a register corresponding to the operations of FIG. 63, FIG. 78(J) is a diagram for explaining the state of a register corresponding to the operations of FIG. 64, and FIG. 78(K) is a diagram for explaining the state of a register corresponding to the operations of FIG. 65;
FIG. 79(L) is a diagram for explaining the state of a register corresponding to the operations of FIG. 66, FIG. 79(M) is a diagram for, explaining the state of a register corresponding to the operations of FIG. 67, and FIG. 79(N) is a diagram for explaining the state of a register corresponding to the operations of FIG. 68;
FIG. 80(O) is a diagram for explaining the state of a register corresponding to the operations of FIG. 69, FIG. 80(P) is a diagram for explaining the state of a register corresponding to the operations of FIG. 70, and FIG. 80(Q) is a diagram for explaining the state of a register corresponding to the operations of FIG. 71;
FIG. 81(R) is a diagram for explaining the state of a register corresponding to the operations of FIG. 72, FIG. 81(S) is a diagram for explaining the state of a register corresponding to the operations of FIG. 73, and FIG. 81(T) is a diagram for explaining the state of a register corresponding to the operations of FIG. 74;
FIG. 82(A) is a flow chart showing the entirety of a coded dividing processing explained in FIGS. 54 to 74, and FIG. 82(B) is a flow chart showing a pre-processing of the same;
FIG. 83(A) is a flow chart showing the detail of the division 1 of FIG. 82, and FIG. 83(B) is a flow chart showing the processing of a division step;
FIG. 84(A) is a flow chart showing the detail of the entirety of the post-processing of FIG. 82, and FIG. 84(B) is a flow chart showing the processing of a quotient correction;
FIG. 85(A) is a flow chart showing the detail of first remainder correcting means of the post-processing of FIG. 84, and FIG. 85(B) is a flow chart showing the processing of second remainder processing means;
FIG. 86 is a diagram for explaining one example of an instruction description for a coded division of 8 bitsΓ·8 bits;
FIG. 87 is a diagram for explaining one example of an instruction description for a coded division of 64 bitsΓ·32 bits;
FIG. 88 is a diagram for explaining one example of an instruction description for a coded division of 32 bitsΓ·32 bits;
FIG. 89 is a diagram for explaining one example of an instruction description for a coded division of 16 bitsΓ·16 bits;
FIG. 90 is a diagram for explaining one example of an instruction description for a coded division of 16 bitsΓ·8 bits; and
FIG. 91 is a diagram for explaining one example of an instruction description for a coded division of 32 bitsΓ·16 bits.
The present invention will be described in the following in connection with the embodiments thereof in the order of items which are broadly itemized into: a microcomputer adopting an instruction form a of fixed length having a smaller bit number than that of the maximum data word length; and coded divisions to be executed by such microcomputer. The contents of the former will be described under Items [1] to [17] whereas the contents of the latter will be described under Items [18] to [24].
[1] Application System of Microcomputer
FIG. 1 shows one example of a system which makes use of a microcomputer MCU according to one embodiment of the present invention. This microcomputer MCU is coupled through an external control bus ECB, an external data bus EDB and an external address bus EAB to an external memory EMRY and an external input/output block EI/O defined by the user and is further connected with a port input/output bus PIOB to an external equipment EEQ. This external equipment EEQ is a predetermined device to package the microcomputer system.
[2] Block Structure of Microcomputer
FIG. 2 shows the microcomputer MCU according to one embodiment of the present invention. The microcomputer MCU, as shown, is packaged in a single semiconductor substrate such as a silicon substrate by the well-known semiconductor integrated circuit manufacture technology. Reference letters CPU appearing in the Figure designates a central processing unit for controlling the microcomputer MCU in its entirety. Letters Port/I/O designate an input/output port to be used for the central processing unit CPU to input/output a signal, to drive an external display device and to inspect the state of an external switch. The central processing unit CPU inputs/outputs by reading/writing a register assigned to a certain address. Letters Port/Cont designate a port for an input/output of the data bus. Letters Port/Address designate a port for an input/output of the address bus. Letters I/O designate such a peripheral device on the chip of the microcomputer MCU as includes a serial communication interface, a timer and so on. Letters DMAC designate a direct memory access (DMA) controller. A ROM (Read Only Memory) is an instruction memory packaged on-chip and stores the instructions (i.e., operation programs) of the central processing unit CPU and a constant table. A RAM (Random Access Memory) is a memory packaged on-chip and is used as the working area of the central processing unit CPU or a primary storage area for data. Letters BSC designate a bus state controller for controlling the bus access to the inside and outside of the microcomputer MCU. Letters CACHE designate a cache memory, i.e., a storage device for latching an instruction, which is anticipated to be most frequently used by recognizing the access pattern of an instruction of the central processing unit CPU, to reduce the frequency for accessing to an application program or the like from an external memory having a low access rate, thereby to accelerate the processing. Letters BURST/REFRESH designate a burst/refresh device for burst control of a continuous data transfer and for refresh control of a dynamic random access memory (DRAM) and is applied to a high-speed page mode access, when the DRAM is used as an external memory, and to a refreshing of the DRAM. Letters edb designate an internal data bus coupled through a port Port/Data to the external data EDB, and letters eab designate an internal address bus coupled through a port Port/Add to the external address bus EAB. These two internal buses are not coupled to the central processing unit CPU. On the other hand, characters IDB31-0 designate internal data buses of 32 bits, and IAB23-0 designate internal address buses of 24 bits. These two internal buses are coupled to the central processing unit CPU.
This central processing unit CPU is given an instruction from the instruction memory ROM or the cache memory CACHE so that the data issued from the data memory RAM or the external memory EMRY are subjected to a predetermined processing in accordance with the given instruction.
[3] Pin Arrangement of Package of Microcomputer
FIG. 3 conceptionally shows a pin arrangement of the package of the aforementioned microcomputer MCU. In the same Figure, free running timers FRT0 and FRT1, an analog/digital converter A/D, a digital/analog converter. D/A, and serial communication interfaces SCI0 and SCI1 exemplify the peripheral circuit I/O of FIG. 2, and corresponding ports PORT1 to PORT4 shown in FIG. 3 are input/output ports corresponding to individual peripheral devices and accordingly to the port Port/I/O of FIG. 2. The microcomputer MCU is filled in a QFP type package of 112 pins. Address buses (A0-23) of 24 bits are connected with the aforementioned address bus EAB, and data buses (D0-31) of 32 bits are connected with the aforementioned data bus EDB. These buses A0-23 and D0-31 are used when the central processing unit CPU, the direct memory access controller DMAC or the burst/refresh control block BURST/REFRESH accesses the external memory EMRY. Clock signals are those for specifying the basic timing of the instant when the inside of the microcomputer MCU and its external systems operate synchronously. If a not-shown quartz oscillator is coupled to terminals EXTAL and XTAL, for example, it resonates to oscillate with an electric circuit in the chip of the microcomputer MCU. This chip detects the oscillating voltage to generate internally synchronizing clocks Ο1 and Ο2, as will be described hereinafter. These clocks Ο1 and Ο2 are non-overlap clock signals which have neither of their high periods overlapped, although not especially limitative thereto. At the same time, the microcomputer MCU outputs a clock signal having a waveform and a phase substantially identical to those of the signal Ο1 from its terminal CLK so as to synchronize its external system and the inside of the LSI. The control signal includes: an operation mode setting signal and an interruption inputting signal such as a reset signal (RES) or a standby signal (STBY); a data bus control signal such as a read strobe (RD) or a write strobe (WRHH); or a DRAM refresh control or bus arbitration signal. Letters Vss and Vcc designate a ground terminal and a power supply terminal. The port PORT1 inputs/outputs two channels of the control signal DMAC concerning the direct memory access controller DMAC. The port PORT2 inputs/outputs the FRT signal for controlling and reading the free running timers FRT0 and FRT1 from the outside of the microcomputer MCU. The port PORT3 inputs/outputs the analog signals which are fed to the analog/digital converter A/D and the digital/analog converter D/A. Reference potentials of the analog/digital converter A/D and the digital/analog converter D/A are fed from terminals AVcc and AVss. The port PORT4 inputs/outputs the serial communication signals which belong to three clock, data transmission and data reception systems for two channels.
[4] Instruction Word Length and Data Word Length
FIG. 4 shows one example of the relation of the data word length and the instruction word length to a bus width (i.e., the number of signal lines composing a bus) in the microcomputer MCU of the present embodiment. This microcomputer MCU has an architecture of RISC type and an instruction form a of fixed length. The buses such as internal data buses IDB31-0, through which data and instructions are transferred, are given 32 bits (corresponding to 32 signal lines). At this time, the bit number of later-described various registers is 32 bits. The data on a memory are arranged at the units of byte (of 8 bits), word (of 16 bits) and long word (of 32 bits) in a memory area having a width of 32 bits. Addresses are assigned at the byte unit to the memory. As a result: the byte data are accessed at the unit of n addresses (n: an integer); the word data are accessed at the unit of 2n addresses; and the long word data are accessed at the unit of 4n addresses. Other memory accesses are deemed to belong to an address error. On the other hand, instructions are formatted into an instruction format having a fixed length of 16 bits (corresponding to 16 signal lines). In short, an instruction of fixed length is composed of bits of the n-th power of 2, and the relation of mβ§n holds, if the number of signal lines composing the bus width is the m-th power of 2.
In FIG. 4 showing several examples of the aforementioned instruction format of fixed length of 16 bits: four bits of βrrrrβ designate an assigned field of a source register; four bits of βRRRRβ designate an assigned field of a destination register; bits of βd---ddβ designate a displacement; and bits βii-iβ designate an immediate data. In an instruction format of 16 bits, the destination register assigned field RRRR falls at the eighth bit from the fourth bit with reference to the lefthand side of the format, and the source register assigned field rrrr falls at the twelfth bit from the ninth bit. The lefthand four bits of the instruction format are assigned to at least an operation code assigned field. The instruction system of the microcomputer MCU allows the destination register assigned field RRRR to be used as a portion of the operation code assigned field and the source register assigned field rrrr to be used as a portion of the displacement or immediate data.
Thanks to adoption of the instruction format of fixed length of 16 bits for the data word length of 32 bits, where the instruction boundary resides can be decided before the end of a preceding instruction like the RISC machine of the prior art having the instruction format of fixed length of 32 bits, thereby to warrant the advantage such as simplification of the instruction decoding process. In addition, the program capacity can be made smaller than that of the case in which the instruction format of fixed length of 32 bits is adopted. In the RISC architecture intended to accelerate the execution of instructions by reducing the number of kinds of instructions, there is a tendency that undefined operation codes increase in an instruction set. If the instruction length is reduced at this time to one half of the prior art, the efficiency of using the program memory can be improved. Thanks to the reduced instruction word length, as compared with the data word length, the substantially useless bit array can be made less than that of the case, in which the two word lengths are equalized, so that the efficiency of using the program memory can be enhanced. As a result, the efficiency of using the memory for storing the program can be improved to keep an application field, which uses a memory having a limited capacity on the board or a program memory packaged on-chip in the processor, away from problems such as shortage in the storage capacity of the program memory at the time of constructing the system or unavoidably large scale of the memory. Thus, the system cost can be reduced.
Since, moreover, the instruction format of fixed length of 16 bits has one half of the data word length and bus width of 32 bits, an instruction misalignment to the program memory such that an instruction of single format is arranged across the boundary of the memory (or word) occurs less frequently than the case, in which the instruction word length is shortened by setting the instruction word length to a fragmentary bit number (e.g., bit number other than a power of 2) with respect to the bus width or data word length.
[5] Instruction Control System of CPU
FIG. 5 shows one example of the internal block, i.e., its instruction control system of the aforementioned central processing unit CPU. Letters IRH and IRL designate individual instruction buffers (i.e., instruction queues) of 16 bits for latching instructions of fixed length of 16 bits one by one. These registers IRH and IRL are individually loaded with the instructions in one instruction fetch cycle. This is because the instructions are transferred at the unit of 32 bits through the internal data buses IDB31-0. These instructions are loaded in the instruction register IR1 through a multiplexer MPX. The instruction register IR1 has 16 bits. This instruction register IR1 latches the instruction which is present at the instruction decode stage. In the instruction register IR1, with reference to the lefthand end indicated as βRRRRβ in accordance with the instruction format of fixed length of 16 bits, the fifth to eighth bits are caused to belong to the destination register field, and the ninth to twelfth bits indicated as βrrrrβ are caused to belong to the source register field. These fields are fixed in the instruction field. At this time, as has been described hereinbefore, the source register field never fails to be used for selecting the source operand, and the destination register field never fails to be used for selecting the second source operand or destination operand. Each register field may mean a portion of the operation code or the number of a register. Whether or not the contents of the register assigned fields RRRR and rrrr are pieces of information for selecting a register is determined at the left end of the aforementioned instruction format of fixed length by the contents of the 1st to 4th bit operations codes. Nevertheless, the values of the register fields RRRR and rrrr are inputted to and decoded by a source register decoder SRD and a destination register decoder DRD through the instruction register IR2.
The decoded results by the aforementioned source register decoder SRD and destination register decoder DRD are used to decide what of general purpose registers R0H and R0L, - - - , and R15H and R15L contained in an execution unit for arithmetic operations is to be selected. On the other hand, the values of the register fields RRRR and rrrr outputted from the aforementioned instruction register IR2 are fed through temporary latches WBR0 and WBR1 to a write back register decoder WBRD so that the arithmetic results obtained by the instruction executions are written for selecting the general purpose registers in accordance with the decoded results. Moreover, the values of the register fields RRRR and rrrr, i.e., the register numbers latched in the aforementioned temporary latch WBR1 and being used are fed to a register content check block RCCB so that they are compared with the outputs of the instruction registers IR1 and IR2 to find out an even (or register conflict), in which each instruction, e.g., a subsequent instruction accesses a common register when the instructions sequentially fetched are executed in the pipe-line manner. The register conflict is fed to a flag operation & pipe control decoder FO&PCD in response to the signal S1. If the signal S1 thus asserted is fed to the flag operation & pipe control decoder FO&PCD, skip controls are executed in accordance with the number of instruction execution cycles being done, to cancel or delay the execution cycles of the instructions using the conflicting registers. In short, when the flag operation & pipe control decoder FO&PCD outputs the control signal Skip, the decoding of the instruction to be subsequently executed is delayed in the source register decoder SRD and the destination register decoder DRD. As a result, the execution cycle of a succeeding instruction is started at a timing after the writing of the conflicting registers is ended by executing the preceding instruction.
The instruction latched by the aforementioned instruction register IR1 is fed to a mapping control block MCB to index the addresses of a high-speed control read only memory (i.e., Hardware Sequence ROM) HSC-ROM. This mapping control block MCB has a role to calculate the entry address of a proper high-speed control read only memory MHSC-ROM in accordance with the content. The high-speed control read only memory HSC-ROM has its output composed of two portions: a micro code field MCF and a pipe control field PCF, which are latched by a hardware sequence control instruction register HIR such as a micro instruction register. The former in the micro instruction field feeds a control signal to the execution unit EXEC through a shallow decode logic, i.e., an instruction decoder ID. The latter establishes the sequence of an instruction having two or more cycles through the flag operation & pipe control decoder FO&PCD or controls the pipe line. The flag operation & pipe control decoder FO&PCD has eight flags C, W, B, L, M, I, S and S for controlling the pipe lines. Moreover, this flag operation & pipe control decoder FO&PCD has a status register SR which has a true bit T (as will be shortly referred to as βT bitβ) used for condition branching. This T bit is set to the truth or false of the arithmetic result of selected conditions described in the instruction, as will be described hereinafter.
The content of the aforementioned instruction register IR1 is transferred before an arithmetic execution phase (EX) to the instruction register IR2 so that whether or not a conflict is caused between instructions in the pipe line state of later memory access phase (MA) and write back phase (WB) is checked through the aforementioned register content check block RCCB, and this result is outputted as the signal S1. What is stored at this time in the instruction register IR2 is the value of the register field. The values of the register fields RRRR and rrrr latched in the instruction registers IR1 and IR2, as has been described hereinbefore, are fed to the aforementioned source register decoder SRD, destination register decoder DRD and write back register decoder WBRD. These source register decoder SRD, destination register decoder DRD and write back register decoder WBRD generates a selection signal for selecting one pair of the sixteen general purpose registers R0H and R0L, - - - , and R15H and R15L and feeds it to the execution unit EXEC.
The memory interface MIF detects whether or not the central processing unit CPU has to access a memory and whether the memory is of the read or write type, and feeds a signal necessary for accessing the memory. On the other hand, an instruction fetch & instruction register control block IF&IRC has a function to determine whether or not an instruction fetch from a memory is necessary and when the contents of the instruction registers IRH and IRL are to be updated, and to output a necessary signal. The function of this instruction fetch & instruction register control block IF&IRC is to output a predetermined control signal with reference to the state of the pipe line, the state of the memory and the state of the instruction queues (IRH and IRL) thereby to control the instruction queue or the instruction fetch. What features the present embodiment is that the instruction fetch is carried out at the unit of 32 bits so that it contains two instructions having an instruction length of 16 bits. This makes it unnecessary to fetch again the instruction, which has been fetched simultaneously as the preceding instruction is fetched, in another phase. These events are totally judged to control when the instruction fetch is to be executed. The instruction fetch & instruction register control block IF&IRC is constructed as an finite state machine, and a detailed description of the structure of this machine will be omitted because the structure per se is well known in the art.
Incidentally, letters IMB appearing in FIG. 5 designate a buffer for sending immediate data contained in an instruction to the execution unit EXEC. Moreover, the instruction queues IRH and IRL and the latch timing of the instruction register IR1 are synchronized with the aforementioned clock signal Ο1. The latch timings of the instruction register IR2, the micro instruction register MIR and the registers WBR0 and WBR1 and the output timing of the signal S1 by the aforementioned register content check block RCCB are synchronized with the aforementioned clock signal Ο2.
Since the data bus width is 32 bits whereas the fixed length instruction is 16 bits, there are provided two instruction buffers IRH and IRL. Despite of this provision, however, the number of instruction buffers is determined depending upon how many fixed length instructions can be transferred within the data bus width, for example: four instruction buffers in case of a fixed length instruction of 8 bits; and eight instruction buffers in case of a fixed length instruction of 4 bits.
[6] Execution Unit of CPU
FIGS. 6 and 7 show one example of the execution unit EXEC of the central processing unit CPU. In the two Figures, buses indicated at A, B, C and D are commonly connected. The execution unit EXEC includes: an instruction fetch block IFB and a general purpose block GRB for fetching an instruction and updating a program counter; an operation block OPB for addition/subtraction and shift operations; and memory access block MAB and a multiplication block MULT for accessing a memory and aligning data. These individual blocks are coupled to one another through the four data buses A, B, C and D having a width of 32 bits.
The aforementioned instruction buffers (or instruction queues) IRH and IRL, multiplexer MPX and instruction register IR1 forming part of the aforementioned instruction fetch block IFB are shown in the block structure of FIG. 5 separately of the execution unit EXEC but may be contained in the execution unit EXEC, as shown in FIG. 6. An immediate buffer IMB is a logic for cutting and bit-shift, if necessary, immediate data. Letters PCH and PCL designate program counters for latching addresses for fetching an instruction. An arithmetic unit high AUH and an arithmetic unit low AUL are adders capable of performing an addition of 32 bits for updating the program counters. A procedure address register high PRH and a procedure address register low PRL are procedure address registers for latching return addresses for a function call. A vector base register high VBRH and a vector base register low VBRL are used as storage areas of an interrupt vector area for latching the base addresses. A global base register high GBRH and a global base register low GBRL are used as storage registers for the base address of the I/O. A break register high BRH and a break register low BRL are used as storage registers for return destination addresses from the break routine.
The aforementioned general purpose register block GRB includes sixteen general purpose registers of 32 bit length, as indicated at R0H and R0L to R15H and R15L. In the aforementioned operation block OPB, a shifter high SFTH and a shifter low SFTL are hardware for bit shifts and rotations. An arithmetic logic unit high and an arithmetic logic unit low are operators for arithmetic logical operations. Letters SWP&EXT designate a hardware for executing a swap instruction, a code (or sign) extension or a zero extension. An aligner ALN is a hardware for aligning the data which are accessed in byte or word from a memory or I/O. A memory read buffer high MRBH and a memory read buffer low MRBL are temporary registers for latching the data which are read from a memory. A memory write buffer high MWBH and a memory write buffer low MWBL are temporary registers for latching data to be written in a memory. A memory address buffer high MABH and a memory address buffer low MABL are temporary registers for latching addresses at the time of a memory access. A MULT buffer MLTB is a temporary register for transferring a multiplier and a multiplicant to the multiplication block MULT.
The connection relations of the inside and outside of the central processing unit CPU through the buses are as follows. Specifically, letters MTBL and MTBH are bilateral special purpose buses for connecting the multiplication block MULT. In FIGS. 6 and 7, letters IDBH and IDBL correspond to the data buses IDB31-0 of FIG. 2, and letters IABH and IABL correspond to the address buses IAB23-0 of FIG. 2. The values of the aforementioned program counters PCH and PCL are outputted to the address buses IABH and IABL, and the instruction buffers IRH and IRL fetch the data from the data buses IDBH and IDBL so that the outputs of the temporary registers MWBH and MWBL are fed to the data buses IDBH and IDBL. The temporary registers MRBH and MRBL input the data from the data buses IDBH and IDBL and the special purpose buses MTBH and MTBL. The address informations latched by the temporary registers MABH and MABL are outputted to address buses IABH and IABL. The multiplying temporary register MLTB has its output fed to the special purpose buses MTBH and MTBL.
[7] Pipe Line Stage by CPU
FIG. 8 shows one example of a stage of a pipe line processing by the central processing unit CPU. This central processing unit CPU has a basic pipe line structure of five stages having the following basic phases:
IF: Instruction Fetch;
ID: Instruction Decode;
Ex: Execute;
MA: Memory Access; and
WB: Write-Back.
In FIG. 8 showing one example of the execution content of each pipe stage, the Address Bus correspond to the address buses IAB23-0 of FIG. 2, and the Data Bus correspond to the IDB31-0 of the same. Letters IR of FIG. 8 correspond to the instruction buffers IRH and IRL of FIGS. 8 and 5. In FIG. 8, letters A-Bus, B-Bus, C-Bus and D-Bus are the A bus, B bus, C bus and D bus of FIG. 7, respectively. Likewise, letters MAB and MRB of FIG. 8 are the MABH, MABL, MRBH and MRBL of FIG. 7.
[8] Pipe Line Sequence in Register Conflicting State
The pipe line sequence in the aforementioned register conflicting state will be described with reference to FIG. 9. First of all, the meanings of signals shown in the same Figure will be described in the following. The waveforms of the aforementioned non-overlap two-phase clock signals Ο1 and Ο2 acting as operation reference clock signals are shown at the top of FIG. 9. One cycle is defined as a period starting from the rise of the clock signal Ο1 and ending the next rise of the signal Ο1. Subsequently, the states of an address bus and a data bus are shown. Next letters IRLatch designate a latch signal of an instruction buffer (IR(32 bits) or IRH and IRL). The IRLatch presents an input latch signal waveform of the IR1 register. The IR1 (16 bits) latches the instruction which is present at an instruction decode stage. The aforementioned hardware sequence control instruction register HIR is a register for latching a partially decoded micro code, a sequence information or a pipe line control information. Letters Reg. Content Flag appearing in FIG. 9 designate a flag indicating it necessary to check the conflict between an LOAD instruction and an instruction using the execution unit EXEC. This conflict is checked in a 4th cycle to set a Content Flag (or C flag). At the same time, there is set a LOAD Flag (or L flag) indicating it necessary to load an operand. Likewise, there is set in the 4th cycle a Bus Cycle Flag (or B flag) indicating a bus operation necessary. This flag indicates whether or not the bus cycle is being executed. An instruction fetch inhibit flag (i.e., IF Inhibit Flag: I Flag) is one indicating that an instruction fetch is interrupted and replaced by a data access. A skip signal (i.e., Skip Sig.) is a flag meaning that a processing to be executed in the execution unit EXEC in that cycle is canceled. The Execution indicates a processing to be executed in the execution unit EXEC. The Reg. Write is a signal to be written in a register. In response to the Reg. Write in the ordinary operation, the destination register, as instructed, latches through the C-Bus. At the time of executing the LOAD instruction and the MULT instruction, the destination register, as instructed, latches through the D-Bus. In this meaning, the signal Reg. Write is shown as divided those for the C-Bus and the D-Bus in the timing chart so that the writing operation is executed in preference of the C-Bus if the two signals Reg. Write for the C-Bus and D-Bus conflict in the same register. In short, only the write from the C-Bus is executed. The signal written in the 5th cycle, as indicated dotted lines, indicates the write in the register which is inhibited by the Skip Sig. The MAB means a memory address bus for outputting an address when a data access is executed. The MRB Latch meaning a memory read buffer is a signal for latching data. The PC indicates the value of a program counter.
FIG. 9 is a timing chart exemplifying the sequences between LOAD instructions (LOAD @R1, R2) and ADD instructions (ADD R2, R3). The register R2 for the LOAD instruction to latch the data and the register R2 for the ADD instruction to use are so common that the value of the register R2 is used for the operations between its value determined if the instruction execution is performed in the ordinary pipe line flow. In this example, what timing the pipe line control is to be executed at is shown over seven cycles when the uses of the registers R2 conflict. The lowermost column indicates the situations of execution of the pipe line. Since the register R2 of the destination of the LOAD instruction and the source register R2 of the ADD instruction conflict, a stall (or delay) occurs at the 5th cycle, as shadowed. For this stall, it becomes necessary at first to detect whether or not the register conflicting state takes place and to recognize how many cycle the execution cycle (EX) is to be delayed for avoiding the register conflict. The former detection is carried by asserting the signal S1 outputted by the aforementioned register content check block RCCB for comparing the register selecting information contained in the preceding instruction outputted by the aforementioned register WBR1 and the register selecting information (e.g., the information contained in the ADD instruction for selecting the register R2 according to this example) contained in the succeeding instruction. The latter recognition can be achieved from the decoded result of the operation code. Since the number of the execution cycle (EX) of the LOAD instruction is one in the shown example, the stall occurs only in the 5th cycle.
FIG. 10 shows another example of the pipe line sequence in the register conflicting state. FIG. 10 is a timing chart exemplifying the sequences among the MULT instructions (MUL R1, R2) as multiplying instructions, the ADD instructions (ADD R4, R3) and the SUB instructions (SUB R3, R2). The register R2 for the MUL instruction to latch the data and the register R2 to be used by the SUB instructions are common. Unless the register conflicting state is reflected upon the pipe line sequences, it occurs that the register R2 is used for another operation before its value is determined if the instruction is executed. In the present example, what timing the control of the pipe line is executed at in case of such conflict of register uses is shown over seven cycles. The format of expression of the present Figure is similar to that of FIG. 9 and illustrates the executions of multiplications in four cycles, although not detailed. The MULT instructions are executed in four stages EX, ML, ML and ML. The multiplier can execute the multiplications for latching the result of 16b*16b in 32b in the four cycles. These calculations can be executed by determining the partial product of 16b*4b and their cumulative sum for each cycle. In case of this example, the SUB instruction is fetched in the register R1 with a delay of 2 cycles from the MULT instruction, and the execution cycle (EX) of the SUB instruction is delayed by two cycles because the MULT instruction are multiplied in the four cycles EX, ML, ML and ML.
[9] Pipe Line Sequence at Memory Access Conflicting Time
FIG. 11 shows a pipe control sequence exemplifying the case, in which a data fetch from a memory and an instruction fetch conflict. In this case, the data fetch is preferred so that the instruction execution schedule containing a conflicting instruction fetch is shifted in its entirety. For this control, the instruction fetch wait flag (IF Wait Flag) is set to delay the start of the instruction fetch cycle while the load flag (LOAD Flag) and the bus cycle flag (Bus Cycle Flag) are conflicting.
[10] Sequence of Instruction Execution of Plural Cycles
FIG. 12 is a timing chart showing one example when a plurality of cycle instructions are executed. Here will be explained by way of example an instruction βAND.B #imm, @R1β or a kind of AND instructions (i.e., logical product). This is an instruction for calculating the logical product between the 8 bit data of a memory selected relative to the register R1 and the 8 bit immediate data. This AND.B instruction is a plurality cycle instructions to be executed in response to the macro instruction 1, the micro instruction 1 and the micro instruction 2. The aforementioned macro instruction 1 is an instruction for fetching a byte operand from the area of a memory, which is selected according to the content of the register R1. The aforementioned micro instruction 1 is an instruction for taking an AND of the aforementioned byte operand and the immediate data. The aforementioned micro instruction 2 is an instruction for writing the byte operand in the area of a memory, which is selected according to the content of the register R1.
The execution content of the aforementioned AND.B instruction is described in the C language:
| ANDM(int i)/*AND.B#imm:8, @R1*/ | |
| { | |
| ββlong temp; | |
| ββtenp=(long)Read_Byte(R[1]); | |
| ββtemp&=(long)i; | |
| ββWrite_Byte(R[1], temp); | |
| ββPC+=2; | |
| }. | |
[11] Instruction Assignment of CPU
The instructions to be assigned to the central processing unit CPU are: data transfer instructions shown in FIGS. 13 and 14; logical operation instructions shown in FIG. 15; arithmetic operation instructions shown in FIGS. 16 and 17; shift instructions shown in FIG. 18; branch instructions shown in FIG. 19; and system control instructions shown in FIGS. 20 and 21. FIG. 22 explains the description formats of FIGS. 13 to 21. According to these formats, the items of the instructions in FIGS. 13 to 21 are mnemonically indicated. The addressing modes in this mnemonic indications are tabulated in FIG. 23. As apparent from the various instruction codes, all of the integer calculations, branching methods and control instructions of the general purpose register system can be selected even in the 65,536 combinations which can be expressed in the instruction format of fixed length of 16 bits. The decoding can be realized with less logical expressions by devising the bit assignments to group instructions of similar functions. An instruction array having the operation code starting from β1111β is wholly reserved so that calculations of single or double accuracy can be selected in conformity with the IEEE floating point standards.
[12] Displacement Length of Branch Instruction
FIGS. 24, 25, 26 and 27 plot the relations between the displacement lengths of branch instructions and instructions in various programs extracted as samples and the appearance frequencies of the instructions having those displacement lengths. FIGS. 24 and 25 relate to conditional branch instructions (i.e., branch instructions) and unconditional branch instructions (i.e., branch always instructions); FIG. 26 relates to subroutine call instructions; and FIG. 27 relates to jump instructions or jump subroutine instructions. Here, the βbranchβ is to select one of numerous instruction sets which can be selected in the execution of a computer program. The βjumpβ means a departure from the implicit or specific execution order of instructions, which is actually done in the execution of the computer program. The βdisplacementβ is used to select a jumped address. For the more bit number of the displacement length, therefore, the farther address can be jumped to.
The frequency distributions of the displacement in response to the branch instructions, as shown in FIGS. 24 to 26, are the data which were obtained by analyzing the various programs of Microcomputer H8/500 of Hitachi, Ltd. These Figures illustrate the distributions of the displacement values of the individual kinds of the branch instructions used. The abscissa indicates the log 2 values of the used displacement values. At the righthand of the origin 0, the log 2 {i.e., displacement} is expressed by a positive integer (1, 3, 5, 7, - - - ) in case the displacement value is positive. At the lefthand, the βlog 2 {i.e., -displacement} is expressed by a negative number for a displacement having a negative value. The ordinate indicates the appearance frequency at the unit of %. The data were sampled for nine different programs.
As could be apparent from FIGS. 24 and 25, the branch instructions and the branch always instructions having the higher appearance frequencies are distributed the closer to the center so that the distribution can be substantially covered with a displacement of 8 bits. It could also be found that the distribution of the subroutine call instructions of FIG. 26 can be wholly covered with a displacement field of 12 to 13 bits although it is considerably wide. In case of the jump instructions or jump subroutine instructions shown in FIG. 27, moreover, the value of the abscissa takes such a displacement as is defined to mean the difference between the address, at which the jump instruction is present, and the address of the jump destination. It could be found that the jump destination is also far.
In the microcomputer MCU of the present embodiment, the displacement of the conditional branch instructions is fixed at 8 bits, and the displacement of the subroutine branch instructions and the unconditional branch instructions is fixed at 12 bits so that those instructions are confined in the instruction format of fixed length of 16 bits. In the various branch instructions shown in FIG. 19, for example: the individual instructions BC, BT and BF are made to belong to the conditional branch instructions; the instruction BSR in the same Figure is made to belong to the subroutine branch instructions; and the instruction BRA is made to belong to the unconditional branch instructions. The detailed contents of the individual instructions should be referred to the description items of instructions, as follows.
In the modular programming method for preparing a program as a set of relatively small subroutines (or functions), the conditional branch instructions will jump within the functions. Since most functions have a size as large as several hundreds bytes, the distribution can be substantially covered with the displacement of 8 bits. On the other hand, the subroutine branch has a tendency to jump to the outside of a function itself, i.e., to a far place so that it requires a displacement of a larger bit number than that of the condition branch instruction. The unconditional branch may be used for calling another function at the last of functions so as to accelerate the program. Since it seems advantageous that the unconditional branch be handled similarly to the subroutine branch condition, the bit number of the displacement is equalized to that of the subroutine branch. Thus, the fixed assignment of the proper displacement length according to the kind of the branch instruction contributes to realization of the instruction format of fixed length of 18 bits without any substantial trouble.
[13] Processing of Immediate Data
In case the instruction format of 16 bit fixed length is adopted, it is not practical to limit all the immediate values to 16 bits or less in view of the fact that the data word length is 32 bits. In the present embodiment, a method of using the value of a register such as the program counter PC and the relative address is adopted so as to select the immediate values of 16 bits or more within one instruction format.
The instructions for the immediate processing are exemplified by the load instructions shown in FIG. 13, such as MOV.W@(disp, PC)Rn or MOV.L@(disp, PC)Rn. These instructions are those for storing the immediate data in the general purpose register Rn. If the data are words/long words, there are referred to the data in a table stored in the address which is specified by adding the displacement to the program counter PC. If the data are words, the displacement is shifted leftward by 1 bit to 9 bits so that the relative distance from the table is changed from β256 to +254 bytes. The program counter PC is the head address which is behind the present instruction by two instructions. This makes it necessary to arrange the word data at the boundary of 2 bytes. If the data are the long words, the displacement is shifted leftward by 2 bits to 10 bits so that the relative distance from the operand is changed from β512 to +508 bytes. The program counter PC is the head address which is behind the present instruction by two instructions, but its less significant 2 bits are corrected to B and 00. This makes it necessary to arrange the long word data at the boundary of 4 bytes.
[14] Implicit Register Selection
The implicit register selection is said to select a general purpose register fixed as an operand notwithstanding that no register selecting field is present in an instruction. The general purpose register, as specified herein, is used for determining a memory address, for example, or for storing the data fetched from a memory. The instruction for this implicit register selection can be exemplified by the MOV @(disp, R1)R0 or MOV R0, @(disp, R1), as shown in FIG. 14. As is apparent from the codes corresponding to the instruction in the same Figure, the instruction contains only the operation code and the displacement dddddddd of 8 bits but not the register selecting field. This displacement is used for determining a memory address together with the value of the implicitly selected register R1. Thanks to this implicit register selection, even in an instruction requiring the value of the register and the displacement, the instruction word length can be restricted within 16 bits without any reduction in the bit number required as the displacement.
[15] Functionally Composite Instruction
The functionally composite instruction can be exemplified by a bit operation instruction such as AND.B #imm, @R1 shown in FIG. 15. This instruction is one composed of three instructions for taking a logical product (i.e., AND operation) between the 8 bit data of a memory selected relative to the register R1 selected implicitly like before and the immediate data of 8 bits to execute the reading of the memory, the AND operation and the write return of the result of the AND operation in said memory. The operation of this kind appears highly frequently in controlling the packaged devices, and the adoption of such functionally composite instruction in the instruction format of 16 bit fixed length contributes to an improvement in the code efficiency.
[16] Truth/False Setting Instruction for Selected Condition
An instruction for setting the truth/false of the arithmetic result for a selected condition can be exemplified by eight kinds of CMP instructions shown in FIG. 16, for example. These are instructions for comparing operands to set the comparison result to the T (True) bit of the aforementioned status register SR. For example, the instructions as designated at COMP/EQ, Rm and RnFF compare whether or not the values of the registers Rm and Rn are equal, and set the T bit to 1, if YES, but clear the same to 0. By assigning the T bit to the status register so that the operation of setting the truth/false for the compared result to the T bit may be executed in response to one instruction of the instruction format of 16 bit fixed length, the next instruction such as the aforementioned conditional branch instruction BT for the operation based on the resultant truth/false may refer directly to the T bit. Thus, the description of the condition necessary for the arithmetic result according to the preceding instruction need not be made in said BT instruction itself so that the area of the displacement necessary for the BT instruction can be accordingly enlarged in the limited instruction format of fixed length. As a result, this structure contributes to realization of the instruction format of 16 bit fixed length.
[17] List of Instructions
The featuring ones of the instructions of having the formats of 16 bit fixed length have been representatively described hereinbefore. In order to clarify the whole aspect of the instruction format of 16 bit fixed length, all the instructions of the microcomputer of the present embodiment will be further described sequentially in the alphabetical order. The descriptions of the individual Instructions include the names of instructions, the formats (wherein βimmβ and βdispβ designate numerical values or symbols) expressed by the input formats of the assembler, the notes for using the instructions, the descriptions of the operations expressed by the C language, the operation examples (indicating the states before and after the instruction executions) exemplified assembler-mnemonically, and the codes. Before the descriptions of the individual instructions, here will be described the register structures as the programmer's models to be noted when a program is to be executed, with reference to FIG. 28. The registers as the programmer's models are exemplified not only by the aforementioned general purpose registers R0 (i.e., R0H, R0L) to R15 (i.e., R15H, R15L) but also by control registers such as a status register SR, a procedure register PR (i.e., PRH, PRL), a global base register GBR (BGRH, GBRL), a program counter PC (PCH, PCL), a vector base register VBR (VBRH, VBRL) or a break register BR (BRH, BRL). In the example of FIG. 28: the register R0 is an accumulator; the register R1 is an index register; and the register R15 is a stack pointer. In the status register SR of FIG. 28: the M/Q bit is referred to in the DIV instruction; the I bit is a mask bit; the sign βββ is a reserved bit; the D bit is referred to in the PASS instruction; the C bit is one reflecting on the carry/borrow/overflow/underflow/shift-out; and the T bit is one expressing the truth (1) and the false (0), as has been described hereinbefore.
The descriptions of the operations, whose contents are indicated in C, assume the use of the following resources, although not especially limitative thereto:
unsigned char Read_Byte (unsigned long Addr);
unsigned short Read_Word (unsigned long Addr);
unsigned long Read_Long (unsigned long Addr);
The data Data are written with their individual sizes in the address Addr.
Individual Register Bodies
#define SR (CR[0])
#define PR (CR[1])
#define GBR (CR[2])
Correspondences Between Proper Names of Registers and Indications of CRn Formats
| struct SR0 { |
| unsigned long dummy | 0:22; | |
| unsigned long | M0:1; | |
| unsigned long | Q0:1; | |
| unsigned long | I0:4; | |
| unsigned long dummy | 2:1; | |
| unsigned long | D0:1; | |
| unsigned long | C0:1; | |
| unsigned long | T0:1; | |
| }; | ||
Definitions of SR Structures
#define M ((*(struct SR0 *)(&CR[0])).M0)
#define Q ((*(struct SR0 *)(&CR[0])).Q0)
#define D ((*(struct SR0 *)(&CR[0])).D0)
#define C ((*(struct SR0 *)(&CR[0])).C0)
#define T ((*(struct SR0 *)(&CR[0])).T0)
Definitions of Bits in SR
#define BRKVEC 0x0000001C
#define PASSVEC 0x00000014
Definitions of Vector Addresses
#define SHAL( ) SHLL( )
Definitions of Identical Instructions of Different Names
Error (char *er);
Error Indicating Function
In addition it is assumed that the PC indicates the address of 4 bytes (i.e., 2 instructions) before of the instruction being executed. This means that (PC=4:) indicates a shift of execution from the instruction of not the 4th address but the 0th address.
In the example of use described in the assembler mnemonic format, the codes indicate the binary codes.
| ββr: | rrrr | |
| ββR: | RRRR | |
| imm: | iiiiiiii | |
| disp: | dddd or | |
| dddddddd or | ||
| dddddddddddd. | ||
ADD (Addition) Instruction
ADD Rm, Rn
ADD #imm, Rn
| ADD(long m, long n) ββ/*ADD Rm, Rn */ | |
| { | |
| ββR[n]+=R[m]; | |
| ββPC+=2; | |
| ADDI(long i, long n) ββ/*ADD #imm, Rn */ | |
| { | |
| ββif ((i&0x80)==0) R[n]+=(0x000000FF & (long)i); | |
| ββββelse R[n]+=(0xFFFFFF00 | β(long)i); | |
| ββPC+=2; | |
| } | |
| ADD | R0,R1; |
| before βexecution βR0=Hβ²7FFFFFFF,R1=Hβ²00000001 | |
| after βexecution βR1=Hβ²80000000 | |
| ADD | #Hβ²01,R2; |
| before βexecution βR2=Hβ²00000000 | |
| after βexecution βR2=Hβ²00000001 |
| ADD | #Hβ²FE,R3; | |
| before βexecution βR3=Hβ²00000001 | ||
| after βexecution βR3=Hβ²FFFFFFFF |
| Code: ββββMSB ββββββLSB |
| ADD | r.R | 0010RRRRrrrr0000 | |
| ADD | #imm,R | 0101RRRRiiiiiiii |
| ADDC | (Addition with Carry) Instruction |
| Format: |
| ADDC | Rm, Rn | |
| ADDC(long m, long n)ββ/*ADDC Rm, Rn */ | |
| { | |
| βββunsigned long temp; | |
| βββtemp=R[n}; | |
| βββR[n]+=(R[m]+C); | |
| βββif (temp>R[n]) C=1; else C=0; | |
| βββPC+=2; | |
| { | |
| βββADDC | βR0,R1; | ||
| before execution | C=1,R0=Hβ²00000001, | ||
| R1=Hβ²00000001 | |||
| afterβexecution | C=0,R1=Hβ²00000003 | ||
| βββADDC | βR2,R3; | ||
| before execution | C=0,R2=Hβ²00000002, | ||
| 3R=Hβ²FFFFFFFF | |||
| afterβexecution | C=1,R3=Hβ²00000001 | ||
| βββADDC | βR4,R5; | ||
| before execution | C=1,R4=Hβ²00000001, | ||
| R5=Hβ²FFFFFFFF | |||
| afterβexecution | C=1,R5=Hβ²00000001 |
| Codes:βββββMSBββββββββLSB | |
| βββADDCβr.Rβββ0010RRRRrrrr0010 | |
| βββADDCβ(Addition with Saturation) Instruction | |
| Format: | |
| βββADDSβRm, Rn | |
| ADDS(long m, long n)β/*ADDS Rm, Rn */ | |
| { | |
| βββlong dest,src,ans; | |
| βββifβ((long)R[n]>=0)ββdest=0; else dest=1; | |
| βββifβ((long)R[m]>=0)βsrc=0; else src=1; | |
| βββsrc+=dest; | |
| βββR[n]+=R[m]; | |
| βββifβ((long)R[n]>=0) ans=0; else ans=1; | |
| βββans+=dest; | |
| βββifβ(ans==1) { | |
| ββββββifβ(src==0)β{R[n]=0x7FFFFFFF; C=1;}; | |
| ββββββelse C=0; | |
| ββββββifβ(src==2)β{R[n]=0x80000000; C=1;}; | |
| ββββββelse C=0; | |
| βββ} | |
| βββelse C=0; | |
| βββPC+=2; | |
| } | |
| βββADDS | βR0,R1; | ||
| before execution | R0=Hβ²00000001,R1=Hβ²7FFFFFFE, | ||
| C=0 | |||
| afterβexecution | R1=Hβ²7FFFFFFF,C=0 | ||
| βββADDS | βR0,R1; | ||
| before execution | R0=Hβ²00000002,R1=Hβ²7FFFFFFE, | ||
| C=0 | |||
| afterβexecution | R1=Hβ²7FFFFFFF,C=1 |
| Code:ββββββMSBβββββββββLSB |
| βββADDS | βr.Rβββ0010RRRRrrrr0011 |
| βββADDVβ(Addition with Overflow) Instruction | |
| Format: |
| βββADDV | βRm, Rn | |
| ADDV(long m, long n)β/*ADDV Rm, Rn */ | |
| { | |
| ββββlong dest,src,ans; | |
| ββββifβ((long)R[n]>=0) dest=0; else dest=1; | |
| ββββifβ((long)R[m]>=0) src=0; else src=1; | |
| ββββsrc+=dest; | |
| ββββR[n]+=R[m]; | |
| ββββifβ((long)R[n]>=0) ans=0; else ans=1; | |
| ββββans+=dest; | |
| ββββifβ(src==0β|β|βsrc==2) {ifβ(ans==1) C=1; | |
| βββββββββββββββelse C=0;} | |
| ββββββelse C=0; | |
| ββββPC+=2; | |
| } | |
| βββADDV | βR0,R1; | ||
| before execution | R0=Hβ²00000001,R1=Hβ²7FFFFFFE, | ||
| C=0 | |||
| afterβexecution | R1=Hβ²7FFFFFFF,C=0 | ||
| βββADDV | βR0,R1; | ||
| before execution | R0=Hβ²00000002,R1=Hβ²7FFFFFFE, | ||
| C=0 | |||
| afterβexecution | R1=Hβ²80000000,C=1 |
| Code:ββββββMSBβββββββLSB |
| βββADDV | βr.R 0010RRRRrrrr0001 |
| βββANDβ(Logical Product)βInstruction | |
| Format: |
| βββAND | βRm, Rn | |
| βββAND | β#imm, R0 | |
| ββAND.B | β#imm, @R1 | |
| AND(long m, long n)β/*AND Rm,βRn */ | |
| { | |
| βββR[n]&=R[m]; | |
| βββPC+=2; | |
| } | |
| ANDI(long i)β/*AND #imm,βR0 */ | |
| { | |
| βββR[0]&=(0x000000FFβ&β(long)i); | |
| βββPC+=2; | |
| } | |
| ANDM(long i)ββ/*AND.B #imm,@R1 */ | |
| { | |
| ββββlong temp; | |
| ββββtemp=(long)Read_Byte(R[1]); | |
| ββββtemp&=(0xFFFFFF00β|β(long)i); | |
| ββββWrite_Byte(R[1],temp); | |
| ββββPC+=2; | |
| } | |
| βββAND | R0,R1; | |
| before execution | R0=Hβ²AAAAAAAA,R1=Hβ²55555555 | |
| afterβexecution | R1=Hβ²00000000 | |
| βββAND | #Hβ²0F,R0; | |
| before execution | R0=Hβ²FFFFFFFF | |
| afterβexecution | R0=Hβ²0000000F | |
| ββAND.B | #Hβ²80,@R1; | |
| before execution | @R1=Hβ²A5 | |
| afterβexecution | @R1=Hβ²80 |
| Code:βββββββMSBβββββββββLSB |
| βββAND | r.Rββββ0001RRRRrrrr1001 |
| βββAND | #imm,R0ββ10001001iiiiiiii |
| ββAND.B | #imm,@R1β10000001iiiiiiii |
| βββBC/BF/BTβ(Conditional Branch)βInstruction |
| Format: |
| βββBC | disp |
| βββBF | disp |
| βββBT | disp |
| BC(long d)β/*BC disp */ | |
| { | |
| βββlong disp; | |
| βββifβ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| βββββelse disp=(0xFFFFFF00β|β(long)d); | |
| βββifβ(C==1) PC=PC+(disp<<1)+4; | |
| βββββelse PC+=2; | |
| } | |
| BF(long d)β/*BF disp */ | |
| { | |
| βββlong disp; | |
| βββifβ((d&0x80)==0) disp=(0x000000FFβ&β(long)d); | |
| βββββelse disp=(0xFFFFFF00β|β(long)d); | |
| βββifβ(T==0) PC=PC+(disp<<1)+4; | |
| βββββelse PC+=2; | |
| } | |
| BT(long d)β/*BT disp */ | |
| { | |
| βββlong disp; | |
| βββifβ((d&0x80)==0) disp=(0x000000FFβ&β(long)d); | |
| βββββelse disp=(0xFFFFFF00β|β(long)d); | |
| βββifβ(T==1) PC=PC+(disp<<1)+4; | |
| βββββelse PC+=2; | |
| } | |
| βββCLRT; | always T = 0 | |
| βββBTββTRGET_T; | no branch because T = 0 | |
| βββBFββTRGET_F; | branch to TRGET_F because T = 0 | |
| βββNOP; | ||
| βββNOP; | position of PC used in BF instruction | |
| for calculation of branch destination | ||
| address | ||
| βββTRGET_F; | branch destination of BF instruction |
| Code:ββββMSBββββββββββLSB | |
| βββBCββdispββ11001100dddddddd | |
| βββBFββdispββ11001010dddddddd | |
| βββBTββdispββ11001000dddddddd | |
| βββBRAβ(Unconditional Branch)βInstruction | |
| Format: | |
| βββBRAββdisp | |
| BRA(long d)ββ/*BRA disp */ | |
| { | |
| βββunsigned long temp; | |
| βββlong disp; | |
| βββifβ((d&0x800)==0 disp=(0x00000FFF & d); | |
| βββββelse disp=(0xFFFFF000β|βd); | |
| βββtemp=PC; | |
| βββPC=PC+(disp<<1)+4; | |
| βββDelay_Slot(temp+2); | |
| } | |
| βββBRA | TRGET; | branch to TRGET | |
| βββADD | R0,R1; | to be executed before branch | |
| βββNOP; | position of PC used for calculation | ||
| of branch destination | |||
| address in response to BRA instruction |
| βββTRGET; | branch instruction of BRA instruction |
| Code:ββββββMSBββββββββLSB |
| βββBRA | dispββ1010dddddddddddd |
| βββBRKβ(Software Break)βInstruction | |
| Format: | |
| βββBRK | |
| BRK( )β/*BRK*/ | |
| { | |
| βββBR=PCβ4; | |
| βββPC=Read_Long(BRKVEC)+4; | |
| } | |
| βββCMP/EQ R0,R1; | ||
| βββBTββ_TRUE; | βbreak for R0β R1 | |
| βββBRK; | βreturn destination from break routine | |
| ββββββ- - - - | ||
| ββBREAK: | βentrance to break routine | |
| βββMOVβR0,R0; | ||
| βββRTB; | βreturn to above BRK instruction |
| Code:βββββMSBβββββββLSB | |
| βββBRKβββββ0000000000000000 | |
| βββBSRβ(Procedure Call)βInstruction | |
| Format: | |
| βββBSRββdisp | |
| BSR(long d)ββ/*BSR disp */ | |
| { | |
| βββlong disp; | |
| βββif ((d&0x800)==0) disp=(0x00000FFF & d); | |
| βββββelse disp=(0xFFFFF000β|βd); | |
| βββPR=PC; | |
| βββPC=PC+(disp<<1)+4; | |
| βββDelay_Slot(PR+2); | |
| } | |
| ββBSR βTRGET; | branch to TRGET | |
| ββMOV βR3,R4; | to be executed before branch | |
| ββADD ββR0,R1; | position of PC to be used for calculation | |
| of branch address in response | ||
| to BSR instruction | ||
| βTRGET; | entrance of procedure | |
| ββMOV βR2,R3; | ||
| ββRTS; | return to above ADD instruction | |
| ββMOV β#1,R0; | to be executed before branch |
| Code: ββββββMSB ββββββββLSB | |
| ββBSR βdisp ββ1110dddddddddddd | |
| ββCLRC (C Bit Clear) Instruction | |
| Format: | |
| ββCLRC | |
| CLRC( ) ββ/*CLRC*/ | |
| { | |
| ββC=0; | |
| ββPC+=2; | |
| } | |
| ββCLRC; | |
| ββββbefore βexecution C=1 | |
| ββββafter βexecution C=0 | |
| Code: | |
| ββββββββββMSB ββββββββββLSB | |
| ββCLRC ββββ0000000000101001 | |
| ββCLRT(T Bit Clear) Instruction | |
| Format: | |
| ββCLRT | |
| CLRT( ) ββ/*CLRT*/ | |
| { | |
| ββT=0; | |
| ββPC+=2; | |
| } | |
| ββCLRT; | |
| ββββbefore βexecution T=1 | |
| ββββafter βexecution T=0 | |
| Code: | |
| ββββββMSB ββββββββββLSB | |
| ββCLRT ββββββ0000000000101000 | |
| ββCMP/cond (Operand Compare) Instruction | |
| Format: | |
| ββCMP/cond βRm,Rn | |
| Mnemonic | Description | |
| CMP/EQ Rm,Rn | T = 1 for Rn = Rm | |
| CMP/GE Rm,Rn | T = 1 for coded values Rn β§ Rm | |
| CMP/GT Rm,Rn | T = 1 for coded values Rn > Rm | |
| CMP/HI Rm,Rn | T = 1 for uncoded values Rn > Rm | |
| CMP/HS Rm,Rn | T = 1 for uncoded values Rn β§ Rm | |
| CMP/PL Rn | T = 1 for Rn > 0 | |
| CMP/PZ Rn | T = 1 for Rn β§ 0 | |
| CMP/STR Rm,Rn | T = 1 if any byte is equal | |
| CMPEQ(long m, long n) ββ/*CMP_EQ Rm,Rn */ | |
| { | |
| ββif (R[n]==R[m]) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| CMPGE(long m, long n) ββ/*CMP_GE Rm,Rn */ | |
| { | |
| ββif ((long)R[n]>=(long)R[m]) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| CMPGT(long m, long n) ββ/*CMP_GT Rm,Rn */ | |
| { | |
| ββif ((long)R[n]>(long)R[m]) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| CMPHI(long m, long n) ββ/*CMP_HI Rm,Rn */ | |
| { | |
| ββif ((unsigned long)R[n]> | |
| βββ(unsigned long)R[m]) T=1; | |
| ββelse T=0; | |
| ββPC+=2; | |
| } | |
| CMPHS(long m, long n) ββ/* CMP_HS Rm,Rn */ | |
| { | |
| ββif((unsigned long) R[n]>= | |
| βββ(unsigned long) R[m])T=1; | |
| ββelse T=0; | |
| ββPC+=2; | |
| } | |
| CMPPL(long n) ββ/* CMP_PL Rn */ | |
| { | |
| ββif ((long)R[n]>0) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| CMPPZ(long n) ββ/* CMP_PZ Rn */ | |
| { | |
| ββif ((long)R[n]>=0) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| CMPSTR(long m, long n) ββ/* CMP_STR Rm,Rn */ | |
| { | |
| ββunsigned long temp; | |
| ββlong HH,HL,LH,LL; | |
| ββtemp=R[n]{circumflex over (β)}R[m]; | |
| ββHH=(temp&0xFF000000)>>12; | |
| ββHL=(temp&0x00FF0000)>>8; | |
| ββLH=(temp&0x0000FF00)>>4; | |
| ββLL=temp&0x000000FF; | |
| ββHH=HH&&HL&&LH&&LL; | |
| ββif (HH==0) T=1; else T=0; | |
| ββPC+=2; | |
| } | |
| ββCMP/GE ββR0,R1; | R0=Hβ²7FFFFFFF, R1=Hβ²80000000 | |
| ββBT ββTRGET_T; | no branch because T=0 | |
| ββCMP/HS ββR0,R1; | R0=Hβ²7FFFFFFF, R1=Hβ²80000000 | |
| ββBT ββTRGET_T; | branch because T=1 | |
| ββCMP/SRT ββR2,R3; | R2=βABCDβ, R3=βXYCZβ | |
| ββBT ββTRGET_T; | branch because T=1 |
| Code: ββββββMSB ββββββββββLSB |
| ββCMP/EQ | r,R ββ0001RRRRrrrr0000 | |
| ββCMP/GE | r,R ββ0001RRRRrrrr0011 | |
| ββCMP/GT | r,R ββ0001RRRRrrrr0111 | |
| ββCMP/HI | r,R ββ0001RRRRrrrr0110 | |
| ββCMP/HS | r,R ββ0001RRRRrrrr0010 | |
| ββCMP/PL | βR ββ0100RRRR00011101 | |
| ββCMP/PZ | βR ββ0100RRRR00011001 | |
| ββCMP/STR | r,R ββ0010RRRRrrrr1100 |
| ββDIVOS/DIVOU/DIV1(Step Division) Instruction | |
| ββFormat: | |
| ββDIV1 ββRm,Rn | |
| ββDIVOS βRm,Rn | |
| ββDIVOU | |
| DIVOU( ) ββββ/*DIVOU*/ | |
| { | |
| ββM=Q=C=0; | |
| ββPC+=2 | |
| } | |
| DIVOS(long m, long n) ββ/*DIVOS Rm,Rn*/ | |
| { | |
| ββif ((R[n] & 0x80000000)==0) Q=0; | |
| ββelse Q=1; | |
| ββif ((R[m] & 0x80000000)==0) M=0; | |
| ββelse M=1; | |
| ββC=!(M==Q); | |
| ββPC+=2 | |
| } | |
| DIV1(long m, long n) ββ/*DIV1 Rm,Rn*/ | |
| { | |
| ββunsigned long tmp0; | |
| ββunsigned char βold_q, tmp1; | |
| ββold_q=0; | |
| ββQ=(unsigned char)((0x80000000 & R[n])!=0); | |
| ββR[n]<<=1; | |
| ββR[n]| =(unsigned long)C; | |
| ββswitch (old_q){ | |
| ββcase 0: | |
| ββββswitch (M){ | |
| ββββcase 0: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]β=R[m]; | |
| ββββββtmp1=(R[n])>tmp0); | |
| ββββββswitch (Q){ | |
| ββββββcase 0: | |
| ββββββββQ=tmp1; | |
| ββββββββbreak; | |
| ββββββcase 1: | |
| ββββββββQ=(unsigned char)(tmp1==0); | |
| ββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| ββββcase 1: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]+=R[m]; | |
| ββββββtmp1=(R[n]<tmp0); | |
| ββββββswitch (Q){ | |
| ββββββcase 0: | |
| ββββββββQ=(unsigned char)(tmp1==0); | |
| ββββββββbreak; | |
| ββββββcase 1: | |
| ββββββββQ=tmp1; | |
| ββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| ββββ} | |
| ββββbreak; | |
| ββββcase 1: | |
| ββββββswitch(M){ | |
| ββββββcase 0: | |
| ββββββββtmp0=R[n]; | |
| ββββββββR[n]+=R[m]; | |
| ββββββββtmp1=(R[n]<tmp0); | |
| ββββββββswitch (Q){ | |
| ββββββββcase 0: | |
| ββββββββββQ=tmp1; | |
| ββββββββββbreak; | |
| ββββββββcase 1: | |
| ββββββββββQ=(unsigned char)(tmp1==0); | |
| ββββββββββbreak; | |
| ββββββββ} | |
| ββββββββbreak; | |
| ββββββcase 1: | |
| ββββββββtmp0=R[n]; | |
| ββββββββR[n]β=R[m]; | |
| ββββββββtmp1=(R[n]>tmp0); | |
| ββββββββswitch (Q){ | |
| ββββββββcase 0: | |
| ββββββββββQ=(unsigned char)(tmp1==0); | |
| ββββββββββbreak; | |
| ββββββββcase 1: | |
| ββββββββββQ=tmp1; | |
| ββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| ββββ} | |
| ββββbreak; | |
| ββ} | |
| ββC=(Q==M); | |
| ββPC+=2; | |
| } | |
| R1(32bits)Γ· R0(16bits)=R1(16bits): no code |
| SL16 βββR0; | more significant 16 bits set to | |
| divisor, less significant 16 bits | ||
| set to 0 | ||
| TEST ββR0,R0; | zero division check | |
| BT βZERO_DIV; | ||
| CMP/HS βR0,R1; | overflow check | |
| BT βOVER_DIV; | ||
| DIVOU βββββ; | initialization of flag | |
| .arepeat βββ16; | ||
| DIV1 ββR0,R1; | repeat 16 times | |
| .aendr ; | ||
| ROTCL βββR1; | ||
| EXTU.W βR1,R1; | R1=quotient | |
| R1: R2(64bits)Γ· R0(32bits)=R2(32bits): no code |
| TEST ββR0,R0; | zero division check | |
| BT βZERO_DIV; | ||
| CMP/HS βR0,R1; | overflow check | |
| BT βOVER_DIV; | ||
| DIVOU βββββ; | initialization of flag | |
| .arepeat βββ32; | ||
| ROTCL ββR2; | repeat 32 times | |
| DIV1 ββR0,R1; | ||
| .aendr ββββ; | ||
| ROTCL βββR2; | R2=quotient | |
| R1(16bits)Γ· R0(16bits)=R1(16bits): with codes |
| SL16 βββR0; | more significant 16 bits set to | |
| divisor, less significant 16 bits | ||
| set to 0 | ||
| EXTS.W βR1,R1; | dividend is code-extended to 32 bits | |
| EOR βββR2,R2; | R2=0 | |
| MOV ββR1,R3; | ||
| ROTCL βββR3; | ||
| SUBC ββR2,R1; | β1 for negative dividend | |
| DIVOS ββR0,R1; | initialization of flag | |
| .arepeat 16; | ||
| DIV1 ββR0,R1; | repeat 16 times | |
| .aendr ββββ; | ||
| EXTS.W R1,R1; | R1=quotient (expressed in complement | |
| of 1) | ||
| ROTCL ββR1; | ||
| ADDC βR2,R1; | MSB of quotient, if 1, is incremented | |
| by +1 and converted into expression in | ||
| complement of 2 | ||
| EXTS.W R1,R1; | R1=quotient (expressed in complement | |
| of 2) | ||
| R2(32bits)Γ· R0(32bits)=R2(32bits): with codes | |
| EOR ββR3,R3; | |
| MOV ββR2,R4; | |
| ROTCL ββR4; |
| SUBC ββR1,R1; | dividend is code-expanded to 64 | |
| bits | ||
| (R1:R2) | ||
| SUBC βR3,R2; | β1 for negative dividend | |
| DIVOS βR0,R1; | initialization of flag | |
| .arepeat βββ32; | ||
| ROTCL ββR2; | repeat 32 times | |
| DIV1 ββR0,R1; | ||
| .aendr ββββ; | ||
| ROTCL ββR2; | R2=quotient (expressed in complement | |
| of 1) | ||
| ADDC βR3,R2; | MSB of quotient, if 1, is incremented | |
| by +1 and converted into | ||
| expression in complement of 2 | ||
| ββββββ; | R2=quotient (expressed in complement | |
| of 2) |
| Code: ββββββMSB ββββββββLSB |
| ββDIV1 | r,R | 0001RRRRrrrr1100 | |
| ββDIVOS | r,R | 0001RRRRrrrr1101 | |
| DIVOU | 0000000000101010 |
| ββEOR (Exclusive OR) Instruction | |
| Format: |
| ββEOR | Rm, βRn | |
| ββEOR | #imm, βR0 | |
| ββEOR.B | #imm, β@R1 | |
| EOR(long m, long n) ββ/* EOR Rm,Rn */ | |
| { | |
| ββR[n]{circumflex over (β)}=R[m]; | |
| ββPC+=2; | |
| } | |
| EORI(long i) ββ/* EOR #imm,R0 */ | |
| { | |
| ββR[0]{circumflex over (β)}=(0x000000FF & (long)i); | |
| ββPC+=2; | |
| } | |
| EORM(long i) ββ/* EOR.B #imm, @R1 */ | |
| { | |
| ββlong temp; | |
| ββtemp(long)Read_Byte(R[1]); | |
| ββtemp{circumflex over (β)}=(0x000000FF & (long)i); | |
| ββWrite_Byte(R[1], temp); | |
| ββPC+=2; | |
| } | |
| EOR ββββR0,R1; | |
| ββbefore βexecution βR0=Hβ²AAAAAAAA,R1=Hβ²55555555 | |
| ββafter βexecution βR1=Hβ²FFFFFFFF | |
| EOR ββ#Hβ²F0,R0; | |
| ββbefore βexecution βR0=Hβ²FFFFFFFF | |
| ββafter βexecution βR0=Hβ²FFFFFF0F | |
| EOR.B #Hβ²A5,@R1; | |
| ββbefore βexecution β@R1=Hβ²A5 | |
| ββafter βexecution β@R1=Hβ²00 | |
| Code: βββββMSB βββββββLSB |
| ββEOR | βββr,R | 0001RRRRrrrr1010 | |
| ββEOR | β#imm,R0 | 10001010iiiiiiii | |
| ββEOR.B | #imm,@R1 | 10000010iiiiiiii |
| ββEXTS (Code Extension) Instruction | |
| Format: | |
| ββEXTS.B ββRm,Rn | |
| ββEXTS.W βRm,Rn | |
| EXTSB(long m, long n) ββ/*EXTS.B Rm,Rn */ | |
| { | |
| ββR[n]=R[m]; | |
| ββif ((R[m]&0x00000080)==0) R[n]&=0x000000FF; | |
| ββββelse R[n]| β=0xFFFFFF00; | |
| ββPC+=2; | |
| } | |
| EXTSW(long m, long n) ββ/*EXTS.W Rm,Rn */ | |
| { | |
| ββR[n]=R[m]; | |
| ββif ((R[m]&0x00008000)==0) R[n]&=0x0000FFFF; | |
| ββββelse R[n]| β=0xFFFF0000; | |
| ββPC+=2; | |
| } | |
| ββEXTS.B βR0,R1; |
| ββββbefore | execution | R0=Hβ²00000080 | |
| ββββafter | execution | R1=Hβ²FFFFFF80 |
| ββEXTS.W βR0,R1; |
| ββββbefore | execution | R0=Hβ²00008000 | |
| ββββafter | execution | R1=Hβ²FFFF8000 |
| Code: ββββMSB βββββββLSB |
| ββEXTS.B | r,R | 0110RRRRrrrr0010 | |
| ββEXTS.W | r,R | 0110RRRRrrrr0011 |
| ββEXTU (Zero Extension) Instruction | |
| Format: |
| ββEXTU.B | Rm,Rn | |
| ββEXTU.W | Rm,Rn | |
| EXTUB(long m, long n) | /*EXTU.B Rm,Rn */ |
| { | |
| ββR[n]=R[m]; | |
| ββR[n]&=0x000000FF; | |
| ββPC+=2; | |
| } |
| EXTUW(long m, long n) | /*EXTU.W Rm,Rn */ |
| { | |
| ββR[n]=R[m]; | |
| ββR[n]&=0x0000FFFF; | |
| ββPC+=2; | |
| } | |
| ββEXTU.B | R0,R1; |
| ββββbefore | execution | R0=Hβ²FFFFFF80 | |
| ββββafter | execution | R1=Hβ²00000080 |
| ββEXTU.W | R0,R1; |
| ββββbefore | execution | R0=Hβ²FFFF8000 | |
| ββββafter | execution | R1=Hβ²00008000 |
| Code: βββββMSB ββββββββLSB |
| ββEXTU.B | r,R | 0110RRRRrrrr0000 | |
| ββEXTU.W | r,R | 0110RRRRrrrr0001 |
| ββJMP (Unconditional Jump) Instruction | |
| Format: | |
| ββJMP β@Rn | |
| JMP(long n) /* JMP @Rn */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=PC; | |
| ββPC=R[n]+4; | |
| ββDelay_Slot(temp+2); | |
| } | |
| .align 4 |
| ββJMP_TABLE: | .data.1 TRGET; | jump table |
| MOV | JMP_TABLE,R0; | address of R0=TRGET | |
| JMP | @R0; | branch to TRGET | |
| MOV | R0,R1; | executed before branch |
| ββββ- - - - - - - - - - - - |
| ββTRGET: | ADD | #1,R1; | branch destination |
| Code: | MSB | LSB |
| ββJMP @R | β0100RRRR00001010 |
| ββJSR (Procedure Call) Instruction |
| Format: |
| ββJSR @Rn |
| JSR(long n) β/* JSR @Rn */ | |
| { | |
| ββPR=PC; | |
| ββPC=R[n]+4; | |
| ββDelay_Slot(PR+2); | |
| } | |
| .align 4 | ||
| JSR_TABLE: | .data.1 TRGET; | jump table |
| MOV | JSR_TABLE,R0; | address of R0=TRGET | |
| JSR | @R0; | branch to TRGET | |
| EOR | R1,R1; | executed before branch | |
| ADD | R0,R1; | return destination | |
| from procedure |
| ββββ- - - - - - - - - - - - |
| ββTRGET: | NOP; | entrance of procedure | |
| MOV | R2, R3; | ||
| RTS; | return to the above | ||
| ADD instruction | |||
| MOV | #70,R1; | executed before branch |
| Code: | MSB | LSB |
| ββJMP @R | β0100RRRR00001011 |
| ββLDC (CR Transfer) Instruction |
| Format: |
| ββLDC | Rm, CRn |
| ββLDC.L | @Rm+, CRn |
| LDC(long m, long n) β/* LDC Rm,CRn */ | |
| { | |
| ββswitch (n) { | |
| ββββcase 0: SR=R[m]; PC+=2; break; | |
| ββββcase 1: PR=R[m]; PC+=2; break; | |
| ββββcase 2: GBR=R[m]; PC+=2; break; | |
| ββββdefault:Error(βIllegal CR number.β); |
| break; |
| ββ} | |
| } | |
| LDCM(long m, long n) β/* LDC.L @Rm,CRn */ | |
| { | |
| ββswitch (n) { |
| ββββcase 0: | SR=Read_Long(R[m]); R[m]+=4; | |
| PC+=2; break; | ||
| ββββcase 1: | PR=Read_Long(R[m]); R[m]+=4; | |
| PC+=2; break; | ||
| ββββcase 2: | GBR=Read_Long(R[m]); R[m]+=4; | |
| PC+=2; break; |
| ββββdefault:Error(βIllegal CR number.β); |
| break; |
| ββ} | |
| } | |
| ββLDC | βR0,SR; |
| before | execution | R0=Hβ²FFFFFFFF,SR=Hβ²00000000 | |
| after | execution | SR=Hβ²000003F7 |
| ββLDC.L @R15+,PR; |
| before | execution | R15=Hβ²10000000 | |
| after | execution | R15=Hβ²10000004,PR=@Hβ²10000000 |
| Code: | MSB | LSB |
| ββLDC | R,cr | 0100RRRRrrrr0010 |
| ββLDC.L | @R+,cr | 0100RRRRrrrr0001 |
| ββLDBR (BR Transfer) Instruction |
| Format: |
| ββLDBR |
| LDBR( ) ββ/* LDBR */ | |
| { | |
| ββBR=R[0]; | |
| ββPC+=2; | |
| } | |
| ββLDBR | ||
| ββbefore | execution: | R0=Hβ²12345678,BR=Hβ²00000000 |
| ββafter | execution: | BR=Hβ²12345678 |
| Code: | MSB | LSB |
| ββLDBR | 0000000000100001 |
| ββLDVR (VBR Transfer) Instruction |
| Format: |
| ββLDVR |
| LDVR( ) ββ/* LDVR */ | |
| { | |
| ββVBR=R[0]; | |
| ββPC+=2; | |
| } | |
| ββLDVR; |
| ββbefore | execution: R0=Hβ²FFFFFFFF,VBR=Hβ²00000000 |
| ββafter | execution: VBR=Hβ²FFFFFFFF |
| Code: | MSB | LSB |
| ββLDVR | 0000000000001011 |
| ββMOV (Immediate Data Transfer) Instruction |
| ββMOV | #imm,Rn |
| ββMOV.W | @(disp,PC),Rn |
| ββMOV.L | @(disp,PC),Rn |
| MOVI(long i, long n) ββ/* MOV #imm,Rn */ | |
| { | |
| ββif ((i&0x80)==0) R[n]=(0x000000FF & (long)i); | |
| ββββelse R[n]=(0xFFFFFF00 | (long)i); | |
| ββPC+=2; | |
| } | |
| MOVWI(long d, long n) ββ/* MOV.W @(disp,PC),Rn */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 β| β(long)d); | |
| ββR[n]=(long) Read_Word(PC+(disp<<1)); | |
| ββif ((R[n]&0x8000)==0) R[n]&=0x0000FFFF; | |
| ββββelse R[n]| =0xFFFF0000; | |
| ββPC+=2 | |
| } | |
| MOVLI(long d, long n) ββ/* MOV.L @(disp,PC),Rn */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββR[n]=Read_Long((PC&0xFFFFFFFC)+(disp<<2)); | |
| ββPC+=2 | |
| } | |
| Address |
| ββ1000 | MOV | #Hβ²80,R1; | R1=Hβ²FFFFFF80 |
| ββ1002 | MOV.W | IMM+4,R2; | R2=Hβ²FFFF9ABC |
| ββ1004 | MOV.L | IMM,R3; | R3=Hβ²12345678 |
| ββ1006 | NOP; | position of PC used for | |
| address calculations in response | |||
| to MOV.W instruction | |||
| ββ1008 | ADD | #1,R0; | position of PC used for address |
| calculations in response | |||
| to MOV.L instruction | |||
| .align 4; | |||
| ββ100C | IMM: | .data.1 | Hβ²12345678 |
| ββ1010 | .data.w | Hβ²9ABC |
| Code: | MSB | LSB |
| ββMOV | #imm,R | 1101RRRRiiiiiiii |
| ββMOV.W | @(disp,PC)R | 1001RRRRdddddddd |
| ββMOV.L | @(disp,PC)R | 1011RRRRdddddddd |
| ββMOV (Stack Data Transfer) Instruction |
| Format: |
| ββMOV.L | @(disp,Rm), Rn |
| ββMOV.L | Rm, @(disp,Rn) |
| MOVL4(long m, long d, long n) | |
| ββ/* MOV.L @(disp,Rm),Rn */ | |
| { | |
| long disp; | |
| if ((d&0x8)==0) disp=(0x0000000F & (long)d); | |
| ββelse disp=(0xFFFFFFF0 | (long)d); | |
| ββR[n]=Read_Long(R[m]+(disp<<2)); | |
| ββPC+=2; | |
| } | |
| MOVS4(long m, long d, long n) | |
| ββ/* MOV.L Rm,@(disp,Rn) */ | |
| { | |
| long disp; | |
| if ((d&0x8)==0) disp=(0x0000000F & (long)d); | |
| ββelse disp=(0xFFFFFFF0 | (long)d); | |
| ββWrite_Long(R[n]+(disp<<2),R[m]); | |
| ββPC+=2; | |
| } | |
| ββMOV.L β@(2,R0),R1; | |
| ββββbefore execution @(R0+8)=Hβ²12345670 | |
| ββββafter βexecution R1=@Hβ²12345670 | |
| ββMOV.L βR0,@(β1,R1); | |
| ββββbefore execution R0=Hβ²FFFF7F80 | |
| ββββafter βexecution @(R1β4)=Hβ²FFFF7F80 | |
| Code: ββββββMSB ββββββββLSB | |
| ββMOV.L β@(disp,r),R ββ0111RRRRrrrrdddd | |
| ββMOV.L βr,@(disp,R) ββ0011RRRRrrrrdddd | |
| ββMOV(I/O Data Transfer) Instruction | |
| Format: | |
| ββMOV β@(disp,GBR),R0 | |
| ββMOV βR0,@(disp,GBR) | |
| MOV.B | @(12,GBR),R0 | MOV.B | @(12,GBR),R0 | |
| AND | #80,R0 β {circle around (2)} {circle around (1)} β | ADD | #20,R1 | |
| ADD | #20,R1 β {circle around (1)} {circle around (2)} β | AND | #80,R0 | |
| MOVBLG(long d) β/* MOV.B @(disp,GBR),R0 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββR[0]=(long) Read_Byte(GBR+disp); | |
| ββif ((R[0]&0x80)==0) R[0]&=0x000000FF; | |
| ββββelse R[0]| =0xFFFFFF00; | |
| ββPC+=2; | |
| } | |
| MOVWLG(long d) β/* MOV.W @(disp,GBR),R0 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long) d); | |
| ββR[0]=(long)Read_Word(GBR+(disp<<1)); | |
| ββif ((R[0]&0x8000)==0) R[0]&=0x0000FFFF; | |
| ββββelse R[0]1=0xFFFF0000; | |
| ββPC+=2; | |
| } | |
| MOVLLG(long d) β/* MOV.L @(disp,GBR),R0 */ | |
| { | |
| ββlong disp; | |
| ββif((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββR[0]=Read_Long(GBR+(disp<<2)); | |
| ββPC+=2; | |
| } | |
| MOVBSG(long d) β/* MOV.B R0,@(disp,GBR) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββWrite_Byte(GBR+disp, R[0]); | |
| ββPC+=2 | |
| } | |
| MOVWSG(long d) β/* MOV.W R0,@(disp,GBR) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββWrite_Word(GBR+(disp<<1),R[0]); | |
| ββPC+=2; | |
| } | |
| MOVLSG(long d) β/* MOV.L R0,@(disp,GBR) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00 | (long)d); | |
| ββWrite_Word(GBR+(disp<<2),R[0]); | |
| ββPC+=2; | |
| } | |
| ββMOV.L β@(2,GBR),R0; | |
| ββββbefore execution @(GBR+8)=Hβ²12345670 | |
| ββββafter βexecution R0=@Hβ²12345670 | |
| ββMOV.B βR0,@(β1,GBR); | |
| ββββbefore execution R0=Hβ²FFFF7F80 | |
| ββββafter βexecution @(GBRβ1)=Hβ²FFFF7F80 | |
| Code: ββββββββMSB ββββββββββLSB | |
| ββMOV β@(disp,GBR),R0 β110011SSdddddddd | |
| ββMOV βR0,@(disp,GBR) β100011SSdddddddd | |
| ββββββββββSize: | |
| ββββ01 = byte; 10 = Word; 11 = Long Word | |
| ββMOV (Transfer) Instruction | |
| Format: | |
| ββMOV βRm, Rn | |
| ββMOV β@Rm, Rn | |
| ββMOV βRm, @Rn | |
| ββMOV β@Rm+, Rn | |
| ββMOV βRm, @βRn | |
| ββMOV β@(disp,R1), R0 | |
| ββMOV βR0, @(disp,R1) | |
| ββMOV β@(Rm,R1), Rn | |
| ββMOV βRm, @(Rn,R1) | |
| MOV.B | @(12,R1),R0 | MOV.B | @(12,R1),R0 | |
| AND | #80,R0 β {circle around (2)} {circle around (1)} β | ADD | #20,R1 | |
| ADD | #20,R1 β {circle around (1)} {circle around (2)} β | AND | #80,R0 | |
| MOV(long m, long n) β/* MOV Rm,Rn */ | |
| { | |
| ββR[n]=R[m]; | |
| ββPC+=2; | |
| } | |
| MOVBL(long m, long n) β/* MOV.B @Rm,Rn */ | |
| { | |
| ββR[n]=(long)Read_Byte(R[m]); | |
| ββif ((R[n]&0x80)==0) R[n]&=0x000000FF; | |
| ββββelse R[n]| =0xFFFFFF00; | |
| ββPC+=2; | |
| } | |
| MOVWL(long m, long n) β/* MOV.W @Rm,Rn */ | |
| { | |
| ββR[n]=(long)Read_Word(R[m]); | |
| ββif ((R[n]&0x8000)==0) R[n]&=0x0000FFFF; | |
| ββββelse R[n]| =0xFFFF0000; | |
| ββPC+=2; | |
| } | |
| MOVLL(long m, long n) β/* MOV.L @Rm,Rn */ | |
| { | |
| ββR[n]=Read_Long(R[m]); | |
| ββPC+=2; | |
| } | |
| MOVBS(long m, long n) β/* MOV.B Rm,@Rn */ | |
| { | |
| ββWrite_Byte(R[n],R[m]); | |
| ββPC+=2; | |
| } | |
| MOVWS(long m, long n) β/* MOV.W Rm,@Rn */ | |
| { | |
| ββWrite_Word(R[n],R[m]); | |
| ββPC+=2; | |
| } | |
| MOVLS(long m, long n) β/* MOV.L Rm,@Rn */ | |
| { | |
| ββWrite_Long(R[n],R[m]); | |
| ββPC+=2; | |
| } | |
| MOVBP(long m, long n) β/* MOV.B @Rm+,Rn */ | |
| { | |
| ββR[n]=(long)Read_Byte(R[m]); | |
| ββif ((R[n]&0x80)==0) R[n]&=0x000000FF; | |
| ββββelse R[n]| =0xFFFFFF00; | |
| ββif (n!=m) R[m]+=1; | |
| ββPC+=2; | |
| } | |
| MOVWP(long m, long n) β/* MOV.W @Rm+,Rn */ | |
| { | |
| ββR[n]=(long)Read_Word(R[m]); | |
| ββif ((R[n]&0x8000)==0) R[n]&=0x0000FFFF; | |
| ββββelse R[n]| =0xFFFF0000; | |
| ββif (n!=m) R[m]+=2; | |
| ββPC+=2; | |
| } | |
| MOVLP(long m, long n) β/* MOV.L @Rm+,Rn */ | |
| { | |
| ββR[n]=(long)Read_Long(R[m]); | |
| ββif (n!=m) R[m]+=4; | |
| ββPC+=2; | |
| } | |
| MOVBM(long m, long n) β/* MOV.B Rm,@βRn */ | |
| { | |
| ββWrite_Byte(R[n]β1,R[m]); | |
| ββR[n]β=1; | |
| ββPC+=2; | |
| } | |
| MOVWM(long m, long n) β/* MOV.W Rm,@βRn */ | |
| { | |
| ββWrite_Word(R[n]β2,R[m]); | |
| ββR[n]β=2; | |
| ββPC+=2; | |
| } | |
| MOVLM(long m, long n) β/* MOV.L Rm,@βRn */ | |
| { | |
| ββWrite_long(R[n]β4,R[m]); | |
| ββR[n]β=4; | |
| ββPC+=2; | |
| } | |
| MOVBL8(long d) β/* MOV.B @(disp,R1),R0 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββR[0]=(long)Read_Byte(R[1]+disp); | |
| ββif ((R[0]&0x80)==0) R[0]&=0x000000FF; | |
| ββββelse R[0]| =0xFFFFFF00; | |
| ββPC+=2; | |
| } | |
| MOVWL8(long d) β/* MOV.W @(disp,R1),R0 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF&(long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββR[0]=(long)Read_Word(R[1]+disp<<1); | |
| ββif ((R[0]&0x8000)==0) R[0]&=0x0000FFFF; | |
| ββββelse R[0]| =0xFFFF0000; | |
| ββPC+=2; | |
| } | |
| MOVLL8(long d) β/* MOV.L @(disp,R1),R0 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββR[0]=Read_Long(R[1]+disp<<2); | |
| ββPC+=2; | |
| } | |
| MOVBS8(long d) β/* MOV.B R0,@(disp,R1) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββWrite_Byte(R[1]+disp,R[0]); | |
| ββPC+=2; | |
| } | |
| MOVWS8(long d) β/* MOV.W R0,@(disp,R1) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββWrite_Word(R[1]+(disp<<1),R[0]); | |
| ββPC+=2; | |
| } | |
| MOVLS8(long d) β/* MOV.L R0,@(disp,R1) */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββWrite_Long(R[1]+(disp<<2),R[0]); | |
| ββPC+=2; | |
| } | |
| MOVBL1(long m, long n) β/* MOV.B @(Rm,R1),Rn */ | |
| { | |
| ββR[n]=(long)Read_Byte(R[m]+R[1]); | |
| ββif ((R[n]&0x80)==0) R[n]&=0x000000FF; | |
| ββββelse R[n]| =0xFFFFFF00; | |
| ββPC+=2; | |
| } | |
| MOVWL1(long m, long n) β/* MOV.W @(Rm,R1),Rn */ | |
| { | |
| ββR[n]=(long)Read_Word(R[m]+R[1]); | |
| ββif ((R[n]&0x8000)==0) R[n]&=0x0000FFFF; | |
| ββββelse R[n]| =0xFFFF0000; | |
| ββPC+=2; | |
| } | |
| MOVLL1(long m, long n) β/* MOV.L @(Rm,R1),Rn */ | |
| { | |
| ββR[n]=Read_Long(R[m]+R[1]); | |
| ββPC+=2; | |
| } | |
| MOVBS1(long m, long n) β/* MOV.B Rm,@(Rn,R1) */ | |
| { | |
| ββWrite_Byte(R[n]+R[1],R[m]); | |
| ββPC+=2; | |
| } | |
| MOVWS1(long m, long n) β/* MOV.W Rm,@(Rn,R1) */ | |
| { | |
| ββWrite_Word(R[n]+R[1],R[m]); | |
| ββPC+=2; | |
| } | |
| MOVLS1(long m, long n) β/* MOV.L Rm,@(Rn,R1) */ | |
| { | |
| ββWrite_Long(R[n]+R[1],R[m]); | |
| ββPC+=2; | |
| } | |
| βMOV | R0,R1; |
| ββββbefore execution | R0=Hβ²FFFFFFFF,R1=Hβ²00000000 |
| ββββafter βexecution | R1=Hβ²FFFFFFFF |
| βMOV.B | @R0,R1; |
| ββββbefore execution | @R0=Hβ²80,R1=Hβ²00000000 |
| ββββafter βexecution | R1=Hβ²FFFFFF80 |
| βMOV.W | R0,@R1; |
| ββββbefore execution | R0=Hβ²FFFF7F80 |
| ββββafter βexecution | @R1=Hβ²7F80 |
| βMOV.L | @R0+,R1; |
| ββββbefore execution | R0=Hβ²12345670 |
| ββββafter βexecution | R0=Hβ²12345674,R1=@Hβ²12345670 |
| βMOV.W | R0,@βR1; |
| ββββbefore execution | R0=Hβ²AAAAAAAA,R1=Hβ²FFFF7F80 |
| ββββafter βexecution | R1=Hβ²FFFF7F7E,@R1=Hβ²AAAA |
| βMOV.W | @(R2,R1),R0; |
| ββββbefore execution | R2=Hβ²00000004,R1=Hβ²10000000 |
| ββββafter βexecution | R0=@Hβ²10000004 |
| βMOV.W | @(Hβ²04,R1),R0; |
| ββββbefore execution | R1=Hβ²10000000 |
| ββββafter βexecution | R0=@Hβ²10000004 |
| Code: | MSB | LSB |
| βMOV | r,R | 0110RRRRrrrr1000 |
| βMOV | @r,R | 0110RRRRrrrr10SS |
| βMOV | r,@R | 0010RRRRrrrr10SS |
| βMOV | @r+,R | 0110RRRRrrrr11SS |
| βMOV | r,@βR | 0010RRRRrrrr11SS |
| βMOV | @(r,R1),R | 0000RRRRrrrr01SS |
| βMOV | r,@(R,R1) | 0000RRRRrrrr11SS |
| βMOV | @(disp,R1),R0 | 110001SSdddddddd |
| βMOV | R0,@(disp,R1) | 100001SSdddddddd |
| Here, SS: size, | 01=Byte | |
| 10=Word | ||
| 11=Long Word |
| βMOVA (Valid Address Data Transfer) Instruction |
| Format: |
| βMOVA | @(disp,PC),R1 |
| MOVA(long d) β/* MOVA @(disp,PC),R1 */ | |
| { | |
| ββlong disp; | |
| ββif ((d&0x80)==0) disp=(0x000000FF & (long)d); | |
| ββββelse disp=(0xFFFFFF00| (long)d); | |
| ββR[1]=(PC&0xFFFFFFFC)+(disp<<2); | |
| ββPC+=2; | |
| } | |
| Address | .align 4 |
| 1000 | STR:.sdata βXYZP12β |
| 1006 | MOVA | STR,R1; |
| address of STR β R1 |
| 1008 | MOV.B | @R1,R0; |
| R0=βXβ β | position after correction of less | |
| significant 2 bits of PC |
| 100A | ADD | R4,R5; |
| intrinsic position of PC at the time of | |
| calculation of address of MOVA instruction |
| - - - - - - - - - |
| 2002 | BRA | TRGET; |
| delay branch instruction |
| 2004 | MOVA | @(β2,PC),R1; |
| address of TRGET β R1 |
| 2006 | NOP; |
| address to be intrinsically latched in R1 |
| Code: | MSB | LSB |
| MOVA | β@(disp,PC),R1 | 11001011dddddddd |
| MULS (Coded Multiplication) Instruction |
| Format: |
| MULS | Rm,Rn | |
The content of the general purpose register Rn and the Rm are multiplied in 16 bits, and the result of 32 bits is latched in the Rn. The calculation is accomplished in the coded arithmetic operation.
| MULS(long m, long n) β/* MULS Rm,Rn */ | |
| { | |
| ββR[n]=((long)(short)R[n]*(long)(short)R[m]); | |
| ββPC+=2; | |
| } | |
| ββMULS | R0,R1; |
| before execution βR0=Hβ²FFFFFFFE,R1=Hβ²00005555 | |
| after βexecution βR1=Hβ²FFFF5556 |
| Code: | MSB | LSB |
| ββMULS | r,R β0001RRRRrrrr1111 |
| ββMULU β(Uncoded Multiplication) Instruction |
| Format: | |
| ββMULU | Rm,Rn |
| MULU(long m, long n) β/* MULU Rm,Rn */ | |
| { | |
| R[n]=((unsigned long)(unsigned short)R[n]* | |
| ββ(unsigned long)(unsigned short)R[m]); | |
| ββPC+=2; | |
| } | |
| ββMULU | R0,R1; |
| before execution βR0=Hβ²00000002,R1=Hβ²FFFFAAAA | |
| after βexecution βR1=Hβ²00015554 |
| Code: | MSB | LSB |
| ββMULU | r,R ββ0001RRRRrrrr1110 |
| ββNEG (Code Negation) Instruction |
| Format: | |
| ββNEG | Rm,Rn |
| NEG(long m, long n) β/* NEG Rm,Rn */ | |
| { | |
| ββR[n]=0βR[m]; | |
| ββPC+=2; | |
| } | |
| NEG | R0,R1; |
| before | execution R0=Hβ²00000001 | |
| after | execution R1=Hβ²FFFFFFFF |
| Code: | MSB | LSB |
| NEG | r,R | 0110RRRRrrrr0110 |
| NEGC | (Code Negation with Carry) Instruction |
| Format: |
| NEGC | βRm,Rn | |
| NEGC(long m, long n)ββ/* NEGC Rm,Rn */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=R[n]; | |
| ββR[n]=0βR[m]βC; | |
| ββif (temp<R[n]) C=1; else C=0; | |
| ββPC+=2; | |
| } | |
| NEGC | βR0,R1; | |||
| before | execution | R0=Hβ²00000001,C=0 | ||
| after | execution | R1=Hβ²FFFFFFFF,C=1 | ||
| NEGC | βR2,R3; | |||
| before | execution | R2=Hβ²00000000,C=1 | ||
| after | execution | R3=Hβ²FFFFFFFF,C=1 |
| Code: |
| MSB | LSB |
| NEGC | r.R | 0110RRRRrrrr0111 |
| NOP (No Operation) Instruction |
| Format: |
| NOP | |
| NOP( )ββ/* NOP */ | |
| { | |
| ββPC+=2; | |
| } | |
| NOP; |
| passage of one cycle period |
| Code: | MSB | LSB |
| NOP | 0000000000000010 |
| NOT (Logical Negation) Instruction |
| Format: |
| NOT | βRm,Rn | |
A complement of 1 is taken from the content of the general register Rm, and the result is latched in the Rn.
| NOT(long m, long n) β/* NOT Rm,Rn */ | |
| { | |
| ββR[n]=βR[m]; | |
| ββPC+=2; | |
| } | |
| NOT | R0,R1; | |||
| before | execution | R0=Hβ²AAAAAAAA | ||
| after | execution | R1=Hβ²55555555 |
| Code: | MSB | LSB |
| NOT | r,R | 0110RRRRrrrr1100 |
| OR (Logical Sum) Instruction |
| Format: |
| OR | Rm,Rn | |
| OR | #imm,R0 | |
| OR.B | #imm, @R1 | |
| OR(long m, long n) β/* OR Rm,Rn */ | |
| { | |
| ββR[n]| =R[m]; | |
| ββPC+=2; | |
| } | |
| ORI(long i) β/* OR #imm,R0 */ | |
| { | |
| ββR[0]| =(0x000000FF & (long)i); | |
| ββPC+=2; | |
| } | |
| ORM(long i) β/* OR.B #imm,@R1 */ | |
| { | |
| ββlong temp; | |
| ββtemp=(long)Read_Byte(R[1]); | |
| ββTemp| =(0x000000FF & (long)i); | |
| ββWrite_Byte(R[1],temp); | |
| ββPC+=2; | |
| } | |
| OR | βR0,R1; | |||
| before | execution | R0=Hβ²AAAA5555,R1=Hβ²55550000 | ||
| after | execution | R1=Hβ²FFFF5555 |
| OR | β#Hβ²F0,R0; |
| before | execution | R0=Hβ²00000008 | |
| after | execution | R0=Hβ²000000F8 |
| OR.B | β#Hβ²50,@R1; |
| before | execution | @R1=Hβ²A5 | |
| after | execution | @R1=Hβ²F5 |
| Code: | MSB | LSB |
| OR | r,R | 0001RRRRrrrr1011 | |
| OR | #imm,R0 | 10001011iiiiiiii | |
| OR.B | #imm,@R1 | 10000011iiiiiiii |
| PASS | (Pass Confirmation) Instruction |
| Format: |
| PASS | #imm | |
| PASS( ) β/* PASS #imm */ | |
| { | |
| ββif (D==1) PC=Read_Long(VBR+PASSVEC)+4; | |
| ββββelseβPC+=2; | |
| } | |
| _TASK1 | .equ Hβ²01 |
| - - - - - - - - - - |
| LDC | SR,R0 | |
| OR.B | #Hβ²04,R0 | |
| STC | R0,SR; |
| after execution D=1 |
| - - - - - - - - - - |
| TASK1 | PASS | #_TASK1; |
| branch to _PASS because D=1 |
| SUB | #1,R5; |
| return destination of debug routine |
| - - - - - - - - - - |
| _PASS | MOV.L @R15,R1; |
| entrance of debug routine |
| ADD | #β1,R1; |
| R1=(PC on stack) β 1 |
| MOV.B | @R1,R0; |
| R0=#_TASK1 |
| RTE; |
| return to the SUB instruction |
| NOP; |
| executed prior to RTE |
| Code: | MSB | LSB |
| PASSβ#imm | 11001001iiiiiiii |
| ROTL/ ROTR (Rotate) Instruction |
| Format: |
| ROTL | Rn | |
| ROTR | Rn | |
| ββββROTL(long n) β/* ROTL Rn */ | |
| ββββ{ | |
| ββββββif ((R[n]&80000000)==0) C=0; else C=1; | |
| ββββββR[n]<<=1; | |
| ββββββif (C==1) R[n]| =0x00000001; else | |
| R[n]&=0xFFFFFFFE; | |
| ββββββPC+=2; | |
| ββββ} | |
| ββββROTR(long n)ββ/* ROTR Rn */ | |
| ββββ{ | |
| ββββββif ((R[n]&0x00000001)==0) C=0; else C=1; | |
| ββββββR[n]>>=1; | |
| ββββββif (C==1) R[n]| =0x80000000; else | |
| R[n]&=0x7FFFFFFF; | |
| ββββββPC+=2; | |
| ββββ} | |
| ROTL | βR0; |
| before executionβR0=Hβ²80000000,C=0 |
| afterβexecutionβR0=Hβ²00000001,C=1 |
| ROTR | βR0; |
| before | execution | R0=Hβ²00000001,C=0 | |
| after | execution | R0=Hβ²80000000,C=1 |
| Code: | MSB | LSB |
| ROTL | βR | 0100RRRR00101001 | |
| ROTR | βR | 0100RRRR00101000 |
| ROTCL/ ROTCR (Rotate with Carry Bit) | |
| Instruction |
| Format: |
| ROTCL βRnββββROTCR βRn | |
| ROTCL(long n)ββ/* ROTCL Rn */ | |
| { | |
| ββlong temp; | |
| ββif ((R[n]&0x80000000)==0) temp=0; | |
| ββββelse temp=1; | |
| ββR[n]<<=1; | |
| ββif (C==1) R[n]| =0x00000001; | |
| ββββelse R[n]&=0xFFFFFFFE; | |
| ββif (temp==1) C=1; else C=0; | |
| ββPC+=2; | |
| } | |
| ROTCR(long n)β/* ROTCR Rn */ | |
| { | |
| ββlong temp; | |
| ββif ((R[n]&0x00000001)==0) temp=0; | |
| ββββelse temp=1; | |
| ββR[n]>>=1; | |
| ββif (C==1)βR[n]| =0x80000000; | |
| ββββelse R[n]&=0x7FFFFFFF; | |
| ββif (temp==1) C=1; else C=0; | |
| ββPC+=2; | |
| } | |
| ROTCL | βR0; | |||
| before | execution | R0=Hβ²80000000,C=0 | ||
| after | execution | R0=Hβ²00000000,C=1 | ||
| ROTCR | βR0; | |||
| before | execution | R0=Hβ²00000001,C=1 | ||
| after | execution | R0=Hβ²80000000,C=1 |
| Code: | MSB | LSB |
| ROTCL | βR | β0100RRRR00101011 | |
| ROTCR | βR | β0100RRRR00101010 |
| RTB (Return from Break) Instruction |
| Format: |
| RTB | |
| ββββRTB( ) ββ/* RTB */ | |
| ββββ{ | |
| ββββββPC=BR+4; | |
| ββββ} | |
| βExample of Use: | |
| ββββMOV ββR0,R9; | |
| ββββADD ββ#β1,R1; | |
| ββββββbranch destination of RTB | |
| ββββββ(PC released to BR) | |
| ββββTEST R1,R1; | |
| ββββ- - - - - - - | |
| ββββNOP; | |
| ββββRTB; | |
| ββββββADD never fails to be executed if RTBMSK is | |
| ββββββinputted. βOtherwise, an interruption is accepted, | |
| ββββββand the ADD is not executed. | |
| Code: ββββMSB ββββββββLSB | |
| ββββRTB ββββ0000000000000001 | |
| ββββRTE (Return from Exceptional Processing) | |
| ββββInstruction | |
| Format: | |
| ββββRTE | |
| MOV | #0,R0 | β {circle around (1)} {circle around (2)} β | MOV.L @R15+,R15 |
| MOV.L | @R15+,R15 | β {circle around (2)} {circle around (1)} β | MOV | #0,R0 |
| RTE | RTE | |||
| ADD | #8,R15 | ADD | #8,R15 | |
| RTE( ) ββ/* RTE */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=PC; | |
| ββPC=Read_Long(R[15])+4; | |
| ββR[15]+=4; | |
| ββSR=Read_Long(R[15]); | |
| ββR[15]+=4; | |
| ββDelay_Slot(temp+2); | |
| } | |
| ββRTE; | |
| ββββreturn to basic routine | |
| ββADD ββ#8,R15; | |
| ββββexecuted prior to the branch | |
| Code: ββββMSB ββββββββLSB | |
| ββRTE ββββ0000000000010000 | |
| ββRTS (Return from Procedure) Instruction | |
| Format: | |
| ββRTS | |
| RTS( ) ββ/* RTS */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=PC; | |
| ββPC=PR+4; | |
| ββDelay_Slot(temp+2); | |
| } | |
| ββTABEL: .data.1 TRGET; | |
| ββββββjump table | |
| ββββMOV.L ββTABLE,R3; | |
| ββββββaddress of R3=TRGET | |
| ββββJSR ββ@R3; | |
| ββββββbranch to TRGET | |
| ββββNOP; | |
| ββββββexecuted before the branch | |
| ββββADD ββR0,R1; | |
| ββββββreturn destination from the address | |
| ββββββprocedure latched by the PR | |
| ββββ- - - - - - - | |
| ββββ- - - - - - - | |
| ββTRGET: MOV ββR1,R0; | |
| ββββββentrance of procedure | |
| ββββRTS; | |
| ββββββcontent of PC-> PC | |
| ββββMOV ββ#12,R0; | |
| ββββββexecuted before branch | |
| Code: ββMSB ββββββLSB | |
| ββRTS ββββ0000000000010001 | |
| ββSETC (C Bit Set) Instruction | |
| Format: | |
| ββSETC | |
| SETC( ) β/* SETC */ | |
| { | |
| ββC=1; | |
| ββPC+=2; | |
| } | |
| ββSETC; | |
| ββββbefore execution βC=0 | |
| ββββafterβexecution βC=1 | |
| Code: ββββMSB ββββββLSB | |
| ββSETC ββββ0000000000011001 | |
| ββSETT (T Bit Set) Instruction | |
| Format: | |
| ββSETT | |
| SETT( ) ββ/* SETT */ | |
| { | |
| ββT=1; | |
| ββPC+=2; | |
| } | |
| ββSETT; | |
| ββββbefore execution βT=0 | |
| ββββafterβexecution βT=1 | |
| Code: ββββMSB ββββββLSB | |
| ββSETT ββββββ0000000000011000 | |
| ββSHAL/ SHAR (Arithmetic Shift) Instruction | |
| Format: | |
| ββSHAL ββRn | |
| ββSHAR ββRn | |
| SHAL(long n) ββ/* Same as SHLL */ | |
| SHAR(long n) ββ/* SHAR Rn */ | |
| { | |
| ββlong temp; | |
| ββif ((R[n]&0x00000001)==0) C=0; else; C=1 | |
| ββif ((R[n]&0x80000000)==0) temp=0; else temp=1; | |
| ββR[n]>>=1; | |
| ββif (temp==1) R[n]| =0x80000000; | |
| ββββelse (R[n]&=0x7FFFFFFF); | |
| ββPC+=2; | |
| } | |
| ββSHAL ββR0; | |
| ββββbefore execution βR0=Hβ²80000001,C=0 | |
| ββββafterβexecution βR0=Hβ²00000002,C=1 | |
| ββSHAR βR0; | |
| ββββbefore execution βR0=Hβ²80000001,C=0 | |
| ββββafterβexecution βR0=Hβ²C0000000,C=1 | |
| Code: ββββMSB ββββββLSB | |
| ββSHAL βR ββ0100RRRR00011011 | |
| ββSHAR βR ββ0100RRRR00011000 | |
| ββSHLL/ SHLR (Logical Shift) Instruction | |
| Format: | |
| ββSHLL ββRn | |
| ββSHLR ββRn | |
| SHLL(long n) β/* SHLL Rn β(Same as SHAL) */ | |
| { | |
| ββif ((R[n]&0x80000000)==0) C=0; else C=1; | |
| ββR[n]<<=1; | |
| ββPC+=2; | |
| } | |
| SHLR(long n) β/* SHLR Rn */ | |
| { | |
| ββif ((R[n]&0x00000001)==0) C=0; else C=1; | |
| ββR[n]<<=1; | |
| ββR[n]&=0x7FFFFFFF; | |
| ββPC+=2; | |
| } | |
| ββSHLL | R0; |
| ββββbefore execution βR0=Hβ²80000001,C=0 | |
| ββββafterβexecution βR0=Hβ²00000002,C=1 |
| ββSHLR | R0; |
| ββββbefore execution βR0=Hβ²80000001,C=0 | |
| ββββafterβexecution βR0=Hβ²40000000,C=1 | |
| Code: ββββMSB ββββββLSB |
| ββSHLL | R ββ0100RRRR00011011 | |
| ββSHLR | R ββ0100RRRR00011010 |
| ββSLn/ SRn (Multi-Bit Shift) Instruction | |
| Format: |
| ββSL2 | Rn | |
| ββSR2 | Rn | |
| ββSL8 | Rn | |
| ββSR8 | Rn | |
| ββSL16 | Rn | |
| ββSR16 | Rn | |
| SL2(long n) ββ/* SL2 Rn */ | |
| { | |
| ββR[n]<<=2; | |
| ββPC+=2; | |
| } | |
| SR2(long n) ββ/* SR2 Rn */ | |
| { | |
| ββR[n]>>=2; | |
| ββR[n]&=0x3FFFFFFF; | |
| PC+=2; | |
| } | |
| SL8(long n) ββ/* SL8 Rn */ | |
| { | |
| ββR[n]<<=8; | |
| ββPC+=2; | |
| } | |
| SR8(long n) ββ/* SR8 Rn */ | |
| { | |
| ββR[n]>>=8; | |
| ββR[n]&==0x00FFFFFF; | |
| ββPC+=2; | |
| } | |
| SL16(long n) ββ/* SR16 Rn */ | |
| { | |
| ββR[n]<<=16; | |
| ββPC+=2; | |
| } | |
| SR16(long n) ββ/* SR16 Rn */ | |
| { | |
| ββR[n]>>=16; | |
| ββR[n]&=0x0000FFFF; | |
| ββPC+=2; | |
| } | |
| ββSL2 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²48D159EO | |
| ββSR2 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²048D159E | |
| ββSL8 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²34567800 | |
| ββSR8 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²00123456 | |
| ββSL16 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²56780000 | |
| ββSR16 βR0; | |
| ββββbefore execution βR0=Hβ²12345678 | |
| ββββafterβexecution βR0=Hβ²00001234 | |
| Code: ββββMSB ββββββLSB | |
| ββSL2 βR ββ0100RRRR00001111 | |
| ββSR2 βR ββ0100RRRR00001110 | |
| ββSL8 βR ββ0100RRRR00011111 | |
| ββSR8 βR ββ0100RRRR00011110 | |
| ββSL16 βR ββ0100RRRR00101111 | |
| ββSR16 βR ββ0100RRRR00101110 | |
| ββSLP β(Sleep) βInstruction | |
| Format: | |
| ββSLP | |
| SLP( ) βββ/* SLP */ | |
| { | |
| ββPCβ=2; | |
| ββError(βSleep Mode.β); | |
| } | |
| ββSLP; | |
| ββββtransition to a low power consumption mode | |
| Code: βββββMSB ββββLSB | |
| ββSLP βββββββ0000000000001000 | |
| ββSTC (CR Transfer) Instruction | |
| Format: |
| ββSTC | CRm,Rn | |
| ββSTC.L | CRm,@βRn | |
| STC(long m, long n) ββ/* STC CRm,Rn */ | |
| { | |
| ββswitch (m) { | |
| ββββcase 0: R[n]=SR; PC+=2; break; | |
| ββββcase 1: R[n]=PR; PC+=2; break; | |
| ββββcase 2: R[n]=GBR; PC+=2; break; | |
| ββββdefault:Error(βIllegal CR number.β); break; | |
| ββ} | |
| } | |
| STCM(long m, long n) ββ/* STC.L CRm,@βRn */ | |
| { | |
| ββswitch (m) { | |
| ββββcase 0: R[n]β=4; Write_long(R[n],SR); | |
| ββββββPC+=2; break; | |
| ββββcase 1: R[n]β=4; Write_long(R[n],PR); | |
| ββββββPC+=2; break; | |
| ββββcase 2: R[n]β=4; Write_long(R[n],GBR); | |
| ββββββPC+=2; break; | |
| ββββdefault:Error(βIllegal CR number.β); break; | |
| ββ} | |
| } | |
| STC ββSR,R0; |
| ββbefore execution | R0=Hβ²FFFFFFFF,SR=Hβ²00000000 | |
| ββafter execution | R0=Hβ²00000000 |
| STC.L PR,@βR15; |
| ββbefore execution | R15=Hβ²10000004 | |
| ββafter execution | R15=Hβ²00000000,@R15=PR |
| Code: ββββMSB βββLSB |
| STC | cr,R | 0000RRRRrrrr0011 | |
| STC,L | cr,@βR | 0100RRRRrrrr0000 |
| ββSTBR β(BR βTransfer) βInstruction | |
| Format: | |
| ββSTBR | |
| STBR( ) ββ/* STBR */ | |
| { | |
| ββR[0]=BR; | |
| ββPC+=2; | |
| } | |
| STBR; |
| ββββbefore execution | R0=Hβ²FFFFFFFF,BR=Hβ²12345678 | |
| ββββafter execution | R0=Hβ²12345678 |
| Code: ββββMSB βββLSB | |
| ββSTBR βββ0000000000100000 | |
| ββSTVR (VBR Transfer) βInstruction | |
| Format: | |
| ββSTVR | |
| Description: | |
| ββThe content of the control register VBR is latched | |
| ββin the general purpose register R0. | |
| Note: | |
| ββNo interruption is accepted by the present instruction. | |
| ββOperation: | |
| ββSTVR( ) ββ/* STVR */ | |
| ββ{ | |
| ββββR[0]=VBR; | |
| ββββPC+=2; | |
| ββ} | |
| STVR; |
| ββββbefore execution | R0=Hβ²FFFFFFFF,VBR=Hβ²00000000 | |
| ββββafter execution | R0=Hβ²00000000 |
| Code: ββββMSB βββLSB | |
| ββSTVR βββ0000000000001010 | |
| ββSUB (Subtraction) Instruction | |
| Format: | |
| ββSUB Rm,Rn | |
| SUB(long m,long n) ββ/* SUB Rm,Rn */ | |
| { | |
| ββR[n]β=R[m]; | |
| ββPC+=2; | |
| } | |
| SUB R0,R1; |
| ββββbefore execution | R0=Hβ²00000001,R1=Hβ²800000000 | |
| ββββafter execution | R1=Hβ²7FFFFFFF |
| Code: ββββMSB βββLSB | |
| ββSUB ββr,R βββ0010RRRRrrrr0100 | |
| ββSUBC (Subtraction with Carry) Instruction | |
| Format: | |
| ββSUBC Rm,Rn | |
| SUBC(long m,long n) ββ/* SUBC Rm,Rn */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=R[n]; | |
| ββR[n]β=(R[m]+C); | |
| ββif (temp<R[n]) C=1; else C=0; | |
| ββPC+=2; | |
| } | |
| ββSUBC R0,R1; |
| ββββbefore execution | C=1,R0=Hβ²00000001, | |
| R1=Hβ²000000001 | ||
| ββββafter execution | C=1,R1=Hβ²FFFFFFFF |
| ββSUBC R2,R3; |
| ββββbefore execution | C=0,R2=Hβ²00000002, | |
| R3=Hβ²00000001 | ||
| ββββafter execution | C=1,R3=Hβ²FFFFFFFF |
| Code: ββββMSB βββLSB | |
| ββSUBC r,R 0010RRRRrrrr0110 | |
| ββSUBS (Subtraction with Saturation Function) | |
| ββInstruction | |
| Format: | |
| ββSUBS Rm,Rn | |
| SUBS(long m, long n) ββ/* SUBS Rm,Rn */ | |
| { | |
| ββlong dest,src,ans; | |
| ββif ((long)R[n]>=0) dest=0; else dest=1; | |
| ββif ((long)R[m]>=0) src=0; else src=1; | |
| ββsrc+=dest; | |
| ββR[n]β=R[m]; | |
| ββif ((long)R[n]>=0) ans=0; else ans=1; | |
| ββans+=dest; | |
| ββif ((src==1)&&(ans==1)) { | |
| ββββif (dest==0) { R[n]=0x7FFFFFFF; C=1; } | |
| ββββelse C=0; | |
| ββββif (dest==1) { R[n]=0x80000000; C=1; } | |
| ββββelse C=0; | |
| ββ} | |
| ββββelse C=0; | |
| ββββPC+=2 | |
| ββ} | |
| ββSUBS R0,R1; |
| ββββbefore execution | R0=Hβ²00000001,R1=Hβ²80000001 | |
| ββββafter execution | R1=Hβ²80000000,C=0 |
| ββSUBS βR2,R3; |
| ββββbefore execution | R2=Hβ²00000002,R3=Hβ²80000001 | |
| ββββafter execution | R3=Hβ²80000000,C=1 |
| Code: ββββMSB βββLSB | |
| ββSUBS βr,R ββ0010RRRRrrrr0111 | |
| ββSUBV (Subtraction with Underflow) Instruction | |
| Format: | |
| ββSUBV Rm,Rn | |
| SUBV(long m, long n) ββ/* SUBV Rm,Rn */ | |
| { | |
| ββlong dest,src,ans; | |
| ββif ((long)R[n]>=0) dest=0; else dest=1; | |
| ββif ((long)R[m]>=0) src=0; else src=1; | |
| ββsrc+=dest; | |
| ββR[n]β=R[m]; | |
| ββif ((long)R[n]>=0) ans=0; else ans=1; | |
| ββans+=dest; | |
| ββif (src==1) { if (ans==1) C=1; else C=0; } | |
| ββββelse C=0; | |
| ββPC+=2; | |
| } | |
| ββSUBV R0,R1; |
| ββββbefore execution | R0=Hβ²00000002,R1=Hβ²80000001 | |
| ββββafter execution | R1=Hβ²7FFFFFFF,C=1 |
| ββSUBV βR2,R3; |
| ββββbefore execution | R2=Hβ²FFFFFFFE,R3=Hβ²7FFFFFFE | |
| ββββafter execution | R3=Hβ²80000000,C=1 |
| Code: ββββMSB βββLSB | |
| ββSUBV βr,R ββ0010RRRRrrrr0101 | |
| ββSWAP (Swapping) Instruction | |
| Format: | |
| ββSWAP.B Rm,Rn | |
| ββSWAP.W Rm,Rn | |
| SWAP.B(long m,long n) β/* SWAP.B Rm,Rn */ | |
| { | |
| ββunsigned long temp0,temp1; | |
| ββtemp0=R[m]&0xffff0000; | |
| ββtemp1=(R[m]&0x000000ff)<<8; | |
| ββR[n]=(R[m]&0x0000ff00)>>8; | |
| ββR[n]=R[n]| temp1| temp0; | |
| ββPC+=2; | |
| } | |
| SWAP.W(long m,long n) β/* SWAP.W Rm,Rn */ | |
| { | |
| ββunsigned long temp; | |
| ββtemp=R[m]>>8; | |
| ββR[n]=R[m]<<8; | |
| ββR[n]| =temp; | |
| ββPC+=2; | |
| } | |
| βββSWAP.B βR0,R1; | |
| ββββββbefore execution βR0=Hβ²12345678 | |
| ββββββafter ββexecution βR1=Hβ²12347856 | |
| βββSWAP.W βR0,R1; | |
| βββbefore execution βR0=Hβ²12345678 | |
| βββafter ββexecution βR1=Hβ²56781234 | |
| Code: ββββββMSB βββββββββLSB | |
| βββSWAP.B ββr,R β0110RRRRrrrr0100 | |
| βββSWAP.W βr,R β0110RRRRrrrr0101 | |
| βββTAS β(Read/Modify/Write) βInstruction | |
| Format: | |
| βββTAS.B ββ@Rn | |
| TAS(long n) β/* TAS.B @Rn */ | ||
| { | ||
| βββlong temp; | ||
| βββtemp=(long)Read_Byte(R[n]); | /* Bus Lock enable */ | |
| βββif (temp==0) T=1; else T=0; | ||
| βββtemp| =0x00000080; | ||
| βββWrite_Byte(R[n],temp); | /* Bus Lock disable */ | |
| βββPC+=2; | ||
| } | ||
| βββ_LOOP TAS.B @R7; | |
| ββββββR7=1000 | |
| βββBF ββ_LOOP; | |
| ββββββlooped till 1,000 addresses becomes zero | |
| Code: ββββββMSB ββββββββββLSB | |
| βββTAS.B β@R ββ0100RRRR00001000 | |
| βββTEST (Test) Instruction | |
| Format: | |
| βββTEST ββRm,Rn | |
| βββTEST ββ#imm,R0 | |
| βββTEST.B β#imm,@R1 | |
| TEST(long m, long n) β/* TEST Rm,Rn */ | |
| { | |
| βββif ((R[n]&R[m])==0) T=1; else T=0; | |
| βββPC+=2; | |
| } | |
| TESTI(long i) ββ/* TEST #imm,R0 */ | |
| { | |
| βββlong temp; | |
| βββtemp=R[0]&(0x000000FF & (long)i); | |
| βββif (temp==0) T=1; else T=0; | |
| βββPC+=2; | |
| } | |
| TESTM(long i) ββ/*TEST.B #imm,@R1 */ | |
| { | |
| βββlong temp; | |
| βββtemp=(long)Read_Byte(R[1]); | |
| βββtemp&=(0x000000FF & (long)i); | |
| βββif (temp==0) T=1; else T=0, | |
| βββPC+=2; | |
| } | |
| βββTEST ββR0,R0; | |
| ββββββbefore execution βR0=Hβ²00000000 | |
| ββββββafter ββexecution βT=1 | |
| βββTEST ββ#Hβ²80,R0; | |
| ββββββbefore execution βR0=Hβ²FFFFFF7F | |
| ββββββafter ββexecution βT=1 | |
| βββTEST.B β#Hβ²A5,@R1; | |
| ββββββbefore execution β@R1=Hβ²A5 | |
| ββββββafter ββexecution βT=0 | |
| Code: βββββββMSB βββββββββLSB |
| βββTEST ββr,R | 0001RRRRrrrr1000 | |
| βββTEST ββ#imm,R0 | 10001000iiiiiiii | |
| βββTEST.B β#imm,@R1 | 10000000iiiiiiii |
| βββTRAP (Software Trap) Instruction | |
| Format: | |
| βββTRAP ββ#imm | |
| MOV | #0,R0 | β {circle around (1)} {circle around (2)} β | MOV.L | @R15+,R15 |
| MOV.L | @R15+,R15 | β {circle around (2)} {circle around (1)} β | MOV | #0,R0 |
| TRAP | #15 | TRAP | #15 | |
| TRAP(long i) β/* TRAP #imm */ | |
| { | |
| βββunsigned long temp; | |
| βββlong imm; | |
| βββif ((i&0x80)==0) imm=(0x000000FF & i); | |
| ββββββelse imm=(0xFFFFFF00| i); | |
| βββtemp=PC; | |
| βββR[15]β=4; | |
| βββWrite_Long(R[15],SR); | |
| βββR[15]β=4; | |
| βββWrite_Long(R[15],PC); | |
| βββPC=Read_Long(VBR+(imm<<2))+4; | |
| βββDelay_Slot(temp+2); | |
| } | |
| 0010 ββ.data.1 ββ10000000; | |
| βββ- - - - - - - | |
| βββTRAP ββ#Hβ²10; | |
| ββββββbranch to address of the content of | |
| ββββββHβ²10 address | |
| βββADD ββR1,R7; | |
| ββββββexecuted prior to the branching | |
| ββββββTEST ββ#0,R0; | |
| βββββββββreturn destination of the trap routine | |
| ββββββ- - - - - - - - | |
| βββ10000000 βββMOV βββR0,R0; | |
| βββββββββentrance of the trap routine | |
| βββ10000002 βββRTE; | |
| βββββββββreturn to the TEST instruction | |
| βββ10000004 βββNOP; | |
| βββββββββexecuted prior to the RTE | |
| Code: ββββββMSB ββββββββLSB | |
| βββTRAP β#imm ββ11000011iiiiiiii | |
| βββXTRCT (Extract) Instruction | |
| Format: | |
| βββXTRCT βRm,Rn | |
| XTRCT(long m, long n) β/* XTRCT Rm,Rn */ | |
| { | |
| βββunsigned long temp; | |
| βββtemp=(R[m]<<16)&0xFFFF0000; | |
| βββR[n]=(R[n]>>16)&0x0000FFFF; | |
| βββR[n]| =R[m]; | |
| βββPC+=2; | |
| } | |
| βββXTRCT βR0,R1; | |
| ββββββbefore execution βR0=Hβ²01234567,R1=Hβ²89ABCDEF | |
| ββββββafter ββexecution βR1=Hβ²456789AB | |
| Code: ββββββMSB βββββββββLSB | |
| βββXTRCT βr,R ββ0010RRRRrrrr1000 | |
Next, embodiments of the coded divisions to be executed by using the microcomputer or the like thus far described will be described in the following.
[18] Principle of Pre-Processing of Dividend in Coded Division
FIG. 29 conceptionally shows the principle of a pre-processing of a dividend in a coded division according to the present embodiment. In the coded division expressed by Y (Quotient)=X (Dividend)Γ·3 (Divisor), for example, the value (Xβ1), i.e., the difference obtained by subtracting 1 from the dividend X is used as a dividend if the dividend is negative. Conceptionally, the division is processed in the state, in which the coordinate of the quotient Y is shifted leftward by 1, as shown in the same Figure. Thus, it is needless unlike the prior art to decide whether or not the partial remainder is zero, at each time in the course of the operation for determining the quotient and to provide a hardware for the decision. When an accurate rest is to be determined, the rest determined at last is corrected.
[19] Processing Procedure of Principle Example of Coded Division
FIG. 30 shows the processing procedure of a principle example of the coded division in case the dividend is negative. In the same Figure, the division of β9Γ·β3 is an example. The number ββ9β is expressed by β110111β in a complement of 2, and the number ββ3β is expressed by β101β. Since the dividend is negative, the value β110110β obtained by subtracting 1 from β9 is used as the dividend. The code of the quotient is determined (*1) from the exclusive OR of the code β1β of the dividend and the code β1β of the divisor. The first calculation of the partial remainder is executed by adding or subtracting the dividend β110110β and the value β1101β extended from the code bit of the divisor to the more significant side (i.e., to the left), while the digits of the code bits are equalized. The calculation is the subtraction, if the exclusive OR of the two code bits are 0, and the addition if the exclusive OR is 1 (*2). The subtraction is executed in case of this example. As a result, the first partial remainder β000010β is obtained. The quotient corresponding to the first partial remainder is given (*3) by the inverted logical value of the exclusive OR between the most significant bit of the partial remainder and the code bit of the divisor. Likewise, the quotient bits are sequentially determined. In case an accurate rest is necessary, the value 1 is added to the final remainder in accordance with this example. In case the division is executed while leaving the dividend at the value β110111β as it is, as shown at the lower hide in the same Figure, a correct quotient bit is not determined as its because all the bits of the remainder are set to β0β. Therefore, whether or not all the bits of the partial remainder is β0β is decided each time the partial remainder is calculated. If YES, the logical value of the quotient bit has to be inverted. Incidentally, FIG. 31 shows one example of a coded division in case of negativeΓ·positive, and FIG. 32 shows individual examples of the coded divisions in cases of positiveΓ·positive and positiveΓ·negative.
[20] Whole Processing Procedure of Coded Division
FIG. 33 is a general format showing the entirety of the basic assumptions or processing procedures of a coded division according to the present embodiment, which seem to have been schematically understood from the description thus far made.
<1> A correction is made for a dividend. Specifically, the value 1 is subtracted from the dividend, as shown in FIG. 34(A), if the dividend is negative. This processing could be individually executed by examining the code of the dividend, but the method of extracting the code bit of the dividend to subtract the code bit from the dividend is adopted in the present embodiment. In other words, the operation of subtracting the code bit or the MSB of the dividend is adopted as a pre-processing of the division. Since the MSB of the dividend is 1 if the dividend is negative, the value 1 is subtracted from the dividend. Since the dividend has a MSB of 0 if positive, it is left as it is. Thus, by adopting the processing of subtracting the MSB from the dividend having the MSB, the division program can be prepared without considering whether the dividend is positive or negative. Since, moreover, such decision is not required, the division processing is speeded up, and still the better the division itself can be executed by using a common circuit notwithstanding whether the dividend is positive or negative.
Here, the value to be subtracted from the dividend is understood to have the weight of the LSB of the dividend. The bit position or digit of the dividend, from which the aforementioned value β1β is to be subtracted, is the least significant bit (LSB) of the dividend. The reason why we dare to make such description is to consider the case, in which the dividend has a fixed point, as has been described hereinbefore. Moreover, noting that the code bit is 1 if the dividend is negative and 0 if positive, it is the subtraction of 1 from the negative dividend if the code bit (i.e., the MSB of the dividend) is subtracted from the dividend having the code bit. This could be deemed as a transformation from the negative integer expressed in the complement of 2 into the complement of 1. Thus, the pre-processing for the dividend can be executed without considering whether the dividend is positive or negative. FIG. 35 shows the state of transformation, in which the value 1 is subtracted from a negative integer of 4 bits. Since extra 1 bit is necessary for transforming the minimum of the complement of 2 of a finite bit number into a complement of 1, a 1 bit extension is executed if necessary. Since the partial remainder may be positive, on the other hand, the aforementioned transformation for the negative integer is extended all over the integer to introduce an expression of a new integer. An expression shown in FIG. 36 is adopted within a range of a coded integer of 4 bits, for example. Incidentally, if an arbitrary integer is expressed by ZZ in the expression, in which the value 1 is subtracted from that number, the expression ZZ, which has been subjected to a transformation of subtracting 1 from the integer using a complement of 2, can be deemed as identical to the complement of 1 so that it can be expressed by a number 0 or more, which is smaller by 1 than the intrinsic value. At this time, the code bit of 0 is 1 as in a negative number.
<2> The code of a quotient is determined from a dividend and a divisor, as shown in FIG. 34(B). Specifically, the code of the quotient is predicted from the exclusive OR between the code of the dividend and the code of the divisor.
<3> Quotient bits are made while determining the partial remainders sequentially. The addition and subtraction commands for determining the partial remainder are determined in accordance with FIG. 37(A). Specifically, if the exclusive OR between the code Q of the partial remainder (or dividend) and the code M of the divisor is 0, the subtraction is commanded to subtract the divisor schematically from the partial remainder (or dividend). If the exclusive OR between the code Q of the partial remainder (or dividend) and the code M of the divisor is 1, the addition is commanded to add the divisor schematically to the partial remainder (or dividend). The quotient bit is obtained, as shown in FIG. 37(B), by inverting the result of the exclusive OR between the code bit of the partial remainder after the aforementioned subtraction or addition and the code bit of the divisor.
Here will be described in more detail the method of calculating the quotient bit. The summed contents of the quotient bit calculating method are classified into the following a), b), c) and d), as shown in FIG. 37(B):
a) Case of AΓ·B (Aβ§0, B>0, A and B: complements of 2)
As is well known in the art, the quotient bit is set to 1, if the code bit of the partial remainder is 0, and to 0 if the code bit of the partial remainder is 1.
b) Case of AΓ·B (Aβ§0, B<0, A and B: complements of 2)
Since the quotient is negative, how to make the quotient bit is inverted from the case of (a). In short, the quotient bit is set to 0, if the code bit of the partial remainder is 0, and to 1 if the code bit of the partial remainder is 1. The quotient is a complement of 1. The quotient is finally transformed into a complement of 2, as will be described in a later-described item <4>, if all the quotient bits are determined.
c) Case of AΓ·B (A<0, B<0, A and B: complements of 2)
The weight 1 of the LSB of the dividend is subtracted in advance from the dividend having the LSB. Negative expressions of the dividend and the present embodiment are complements of 1, and the positive expression is smaller than the intrinsic value by the weight 1 of the LSB. The code bit MSB is set to 1, if less than 0, and to 0 if more than 0. Since the quotient is positive, the quotient bit is set to 1, if the code bit MSB of the present embodiment is 1, and to 0 if the code bit MSB of the present embodiment is 0.
d) Case of AΓ·B (A<0, B>0, A and B: complements of 2)
The weight 1 of the LSB of the dividend is subtracted in advance from the dividend having the LSB. Negative expressions of the dividend and the present embodiment are complements of 1, and the positive expression is smaller than the intrinsic value by the weight 1 of the LSB. The code bit MSB is set to 1, if less than 0, and to 0 if more than 0. Since the quotient is negative, how to make the quotient bit is inverted from that of the case (c). The quotient bit is set to 1, if the code bit MSB of the present embodiment is 1, and to 0 if the code bit MSB of the present embodiment is 0. The quotient is finally transformed into a complement of 2, as will be described in a later-described item <4>, if all the quotient bits are determined.
<4> The quotient obtained in the aforementioned item <3> may not always be an accurate value due to its code. This is because the quotient is a complement of 1 when its code determined in the aforementioned item <2> is 1. As a result, the final quotient is determined in accordance with the code of the aforementioned quotient and the quotient bit. Since the quotient is expressed, if negative (wherein the code bit of the quotient is 1), by a complement of 1, as shown in FIG. 38, a correction is executed by adding 1 to the quotient obtained in the item (3) to transform it into a complement of 2. Thus, a correct quotient is determined. Moreover, a remainder correction for the final present embodiment is executed, as shown in FIG. 38.
[21] Specific Examples of Coded Division
FIGS. 39 and 40 show a specific example of the processing which adopts the aforementioned basic procedures of the coded division. The shown example is directed to a coded division of β8Γ·β, which will be described as using a general purpose register of 6 bits so as to facilitate their understanding. FIG. 40 shows the processing to be executed subsequent to the final processing shown in FIG. 39, and the descriptions in the column direction are made identical to those of FIG. 39. In these Figures, characters R0 to R4 designate individual general purpose registers of 6 bits, and letters Q, M and T designate bit flags in the control registers or status registers. Of these: the letter Q designates the bits for latching the codes of the dividends or partial remainders; the letter M designates the bits for latching the codes of the divisors; and the letter T designates the bits for latching the quotient bits or carries. At the lefthand ends of the Figures, there are described the instruction codes and the operands, and the contents of the general purpose registers and the bit flags are shown in the corresponding columns. In the descriptions indicating the contents of the general purpose registers and the bit flags, the underlined contents mean that they are updated by executing the corresponding instructions. Letter X designates the bits having their values unfixed. Under this item, the processing of the coded division will be sequentially described, and examples of the symbols to be used in the description will be enumerated in the following: β: to latch;
The instruction DIV1 R1,R2 between β.arepeat 3β and β.aendrβ is repeated three times.
In each execution cycle of the instruction DIV1:
a subtraction instruction is issued for QΜM=0, and an addition instruction is issued for QΜM=1;
the Q bit is obtained by QβMSB(R2); the dividend of the R2 is shifted leftward by 1 bit by R2<<=1; and the T bit (the code of the quotient at this time) is latched in the LSB of the R2 by LSB(R2)βT;
the operation is executed according to the addition/subtraction commands by (Q:R2)β(Q:R2)Β±(M:R1); and
the quotient bit is latched in the T bit by TβΛ(QΜM).
By executing the instruction DIV1 three times: code of the last partial remainder is introduced into the Q bit; the least significant bit of the quotient is introduced into the T bit; the last partial remainder is introduced into the more significant 3 bits of the R2; and the quotient is introduced into the less significant 3 bits of the same. The code of the quotient obtained in the T bit by the (6) DIVOS R1,R2 is introduced into the less significant 3rd bit.
The R2 is copied to the R4. This is to determined the rest by making use of the R4.
The less significant 3rd bit is code-extended to the more significant 3 bits. This code indicates the code of the quotient.
The (R2:T) is rotated counterclockwise. Specifically, the value of the register R2 is shifted leftward while shifting the T bit in the LSB of the register R2 to latch the MSB of the shifted-out value in the T bit. As a result, the quotient is latched in the less significant 3 bits of the R2, and the code of the quotient is latched in the T bit.
A complement of 1 is transformed into a complement of 2 by R2βR2+T. Specifically, immediately before execution of this instruction, the quotient is latched by the R2, and its code is latched in the T bit. As a result, the complement of 1 is transformed, if latched by the R2, into the complement of 2 by adding the value of the T bit to the value of the R2. Since T=0 when the quotient is negative, the value of the R2 is transformed from the complement of 1 to the complement of 2 by adding the T. Thus, a correct quotient is determined.
The MSB (the code of the rest) of the R4 is latched in the Q bit by QβMSB(R4);
The MSB of the R0 (=0) is latched in the M bit by MβMSB (R0) and
the exclusive OR between the Q bit and the M bit, i.e., the Q bit (the code of the rest) is latched in the T bit by TβQΜM=QΜ0=Q, so that the code of the rest is obtained at the T bit.
The code of the rest before correction, which is latched in the T bit, is latched in the LSB of the R0 by R0βT. This is used to correct the rest.
The result of the exclusive OR between the code of the dividend and the code of the rest before correction is latched in the LSB of the R0 by R0βR3ΜR0.
By the clockwise rotation of (R0:T), the value of the register R0 is shifted rightward while shifting the T bit in the MSB of the register R0 to latch the LSB of the shifted-out value in the T bit. As a result, the result of the exclusive OR between the code of the dividend and the code of the rest before correction is introduced into the T bit.
If the value of the T bit is 0, a branching is made to the label L1. No correction of the rest is necessary because the codes of the dividend and the rest are identical for T=0.
The code of the rest before correction is latched in the Q bit by QβMSB(R4);
The code of the divisor is latched in the M bit by MβMSB(R1); and
The result of the exclusive OR between the Q bit and the M bit is latched in the T bit by TβQΜM.
By the clockwise of (R4:T), a processing is executed for negating the leftward shift of the following DIV1 instruction.
A subtraction command is issued for QΜM=0, and an addition command is issued for QΜM=1;
The Q bit is obtained by QβMSB(R4); the value of the R4 is shifted leftward by 1 bit by R4<<=1; and the T bit (having the result of the exclusive OR between the code of the divisor and the code of the rest before correction at this time) is latched in the LSB of the R4 by LSB(R4)βT;
The 7 bits summed of the M bit and the value of the R1 are added to or subtracted from the 7 bits summed of the Q bit and the value of the R4 by (Q:R4) β(Q:R4)Β±(M:R1) in accordance with the decision result for the aforementioned addition/subtraction, and the result is latched in the Q bit and the R4; and
The value inverted from the result of that exclusive OR is latched in the T bit by TβΛ(QΜM).
The more significant 3 bits (corresponding to the rest) of the R4 are shifted rightward to the less significant 3 bits of the R4.
The R3 latches the code of the dividend. The R4 latches the rest before correction. Since the code of a dividend is subtracted from the dividend by the aforementioned instruction (5) of SUBC R0,R2, the correct rest is obtained at the less significant 3 bits of the R4 by adding the R3 to the R4, that is, by transforming the rest, if a complement of 1, into a complement of 2.
The more significant side of the R4 for latching the corrected rest in the less significant 3 bits is code-extended to determine the final rest with the total 6 bits.
Here in the foregoing descriptions of FIGS. 39 and 40, in the repetition of three times of the DIV1 instruction, both the quotient and the rest are latched in the R2, and the value of this R2 is shifted leftward (R2<<=1) bit by bit at each time of execution of the DIV1 instruction. If, in this regard, it is necessary as in the operation method of the prior art to decide whether or not all the bits of the partial remainder are 0, in case the dividend is negative, the decision has to be executed relatively complicatedly by changing at each time the digit position of the partial remainder to be decided in the R2. In the operation method, therefore, in which whether or not all the bits of the partial remainder are 0 has to be decided as in the prior art in case the dividend is negative, the decision need not be executed by changing the digit position of the partial remainder at each time if the quotient and the rest are latched in different registers. In this modification, on the contrary, the number of transfer instructions to be executed for latching the quotient and the rest in the different registers is increased. Since, in case of the present embodiment, it is needless to decide at each time whether or not all the bits of the partial remainder are 0, the number of instructions to be executed can be reduced by latching both the quotient and the rest in the R2, to facilitate the speed-up of the processing of the coded division.
Incidentally: FIGS. 41 and 42 show a specific example of the processing of a coded division of β8Γ·3; FIGS. 43 and 44 show a specific example of the processing of a coded division of β9Γ·β3; FIGS. 45 and 46 show a specific example of the processing of a coded division of β9Γ·β3; FIGS. 47 and 48 show a specific example of the processing of a coded division of 8Γ·3; and FIGS. 49 and 50 show a specific example of the processing of a coded division of 8Γ·β3. These contents are different from those of FIGS. 39 and 40 in the values of the dividend and the divisor, and their detailed description will be omitted.
[22] Operation Unit for Coded Division
FIG. 51 shows one embodiment of the operation unit capable of executing the aforementioned coded division. This operation unit can be grasped as a different expression which is so modified from the general purpose register block GRB and the operation block OPB shown in FIGS. 6 and 7 as to facilitate the explanation of the coded division. In FIG. 51, the operation unit is represented by five general purpose registers R0 to R4. The register R2 is used to latch a dividend or partial remainder, and the register R1 is used to latch a divisor. Numeral 3 designates a control bit register (i.e., third control bit latch means) for latching the code bit of a quotient or a quotient bit temporarily. This control bit register 3 will be shortly referred to the βT bitβ in the following. Numeral 4 designates a shifter which is made responsive to the command of a shift control signal to shift in the aforementioned T bit to the less significant bit or the most significant bit through a selector circuit 14 and to shift out the most significant bit or the least significant bit to a selector circuit 15. In response to the command of a shift control signal, moreover, this shifter logically shifts either the more significant 16 bits of a 32 bit input to the less significant 16 bits or the less significant 16 bits to the more significant 16 bits, and outputs it. Numeral 5 designates a control bit register (i.e., first control bit latch means) for playing the role of a bit which is added to a higher bit than the most significant bit of the dividend or partial remainder. This control bit register will be shortly referred to as the βQ bitβ. Numeral 6 designates a control bit register (i.e., second control bit latch means) for playing the role of a bit which is added to a higher bit than the most significant bit of the divisor. This control bit register 6 will be shortly referred to as the βM bitβ. Numeral 7 designates an operation control circuit for instructing an addition/subtraction to an arithmetic logical operation circuit 8. This numeral 8 designates an arithmetic logical operation circuit of 32 bits. This arithmetic logical operation circuit 8 can add or subtract the input of a B port to or from the input of an A port in accordance with the command of the operation control circuit 7 and can output the result to a bus linked to the dividend register R2 or the like, and executes an arithmetic logical operation with carry or borrow flags. The arithmetic logical operation circuit 8 is further enabled not only to output the input MSB (Most Significant Bit) of the B port to the M bit but also to execute operations such as an addition, a subtraction with carry, an addition with carry, an exclusive OR (EOR) or a logical AND. Numeral 9 designates an operation circuit for adding or subtracting the value of the control bit register 6 to or from the value of the control bit register 5 together with the carry or borrow of the arithmetic logical operation circuit 8. Numeral 10 designates can calculate the negation between the result of the operation circuit 9 and the exclusive OR of the control bit register to output the result to the selector circuit 12 and can calculate the exclusive OR between the value of the control bit register 5 and the value of the control bit register 6 to output the result to the selector circuit 12. Numeral 11 designates a selector circuit for selecting the input of the control bit register 5 and for selecting either of the output from the shifter through the selector circuit 15 or the output from the operation circuit 9. The numeral 12 designates the selector circuit for selecting any of the carry or borrow of the arithmetic logical operation circuit 8, the operation result of the operation circuit 10 and the output of the selector circuit 15 to output the selected one to the control bit register 3 or the operation circuit 9. Numeral 13 designates a selector circuit for selecting and outputting either of the selector circuit 11 for selecting the input to the control bit register 5 and the selector circuit 13 for selecting the input to the operation circuit 9. Numeral 16 designates a selector circuit for feeding the output of the control register 3 to the arithmetic logical operation circuit 8 or the selector circuit 14. Numeral 17 designates a code extension circuit which has its input connected with the B port of the arithmetic logical operation circuit 8. This code extension circuit 17 can execute a zero extension, too.
FIG. 52 shows one example of the arithmetic logical operation circuit 8, the operation circuit 9, the operation circuit 10 and the operation control circuit 7, which are shown in FIG. 51. The operation control circuit 7 is constructed, as shown at (b) of the same Figure, to include a two-input type exclusive OR circuit and an exclusive OR circuit having two inputs for the output of the former and a control signal. The operation circuit 7 outputs the output of the former exclusive OR circuit as it is, if the control signal is 0, and negates (inverts) and outputs the output of the former exclusive OR circuit if the control signal is 1. The operation control circuit 10 is constructed, as shown at (d) in FIG. 52, to include a two-input type exclusive OR circuit and an exclusive OR circuit having two inputs for the output of the former and a control signal. The operation circuit 10 outputs the output of the former exclusive OR circuit as it is, if the control signal is 0, and negates (inverts) and outputs the output of the former exclusive OR circuit if the control signal is 1. As shown at (a) in FIG. 52, the arithmetic logical operation circuit 8 is equipped with full adders of 32 bits, as its logics for additions and subtractions are representatively shown. Characters B00 to B31 designate B port inputs; characters A00 to A31 designate A port inputs; characters C/B designate carry/borrow; and letters SUB designate the output of the operation control circuit.
[23] Examples of Operation of Operation Unit for Coded Division
FIG. 53 shows one example of an instruction array for a coded division. The description shown in the same Figure is to determine the quotient and the remainder (or rest) by executing a coded division of 32 bitsΓ·16 bits using the circuit shown in FIG. 51. In this division, the dividend of coded 32 bits is latched by the register R2, and the divisor of coded 16 bits is latched in the register R1, as expressed in the following:
R2Γ·R1=R2 - - - R4.
The quotient is latched in the register R2, and the remainder is latched in the register R4.
FIGS. 54 to 74 show the operations of the circuit of FIG. 51 sequentially when the instructions of FIG. 53 are sequentially executed, and FIGS. 75 to 81 likewise show the operations sequentially while stressing the states of the registers. With reference to these Figures, the operations of the operation units will be described sequentially at the unit of instruction for the coded division. Incidentally, in the following description, it is assumed that the 32 bit data are divided by the 16 bit data, as has been described hereinbefore. It is also assumed that the dividend and the divisor are given as complements of 2 having code bits as their most significant bits and that the quotient is also given as a complement of 2. In this description, the detection of the overflow of the quotient is not executed. In case the dividend is the negative minimum of the complement of 2, the processing procedure is different from the intended algorithm. In this case, the overflow never fails to occur so that the quotient is not warranted. The detection of the overflow is executed, if necessary, in advance. As the prerequisite for executing the instruction array of FIG. 53, the 16 bit coded divisor is latched in the register R1, and the dividend is latched in the register R2. The registers are used as the working registers. The quotient is latched in the register R2.
(1) EOR R0,R0
As shown in FIGS. 54 and 75, the working register R0 has its value set to 0 by executing this instruction. This instruction is not necessary if the value of the R0 is already 0. In FIG. 54, the shifter 4 and the code extension circuit 17 are not operated to output the input therethrough. The arithmetic logical operation circuit 8 takes an exclusive OR between the A port input and the B port input bit by bit. Thus, all the bits of the value of the register R0 is set to 0.
(2) SL16 R1
As shown in FIGS. 65 and 75, by executing this instruction, the divisor latched in the divisor register R1 is shifted (leftward) to a bit more significant by 16 bits, and the value 0 is shifted in the less significant 16 bits. The leftward shift of 16 bits is executed by the shifter 4. The arithmetic logical operation circuit 8 outputs the A port input therethrough.
(3) DIVOS R0,R2
In response to this instruction, as shown in FIGS. 56 and 75: the MSB of the register R2 is latched in the Q bit; the MSB of the register R0 is latched in the M bit; and the exclusive OR between the Q bit and the M bit is latched in the T bit. Since the value of the register R0 is set to 0 at this time, the T bit latches the MSB of the dividend latched by the register R2. In this processing, the shifter 4 feeds the input MSB to the selector circuit 15. The code extension circuit 17 outputs the input therethrough. The arithmetic logical operation circuit 8 outputs the MSB of the B port input. The operation of the exclusive OR between the Q bit and the M bit is executed by the operation circuit 10.
(4) MOVT R3
In response to this instruction, as shown in FIGS. 57 and 76, the value of the T bit, i.e., the code of the dividend is latched in the register R3. This is because the code bit of the dividend is stored for determining the rest. In this processing, the arithmetic logical operation circuit 8 adds the value of the T bit to the bit array of 32 bits of each bit 0 and outputs it.
(5) SUBC R0,R2
In response to this instruction, as shown in FIGS. 58 and 76, the register R0 is subtracted with carry from the register R2. The T bit is the carry bit. Since the register R0 is 0, the complement of 2 is transformed into that of 1 by subtracting the T bit (i.e., the code bit of the dividend) from the register R2. In this processing, the shifter 4 and the code extension circuit 17 output their inputs therethrough. The arithmetic logic operation circuit 8 subtracts the B port input and the C/B input from the A port input and outputs the subtraction result and the C/B. In other words, the R0 is subtracted with carry from the dividend register R2 in response to the SUBC instruction. The carry is recognized as identical to the control bit register 3. Since the R0 has the value of 0 the value of the control bit register 3 is subtracted from the dividend register R2. Thus, the processing of subtracting the value of the code bit of a dividend from the dividend is ended. As a result of this processing, the dividend is left as it is, if it is 0 or more, and is expressed by the complement of 1 if it is negative. FIG. 35 shows an example exemplifying how the expression of the dividend is changed by the correction, if the dividend is negative and of 4 bits. If the aforementioned correction is applied to the minimum β1000β of the coded complement of 2 of 4 bits, the expression requires 5 bits such as β10111β. Since, in the present embodiment, the dividend is expressed by a coded complement of 2 of 32 bits, the expression requires 33 bits if the aforementioned correction is applied to the minimum of the coded complement of 2 of 32 bits. Although the expression can be made with the 33 bits having the control bit register 3 as the most significant bit, the present embodiment does not go so far. This is because the case of an overflow may be detected and precluded in advance, although the overflow never fails to occur to make it impossible to obtain a correct quotient if the dividend is the minimum of the coded complement of 2 of 32 bits.
(6) DIVOS R1,R2
In response to this instruction, as shown in FIGS. 59 and 76: the MSB (code bit) of the dividend latched in the register R2 is latched in the Q bit; the MSB (code bit) of the divisor latched in the register R1 is latched in the M bit; and an exclusive OR between the Q bit and the M bit is taken and latched as the code of the quotient in the T bit. This operation is warranted if no overflow is caused by the execution of the instruction SUBC R0,R2 preceding by one. At this time, the shifter 4 outputs the MSB of the 32 bit input. The code extension circuit 17 outputs its input therethrough. The arithmetic logical operation circuit 8 outputs the MSB of the B port input. The exclusive OR operation is executed by the operation circuit 10. In response to this DIVOS instruction, the three control bit registers are initialized. The first operand of the DIVOS instruction is set with the divisor register R1, and the second operand is set with the R2, i.e., the dividend register R2. The DIVOS instruction inputs the first operand to the arithmetic logical operation circuit 8 to latch the MSB of the first operand in the control bit register 6. In parallel with this processing, the DIVOS instruction causes the shifter 4 to shift out the MSB of the second operand and to latch it in the control bit register 5 through the selector circuit 15 and the selector circuit 11. The values of the control bit register 5 and the control bit register 6 are latched even after the end of the DIVOS instruction. The value of the control bit register 5 is inputted through the selector circuit 13 ton the operation circuit 10. The value of the control bit register 6 is inputted to the operation circuit 10. This operation circuit 10 calculates the aforementioned two input exclusive ORs and latch the result in the control bit register 3 through the selector circuit 12. The value of the control bit register 3 is latched even after the end of the DIVOS instruction. The R1 of the first operand and the R2 of the second operand are not rewritten.
This DIVOS instruction causes the code bit of the dividend to be latched in the control bit register 5, the code bit of the divisor to be latched in the control bit register 6, and the exclusive OR of the control bit register 5 and the control bit register 6 to be latched in the control bit register 3. The values of the control bit register 5 and the control bit register 6 are used to decide whether the addition or the subtraction is to be executed to the first step of a subsequent division. The control bit register 6 is used as a code extension unit of the divisor in the subsequent division. The value of the control bit register 3 indicates the code of the quotient. In case this quotient is negative, it is transformed into a complement of 2 once it has been determined as a complement of 1. In case the minimum of a 16 bit coded complement of 2 is the quotient, 17 bits are required for the expression of a complement of 1. It is the value of the control bit register 3 immediately after the end of the present DIVOS instruction that becomes the code bit of the complement of 1 of 17 bits.
In case the dividend takes the minimum of a 32 bit coded complement of 2, the dividend register R2 is given the positive maximum by the aforementioned correction of the subtraction of 1 so that the value of the control bit register 5 immediately after the end of the DIVOS instruction is 0. Since the control bit register 5 intrinsically receives the code bit of the dividend, its value should be 1. In case, therefore, the dividend takes the minimum of the 32 bit coded complement of 2, the control procedure is different from that of the intrinsic intention. As has been noted above, the overflows never falls to occur in case the dividend takes the minimum of the 32 bit coded complement of 2. However, this overflow case may be detected in advance and precluded. In the following, no special consideration is taken into the case, in which the dividend takes the minimum of the 32 bit coded complement of 2.
(7) DIV1 R1, R2
In the description of FIG. 53, the instruction β.arepeat 16β is a micro instruction of an assembler, which means that an instruction between β.arepeat 16β and β.aendrβ is extended sixteen times. Thus, the DIV1 instruction is repeated sixteen times to effect the substantial division. The R1 of the first operand of the DIV1 instruction is a divisor register, and the R2 of the second operand of the DIV1 instruction is a dividend register. In FIGS. 60 and 77, the execution of the DIV1 instruction of one time is roughly classified into the processings (ii), (iii) and (iv).
(i) At first, the values of the control bit register 5 and the control bit register 6 are fetched by the operation control circuit 7 to calculate the negation of the exclusive OR between the two inputs. This result is fed to the arithmetic logical operation circuit 8, which latches the value as an operation command. This operation command is directed to a subtraction, if the result of the exclusive OR is 1, and an addition if the result is 0.
(ii) Next, the value of the dividend register R2 is inputted to the shifter 4. The shifter 4 shifts the inputted 32 bits by 1 bit to the more significant bits. Simultaneously with this, the value of the control bit register 3 is shifted in the LSD, and the shifted-out MSB bit is fed through the selector circuit 15 to the selector circuit 11 and latched in the control bit register 5.
(iii) Next, the 33 bits, which are prepared by adding the control bit register to the most significant bit of the divisor register R1, are added to or subtracted from the 33 bits which are prepared by adding the value of the control bit register 5 to the most significant bit of the 32 bit output of the shifter 4. An addition is executed, if the addition command is fed in the processing (i), and a subtraction is executed if the subtraction command is fed in the processing (i). The addition/subtraction between the 32 bit output of the shifter 4 and the value of the divisor register R1 are executed by the arithmetic logical operation circuit 8. As a result, the carry or borrow established by the arithmetic logical operation circuit 8 is fed through the selector circuit 12 to the operation circuit 9. The operation result of the 32 bits obtained by the arithmetic logical operation circuit 8 is latched in the dividend register R2. The addition/subtraction between the control bit register 5 and the control bit register 6 are executed with the carry or borrow, which was established in the arithmetic logical operation circuit 8, by the operation circuit 9. The result of the operation circuit 9 is the code bit of the partial remainder. This code of the partial remainder is fed in one way to the selector circuit 11 and latched in the control bit register 5 and is inputted in the other to the operation circuit 10.
(iv) The operation circuit 10 calculates the negation of the exclusive OR between the code of the partial remainder and the value of the control bit register 8. The result is fed to the selector circuit 12 and is latched in the control bit register 3. The value of the control bit register 3 at this time is the quotient bit.
Immediately after the DIV1 instruction has been repeated sixteen times: the last partial remainder is in the control bit register 5; the least significant bit of the quotient is in the control bit register 3; the last partial remainder is in the more significant 16 bits of the dividend register R2; and the more significant 16 bits of the quotient of 17 bits are in the less significant 16 bits.
(8) MOV R2,R4
In response to this instruction, as shown in FIG. 61, the value of the register R2 is released to the register R4 so that the last partial remainder latched in the more significant 16 bits of the register R2 may not be broken by the means for determining the quotient.
(9) EXTS.W R2,R2
The code of the quotient outputted to the T bit in response to the aforementioned DIVOS instruction is brought to the position of the code bit of the less significant 16 bits of the register R2 by repeating the aforementioned DIV1 instruction by sixteen times. The instruction EXTS.W R2,R2 code-extends the code bit of the less significant 18 bits to the more significant 16 bits, as shown in FIGS. 62 and 77. In this processing, the code extension circuit of FIG. 62 code-extends the less significant 16 bits to 32 bits. Specifically, in response to the EXTX.W instruction, the codes of the less significant 16 bits of the dividend register R2 are extended to the more significant 16 bits. Since the code bit of the quotient determined in the foregoing processing (6) DIVOS R1,R2 is latched in the code bit of the less significant 16 bits of the dividend register R2, this quotient code is extended to the more significant 16 bits.
(10) ROTCL R2
The T bit has the last quotient bit that has been determined at the sixteenth DIV1 instruction. In response to the ROTCL R2, as shown in FIGS. 63 and 78, the shifter 4 is used to shift the T bit in the LSB of the register R2. Simultaneously with this, the value of the register R2 is shifted leftward to output the shifted out MSB (code bit) to the T bit. Specifically, the least significant bit of the quotient latched in the control bit register 3 is shifted in the dividend register R2. The shifted-out code bit is latched in the control bit register 3. At this time, the quotient is latched in the dividend register R2. If the control bit register 3 has the value 0, that is, if the quotient is positive, no correction is necessary. On the contrary, if the control bit register 3 has the value 1, that is, if the quotient is negative, the quotient has to be transformed into a complement of 2 because it is expressed in a complement of 1.
(11) ADDC R0,R2
Immediately before this instruction is executed, the register R2 latches the quotient, and the T bit latches the code of the quotient. In response to this ADDC instruction, as shown in FIGS. 64 and 78, the value of the T bit is added to the value of the register R2 to transform the complement of 1 latched in the register R2 into a complement of 2. Because T=0 if the quotient is positive, the value of the register R2 is not changed even if the T is added. Because T=1 if the quotient is negative, the value of the register R2 is transformed from the complement of 1 into the complement of 2 by adding the T. As a result, a correct quotient is determined. In this processing, the arithmetic logical operation circuit 8 subtracts the B port input from the A port input and further subtracts the T bit (carry/borrow) to latch the borrow in the T bit. In short, the ADDC instruction is an addition instruction with carry. The control bit register 3 is recognized as identical to the carry, and the ADDC instruction adds the register R0 having the value 0 and the control bit register 3 to the dividend register R2. The value of the dividend register R2 is unchanged from that before the execution of the ADDC instruction, if the control bit register 3 has the value 0, but the quotient latched in the dividend register R2 is transformed from the complement of 1 into the complement of 2 if the control bit register 3 has the value 1. As a result, a correct quotient can be obtained.
In FIG. 53, the following instructions DIVOS to EXTS.W of the aforementioned instruction ADDC are necessary for determining the rest.
(12) DIVOS R0,R4
This instruction is to latch the MSB (code of the rest) of the register R4 in the T bit. Specifically: the MSB of the register R4 is introduced into the Q bit; the MSB of the register R0 is introduced into the M bit; and the exclusive OR between the Q bit and the M bit is introduced into the T bit, as shown in FIGS. 65 and 78. Since the register R0 has the value 0 at this time, as has been described hereinbefore, the M bit is 0, and the value (code of the rest) of the Q bit is introduced as it is into the T bit. In this processing, the shifter 4 outputs the MSB of the input to the Q bit. The code extension circuit 17 outputs its input therethrough. The arithmetic logical operation circuit 8 outputs the MSB (code bit) of the B port input as the M bit. The operation circuit 10 takes and outputs the exclusive OR of the two inputs.
(13) MOVT R0
In response to this instruction, as shown in FIGS. 66 and 79, the value (code of the rest before correction) of the T bit is latched in the register R0. In this processing, the arithmetic logical operation circuit 8 adds the value of the T bit to the 32 bit data of all bits and outputs the addition to the register R0.
(14) EOR R3,R0
In response to this instruction, as shown in FIGS. 67 and 79, an exclusive OR is taken between the content of the register R3 and the content of the register R0. In this processing, the shifter 4 and the code extension circuit 17 output their inputs therethrough. The arithmetic logical operation circuit 8 takes an exclusive OR for each bit between the A port input and the B port input and outputs it to the register R0.
(15) ROTCR R0
In response to the aforementioned instruction EOR, the LSB of the register R0 is set to 1, if the code of the dividend and the code of the rest (before correction) are different, and to 0 if the codes are identical. In response to the instruction ROTCR R0, as shown in FIGS. 68 and 79, the LSB of the register R0 is latched in the T bit. In this processing, the shifter 4 shifts the value of the register R0 leftward, while shifting the T bit in the MSB, and latches the shifted-out LSB in the T bit. The arithmetic logical operation circuit 8 outputs the A port input therethrough.
(16) BF L1
This instruction instructs that the value of the T bit is branched, if at 0, into an instruction having the label L1, and that the next instruction DIVOS of this BF instruction is executed if the value of the T bit is at 1.
(17) DIVOS R1,R4
This instruction causes the rest to be corrected together with the instruction ROTCR and the instruction DIV1, which are to be executed subsequent to that instruction. At this time, the rest before correction is latched in the more significant 16 bits of the register R4, and the divisor is latched in the more significant 16 bits of the register R1. An addition is executed, if the codes of the two are different, and a subtraction is executed if identical. Thus, in response to said DIVOS instruction, as shown in FIGS. 69 and 80, the code of the rest (before correction) is latched in the Q bit, and the code of the divisor is latched in the M bit so that they may be used for deciding the addition/subtraction in the later-described instruction DIV1. The T bit latches the result of an exclusive OR between the Q bit and the M bit. In this processing, the shifter 4 outputs its input MSB to the Q bit. The code extension circuit 17 outputs its input therethrough. The arithmetic logical operation circuit 8 outputs the MSB (code bit) of the B port input. The operation circuit 10 takes and outputs an exclusive OR between the two inputs.
(18) ROTCR R4
In response to the later-described instruction DIV1, for an addition or subtraction after the leftward shift, the value of the register R4 is rotated clockwise to cancel that leftward shift. This state is shown in FIGS. 70 and 80. In this processing, the shift shifts the value of the register R4 rightward while shifting the T bit in the MSB and latches the shifted-out LSB as the T bit. The arithmetic logical operation circuit 8 outputs the A port input therethrough.
(19) DIV1 R1,R4
This instruction DIV1 is roughly classified into the following processings (i), (ii), (iii) and (iv), as shown in FIGS. 71 and 80.
(i) At first, the Q bit of the control bit register 5 and the M bit of the control bit register 6 are fetched in the arithmetic control circuit 7 to calculate the negation of the exclusive OR of the two inputs. This result is fed to the arithmetic logical operation circuit 8, which latches that value as an operation command. This operation command is a subtraction command, if the result of the aforementioned exclusive OR is 1 (i.e., if the code of the rest before correction and the code of the divisor are identical), and an addition command, if the same is 0 (i.e., if the code of the rest before correction and the rest of the divisor are different).
(ii) Next, the value of the register R4 is inputted to the shifter 4. This shifter 4 shifts the value of the register R4 leftward by 1 bit, while shifting the T bit in the LSB of the value of the register R4, and latches the shifted-out MSB in the Q bit.
(iii) Next, the 33 bits of the addition of the M bit and the value of the register R1 are added to or subtracted from the 33 bits of the addition of the Q bit and the value of the register R4, and the result is latched in the Q bit and the register R4. The addition/subtraction between the output of the shifter 4 and the value of the register R1 are executed by the arithmetic logical operation circuit 8. As a result, the carry or borrow established by the arithmetic logical operation circuit 8 is fed through the selector circuit 12 to the operation circuit 9. This operation circuit 9 inputs that carry/borrow and executes the addition/subtraction of the Q bit and the M bit in accordance with the carry/borrow.
(iv) The operation circuit 10 calculates the negation of the value calculated by the aforementioned operation circuit 9, i.e., an exclusive OR between the Q bit and the M bit. This result is latched through the selector circuit 12 in the T bit.
(20) SR16 R4
In response to this instruction, as shown in FIGS. 72 and 81, the more significant 16 bits (corresponding to the rest) of the register R4 are shifted rightward to the less significant 16 bits of the register R4. The shift processing is executed by the shifter 4.
(21) ADD R3,R4
The register R3 latches the code of the dividend in response to the aforementioned instruction MOVT R3. Since the code (MSB) of the dividend is subtracted from that dividend in response to the aforementioned instruction (5) SUBC R0,R2, the rest latched in the register R4 may have to be corrected so as to determined the correct rest. In response to the instruction ADD R3,R4, the code (R3) of the dividend is added to the rest before correction. In this processing, s shown in FIGS. 73 and 81, the shifter 4 and the code extension circuit 17 output their individual inputs therethrough. The arithmetic logical operation circuit 8 adds the B port input to the A port input and outputs the addition result and the carry. The addition result is latched in the register R4, and the correct rest is latched in the less significant 16 bits of said register R4.
(22) EXTS.W R4,R4
In response to this instruction, as shown in FIGS. 74 and 81, the more significant side of the register R4 having the correct rest latched in the less significant 16 bits is code-extended to determine the final rest of whole 32 bits. In this processing, the code extension circuit 17 extends the code at the 16th bit from the less significant side of the input to the more significant 16 bits. The arithmetic logical operation circuit 8 outputs the B port input therethrough toward the register R4.
The coded division processing having been described with reference to FIGS. 54 to 74 is roughly classified, if summarized in a flow chart, into the pre-processing, division 1 and post-processing, as shown in FIG. 82(A), and the processing of the aforementioned division 1 is to repeat the division step sixteen times, as shown in FIG. 83(A). The content of the pre-processing is shown in FIG. 82(B); the content of the processing of the division step is shown in FIG. 83(B); and the content of the post-processing is shown in FIG. 85. In this post-processing, there are executed a quotient correction, first partial remainder correction means, and second partial remainder correction means. The processing of the quotient correction is shown in FIG. 84(B); the first partial remainder correction means is shown in FIG. 85(A); and the second partial remainder correction means is shown in FIG. 85(B). The contents of the individual flow charts will be easily understood from the description thus far made, although any further description is not made.
The quotient and the rest are latched in the common register R2 in the example according to the instruction description of FIG. 53 but may be latched in different registers. If the quotient is to be latched in the not-shown register R5, for example, in the description of FIG. 53, the instruction MOV R0,R5 is inserted to the next of the instruction EOR R0,R0, and the instruction ROTCL R5 is inserted before the instruction DIV1 R1,R2 so that these instructions DIV1 R1,R2 and instruction ROTCL are repeated sixteen times. Then: the instruction EXTS.W R2,R2 may be changed into the instruction EXTS.W R5,R5; the next instruction ROTCL R2 may be changed into the instruction ROTCL R5; and the next instruction ADDC R0,R2 may be changed into the instruction ADDC R0,R5.
Incidentally, FIGS. 86 to 91 show other examples of modification of the instruction description for the coded division. These modes omit the description of the correction processing relating to the rest. The SL8 Rn instruction is one for shifting the register Rn leftward by 8 bits. The individual bits of the less significant 8 bits of the Rn after the instruction execution are 0. The EXTS.B Rn,Rm instruction is one for code-extending the less significant 8 bits of the Rn to 32 bits and to latch the 32 bits in the Rm. These contents will be easily understood from the description of the foregoing embodiments although no detailed description is made.
[24] DIVOS/DIVOU/DIV1 (Step Division) Instruction
Here will be described the DIVOS instruction used in the foregoing description, and the examples of the operation and use of the DIV1 instruction. The contents to be described share the prerequisites in the aforementioned item [17] List of Instructions. However, these contents are different in detail in the operation examples expressed by the C language from the DIV1 instruction contained in the Item.
The content of 32 bits of the general purpose register Rn is divided at one step with the content of the Rm, and the result of 1 bit is latched in the T bit. The instruction DIVOS is a coded division initialization instruction for latching the MSB of the dividend (Rn) in the Q bit, the MSB of the divisor (Rm) in the M bit, and the EOR of the M bit and the Q bit in the T bit. The DIVOU instruction is a codeless division initialization instruction for clearing the M/Q/T bits to 0. The quotient is obtained by releasing the instruction DIV1 (in combination with the ROTCL, if necessary) by the number of bits of the divisor. During this repetition, an intermediate result is latched in the assigned register and the M/Q/T bits. If these are unnecessarily rewritten by a software, the operation result cannot be warranted. There are not prepared the detection of a zero division and an overflow and the operation of the partial remainder. The division sequence can be referred to the following examples of use.
| extern unsigned char Q,M,T; | |
| extern unsigned long PC,R[16] | |
| DIVOU( ) ββββββ/* DIVOU */ | |
| { | |
| βββM=Q=T=0; | |
| βββPC+=2; | |
| } | |
| DIVOS(long m, long n) ββ/* DIVOS Rm,Rn */ | |
| { | |
| βββif ((R[n] & 0x80000000)==0) Q=0; | |
| βββelse Q=1; | |
| βββif ((R[m] & 0x80000000)==0) M=0; | |
| βββelse M=1; | |
| βββT=!(M==Q); | |
| βββPC+=2; | |
| } | |
| DIV1(long m,long n) ββ/* DIV1 Rm,Rn */ | |
| { | |
| βββunsigned long tmp0; | |
| βββunsigned char ββold_q, tmp1; | |
| βββold_q=Q; | |
| βββQ=(unsigned char)((0x80000000 & R[n])!=0); | |
| βββR[n]<<=1; | |
| βββR[n]| =(unsignedβ²long)T; | |
| βββswitch(old_q){ | |
| case 0: | |
| βββswitch(M){ | |
| βββcase 0: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]β=R[m]; | |
| ββββββtmp1=(R[n]>tmp0); | |
| ββββββswitch(Q){ | |
| ββββββcase 0: | |
| βββββββββQ=tmp1; | |
| βββββββββbreak; | |
| ββββββcase 1: | |
| βββββββββQ=(unsigned char)(tmp1==0); | |
| βββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| βββcase 1: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]+=R[m]; | |
| ββββββtmp1=(R[n]<tmp0); | |
| ββββββswitch(Q){ | |
| ββββββcase 0: | |
| βββββββββQ=(unsigned char)(tmp1==0); | |
| βββββββββbreak; | |
| ββββββcase 1: | |
| βββββββββQ=tmp1; | |
| βββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| βββ} | |
| βββbreak; | |
| case 1: | |
| βββswitch(M){ | |
| βββcase 0: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]+=R[m]; | |
| ββββββtmp1=(R[n]<tmp0); | |
| ββββββswitch(Q){ | |
| ββββββcase 0: | |
| βββββββββQ=tmp1; | |
| βββββββββbreak; | |
| ββββββcase 1: | |
| βββββββββQ=(unsigned char)(tmp1==0); | |
| βββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| βββcase 1: | |
| ββββββtmp0=R[n]; | |
| ββββββR[n]β=R[m]; | |
| ββββββtmp1=(R[n]>tmp0); | |
| ββββββswitch(Q){ | |
| βββββββββcase 0: | |
| ββββββββββββQ=(unsigned char)(tmp1==0); | |
| ββββββββββββbreak; | |
| βββββββββcase 1: | |
| ββββββββββββQ=tmp1; | |
| ββββββββββββbreak; | |
| βββββββββ} | |
| βββββββββbreak; | |
| ββββββ} | |
| ββββββbreak; | |
| βββ} | |
| βββT=(Q==M); | |
| βββPC+=2; | |
| } | |
| R1(32bits) Γ· R0(16bits) = R1(16bits): no code |
| SL16 | R0; | divisor is set to the more significant | |
| 16 bits, and the less | |||
| significant 16 bits is set to 0. | |||
| TEST | R0,R0; | zero division is checked. TEST | |
| R0,R0 is an instruction for setting | |||
| the T bit to 1, if the OR | |||
| between R0 and R0 is 0, and to 0 | |||
| if 1. | |||
| BT | ZERO_DIV; | branches into ZERO_DIV, if T=0. | |
| CMP/HS | R0,R1; | overflow is checked. T bit is | |
| set to 1 if R0β¦R1 without code. | |||
| BT | OVER_DIV; | ||
| DIVOU | ; | initialization of flag | |
| .arepeat 16 | ; | ||
| DIV1 | R0,R1; | repeat 16 times | |
| .aendr | ; | ||
| ROTCL | R1; | ||
| EXTU.W | R1,R1; | R1=quotient | |
| R1:R2(64bits) Γ· R0(32bits) = R2(32bits):no code |
| TEST | R0,R0; | zero division is checked. | |
| BT | ZERO_DIV; | ||
| CMP/HS | R0,R1; | overflow is checked. | |
| BT | OVER_DIV; | ||
| DIVOU | ; | initialization of flag | |
| .arepeat 32 | ; | ||
| ROTCL | R2; | repeat 32 times | |
| DIV1 | R0,R1; | ||
| .aredr | ; | ||
| ROTCL | R2; | R2= quotient | |
| R1(16bits) Γ· R0(16bits) = R1(16bits): no code |
| SL16 | R0; | divisor is set to the more significant | |
| 16 bits, and the less | |||
| significant 16 bits is set to 0. | |||
| EXTS.W | R1,R1; | dividend is code-extended to 32 | |
| bits. | |||
| EOR | R2,R2; | R2=0 | |
| DIVOS | R2,R1; | ||
| SUBC | R2,R1; | decremented by β1 if dividend is | |
| negative. | |||
| DIVOS | R0,R1; | initialization of flag | |
| .arepeat 16 | ; | ||
| DIV1 | R0,R1; | repeat 16 times | |
| .aendr | ; | ||
| EXTS.W | R1,R1; | R1=quotient (expression of complement | |
| of 1) | |||
| ROTCL | R1; | ||
| ADDC | R2,R1; | incremented by +1, if code bit of | |
| MSB of quotient is at 1, and | |||
| transformed into expression of | |||
| complement of 2. | |||
| EXTS.W | R1,R1; | R1= quotient (expression of complement | |
| of 2) | |||
| R2(32bits) Γ· R0(32bits) = R2(32bits): no code |
| EOR | R3,R3; | ||
| DIVOS | R3,R2; | ||
| SUBC | R1,R1; | dividend is code-extended to 64 | |
| bits (R1 : R2) | |||
| SUBC | R3,R2; | decremented by β1 if dividend is | |
| negative. | |||
| DIVOS | R0,R1; | initialization of flag | |
| .arepeat 32 | ; | ||
| ROTCL | R2; | repeat 32 times | |
| DIV1 | R0,R1; | ||
| .aendr | ; | ||
| ROTCL | R2; | R2=quotient (expression of complement | |
| of 1) | |||
| ADDC | R3,R2; | incremented by +1, if code bit | |
| MSB of quotient is at 1, and | |||
| transformed into expression of | |||
| complement of 2. | |||
| ; | R2=quotient (expression of complement | ||
| of 2) | |||
Although our invention has been described specifically in connection with the embodiments thereof, it should not be limited thereto but can naturally be modified in various manners without departing from the scope thereof.
For example, the data word length and the bit number of the fixed length instruction format should not be limited to the data word length of 32 bits and the 16 bit fixed length instruction format but can be individually modified by bit numbers of powers of 2. The coded division can also be applied to the 32 bit 3-operand RISC instruction. The control for the coded division can be executed by not only the microprogram method but also a wired logic forming a special purpose operation circuit. If, in the coded division, there is no special instruction such as the aforementioned DIV1 instruction, this situation can be coped with by forming a similar processing into a subroutine in response to another instruction.
Although the description thus far made is directed to the case in which our invention is applied to a microcomputer having a program ROM packaged therein and presenting the field of application backgrounding the invention, the invention should not be limited thereto but can also be applied widely to a microcomputer containing neither the program ROM nor its peripheral circuit. In addition, the foregoing descriptions have been described in case the coded division is applied to the non-recovery method, but they can naturally be applied to the recovery method.
The effects to be obtained by the representatives of the invention disclosed herein will be briefly described in the following.
(1) In a microcomputer adopting the general purpose register method, there is adopted a fixed length instruction format which has a smaller bit number than that of the maximum data word length fed to instruction execution means. As a result, there is achieved an effect that it is possible to provide a microprocessor which has a small program capacity or a high using efficiency of program memory and a low system cost while enjoying the advantage of simplification of such an instruction decoding as exemplified in the RISC machine of the prior art having a fixed length instruction format of 32 bits or the like.
(2) The fixed length instruction format and the maximum data word length are set to a bit number of a power of 2 so that the maximum data word length is 32 bits, for example, the instruction format is fixed to 16 bits. Thus, another effect achieved is that either the instruction or the data can be extended over the ROM/RAM having an identical bit structure while preventing the misalignment of the program on the memory and holding the consistency with the general memory commercially available.
(3) When the aforementioned fixed length instruction format and the aforementioned maximum data word length are to be individually set to the bit numbers of powers of 2, a plurality of instructions efficiently can be efficiently fetched by the use of an internal bus of a bit number equal to that of the maximum data word length, and the bus access number for the instruction fetch can be reduced by prefetching the instructions in a common cycle.
(4) In ease the internal bus is shared between the data transfer and the instruction fetch, the pipe control is executed to prefer the data fetch thereby to delay the whole instruction execution schedule including an instruction fetch conflicting with that data fetch, if the data fetch and the instruction fetch for the memory conflict.
(5) A further effect achieved is that the restriction on the bit number of the fixed length instruction format is enabled not to limit the use of immediate data by supporting the instruction containing a description for assigning the immediate data in a data relation for offsetting the value of a displacement relative to the value of a predetermined register.
(6) A further effect achieved is that, even in the fixed length instruction format having a restricted bit number, the displacement necessary for the processing or the bit number of the immediate data can be maximized by supporting an instruction for implicitly assigning a predetermined general purpose register which is fixed as an operand despite of no register assigning field in the instruction.
(7) A further effect achieved is that the displacement necessary for the processing or the bit number of the immediate data can be maximized, even for the fixed length instruction format having a limited bit number, by supporting an instruction containing a description for reflecting the truth or false of the arithmetic result for a specified condition upon a predetermined status flag.
(8) Thanks to these effects, it is possible to solve the various problems accompanying the adoption of the fixed length instruction format having a smaller bit number than that of the data word length. For example: neither the use of immediate data nor the assignment of an absolute address is restricted even if the bit number of the fixed length instruction format is less than that of the data word length; a description such as a necessary displacement can be executed in the fixed length instruction format having a limited bit number; a contribution is made to the prevention of a misalignment of the program arrangement on a memory; that the code efficiency or memory using efficiency is improved better from the standpoint of the content of a supporting instruction.
(9) The conflicting state between the uses of the general purpose registers in response to the instructions before and after the pipe-line execution making use of the general purpose register method, can be simply coped with by detecting the register conflicting state in the general purpose register on the basis of the information of a register assigned area contained in the instruction format and by adopting the pipe-line control means for relatively delaying execution of the subsequent instructions on the basis of the detection result and the instruction execution cycle number.
(10) For a 16 bit fixed length instruction format, the displacement of a condition branching instruction is fixed at 8 bits, and the displacements of a subroutine branching instruction and an unconditional branching instruction are fixed to 12 bits. As a result, a proper branching destination can be assigned according to the kinds of the branching instruction without exerting substantial affections upon the actual operation while the instruction format length being restricted.
(11) In case a dividend is negative, a preliminary processing is executed by subtracting the value β1β having a weight of the LSB of a dividend from the dividend itself so that the division can be executed with the codes unlike the prior art, in which whether or not the partial remainder is 0 is decided at each time. As a result, the division can be executed at a high speed. In other words, effects similar to or better than those of the prior art, in which the division is speeded up by providing a special purpose hardware for deciding whether or not the partial remainder is 0 at a shorter number of steps, can be realized without increasing the scale of the hardware.
(12) In case a division with codes of multiple length (or arbitrary length) is to be executed in the prior art for deciding whether or not the partial remainder is 0 at each time, the decision of partial remainder=0 has to be executed in accordance with the bit number (e.g., 8 bits, 16 bits, 32 bits or 64 bits) of the partial remainder so that the amounts of the software and hardware will increase in proportion to that bit number. In this regard, since the present invention requires no decision of partial remainder=0, the multi-length (or arbitrary length) coded division or the coded decision of arbitrary length and arbitrary accuracy can be easily coped with out increasing the software amount and the hardware amount.
(13) By adopting the operation of subtracting the code bit or the MSB of the dividend as a pre-processing of the division, the division program can be prepared without considering whether the dividend is positive or negative. Since such decision is not required, the dividing speed can be raised, and the division itself can be executed by making use of a common circuit despite whether the dividend is positive or negative.
(14) Since the decision of excess subtraction or addition of the divisor to or from the partial remainder and the calculation of the quotient bit can be executed only from the MSB of the dividend or the partial remainder and the MSB of the divisor, the hardware for the division can be further simplified. Since, moreover, the decision of excess subtraction or addition of the divisor from or to the partial remainder, the decision of the addition/subtraction and the calculation of the quotient bit can be executed only from the MSB of the divided or the partial remainder and the MSB of the divisor, an easy application can also be made to the division of arbitrary length. Since, still moreover, the decision of the addition/subtraction at the division step can be executed only by the MSB, the common division step can be used for the coded and codeless divisions by initializing the division.
(15) When the quotient and rest are to be latched in a single dividend register while being shifted, the decision of partial remainder=0 has to be executed in the prior art by changing the digit positions of the partial remainder to be decided, at each time. On the basis of this fact, the prior art is restricted by the complicated processing and an elongated processing time. However, the present invention is subjected to neither such restriction nor another restriction, in which the transfer instructions to be executed for latching the quotient and the rest in different registers are increased. As a result, the coded division can be further speeded up with ease.
1. (canceled)
2. A microcomputer formed on a single semiconductor device comprising:
a CPU having general purpose registers and a program counter; and
a memory coupled to said CPU,
wherein the CPU is capable of processing a data transfer instruction, a conditional branch instruction and an unconditional branch instruction,
wherein each of the data transfer instruction, the conditional branch instruction and the unconditional branch instruction is of 16 bits in length,
wherein the memory stores instructions to be processed by said CPU,
wherein the conditional branch instruction includes a first area for a first displacement,
wherein the unconditional branch instruction includes a second area for a second displacement,
wherein a length of the first area of the conditional branch instruction is smaller than that of the unconditional branch instruction,
wherein the data transfer instruction includes a third area for a third displacement and a fourth area for destination register information to designate the general purpose registers where source data is to be loaded,
wherein a first branch target address of the conditional branch instruction is obtained based on the first displacement in the first area of the conditional branch instruction and an address in the program counter,
wherein a second branch target address of the unconditional branch instruction is obtained based on the second displacement in the second area of the unconditional branch instruction and an address in the program counter, and
wherein 32 bits of the source data is obtained from a memory location indicated by an address obtained based on the third displacement in the third area of the data transfer instruction and an address in the program counter, and the source data is loaded into one of the general purpose registers which is designated by the fourth area of the data transfer instruction.
3. The microcomputer according to claim 2, wherein the third area of the data transfer instruction is of 8 bits in length.
4. The microcomputer according to claim 2, wherein the program counter is of 32 bits in length.
5. The microcomputer according to claim 2, wherein the general purpose registers are of 32 bits in length.
6. The microcomputer according to claim 2, wherein the first area of the conditional branch instruction is of 8 bits in length.
7. The microcomputer according to claim 2, wherein the second area of the unconditional branch instruction is of 12 bits in length.
8. The microcomputer according to claim 2, wherein the memory is a cache memory.
9. The microcomputer according to claim 2, wherein the first branch target address is obtained by adding the displacement in the first area with an address in the program counter.
10. The microcomputer according to claim 2,
wherein the data transfer instruction further includes a fifth area to indicate an operation code defining a data transfer operation, and
wherein the third displacement is shifted by 2 bits and the shifted displacement is added to the address in the program counter.
11. A central processing unit of RISC architecture on a semiconductor chip and adapted to execute a data transfer instruction, the central processing unit comprising:
a program counter;
a plurality of registers;
wherein the data transfer instruction is of 16 bits in length and includes:
a first field to indicate an operation code for a data transfer operation,
a second field to indicate a destination register which is one of the plurality of registers where data of a bit length greater than the 16 bit length is to be loaded, and
a third field to indicate a displacement which is utilized for indicating a first address by adding to a second address in the program counter,
wherein the central processing unit executes the data transfer instruction to load the data of a bit length greater than the 16 bits in length stored in the first address to the destination register.
12. The central processing unit according to claim 11,
wherein the program counter is of 32 bits in length.
13. The central processing unit according to claim 11,
wherein the plurality of registers are general purpose registers of 32 bits in length.
14. The central processing unit according to claim 11,
wherein displacement is of 8 bits in length.
15. The central processing unit according to claim 11,
wherein the data is of 32 bits in length.
16. The central processing unit according to claim 15,
wherein the displacement is shifted leftward by 2 bits and the shifted displacement is added to the second address in the program counter.
17. A data processor on a single semiconductor device, comprising:
a RISC type CPU to have 32-bit general purpose registers and a program counter; and
a memory coupled to the CPU and to store instructions to be executed by the RISC type CPU,
wherein the instructions include a data transfer instruction of 16 bits in length and include:
a first area to indicate an operation code for a data transfer operation,
a second area to indicate a destination register which is one of the 32-bit general purpose registers where data of 32 bits in length is to be loaded, and
a third area to indicate a first displacement which is used for indicating a first address by adding to a second address in the program counter,
wherein the RISC type CPU executes the data transfer instruction to load the data stored in the first address to the destination register.
18. The data processor according to claim 17,
wherein the program counter is of 32 bits in length.
19. The data processor according to claim 17,
wherein displacement is of 8 bits in length.
20. The data processor according to claim 17,
wherein the displacement is shifted leftward by 2 bits and the shifted displacement is added to the second address in the program counter.
21. The data processor according to claim 17,
wherein the instructions include:
a conditional branch instruction of 16 bits in length including a fourth area to indicate a second displacement which is used for indicating a third address by adding to the second address in the program counter, and
an unconditional branch instruction of 16 bits in length including a fifth area indicating a third displacement which is used for indicating a fourth address by adding to the second address in the program counter, and
wherein a length of the fourth area is smaller than that of the fifth area.
22. A microcomputer on a single semiconductor device comprising:
a CPU having general purpose registers and a program counter;
a RAM coupled to the CPU;
a DMA controller coupled to the RAM; and
a memory coupled to the CPU and for storing instructions to be processed by the CPU;
wherein the instructions include:
a conditional branch instruction of 16 bits in length and including a first area for a first displacement which is utilized for indicating a first branch target address by adding to a second address in the program counter,
an unconditional branch instruction of 16 bits in length and including a second area for a second displacement which is utilized for indicating a second branch target address by adding to the second address in the program counter and whose length is longer than that of the first area, and
a data transfer instruction of 16 bits in length and including a third area for a third displacement which is utilized for indicating a first address by adding to the second address in the program counter and a fourth area for a destination register information for designating one of the general purpose registers where data of 32 bits in length which is stored in the first address is loaded.
23. The microcomputer according to claim 22, wherein the third area of the data transfer instruction is of 8 bits in length.
24. The microcomputer according to claim 22, wherein the program counter is of 32 bits in length.
25. The microcomputer according to claim 22, wherein the general purpose registers are of 32 bits in length.
26. The microcomputer according to claim 22, wherein the first area of the conditional branch instruction is of 8 bits in length.
27. The microcomputer according to claim 22, wherein the second area of the unconditional branch instruction is of 12 bits in length.
28. The microcomputer according to claim 22, wherein the memory is a cache memory.
29. The microcomputer according to claim 22, wherein the first address is obtained by adding the third displacement in the first area with the address in the program counter.
30. The microcomputer according to claim 22,
wherein the data transfer instruction further includes a fifth area for an operation code defining a data transfer operation, and
wherein the third displacement is shifted leftward by 2 bits and the shifted third displacement is added to the second address in the program counter.
31. A central processing unit of RISC architecture on a semiconductor chip and adapted to execute a data transfer instruction, the central processing unit comprising:
a program counter; and
a plurality of registers,
wherein the data transfer instruction is of 16 bits in length and includes:
a first field to indicate an operation code for a data transfer operation,
a second field to indicate a destination register which is one of the plurality of registers, data of a bit length being greater than the 16 bit length to be loaded in to the destination register, and
a third field to indicate a first displacement which is utilized for indicating a first address by adding to a second address in the program counter,
wherein the central processing unit executes the data transfer instruction to load the data stored in the first address to the destination register.
32. The central processing unit according to claim 31,
wherein the program counter is of 32 bits in length, and
wherein the plurality of registers are of 32 bits in length.
33. The central processing unit according to claim 32,
wherein the central processing unit is adapted to execute a conditional branch instruction, and
wherein the conditional branch instruction is 16 bits in length, and includes a fourth field to indicate a second displacement which is used for indicating a third address by adding to the second address in the program counter.
34. The central processing unit according to claim 33,
wherein the central processing unit is adapted to execute an unconditional branch instruction, and
wherein the unconditional branch instruction is 16 bits in length, and includes a fifth field to indicate a third displacement which is used for indicating a fourth address by adding to the second address in the program counter.