JPH04353925A - Arithmetic unit - Google Patents

Arithmetic unit

Info

Publication number
JPH04353925A
JPH04353925A JP3127941A JP12794191A JPH04353925A JP H04353925 A JPH04353925 A JP H04353925A JP 3127941 A JP3127941 A JP 3127941A JP 12794191 A JP12794191 A JP 12794191A JP H04353925 A JPH04353925 A JP H04353925A
Authority
JP
Japan
Prior art keywords
register
subtraction
latch pulse
instruction
result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
JP3127941A
Other languages
Japanese (ja)
Inventor
Hideyuki Odaka
小高 秀之
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fuji Electric Co Ltd
Original Assignee
Fuji Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuji Electric Co Ltd filed Critical Fuji Electric Co Ltd
Priority to JP3127941A priority Critical patent/JPH04353925A/en
Publication of JPH04353925A publication Critical patent/JPH04353925A/en
Withdrawn legal-status Critical Current

Links

Landscapes

  • Executing Machine-Instructions (AREA)

Abstract

PURPOSE:To shorten the processing time of a division program for an arithmetic unit executing division by means of combining addition and subtraction. CONSTITUTION:A latch pulse generation part 32 supplies a latch pulse RLP to a register 17 based on the decoding result of an instruction decoder 31 and a carry flag outputted from a computing element 19. The register 17 latches an operated result in synchronizing with the latch pulse RLP. When subtraction is executed in the computing element 19, a subtraction result is negative, and the carry flag is '1', for example, the latch pulse RLP is not outputted from the latch pulse generation part 32 to the register 17 and the operated at that time result is not latched by the register 17. When the subtraction result becomes negative at the time of executing division by combining addition and subtraction, a processing for adding a divisor is not required and the number of the steps of the program can be reduced.

Description

【発明の詳細な説明】[Detailed description of the invention]

【0001】0001

【産業上の利用分野】本発明は、加減算命令を組み合わ
せて除算を実現する演算装置に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to an arithmetic device that performs division by combining addition and subtraction instructions.

【0002】0002

【従来の技術】初期のプログラマブルコントローラ(以
下、PCと呼ぶ)は、それまでのリレー盤の機能である
シーケンス制御(ビット単位の論理の制御)のみを実行
するものであったが、最近のPCは、数値演算制御機能
(ワード単位の論理の制御、すなわち、量の制御)、デ
ータ処理機能などを持っものが実用化されている。数値
演算機能は、AND、ORなどの論理演算と、四則演算
や平方根などの算術演算とに分けられる。
[Prior Art] Early programmable controllers (hereinafter referred to as PCs) only performed sequence control (bit-by-bit logic control), which was the function of relay boards up until then. Some have been put into practical use that have numerical arithmetic control functions (word-by-word logic control, ie, quantity control), data processing functions, etc. Numerical calculation functions are divided into logical operations such as AND and OR, and arithmetic operations such as arithmetic operations and square roots.

【0003】先ず、従来の命令コードの構成とその命令
コードを解読して演算を行う演算回路を、図7を参照し
て説明する。命令コードは、他の命令と区別する為の命
令分類部11と、その命令で使用するレジスタを指定す
るレジスタ指定部R1、R2とからなり、その他の部分
は使用しない。
First, the structure of a conventional instruction code and an arithmetic circuit that decodes the instruction code and performs an operation will be explained with reference to FIG. The instruction code consists of an instruction classification section 11 for distinguishing it from other instructions, and register specification sections R1 and R2 for specifying registers to be used in the instruction, and other sections are not used.

【0004】命令分類部11は、命令デコーダ12でデ
コードされ、レジスタ指定部R1は、R1デコーダ13
で、レジスタ指定部R2は、R2デコーダ14でそれぞ
れデコードされる。
The instruction classification section 11 is decoded by an instruction decoder 12, and the register specification section R1 is decoded by an R1 decoder 13.
The register designation portions R2 are respectively decoded by the R2 decoder 14.

【0005】ラッチパルス生成部15は、命令デコーダ
12でのデコード結果とR1デコーダでのデコード結果
に基づいて、複数のレジスタ17の中の該当するレジス
タにラッチパルスRLPを出力する。
[0005] The latch pulse generating section 15 outputs a latch pulse RLP to a corresponding register among the plurality of registers 17 based on the decoding result at the instruction decoder 12 and the decoding result at the R1 decoder.

【0006】レジスタファイル16は、上記の複数のレ
ジスタ17と、レジスタ17の出力の1つを選択する2
個のセレクタ18a、18bと、それらセレクタ18a
、18bの出力を入力とする演算器19とで構成されて
いる。
[0006] The register file 16 includes the plurality of registers 17 described above and 2 registers for selecting one of the outputs of the registers 17.
selectors 18a, 18b and the selectors 18a
, 18b as inputs.

【0007】セレクタ18aの選択端子には、R1デコ
ーダのデコード結果が入力し、他方のセレクタ18bの
選択端子には、R2デコーダのデコード結果が入力して
おり、レジスタ指定部R1及びR2で指定されるレジス
タ17を選択して、その内容を演算器19に出力する。
The decoding result of the R1 decoder is input to the selection terminal of the selector 18a, and the decoding result of the R2 decoder is input to the selection terminal of the other selector 18b. The register 17 is selected and its contents are output to the arithmetic unit 19.

【0008】演算器19は、汎用の4ビットALUなど
を必要なビット数分組み合わせたものであり、この演算
器19の制御端子には、命令デコーダ12でのデコード
結果である演算の種類を示す情報が入力しており、その
情報に従って減算、あるいは加算が行われ、演算結果が
該当するレジスタ17に取り込まれる。この演算器19
からは、減算の結果、被引数が引数より小さいときに「
1」となり、その他の場合には「0」となるキャリフラ
グCFがフラグレジスタ20に出力される。
[0008] The arithmetic unit 19 is a combination of general-purpose 4-bit ALUs and the like for the necessary number of bits, and the control terminal of this arithmetic unit 19 indicates the type of operation that is the decoding result of the instruction decoder 12. Information is input, subtraction or addition is performed according to the information, and the result of the operation is taken into the corresponding register 17. This computing unit 19
, when the result of subtraction is smaller than the argument,
A carry flag CF which becomes "1" and "0" in other cases is output to the flag register 20.

【0009】フラグレジスタ20は、各種のフラグを記
憶するレジスタであり、ラッチパルス生成部15で生成
されるフラグレジスタ用ラッチパルスFLPの立ち上が
りに同期して、演算器19から出力されるキャリフラグ
CF等をラッチする。
The flag register 20 is a register that stores various flags, and is a carry flag CF output from the arithmetic unit 19 in synchronization with the rise of the flag register latch pulse FLP generated by the latch pulse generator 15. Latch etc.

【0010】ここで、上記のラッチパルス生成部15の
具体的構成を、図8を参照して説明する。デコーダ21
は、命令デコーダ12での命令のデコード結果を基に、
実行すべき命令がフラグレジスタ20の内容を変化させ
る命令であれば出力信号aを「1」にし、複数のレジス
タ17の何れかを変化させる命令であれば出力信号bを
「1」にし、その他の場合には両信号を「0」とする。 なお、命令デコード結果が減算の場合には、信号aと信
号bは共に「1」となる。
The specific configuration of the latch pulse generator 15 will now be described with reference to FIG. 8. Decoder 21
is based on the instruction decoding result in the instruction decoder 12,
If the instruction to be executed is an instruction that changes the contents of the flag register 20, the output signal a is set to "1"; if the instruction is an instruction that changes any of the plurality of registers 17, the output signal b is set to "1"; In this case, both signals are set to "0". Note that when the instruction decode result is a subtraction, both the signal a and the signal b become "1".

【0011】ナンドゲート22の一方の入力端子には、
デコーダ21の出力信号aが入力し、他方の入力端子に
はクロック信号CKをインバータ23で反転した信号が
入力している。従って、信号aが「1」のときには、ク
ロック信号CKに同期したラッチパルスFLPがフラグ
レジスタ20に出力される。
One input terminal of the NAND gate 22 has
The output signal a of the decoder 21 is input, and the signal obtained by inverting the clock signal CK by the inverter 23 is input to the other input terminal. Therefore, when the signal a is "1", a latch pulse FLP synchronized with the clock signal CK is output to the flag register 20.

【0012】複数のナンドゲート24には、R1デコー
ダ13のデコード結果と、デコーダ21の出力信号bと
、インバータ23で反転されたクロック信号とが入力し
ており、信号bが「1」のときは、R1デコード結果が
「1」であるナンドゲート24からクロック信号に同期
したラッチパルスRLPが該当するレジスタ17に出力
される。
The decoding result of the R1 decoder 13, the output signal b of the decoder 21, and the clock signal inverted by the inverter 23 are input to the plurality of NAND gates 24, and when the signal b is "1", , R1 from the NAND gate 24 whose decoding result is "1" outputs a latch pulse RLP synchronized with the clock signal to the corresponding register 17.

【0013】次に、図9は、従来の演算回路の動作タイ
ムチャートであり、同図は、「SUB  R1,R2」
の演算を行う場合のタイムチャートを示している。先ず
、演算器19で、〔R1−R2〕の減算を行い、その減
算結果をレジスタ用ラッチパルスRLPの立ち上がりに
同期してR1の示すレジスタに格納する。同時にフラグ
レジスタ用ラッチパルスFLPの立ち上がりに同期して
CFをフラグレジスタ20にラッチする。
Next, FIG. 9 is an operation time chart of a conventional arithmetic circuit.
A time chart is shown when performing the calculation. First, the arithmetic unit 19 subtracts [R1-R2] and stores the subtraction result in the register indicated by R1 in synchronization with the rise of the register latch pulse RLP. At the same time, CF is latched into the flag register 20 in synchronization with the rising edge of the flag register latch pulse FLP.

【0014】次に、符合無し2進整数の除算をソフトウ
ェアで実現した従来の除算プログラムのフローチャート
を図10を参照して説明する。先ず、部分剰余用レジス
タをゼロにクリアする(図10、S1)。次に、被除数
用レジスタと部分剰余用レジスタの内容を1ビット左に
シフトする(S2)。なお、1ビット左にシフトさせた
とき、被除数用レジスタの最上位ビットが部分剰余用レ
ジスタの最下位ビットにセットされるようになっている
Next, a flowchart of a conventional division program in which division of unsigned binary integers is realized by software will be explained with reference to FIG. First, the partial remainder register is cleared to zero (FIG. 10, S1). Next, the contents of the dividend register and partial remainder register are shifted one bit to the left (S2). Note that when shifted one bit to the left, the most significant bit of the dividend register is set to the least significant bit of the partial remainder register.

【0015】次に、部分剰余用レジスタから除数を減算
する(S3)。そして、減算結果がゼロ又は正か、それ
とも負かを判別する(S4)。減算結果がゼロ又は正の
ときは、部分剰余が除数と等しいか大きい場合であり、
この場合には、ステップS5に進み被除数用レジスタの
最下位ビットを「1」にする。ここで、被除数用レジス
タの最下位ビットに設定される「1」は、除算の商を示
している。
Next, the divisor is subtracted from the partial remainder register (S3). Then, it is determined whether the subtraction result is zero, positive, or negative (S4). If the subtraction result is zero or positive, the partial remainder is equal to or larger than the divisor;
In this case, the process advances to step S5 and the least significant bit of the dividend register is set to "1". Here, "1" set in the least significant bit of the dividend register indicates the quotient of division.

【0016】一方、減算結果が負のときは、部分剰余が
除数より小さい場合であり、この場合には部分剰余用レ
ジスタの値を減算前の値に戻す為に、ステップS6で部
分剰余用レジスタに除数を加算する。
On the other hand, if the subtraction result is negative, this means that the partial remainder is smaller than the divisor, and in this case, in order to return the value of the partial remainder register to the value before subtraction, the partial remainder register is Add the divisor to .

【0017】その後、被除数のビット数分の演算が終了
したか否かを判別する(S7)。ビット数分の演算が終
了していなければ、ステップS2に戻り被除数用レジス
タと部分剰余用レジスタの内容を1ビット左にシフトさ
せ、次のビットに関して同様の演算を行う。
Thereafter, it is determined whether the calculations for the number of bits of the dividend have been completed (S7). If the operation for the number of bits has not been completed, the process returns to step S2, the contents of the dividend register and the partial remainder register are shifted to the left by one bit, and the same operation is performed for the next bit.

【0018】被除数のビット数分の演算が終了すると、
被除数用レジスタに商が、部分剰余用レジスタに剰余が
求まる(S8)。次に、上記のフローチャートに基づく
具体的プログラムの一例を図11に示す。図11のリス
ト1のプログラムは、16×16ビットの符合無し2進
数の除算ルーチィンである。
When the calculation for the number of bits of the dividend is completed,
The quotient is found in the dividend register and the remainder is found in the partial remainder register (S8). Next, an example of a specific program based on the above flowchart is shown in FIG. The program in Listing 1 of FIG. 11 is a division routine for a 16×16 bit unsigned binary number.

【0019】今、被除数レジスタをAX、除数レジスタ
をBX、剰余レジスタをDXとし、除算の商は、左シフ
トにより空きの生じる被除数レジスタAXの右のビット
に順に格納されるものとする。
Assume now that the dividend register is AX, the divisor register is BX, and the remainder register is DX, and the quotient of the division is sequentially stored in the right bit of the dividend register AX, which becomes vacant by left shifting.

【0020】図11に示すように、先ず「OR  BX
,BX」、「JZ  UNSDIV9 」を実行して除
数レジスタBXが「0」でないことを調べ、「XOR 
 DX,DX」を実行して剰余レジスタDXをクリアす
る。
As shown in FIG. 11, first, "OR BX
, BX" and "JZ UNSDIV9" to check that the divisor register BX is not "0" and execute "XOR
DX, DX" to clear the remainder register DX.

【0021】次に、「SHL  AX,1」を実行し被
除数レジスタAXの内容を1ビット左に回転させる。ま
た、「RCL  DX,1」を実行して剰余レジスタD
Xの内容をキャリを通して1ビット左に回転させる。さ
らに、「SUB  DX,BX」を実行して剰余レジス
タDXの値から除数レジスタBXの値を減算する。
Next, "SHL AX, 1" is executed to rotate the contents of the dividend register AX to the left by 1 bit. Also, execute “RCL DX, 1” to set the remainder register D.
Rotate the contents of X one bit to the left through the carry. Furthermore, "SUB DX, BX" is executed to subtract the value of the divisor register BX from the value of the remainder register DX.

【0022】減算の結果、部分剰余が除数と等しいか大
きく、キャリフラグが「0」であれば、JNC命令のオ
ペランド「unsdiv2 」で指定されるアドレスに
進み、アキュムレータAL、すなわち被除数レジスタA
Xの値をインクリメントする。
As a result of the subtraction, if the partial remainder is equal to or larger than the divisor and the carry flag is "0", the process advances to the address specified by the operand "unsdiv2" of the JNC instruction and is stored in the accumulator AL, that is, the dividend register A.
Increment the value of X.

【0023】他方、部分剰余が除数より小さく、キャリ
フラグが「1」であれば、JNC命令の次の命令「AD
D  DX,BX」を実行して部分剰余DXに除数を加
算する。その後、unsdiv1 に戻り上述した処理
を繰り返す。
On the other hand, if the partial remainder is smaller than the divisor and the carry flag is "1", the next instruction "AD" after the JNC instruction is
DX, BX" to add the divisor to the partial remainder DX. Thereafter, the process returns to unsdiv1 and the above-described process is repeated.

【0024】なお、キャリフラグが「1」の場合に、部
分剰余DXに除数BXを加算しているのは、剰余レジス
タDXと除数レジスタBXとの間で減算が行われると、
減算結果が自動的に剰余レジスタDXに格納されるので
、レジスタDXの値を減算前の値に戻す為である。
Note that when the carry flag is "1", the reason why the divisor BX is added to the partial remainder DX is that when subtraction is performed between the remainder register DX and the divisor register BX,
This is to return the value of the register DX to the value before the subtraction, since the result of the subtraction is automatically stored in the remainder register DX.

【0025】[0025]

【発明が解決しようとする課題】上述したように、従来
、加減算命令を組み合わせて除算命令を実現する為には
、減算結果の正負を判別し、減算結果が負の場合には、
除数を剰余に加算する処理等(図10、■及び図11、
■の処理)が必要であった。しかもこれらの処理は、プ
ログラムのループ内に配置され、除算のビット数分繰り
返して実行されるので、命令処理時間が長くなり、除算
プログラムを高速化できない原因となっていた。
[Problems to be Solved by the Invention] As mentioned above, conventionally, in order to realize a division instruction by combining addition and subtraction instructions, it is necessary to determine whether the subtraction result is positive or negative, and when the subtraction result is negative,
Processing of adding the divisor to the remainder, etc. (Figure 10, ■ and Figure 11,
(2) was necessary. Furthermore, these processes are placed in a loop of the program and are repeatedly executed for the number of bits of the division, which increases the instruction processing time and makes it impossible to speed up the division program.

【0026】また、除算をハードウェアで実現した場合
には、除算命令DIVを使用することで、図11のリス
ト2に示すように除算プログラムは簡単となり処理は高
速となるが、ハード構成が複雑で大規模になるという問
題点があった。これらの問題は、除算に限らず平方根等
を求める演算などについても同様である。
[0026] In addition, when division is realized by hardware, by using the division instruction DIV, the division program becomes simple and the processing becomes high-speed, as shown in List 2 of Fig. 11, but the hardware configuration becomes complicated. The problem was that it became large-scale. These problems are not limited to division, but also apply to calculations such as square roots.

【0027】本発明は、加減算を組み合わせて除算を行
う演算装置に関し、除算プログラムの処理時間を短縮す
ることを目的とする。
The present invention relates to an arithmetic device that performs division by combining addition and subtraction, and an object of the present invention is to shorten the processing time of a division program.

【0028】[0028]

【課題を解決するための手段】図1は、本発明の原理説
明図ある。加減算命令を組み合わせて除算を行う演算装
置において、命令解読手段1は命令コードを解読し、演
算手段2は、命令解読手段1で解読された演算を実行す
る。
[Means for Solving the Problems] FIG. 1 is a diagram illustrating the principle of the present invention. In an arithmetic device that performs division by combining addition and subtraction instructions, an instruction decoding means 1 decodes an instruction code, and an arithmetic means 2 executes the operation decoded by the instruction decoding means 1.

【0029】レジスタ3は、上記演算手段2の演算結果
をラッチするレジスタであり、ラッチパルス生成手段4
は、演算手段2における減算の結果、セットあるいはリ
セットされるキャリフラグに基づいてレジスタ3が減算
結果をラッチするか否かを制御するラッチパルスを生成
する。
The register 3 is a register for latching the calculation result of the calculation means 2, and the latch pulse generation means 4
generates a latch pulse that controls whether or not the register 3 latches the subtraction result based on a carry flag that is set or reset as a result of the subtraction in the calculation means 2.

【0030】[0030]

【作用】演算装置では、レジスタ間の減算を行った場合
に減算結果は自動的に同じレジスタに格納される。その
為、前述した従来の2進整数の除算プログラムでは、減
算結果が負となった場合には、除数を加算して被除数レ
ジスタの値を減算前の値に戻す必要があった。
[Operation] In the arithmetic unit, when subtraction is performed between registers, the result of the subtraction is automatically stored in the same register. Therefore, in the conventional binary integer division program described above, when the result of subtraction is negative, it is necessary to add the divisor to return the value of the dividend register to the value before subtraction.

【0031】これに対して、本発明では、減算結果が負
となりキャリフラグがセットされたときには、ラッチパ
ルス生成手段4からラッチパルスが出力されず、減算結
果がレジスタ3にラッチされない。
In contrast, in the present invention, when the subtraction result is negative and the carry flag is set, no latch pulse is output from the latch pulse generating means 4, and the subtraction result is not latched into the register 3.

【0032】従って、減算結果が負となる場合にも、減
算後に同一数値を加算してレジスタ3の値を減算前の値
に戻す必要が無く、除算プログラムのステップ数を少な
くして処理を高速にすることができる。
Therefore, even if the result of subtraction is negative, there is no need to add the same value after subtraction to return the value of register 3 to the value before subtraction, and the number of steps in the division program can be reduced to speed up processing. It can be done.

【0033】[0033]

【実施例】以下、本発明の実施例を図面を参照しながら
説明する。図2は、実施例のプログラマブルコントロー
ラの演算回路の構成図である。同図いおいて、図7に示
した従来の演算回路と同じ回路ブロックには、同じ符号
を付してそれらの説明を省略する。この実施例では、通
常の減算命令(SUB)の他に、減算の結果キャリフラ
グ(CF)がセットされた場合には、減算結果をレジス
タ17にラッチしないSUBNC命令を定義してある。
Embodiments Hereinafter, embodiments of the present invention will be described with reference to the drawings. FIG. 2 is a configuration diagram of the arithmetic circuit of the programmable controller of the embodiment. In this figure, circuit blocks that are the same as those of the conventional arithmetic circuit shown in FIG. 7 are given the same reference numerals, and their explanation will be omitted. In this embodiment, in addition to the normal subtraction instruction (SUB), a SUBNC instruction is defined in which the subtraction result is not latched in the register 17 when the carry flag (CF) is set as a result of the subtraction.

【0034】図2の命令デコーダ31は、命令コードの
命令分類部11をデコードして、デコード結果をラッチ
パルス生成部32に出力すると共に、SUB命令、SU
BNC命令の演算の種類を示す情報をオアゲート33に
出力する。
The instruction decoder 31 in FIG. 2 decodes the instruction classification section 11 of the instruction code, outputs the decoding result to the latch pulse generation section 32, and also outputs the decoding result to the latch pulse generation section 32.
Information indicating the type of operation of the BNC instruction is output to the OR gate 33.

【0035】オアゲート33には、例えばSUB命令又
はSUBNC命令がデコードされたとき「1」となる信
号が入力しており、両者の論理和を取った結果を信号S
Sとして演算器19に出力する。また、この信号SSは
、ラッチパルス生成部32に出力されている。
A signal that becomes "1" when the SUB instruction or SUBNC instruction is decoded, for example, is input to the OR gate 33, and the result of the logical sum of the two is input to the signal S.
It is output as S to the arithmetic unit 19. Further, this signal SS is output to the latch pulse generation section 32.

【0036】ラッチパルス生成部32は、命令デコーダ
31のデコード結果及びR1デコーダ13のデコード結
果に基づいて、フラグレジスタ20用のラッチパルスF
LPと、複数のレジスタ17に対応したラッチパルスR
LPを生成する回路である。
The latch pulse generation unit 32 generates a latch pulse F for the flag register 20 based on the decoding result of the instruction decoder 31 and the decoding result of the R1 decoder 13.
LP and latch pulses R corresponding to multiple registers 17
This is a circuit that generates LP.

【0037】ラッチパルス生成部32は、具体的には図
3に示すような構成を有しており、命令デコーダ31で
のデコード結果はデコーダ34に入力し、命令のデコー
ド結果がフラグレジスタ20を変化させる命令の場合に
は、出力信号aを「1」とし、複数のレジスタ17の何
れかを変化させる命令の場合には、出力信号bを「1」
とし、その他の場合には出力信号a、bを「0」とする
。なお、命令デコーダ31で解読された命令がSUB命
令又はSUBNC命令であった場合には、出力信号a、
bともに「1」となる。
The latch pulse generation section 32 specifically has a configuration as shown in FIG. In the case of an instruction to change, the output signal a is set to "1", and in the case of an instruction to change any of the plurality of registers 17, the output signal b is set to "1".
In other cases, the output signals a and b are set to "0". Note that when the instruction decoded by the instruction decoder 31 is a SUB instruction or a SUBNC instruction, the output signals a,
Both b become "1".

【0038】上記デコーダ34の出力信号aは、ナンド
ゲート35の一方の入力端子に入力し、他方の入力端子
には、クロック信号CKをインバータ36で反転させた
信号が入力している。従って、デコーダ33の出力信号
aが「1」の場合には、クロック信号CKに同期した信
号が、フラグレジスタ20用のラッチパルスFLPとし
てラッチパルス生成部32から出力される。
The output signal a of the decoder 34 is input to one input terminal of a NAND gate 35, and a signal obtained by inverting the clock signal CK by an inverter 36 is input to the other input terminal. Therefore, when the output signal a of the decoder 33 is "1", a signal synchronized with the clock signal CK is outputted from the latch pulse generator 32 as the latch pulse FLP for the flag register 20.

【0039】オアゲード33(図2)の出力信号SSと
、演算の結果、「1」又は「0」となるキャリーフラグ
CFとは、ナンドゲート37に入力している。このナン
ドゲート37の出力は、アンドゲート38の一方の入力
端子に入力し、アンドゲート38の他方の入力端子には
、デコーダ34の出力信号bが入力している。このアン
ドゲート38の出力は、複数の3入力ナンドゲート39
にそれぞれ入力し、3入力ナンドゲート39の他の入力
端子には、R1のデコード結果と、クロック信号CKの
反転信号が入力している。
The output signal SS of the OR gate 33 (FIG. 2) and the carry flag CF which becomes "1" or "0" as a result of the calculation are input to the NAND gate 37. The output of this NAND gate 37 is input to one input terminal of an AND gate 38, and the output signal b of the decoder 34 is input to the other input terminal of the AND gate 38. The output of this AND gate 38 is a plurality of 3-input NAND gates 39
The decoding result of R1 and the inverted signal of the clock signal CK are input to the other input terminals of the three-input NAND gate 39.

【0040】従って、SS信号が「1」、キャリフラグ
CFが「0」のときには、ナンドゲート37の出力信号
cが「1」となり、このときデコーダ34の出力信号b
が「1」であれば、R1デコード結果により選択される
ナンドゲート39からクロック信号CKに同期したラッ
チパルスRLPがレジスタ17に供給される。
Therefore, when the SS signal is "1" and the carry flag CF is "0", the output signal c of the NAND gate 37 becomes "1", and at this time the output signal b of the decoder 34
If is "1", a latch pulse RLP synchronized with the clock signal CK is supplied to the register 17 from the NAND gate 39 selected by the R1 decoding result.

【0041】他方、SS信号が「1」、キャリフラグC
Fが「1」のときには、ナンドゲート37の出力信号c
が「0」となり、アンドゲート38の出力、すなわち3
入力ナンドゲート39の入力信号の1つが「0」となる
。この結果、3入力ナンドゲート39の出力信号RLP
は常時「1」となり、レジスタ17にラッチパルスRL
Pが供給されないこととなる。
On the other hand, the SS signal is "1" and the carry flag C
When F is "1", the output signal c of the NAND gate 37
becomes “0”, and the output of the AND gate 38, that is, 3
One of the input signals of the input NAND gate 39 becomes "0". As a result, the output signal RLP of the 3-input NAND gate 39
is always “1”, and the register 17 receives the latch pulse RL.
P will not be supplied.

【0042】ここで、SUBNC命令が実行されたとき
の演算回路の動作を、図4の動作タイムチャートを参照
して説明する。SUBNC演算の結果、被引数が引数よ
り大きくキャリフラグCFが「0」となった場合には、
上述したようにラッチパルス生成部32からフラグレジ
スタ20用ラッチパルスFLPと、レジスタ17用ラッ
チパルスRLPが、クロック信号に同期したタイミング
で出力される。そして、図4(A) に示すように、ラ
ッチパルスRLPの立ち上がりに同期して演算結果がR
1で示されるレジスタ17にラッチされ、ラッチパルス
FLPの立ち上がりに同期してキャリフラグCFがフラ
グレジスタ20にラッチされる。
The operation of the arithmetic circuit when the SUBNC instruction is executed will now be described with reference to the operation time chart of FIG. As a result of the SUBNC operation, if the argument is larger than the argument and the carry flag CF becomes "0",
As described above, the latch pulse FLP for the flag register 20 and the latch pulse RLP for the register 17 are outputted from the latch pulse generator 32 at timings synchronized with the clock signal. Then, as shown in FIG. 4(A), the calculation result R is synchronized with the rising edge of the latch pulse RLP.
The carry flag CF is latched in the register 17 indicated by 1, and the carry flag CF is latched in the flag register 20 in synchronization with the rising edge of the latch pulse FLP.

【0043】一方、被引数が引数より小さくキャリーフ
ラグCFが「1」となった場合には、ラッチパルス生成
部32からフラグレジスタ20用のラッチパルスFLP
は出力されるが、レジスタ17用ラッチパルスRLPは
出力されない。従って、図4(B) に示すようにラッ
チパルスFLPの立ち上がりに同期してキャリーフラグ
CFはフラグレジスタ20にラッチされるが、演算結果
はレジスタ17にラッチされない。
On the other hand, if the argument is smaller than the argument and the carry flag CF becomes "1", the latch pulse FLP for the flag register 20 is generated from the latch pulse generator 32.
is output, but the latch pulse RLP for the register 17 is not output. Therefore, as shown in FIG. 4B, the carry flag CF is latched in the flag register 20 in synchronization with the rise of the latch pulse FLP, but the operation result is not latched in the register 17.

【0044】次に、上記の演算回路の基で符号無し2進
整数の除算を行う場合のフローチャートを図5を参照し
て説明する。先ず、部分剰余用レジスタをクリアする(
図5、S11)。被剰余数用レジスタと部分剰余用レジ
スタのデータを1ビット左にシフトさせる(S12)。 次に、部分剰余と除数とを比較し、除数が部分剰余を超
過してなければ部分剰余用レジスタから除数用レジスタ
の値を減算する(S13)。
Next, a flowchart for performing division of unsigned binary integers using the above arithmetic circuit will be described with reference to FIG. First, clear the partial remainder register (
Figure 5, S11). The data in the remainder register and partial remainder register are shifted one bit to the left (S12). Next, the partial remainder and the divisor are compared, and if the divisor does not exceed the partial remainder, the value of the divisor register is subtracted from the partial remainder register (S13).

【0045】そして、除数の減算が行えたか否かを判別
する(S14)。除数が減算できた場合には、商として
被除数用レジスタの最下位ビットを「1」にした後(S
15)、被除数のビット数分の演算が終了したか否を判
別する(S16)。一方、減算できなかった場合には、
そのままステップS16に進みビット数分の演算が終了
したか否かを判別する。ステップS15の判別でビット
数分の演算が終了していなければステップS12に戻り
上述した処理を繰り返す。
Then, it is determined whether the divisor has been subtracted (S14). If the divisor can be subtracted, set the least significant bit of the dividend register to 1 as the quotient (S
15) It is determined whether the calculations for the number of bits of the dividend have been completed (S16). On the other hand, if subtraction is not possible,
Proceeding directly to step S16, it is determined whether or not the operations for the number of bits have been completed. If it is determined in step S15 that the calculations for the number of bits have not been completed, the process returns to step S12 and repeats the above-described process.

【0046】ビット数分の演算が終了したなら、被除数
用レジスタに商が、部分剰余用レジスタに剰余が求まる
(S17)。次に、上記のフローチャートに基づく除算
プログラムの一例を図6を参照して説明する。図6のプ
ログラムは、16ビット÷16ビットの符号無し2進整
数の除算ルーチィンである。以下、図11に示した従来
の除算ルーチンと異なる部分について説明する。
When the operations for the number of bits are completed, the quotient is found in the dividend register and the remainder is found in the partial remainder register (S17). Next, an example of a division program based on the above flowchart will be explained with reference to FIG. The program in FIG. 6 is a division routine for an unsigned binary integer of 16 bits/16 bits. Hereinafter, the differences from the conventional division routine shown in FIG. 11 will be explained.

【0047】「SHL  AX,1」、「RCL  D
X,1」を実行し、被除数用レジスタAXのデータを1
ビット左にシフトさせ、部分剰余用レジスタDXのデー
タをキャリを通して1ビット左にシフトさせる。
"SHL AX,1", "RCL D
X, 1" and set the data in the dividend register AX to 1.
The bits are shifted to the left, and the data in the partial remainder register DX is shifted to the left by 1 bit through a carry.

【0048】次に、「SUBNC  DX,BX」を実
行して部分剰余用レジスタDXから除数BXを減算する
。 部分剰余が除数より小さい場合には、減算によりキャリ
フラグが「1」となる。この結果、次の条件付ジャンプ
命令「JC  unsdiv3 」のオペランド「un
sdiv3 」で指定されるアドレスに進む。
Next, "SUBNC DX, BX" is executed to subtract the divisor BX from the partial remainder register DX. If the partial remainder is smaller than the divisor, the carry flag becomes "1" by subtraction. As a result, the operand "un" of the next conditional jump instruction "JC unsdiv3"
Proceed to the address specified by ``sdiv3''.

【0049】この場合、SUBNC命令であるので、信
号SSが「1」となり、かつ減算結果が負でキャリフラ
グが「1」となるので、ラッチパルス生成部32からは
レジスタ用のラッチパルスRLPが出力されない。従っ
て、このときの減算結果は部分剰余用レジスタDXにラ
ッチされず、減算前の値がそのまま部分剰余レジスタD
Xに保存される。
In this case, since it is a SUBNC instruction, the signal SS becomes "1", and the subtraction result is negative and the carry flag becomes "1", so the latch pulse generator 32 generates the latch pulse RLP for the register. No output. Therefore, the result of subtraction at this time is not latched in the partial remainder register DX, and the value before subtraction remains as it is in the partial remainder register D.
Saved in X.

【0050】一方、部分剰余が除数と等しいか大きい場
合には、減算結果は零又は正となりキャリフラグが「0
」となるので、上記の条件付ジャンプ命令は実行されず
、次の「INC  AL」命令が実行される。この命令
により被除数用レジスタAXの最下位ビットに「1」が
セットされ、これが除算の商となる。
On the other hand, if the partial remainder is equal to or larger than the divisor, the subtraction result will be zero or positive and the carry flag will be "0".
”, the above conditional jump instruction is not executed, and the next “INC AL” instruction is executed. This instruction sets the least significant bit of the dividend register AX to "1", which becomes the quotient of the division.

【0051】この場合、SUBNC命令であるので信号
SSは「1」となるが、キャリフラグは「0」であるの
で、ラッチパルス生成部32からレジスタ用のラッチパ
ルスRLPが出力される。これにより、このときの減算
結果が部分剰余用レジスタDXにラッチされる。
In this case, since it is a SUBNC instruction, the signal SS is "1", but since the carry flag is "0", the latch pulse generator 32 outputs the latch pulse RLP for the register. As a result, the subtraction result at this time is latched into the partial remainder register DX.

【0052】以上のように上記実施例では、減算結果が
負となる場合には、減算結果をレジスタ17にラッチす
るラッチパルスRLPを生成しないようにしたので、従
来のように減算結果が負となった場合に、減算結果に除
数を加算する処理が不要となる。例えば、図6に示す実
施例の除算ルーチィンでは、図11の従来の除算ルーチ
ィンのADD命令、JMP命令が不要となる。これらの
命令はループ命令の中にあり除算のビット数分繰り返さ
れるので、ADD命令、JMP命令を無くすことで全体
として(ADD命令の実行時間+JMP命令の実行時間
)×ビット数分の命令処理時間を削減できる。
As described above, in the above embodiment, when the subtraction result is negative, the latch pulse RLP for latching the subtraction result in the register 17 is not generated, so that unlike the conventional case, the subtraction result is negative. In this case, there is no need to add a divisor to the subtraction result. For example, in the division routine of the embodiment shown in FIG. 6, the ADD instruction and JMP instruction of the conventional division routine of FIG. 11 are unnecessary. These instructions are included in the loop instruction and are repeated for the number of bits in the division, so by eliminating the ADD and JMP instructions, the overall instruction processing time is reduced (ADD instruction execution time + JMP instruction execution time) x number of bits. can be reduced.

【0053】なお、本発明は、実施例に述べた演算回路
及びプログラムに限らず他の構成の演算回路及びプログ
ラムに適用できる。また、プログラマブルコントローラ
に限らず加減算により除算、平方根等を求める他の演算
装置に適用できる。
The present invention is not limited to the arithmetic circuits and programs described in the embodiments, but can be applied to arithmetic circuits and programs of other configurations. Furthermore, the present invention is applicable not only to programmable controllers but also to other arithmetic devices that calculate division, square roots, etc. by addition and subtraction.

【0054】[0054]

【発明の効果】本発明によれば、部分剰余から除数を減
算した減算結果が負になった場合に、その減算結果に除
数を加算する処理等が不要となるので、除算プログラム
の命令数を少なくして、全体の処理時間を短縮すること
ができる。
[Effects of the Invention] According to the present invention, when the subtraction result obtained by subtracting the divisor from the partial remainder is negative, there is no need to add the divisor to the subtraction result, so the number of instructions of the division program can be reduced. This can reduce the overall processing time.

【図面の簡単な説明】[Brief explanation of drawings]

【図1】本発明の原理説明図である。FIG. 1 is a diagram explaining the principle of the present invention.

【図2】実施例の演算回路の構成図である。FIG. 2 is a configuration diagram of an arithmetic circuit according to an embodiment.

【図3】実施例のラッチパルス生成部の構成図である。FIG. 3 is a configuration diagram of a latch pulse generation section of the embodiment.

【図4】SUBNC命令実行時の実施例の動作タイムチ
ャートである。
FIG. 4 is an operation time chart of the embodiment when a SUBNC instruction is executed.

【図5】実施例の除算プログラムのフローチャートであ
る。
FIG. 5 is a flowchart of a division program according to the embodiment.

【図6】実施例の除算プログラムの一例を示す図である
FIG. 6 is a diagram showing an example of a division program according to the embodiment.

【図7】従来の演算回路の構成図である。FIG. 7 is a configuration diagram of a conventional arithmetic circuit.

【図8】従来のラッチパルス生成部の構成図である。FIG. 8 is a configuration diagram of a conventional latch pulse generation section.

【図9】SUB命令実行時の従来例の動作タイムチャー
トである。
FIG. 9 is an operation time chart of a conventional example when executing a SUB instruction.

【図10】従来の除算プログラムのフローチャートであ
る。
FIG. 10 is a flowchart of a conventional division program.

【図11】従来の除算プログラムの一例を示す図である
FIG. 11 is a diagram showing an example of a conventional division program.

【符号の説明】[Explanation of symbols]

1    命令解読手段 2    演算手段 3    レジスタ 4    ラッチパルス生成手段 1. Instruction decoding means 2. Calculation means 3 Register 4 Latch pulse generation means

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】加減算命令を組み合わせて除算を行う演算
装置において、命令コードを解読する命令解読手段(1
) と、この命令解読手段(1) で解読された演算を
実行する演算手段(2) と、この演算手段(2) で
の演算結果をラッチするレジスタ(3) と、前記演算
手段(2) における減算によりセット、あるいはリセ
ットされるキャリフラグに基づいて前記レジスタ(3)
 に対する書き込みを制御するラッチパルスを生成する
ラッチパルス生成手段(4) とを備えたことを特徴と
する演算装置。
Claim 1: In an arithmetic unit that performs division by combining addition and subtraction instructions, an instruction decoding means (1) for decoding an instruction code is provided.
), a calculation means (2) for executing the calculation decoded by the instruction decoding means (1), a register (3) for latching the calculation result of the calculation means (2), and the calculation means (2). The register (3) is set or reset based on the carry flag set or reset by subtraction in the register (3).
An arithmetic device comprising: latch pulse generating means (4) for generating a latch pulse for controlling writing to.
JP3127941A 1991-05-30 1991-05-30 Arithmetic unit Withdrawn JPH04353925A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP3127941A JPH04353925A (en) 1991-05-30 1991-05-30 Arithmetic unit

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP3127941A JPH04353925A (en) 1991-05-30 1991-05-30 Arithmetic unit

Publications (1)

Publication Number Publication Date
JPH04353925A true JPH04353925A (en) 1992-12-08

Family

ID=14972427

Family Applications (1)

Application Number Title Priority Date Filing Date
JP3127941A Withdrawn JPH04353925A (en) 1991-05-30 1991-05-30 Arithmetic unit

Country Status (1)

Country Link
JP (1) JPH04353925A (en)

Similar Documents

Publication Publication Date Title
US4639886A (en) Arithmetic system having pipeline structure arithmetic means
US4578750A (en) Code determination using half-adder based operand comparator
US20030105793A1 (en) Long instruction word controlling plural independent processor operations
NL8900608A (en) PROGRAMMABLE PROCESSING DEVICE FOR LARGE-SCALE INTEGRATION.
JPH087084A (en) Three-input arithmetic and logic unit for formation of sum of first boolean combination of first, second and third inputs plus second boolean combination of first, second and third inputs
GB1274830A (en) Data processing system
JPS6351287B2 (en)
US4541045A (en) Microprocessor architecture employing efficient operand and instruction addressing
US5426600A (en) Double precision division circuit and method for digital signal processor
JPH0667851A (en) Multiplier provided with overflow detecting function
JPS6347827A (en) Valid response generator
JPH03286332A (en) Digital data processor
JPH09167083A (en) Division circuit for parallel processing
JPS58182754A (en) Arithmetic processor
EP0594969B1 (en) Data processing system and method for calculating the sum of a base plus offset
US6629118B1 (en) Zero result prediction
US5682342A (en) High-speed counter
JPH1091395A (en) Processor
JPH04353925A (en) Arithmetic unit
US4914581A (en) Method and apparatus for explicitly evaluating conditions in a data processor
US6266757B1 (en) High speed four-to-two carry save adder
JPH1173301A (en) Information processor
JP3114909B2 (en) Calculation error processing method of programmable controller
JPH02284225A (en) Arithmetic processor
JP2615746B2 (en) Bit operation circuit

Legal Events

Date Code Title Description
A300 Application deemed to be withdrawn because no request for examination was validly filed

Free format text: JAPANESE INTERMEDIATE CODE: A300

Effective date: 19980806