JP4626032B2 - Program conversion apparatus, program conversion method, and recording medium - Google Patents
Program conversion apparatus, program conversion method, and recording medium Download PDFInfo
- Publication number
- JP4626032B2 JP4626032B2 JP2000257184A JP2000257184A JP4626032B2 JP 4626032 B2 JP4626032 B2 JP 4626032B2 JP 2000257184 A JP2000257184 A JP 2000257184A JP 2000257184 A JP2000257184 A JP 2000257184A JP 4626032 B2 JP4626032 B2 JP 4626032B2
- Authority
- JP
- Japan
- Prior art keywords
- bit
- expression
- variable
- instruction
- object code
- 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.)
- Expired - Fee Related
Links
- 238000000034 method Methods 0.000 title claims description 26
- 230000008569 process Effects 0.000 description 22
- 238000012545 processing Methods 0.000 description 19
- 238000012360 testing method Methods 0.000 description 10
- 101100412394 Drosophila melanogaster Reg-2 gene Proteins 0.000 description 6
- 238000010586 diagram Methods 0.000 description 4
- 101001084254 Homo sapiens Peptidyl-tRNA hydrolase 2, mitochondrial Proteins 0.000 description 3
- 102100030867 Peptidyl-tRNA hydrolase 2, mitochondrial Human genes 0.000 description 3
- 230000001343 mnemonic effect Effects 0.000 description 3
- 101100272590 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) BIT2 gene Proteins 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—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
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/30007—Arrangements for executing specific machine instructions to perform operations on data operands
- G06F9/30018—Bit or string instructions
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—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
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30094—Condition code generation, e.g. Carry, Zero flag
Description
【0001】
本発明は、ソースコードファイルからRISC型CPUのためのオブジェクトコードファイルを生成するプログラム変換装置,プログラム変換方法及び前記オブジェクトコードファイルを生成させるためのプログラムを記録した記録媒体に関する。
【0002】
【従来の技術】
現在、CPUやマイクロコンピュータなどのプログラム開発は、例えばC言語やC++言語などの高級言語を用いて行われる場合が一般的である。高級言語によって記述されたソースコードは、コンパイラによってプログラム変換(コンパイル)され、CPU等が直接実行可能な命令形式(機械語)のオブジェクトコードが生成されるようになっている。コンパイラによって生成されたオブジェクトコードは、プログラムメモリに格納され、CPU等によって読み出されることで所期の処理が実行されるようになっている。
【0003】
ところで、RISC(Reduced Instruction Set Computer)型CPUは、機能が単純で実行時間が短い命令だけを使用可能とし、複数の命令の実行に伴うプロセスにおける各ステージ(フェッチ,デコード,実行,書込みなど)を複数の命令パイプラインによって並行に実行することでプログラム実行速度の高速化を図ったものである。そのため、ソースコードからコンパイラによって生成されるオブジェクトコードの容量は、CISC(Complex Instruction Set Computer)型CPUに比較して多くなる傾向を示す。
【0004】
図7は、従来のコンパイラによって生成されるオブジェクトコード(ニーモニックで表現)の例を示すプログラムリストである。ソースコードは、
bit1=bit2&bit3 …(1)
であるとする。即ち、ビット変数bit2と、ビット変数bit3との論理積をとった結果をビット変数bit1に代入する、というビット演算である。また、各ビット変数bit1〜bit3は、8ビット変数BIT1〜BIT3の第4ビット(LSBから第3ビット目)に配置されている変数であるとする。
また、図8は、(1)式のビット演算のソースコードをコンパイラが変換する場合のプロセスを示すフローチャートである。
【0005】
図7において、オブジェクトコードの▲1▼部分では、例えばメモリ上に配置された8ビット変数BIT2の内容を汎用レジスタreg1に読み出してからreg1を3ビット右シフトして、その第4ビットをLSBに位置させる。そして、レジスタreg1とマスクデータ$0001(“$”は16進数を示すシンボル)との論理積をとることで、レジスタreg1のLSB以外のビットをクリアする。ここまでが、図8のステップA1に対応する。オブジェクトコードの▲2▼部分では8ビット変数BIT3について同様の処理を行っており、図8のステップA2に対応する。
【0006】
オブジェクトコード▲3▼部分では、レジスタreg1,reg2の論理積演算を行う(図8のステップA3に対応)。続くオブジェクトコード▲4▼部分では、前記論理積演算の結果が格納されているレジスタreg1を3ビット左シフトさせると、8ビット変数BIT1の内容をレジスタreg2に読み出し、レジスタreg2とマスクデータ$fff7との論理積演算を行うことで、代入先となるレジスタreg2の第4ビットをクリアし、それ以外のビットは保存する。そして、レジスタreg1,reg2の論理和演算を行い、その論理積演算結果が格納されているレジスタreg2の内容をメモリ上の8ビット変数BIT1に転送すると(図8のステップA4に対応)、一連の演算処理が終了する。
【0007】
【発明が解決しようとする課題】
このように、RISC型CPUでは命令数が少なくビット変数の値を読み出すための専用命令がないので、他の複数の命令の組み合わせによって所期の処理を実行するようにコード変換されている。その結果、ソースコードにおいて1ステップで記述されたビット演算を実行するのに、オブジェクトコードでは18ステップを要している。従って、CPUのプログラム記憶領域をより多く必要とすることになり、また、ステップ数が多くなった分だけ処理速度が低下するという問題があった。
【0008】
本発明は上記事情に鑑みてなされたものであり、その目的は、プログラム容量をより小さくでき、且つ、処理速度を高速化できるようにオブジェクトコードファイルを生成するプログラム変換装置,プログラム変換方法及び前記オブジェクトコードファイルを生成させるためのプログラムを記録した記録媒体を提供することにある。
【0009】
請求項1記載のプログラム変換装置によれば、ソースコード中に記述されているビット演算式を、そのビット演算式の演算対象である各ビット変数の値を判定する判定命令で構成された条件判定式に変換して、前記条件判定式の真偽に応じて分岐する構成のオブジェクトコードを出力する。そして、前記条件判定式の結果が真である場合と偽である場合との夫々に対応して、ビット演算の結果が格納されるビット変数に異なる即値を代入する代入命令を含む構成のオブジェクトコードを生成することによってオブジェクトコードファイルを生成する。
【0010】
例えば、ビット演算が、ビット変数aとビット変数bとの論理積演算を行った結果をビット変数cに代入するというビット演算、即ち、
c=a&b …(2)
であるとすると、(2)式右辺に記述されたビット演算式“a&b”の結果が “1”となるのは“a=1”且つ“b=1”の場合であり、例えばC言語においてif文やwhile文などに使用される条件判定式で表現すれば、
a==1 && b==1 …(3)
となる。つまり、(2)式は、条件判定式(3)が真である場合に(2)式左辺のビット変数cに“1”を代入し、条件判定式(3)が偽である場合にビット変数cに“0”を代入することと等価であり、ビット演算式は条件判定式に置き換えることが可能である。
【0011】
従って、ソースコード中に記述されているビット演算式については、置き換えた条件判定式に基づいて、各ビット変数の値を判定し、各判定の結果に基づいて条件分岐を行うなどして、前記ビット演算の結果が格納されるビット変数に異なる即値“0,1”を代入するようにオブジェクトコードを生成すれば、ビット演算と等価な処理を行うことができる。
【0012】
即ち、ビット演算について斯様にオブジェクトコードを生成することで、RISC型CPUが実行する命令のステップ数が従来よりも短くなる。そして、一般に、CPUのプログラム中においてビット演算を行う頻度は比較的高いことから、プログラム全体として生成されるオブジェクトコードの量を少なくすることができる。そして、プログラムの容量(サイズ)を従来よりも小さくすることができると共に、RISC型CPUがビット演算を実行する場合の処理速度を高速化することが可能となる。
【0013】
請求項2記載のプログラム変換装置によれば、所謂ビットフィールドと称する複数のビット変数の集合が、レジスタ変数としてRISC型CPUに内蔵されるレジスタに割り当てられているので、ユーザはプログラミングを多様に行うことができ、RISC型CPUによる処理を効率的に行わせることが可能となる。
【0022】
【発明の実施の形態】
以下、本発明の一実施例について図1乃至図6を参照して説明する。図4は、プログラム変換装置の構成を示す図である。プログラム変換装置たるパーソナルコンピュータ(パソコン)若しくはワークステーション1には、コンパイラ2がインストールされている。具体的には、パソコン1の本体1aに内蔵されているハードディスク等の記憶装置(記憶手段)にコンパイラ2のプログラムファイルが記憶されている。
【0023】
本体1a内蔵の記憶装置には、図5に示すように、ユーザが例えばC言語などの高級言語によって記述したソースコードファイル3も記憶されている。そして、ユーザは、コンパイラ2のプログラムをパソコン1上で起動することで、ソースコードファイル3からオブジェクトコードファイル4を変換生成させる。コンパイラ2は、ソースコードファイル3に記述されているC言語のソースコードを読み出してその内容を解釈すると、CPU等が固有の命令によって対応する処理を最も効率的に実行できるようなオブジェクトコードを生成するようにコンパイルを行う。
【0024】
パソコン1の本体1aにはROMライタ5が接続されており、両者は、例えばRS−232C等のシリアル通信プロトコルによって通信が可能となっている。コンパイラ2よって生成されたオブジェクトコードファイル4はROMライタ5に転送されると、ROMライタ5にセットされたマイクロコンピュータ(マイコン)6に内蔵されているプログラムメモリ7(図6参照)にバイナリデータとして書き込まれるようになっている。
【0025】
図6は、マイコン6の電気的構成を示す機能ブロック図である。マイコン6は、RISC型のCPU8,EEPROMやフラッシュROMなどからなるプログラムメモリ7及びSRAMなどからなる内部メモリ9を備え、ワンチップマイコンとして構成されている。また、マイコン6の外部には、DRAMなどからなる外部メモリ10が接続されている。CPU8と、プログラムメモリ7,内部メモリ9及び外部メモリ10は、アドレスバス11及びデータバス12を介して接続されている。
【0026】
CPU8の内部には、演算等を行うための演算部(ALU(Alithmetic Logical Unit) )13,演算部13が演算等を行う場合に使用される複数のレジスタが配置されているレジスタ部14,及びレジスタ部14等にロード/ストア等の制御を行うための制御部15などが配置されている。
【0027】
また、CPU8は、前提構成として固有の命令に、少なくとも、
ビットテスト命令 : tst(.b/w/l)
ビットセット命令 : set(.b/w/l)
ビットクリア命令 : clr(.b/w/l)
を備えている。
【0028】
ビットテスト命令は、指定されたビット変数の値をテスト(判定)する命令であり、そのテスト結果“0,1”は、CPU8のレジスタ部14内にあるコンディションコードレジスタ(CCR)のZフラグに制御部15によって反映されるようになっている。即ち、テスト結果が“0”であれば、CCRのZフラグがセットされ、テスト結果が“1”であればZフラグはクリアされる。
【0029】
また、このビットテスト命令は、ユーザの定義などによりビット変数がメモリに割り当てられている場合と、レジスタ部14内の汎用レジスタに割り当てられている場合との何れであっても実行することが可能である。(.b/w/l)は、メモリ上のビット変数をテスト等する場合のアクセスサイズを指定するものであり、(バイト(8)/ワード(16)/ロングワード(32))に対応する。尚、レジスタ上のビット変数をテスト等する場合は、アクセスサイズの指定は不要である。
また、ビットセット命令は、指定されたビット変数に即値“1”を代入する命令であり、ビットクリア命令は、指定されたビット変数に即値“0”を代入する命令である。
【0030】
次に、本実施例の作用について図1乃至図3をも参照して説明する。図1は、コンパイラ2がビット演算に関するコンパイル処理を行う場合のプロセスを示すフローチャートである。先ず、コンパイラ2は、C言語で記述された右辺のビット演算式を解釈(デコード)すると、ブール代数規則に基づき結果が1(真)または0(偽)となる条件判定式に変換する。そして、その条件判定式に対応するオブジェクトコードを出力する(ステップS1)。
【0031】
次に、コンパイラ2は、条件判定式が真であった場合に、ビット演算式の結果が代入される左辺のビット変数に“1”若しくは“0”(異なる即値)を代入するためのコードを生成し、それから、処理終了へ分岐するためのコードを生成する(ステップS2)。それから、条件判定式が偽であった場合に、ビット演算式の結果が代入される左辺のビット変数に“0”若しくは“1”を代入するためのコードを生成すると(ステップS3)と、処理終了となる。
【0032】
ここで、図2は、図1のフローチャートに基づいて、具体的に(1)式のビット演算をコンパイル処理してオブジェクトコードを生成する場合のフローチャートであり、図3は、図2のフローチャートに従うコンパイル処理によって生成されるオブジェクトコードをニーモニックで示すプログラムリストである。
【0033】
(1)式右辺に記述されたビット演算式“bit2&bit3”の結果が“1”となるのは、“bit2=1”且つ“bit3=1”の場合であり、C言語における条件判定式で表現すると、
bit2==1 && bit3==1 …(4)
となる。従って、(1)式は、条件判定式(4)が真である場合に(1)式左辺のビット変数bit1に“1”を代入し、条件判定式(4)が偽である場合にビット変数bit1に“0”を代入することと等価である。
【0034】
そこで、図2においては、先ずビット変数bit2の値を判定し(ステップB1)、その値が“0”であればビット変数bit1に“0”を書き込んで(ステップB3)処理を終了する。また、ビット変数bit2の値が“1”である場合はビット変数bit1の値を判定し(ステップB2)、その値が“0”であればステップB3に移行し、ビット変数bit1の値が“1”であればビット変数bit1に“1”を書き込んで(ステップB4)処理を終了する。
【0035】
即ち、図2のフローチャートでは、ステップB1,B2が図1のステップS1に基づく処理であり、ステップB1,B2の何れかよりステップB3に移行するケースが条件判定式(4)が偽である場合に対応する。そして、ステップB3は、図1のステップS3に基づく処理である。また、ステップB2よりステップB4に移行するケースが条件判定式(4)が真である場合に対応し、ステップB4は、図1のステップS2に基づく処理である。
【0036】
次に、実際のコンパイル処理結果のプログラムリストである図3を参照すると、ステップ▲1▼でビット変数bit2の値を判定し、ステップ▲2▼ではその値が“0”であればラベルLOO1に分岐させる(ステップB1に対応)。例えば、ビット変数bit2の値が“0”であれば、前述したように、CPU8のレジスタ部14内にあるCCRのZフラグがセットされ、ステップ▲2▼での条件判定は真となる。
【0037】
次のステップ▲3▼,▲4▼では、ビット変数bit3に関してステップ▲1▼,▲2▼と同様の処理を行う(ステップB2に対応)。以上のステップ▲1▼〜▲4▼が図1のステップS1を実行した結果であり、条件判定式(4)に対応して出力されたオブジェクトコードとなる。そして、ステップ▲2▼,▲4▼の何れかにおいてラベルLOO1に分岐するケースが、条件判定式の結果が偽の場合に対応する。また、ステップ▲2▼,▲4▼の何れにおいてもラベルLOO1に分岐することなく、次のステップ▲5▼を実行するケースが、条件判定式の結果が真の場合に対応する。
【0038】
条件判定式の結果が真の場合に対応するステップ▲5▼では、ビット変数bit1に“1”をセットし、このビット演算処理を終了するためにラベルLOO2に分岐する(ステップ▲6▼)。この部分が図1のステップS2を実行した結果であり、図2ではステップB4に対応する。
また、条件判定式の結果が偽の場合に対応するステップ▲7▼では、ビット1をゼロクリアして処理を終了する。この部分が図1のステップS3を実行した結果であり、図2ではステップB3に対応する。
【0039】
斯様にコンパイラ2によって生成されたオブジェクトコードのサイズは、図7に示す従来のコンパイラによって生成されたコードのサイズに比較すると大幅に縮小されている。
【0040】
以上のようにコンパイラ2によってコンパイル処理が行われた結果生成されたオブジェクトコードファイル4は、上述のようにパソコン1よりROMライタ5に転送され、ROMライタ5にセットされたマイコン6内蔵のプログラムメモリ7にバイナリデータとして書き込まれる。
【0041】
そして、マイコン6のCPU8は、プログラムメモリ7に記憶されたオブジェクトコードをプログラムとして読み出して実行する。尚、ビット変数bit1〜bit3は、ユーザの定義により内部メモリ9,外部メモリ10またはレジスタ部14内の汎用レジスタなどの何れに配置されているものでも構わない。ビット変数が汎用レジスタ上に割り付けられている場合は、例えば、図3のステップ▲1▼における“tst.b bit2”に代えて、“tst bit2”がオブジェクトコードとして生成される。
【0042】
ところで、例えば、ビット変数bit2が内部メモリ9上に配置されている場合、図3のステップ▲1▼における“tst.b bit2”を実行すると、CPU8の演算部13は、内部メモリ9よりビット変数bit2の内容を読み出して判定を行う。この場合、例えば、図6に示すコードの“mov BIT2,reg1”などの命令が1クロック(CPU8の動作クロック)で実行可能であるとすると、“tst.b bit2”の実行には2〜3クロックを要することになるが、コードサイズの全体が大幅に縮小されているので、トータルでの処理時間は短縮される。
【0043】
以上のように本実施例によれば、パソコン1の本体1aにインストールされたコンパイラ2は、プログラムとして記述されたソースコードファイル3のソースコード中に記述されているビット演算式を、演算対象である各ビット変数bit2,bit3の値に基づいて条件を判定する式に変換し、その判定式の結果が真である場合と偽である場合との夫々に対応して、ビット演算の結果が格納されるビット変数bit1に異なる即値“0,1”を夫々代入する処理を行うようにオブジェクトコードを生成し、RISC型CPU8に最適なオブジェクトコードファイル4を出力するようにした。
【0044】
従って、CPU8が実行する命令のステップ数が従来よりも短くなり、プログラム全体として生成されるオブジェクトコードの量が少なくなるので、プログラムの容量を従来よりも小さくすることができると共に、CPU8がビット演算を実行する場合の処理速度を高速化することが可能となる。
【0045】
また、マイコン6のプログラムメモリ7には、コンパイラ2によってコード変換されたプログラムが記憶され、マイコン6のCPU8は、プログラムメモリ7に記憶されたオブジェクトコードをプログラムとして読み出して実行するので、CPU8が実行する命令のステップ数が従来よりも短くなって、プログラム全体として生成されるオブジェクトコードの量が少なくなり、プログラムメモリ7の容量を従来よりも小さくすることができる。そして、CPU8がビット演算を実行する場合の処理速度が高速化されるので、マイコン6の処理能力を向上させることができる。
【0046】
本発明は上記し且つ図面に記載した実施例にのみ限定されるものではなく、次のような変形または拡張が可能である。
ビット演算式は、論理積に限ることなく、論理和や排他的論理和などを行うものでも良い。その場合、論理の違いに応じて、条件分岐コマンド“beq”に代えて“bne(not equal)”などをオブジェクトコードとして生成すれば良い。
また、ソースコードにおいて複数のビット変数の集合,所謂ビットフィールドがレジスタ変数としてCPU8のレジスタ部14に割り当てている場合であっても、コンパイラ2は、ビットテスト命令によってビットフィールドの各ビット変数毎に値の判定を行うようにコードを出力する。従って、ユーザはプログラミングを多様に行うことができ、CPU8による処理を効率的に行わせることが可能となる。
【0047】
プログラムメモリ7に対するプログラムデータの書き込みは、ROMライタ5を使用するものに限らない。例えば、マイコン6側にRS−232C等のシリアル通信インターフェイスを設けて、パソコン1側よりマイコン6にプログラムデータを直接送信することで、CPU8によってプログラムデータをプログラムメモリ7に書き込ませるようにしても良い。
コンパイラ2のプログラムを、CD−ROM,フロッピーディスクやMOディスク等の記録媒体に記憶させても良く、また、そのような記録媒体に記憶されている状態で、パソコン1の主記憶上にプログラムを読み出してコンパイル処理を行っても良い。
マイクロコンピュータとしては、マイコン6のようなワンチップマイコンに限ることなく、CPU8とプログラムメモリ7とが夫々独立のチップとして形成されて同一のプリント基板上に搭載されているようなマイクロコンピュータであっても良い。この場合、ROMライタ5には、プログラムメモリ7のみを接続してプログラムデータを書き込むようにすれば良い。
また、プログラムメモリは、書き替え可能なメモリに限らず、例えばマスクROMなどの書き替え不可能なメモリを用いても良い。
【図面の簡単な説明】
【図1】本発明の一実施例であり、コンパイラがビット演算に関するコンパイル処理を行う場合のプロセスを示すフローチャート
【図2】図1のフローチャートに基づいて、コンパイラが(1)式のビット演算をコンパイル処理してオブジェクトコードを生成する場合のフローチャート
【図3】図2のフローチャートに従うコンパイル処理によって生成されるオブジェクトコードをニーモニックで示すプログラムリスト
【図4】プログラム変換装置たるパーソナルコンピュータ若しくはワークステーションの構成を示す図
【図5】コンパイラが、ソースコードファイルからオブジェクトコードファイルを変換生成する処理を概念的に示す図
【図6】マイクロコンピュータの電気的構成を示す機能ブロック図
【図7】従来技術を示す図3相当図
【図8】(1)式のビット演算のソースコードを、従来のコンパイラが変換する場合のプロセスを示すフローチャート
【符号の説明】
1はパーソナルコンピュータ若しくはワークステーション(プログラム変換装置)、2はコンパイラ、3はソースコードファイル、4はオブジェクトコードファイル、6はマイクロコンピュータ、7はプログラムメモリ、8はCPUを示す。[0001]
The present invention relates to a recording medium recording a program for an object code generated to Help program conversion apparatus the file to produce a program transformation method and the object code files for the RISC CPU from source Sukodo file.
[0002]
[Prior art]
Currently, the development of programs such as CPUs and microcomputers is generally performed using high-level languages such as C language and C ++ language. The source code described in a high-level language is converted into a program (compiled) by a compiler, and an object code in an instruction format (machine language) that can be directly executed by a CPU or the like is generated. The object code generated by the compiler is stored in a program memory, and is read out by a CPU or the like, so that an intended process is executed.
[0003]
By the way, a RISC (Reduced Instruction Set Computer) type CPU makes it possible to use only instructions having a simple function and a short execution time, and each stage (fetch, decode, execute, write, etc.) in a process accompanying execution of a plurality of instructions. The program execution speed is increased by executing in parallel by a plurality of instruction pipelines. Therefore, the capacity of the object code generated by the compiler from the source code tends to be larger than that of a CISC (Complex Instruction Set Computer) type CPU.
[0004]
FIG. 7 is a program list showing an example of object code (expressed in mnemonics) generated by a conventional compiler. The source code is
bit1 = bit2 & bit3 (1)
Suppose that That is, it is a bit operation of substituting the result of logical product of the bit variable bit2 and the bit variable bit3 into the bit variable bit1. Each bit variable bit1 to bit3 is a variable arranged in the fourth bit (the third bit from the LSB) of the 8-bit variable BIT1 to BIT3.
FIG. 8 is a flowchart showing a process when the compiler converts the source code of the bit operation of equation (1).
[0005]
In FIG. 7, in the portion (1) of the object code, for example, the contents of the 8-bit variable BIT2 arranged in the memory are read to the general register reg1, and then reg1 is shifted right by 3 bits, and the fourth bit is set to LSB. Position. Then, by taking the logical product of the register reg1 and the mask data $ 0001 ("$" is a symbol indicating a hexadecimal number), bits other than the LSB of the register reg1 are cleared. The steps so far correspond to step A1 in FIG. In the portion (2) of the object code, the same processing is performed for the 8-bit variable BIT3, which corresponds to step A2 in FIG.
[0006]
In the object code {circle around (3)}, the logical product operation of the registers reg1 and reg2 is performed (corresponding to step A3 in FIG. 8). In the subsequent object code {circle over (4)}, when the register reg1 storing the result of the logical product operation is shifted left by 3 bits, the contents of the 8-bit variable BIT1 are read into the register reg2, and the register reg2 and the mask data $ fff7 Is performed, the fourth bit of the register reg2 to be substituted is cleared, and the other bits are saved. Then, the logical sum operation of the registers reg1 and reg2 is performed, and the content of the register reg2 storing the logical product operation result is transferred to the 8-bit variable BIT1 on the memory (corresponding to step A4 in FIG. 8). The calculation process ends.
[0007]
[Problems to be solved by the invention]
As described above, since the RISC type CPU has a small number of instructions and no dedicated instruction for reading the value of the bit variable, the code conversion is performed so that a desired process is executed by a combination of other plural instructions. As a result, 18 steps are required in the object code to execute the bit operation described in one step in the source code. Accordingly, there is a problem that a larger program storage area of the CPU is required, and the processing speed is reduced by the increase in the number of steps.
[0008]
The present invention has been made in view of the above circumstances, and its object is able smaller program size and the processing speed can be faster to generate object code files Help program conversion apparatus, the program conversion method And providing a recording medium on which a program for generating the object code file is recorded .
[0009]
According to the program conversion apparatus according to claim 1, the bit arithmetic expression is described in a source Sukodo, conditions determined composed determination instruction value of each bit variable is the bit arithmetic expression operand An object code that is converted into an expression and branches according to whether the condition determination expression is true or false is output . The object of the configuration including the assignment instruction where the condition determination expression results in response to people husband and when the case and false true and substituted into different immediate bit variable the result of bit operation is stored Generate an object code file by generating code .
[0010]
For example, a bit operation in which a bit operation assigns a result obtained by performing an AND operation between the bit variable a and the bit variable b to the bit variable c, that is,
c = a & b (2)
If the result of the bit operation expression “a & b” described on the right side of the expression (2) is “1”, it is in the case of “a = 1” and “b = 1”. If it is expressed by a condition judgment expression used in an if sentence or a while sentence,
a == 1 && b == 1 (3)
It becomes. That is, equation (2) substitutes “1” for the bit variable c on the left side of equation (2) when condition judgment equation (3) is true, and bit when condition judgment equation (3) is false. This is equivalent to substituting “0” for the variable c, and the bit operation expression can be replaced with a condition determination expression.
[0011]
Therefore, for the bit operation expression described in the source code, the value of each bit variable is determined based on the replaced condition determination expression, and conditional branching is performed based on the result of each determination. If the object code is generated so that different immediate values “0, 1” are substituted into the bit variable in which the result of the bit operation is stored, processing equivalent to the bit operation can be performed.
[0012]
That is, by generating the object code in this way for the bit operation, the number of steps of the instruction executed by the RISC type CPU becomes shorter than before. In general, since the frequency of performing bit operations in a CPU program is relatively high, the amount of object code generated as a whole program can be reduced. In addition, the capacity (size) of the program can be made smaller than before, and the processing speed when the RISC type CPU executes the bit operation can be increased.
[0013]
According to the program conversion apparatus according to
[0022]
DETAILED DESCRIPTION OF THE INVENTION
An embodiment of the present invention will be described below with reference to FIGS. FIG. 4 is a diagram showing the configuration of the program conversion apparatus. A
[0023]
As shown in FIG. 5, a
[0024]
A ROM writer 5 is connected to the
[0025]
FIG. 6 is a functional block diagram showing an electrical configuration of the
[0026]
Inside the CPU 8, an arithmetic unit (ALU (Alithmetic Logical Unit)) 13 for performing arithmetic operations, a
[0027]
Further, the CPU 8 sends at least a command unique to the premise configuration,
Bit test instruction: tst (.b / w / l)
Bit set instruction: set (.b / w / l)
Bit clear instruction: clr (.b / w / l)
It has.
[0028]
The bit test instruction is an instruction for testing (determining) the value of a designated bit variable, and the test result “0, 1” is stored in the Z flag of the condition code register (CCR) in the
[0029]
The bit test instruction can be executed regardless of whether a bit variable is allocated to the memory or a general-purpose register in the
The bit set instruction is an instruction for assigning an immediate value “1” to a designated bit variable, and the bit clear instruction is an instruction for assigning an immediate value “0” to a designated bit variable.
[0030]
Next, the operation of the present embodiment will be described with reference to FIGS. FIG. 1 is a flowchart showing a process when the
[0031]
Next, when the condition judgment expression is true, the
[0032]
Here, FIG. 2 is a flowchart in the case where object code is generated by specifically compiling the bit operation of the expression (1) based on the flowchart of FIG. 1, and FIG. 3 follows the flowchart of FIG. It is a program list which shows the object code produced | generated by a compile process by mnemonic.
[0033]
The result of the bit operation expression “bit2 & bit3” described on the right side of the expression (1) is “1” in the case of “bit2 = 1” and “bit3 = 1”, and is expressed by a condition determination expression in C language. Then
bit2 == 1 && bit3 == 1 (4)
It becomes. Therefore, the expression (1) substitutes “1” for the bit variable bit1 on the left side of the expression (1) when the condition determination expression (4) is true, and the bit when the condition determination expression (4) is false. This is equivalent to substituting “0” into the variable bit1.
[0034]
Therefore, in FIG. 2, first, the value of the bit variable bit2 is determined (step B1). If the value is “0”, “0” is written in the bit variable bit1 (step B3), and the process is terminated. If the value of the bit variable bit2 is “1”, the value of the bit variable bit1 is determined (step B2). If the value is “0”, the process proceeds to step B3, and the value of the bit variable bit1 is “0”. If “1”, “1” is written in the bit variable bit1 (step B4), and the process is terminated.
[0035]
That is, in the flowchart of FIG. 2, when steps B1 and B2 are processing based on step S1 of FIG. 1, the condition determination formula (4) is false in the case of shifting to either step B1 or B2 to step B3 Corresponding to Step B3 is processing based on step S3 in FIG. Further, the case where the process proceeds from step B2 to step B4 corresponds to the case where the condition determination formula (4) is true, and step B4 is a process based on step S2 in FIG.
[0036]
Next, referring to FIG. 3 which is a program list of actual compilation processing results, the value of the bit variable bit2 is determined in step {circle around (1)}. If the value is “0” in step {circle around (2)}, the label LOO1 is displayed. Branch (corresponding to step B1). For example, if the value of the bit variable bit2 is “0”, as described above, the Z flag of the CCR in the
[0037]
In the next steps (3) and (4), the same processing as in steps (1) and (2) is performed for the bit variable bit3 (corresponding to step B2). Steps {circle around (1)} to {circle around (4)} above are the results of executing step S1 in FIG. 1, and become the object code output corresponding to the condition determination formula (4). Then, the case of branching to the label LOO1 in any one of steps (2) and (4) corresponds to the case where the result of the condition determination formula is false. Further, the case of executing the next step (5) without branching to the label LOO1 in any of the steps (2) and (4) corresponds to the case where the result of the condition determination formula is true.
[0038]
In step {circle around (5)} corresponding to the case where the result of the condition judgment expression is true, “1” is set to the bit variable bit1, and the process branches to the label LOO2 to end this bit operation processing (step {circle around (6)}). This part is the result of executing step S2 in FIG. 1, and corresponds to step B4 in FIG.
In step {circle around (7)} corresponding to the case where the result of the condition determination expression is false, bit 1 is cleared to zero and the process is terminated. This part is the result of executing step S3 in FIG. 1, and corresponds to step B3 in FIG.
[0039]
Thus, the size of the object code generated by the
[0040]
As described above, the object code file 4 generated as a result of the compiling process by the
[0041]
Then, the CPU 8 of the
[0042]
By the way, for example, when the bit
[0043]
As described above, according to the present embodiment, the
[0044]
Accordingly, the number of steps executed by the CPU 8 is shorter than before, and the amount of object code generated as a whole program is reduced. Therefore, the capacity of the program can be made smaller than before, and the CPU 8 can perform bit operations. It is possible to increase the processing speed when executing.
[0045]
Further, the program memory 7 of the
[0046]
The present invention is not limited to the embodiments described above and illustrated in the drawings, and the following modifications or expansions are possible.
The bit arithmetic expression is not limited to the logical product but may be a logical sum or an exclusive logical sum. In this case, “bne (not equal)” or the like may be generated as an object code instead of the conditional branch command “beq” according to the difference in logic.
Even if a set of bit variables in the source code, a so-called bit field, is assigned to the
[0047]
Writing program data to the program memory 7 is not limited to using the ROM writer 5. For example, a serial communication interface such as RS-232C may be provided on the
The program of the
The microcomputer is not limited to a one-chip microcomputer such as the
The program memory is not limited to a rewritable memory, and a non-rewritable memory such as a mask ROM may be used.
[Brief description of the drawings]
FIG. 1 is a flowchart showing a process in a case where a compiler performs a compile process related to a bit operation according to an embodiment of the present invention. FIG. 2 is a flowchart illustrating a bit operation of an expression (1) based on the flowchart of FIG. Flowchart when generating object code by compiling processing [FIG. 3] FIG. 4 is a program list showing mnemonic object code generated by compiling processing according to the flowchart of FIG. 2 [FIG. 4] Configuration of personal computer or workstation as program conversion device FIG. 5 is a diagram conceptually showing a process in which a compiler converts and generates an object code file from a source code file. FIG. 6 is a functional block diagram showing an electrical configuration of a microcomputer. Figure 3 equivalent figure 8 (1) the source code for bit operations expression, the flowchart [code indicating the process where conventional compiler converts]
1 is a personal computer or workstation (program conversion device), 2 is a compiler, 3 is a source code file, 4 is an object code file, 6 is a microcomputer, 7 is a program memory, and 8 is a CPU.
Claims (6)
前記ソースコード中に記述されているビット演算式を、前記ビット演算式の演算対象である各ビット変数の値を判定する判定命令で構成された条件判定式に変換して、前記条件判定式の真偽に応じて分岐する構成のオブジェクトコードを出力するとともに、
前記条件判定式の結果が真である場合と偽である場合との夫々に対応して、前記ビット演算の結果が格納されるビット変数に異なる即値を代入する代入命令を含む構成のオブジェクトコードを生成することによって、
前記オブジェクトコードファイルを生成することを特徴とするプログラム変換装置。Reads the source code from the source over the scan code file for the RISC CPU with at least includes instruction sets and assignment instruction for assigning the immediate relative judgment instruction and before Symbol bit variable determines the value of the bit variable In a program conversion device for generating an object code file ,
The bit arithmetic expression that is described in the source code, and converts the bit arithmetic expression condition judgment equation configured with determination instruction value of each bit variable which is the operation target of the condition determination formula Output the object code of the structure that branches according to authenticity,
And the condition determination expression results corresponding to s husband and when the case and the false true, object code of the configuration including the assignment instruction where the result of the bitwise operation is entering a different immediate bit variables stored cash by generating,
A program conversion apparatus for generating the object code file .
前記ソースコード中に記述されているビット演算式を、前記ビット演算式の演算対象である各ビット変数の値を判定する判定命令で構成された条件判定式に変換して、前記条件判定式の真偽に応じて分岐する構成のオブジェクトコードを出力する工程と、
前記条件判定式の結果が真である場合と偽である場合との夫々に対応して、前記ビット演算の結果が格納されるビット変数に異なる即値を代入する代入命令を含む構成のオブジェクトコードを生成する工程と、
によって、前記オブジェクトコードファイルを生成することを特徴とするプログラム変換方法。 Read the source code from the source code file and generate an object code file for a RISC type CPU having an instruction set including at least a determination instruction for determining the value of the bit variable and an assignment instruction for assigning an immediate value to the bit variable. In a program conversion method executed by a computer,
The bit operation expression described in the source code is converted into a condition determination expression configured by a determination instruction for determining the value of each bit variable that is an operation target of the bit operation expression, and the condition determination expression A step of outputting an object code configured to branch according to authenticity;
Corresponding to the case where the result of the condition judgment expression is true and the case where it is false, an object code including an assignment instruction for assigning a different immediate value to a bit variable in which the result of the bit operation is stored Generating step;
To generate the object code file .
前記プログラムは、前記コンピュータに、
前記ソースコード中に記述されているビット演算式を、前記ビット演算式の演算対象である各ビット変数の値を判定する判定命令で構成された条件判定式に変換して、前記条件判定式の真偽に応じて分岐する構成のオブジェクトコードを出力する工程と、
前記条件判定式の結果が真である場合と偽である場合との夫々に対応して、前記ビット演算の結果が格納されるビット変数に異なる即値を代入する代入命令を含む構成のオブジェクトコードを生成する工程と、
を実行させることによって、前記オブジェクトコードファイルを生成させるためのものであることを特徴とする記録媒体。 A RISC type CPU having an instruction set including at least a determination instruction for reading a source code from a source code file and determining a value of a bit variable and an assignment instruction for assigning an immediate value to the bit variable. In a computer-readable recording medium on which a program for generating an object code file is recorded,
The program is stored in the computer.
The bit operation expression described in the source code is converted into a condition determination expression configured by a determination instruction for determining the value of each bit variable that is an operation target of the bit operation expression, and the condition determination expression A step of outputting an object code configured to branch according to authenticity;
Corresponding to the case where the result of the condition judgment expression is true and the case where it is false, an object code including an assignment instruction for assigning a different immediate value to a bit variable in which the result of the bit operation is stored Generating step;
A recording medium for generating the object code file by executing
Priority Applications (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2000257184A JP4626032B2 (en) | 2000-08-28 | 2000-08-28 | Program conversion apparatus, program conversion method, and recording medium |
US09/935,686 US6934941B2 (en) | 2000-08-28 | 2001-08-24 | Compiler for generating risc object code whereby operations on bit variables written in source code are executed by processing based on bit judgement operations to thereby reduce the amount of object code |
DE10141999A DE10141999A1 (en) | 2000-08-28 | 2001-08-28 | Compiler for generating RISC machine code, where operations are performed on BIT variables written in the source code by processing based on BIT judgment operations to reduce the size of the machine code |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2000257184A JP4626032B2 (en) | 2000-08-28 | 2000-08-28 | Program conversion apparatus, program conversion method, and recording medium |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2002073346A JP2002073346A (en) | 2002-03-12 |
JP4626032B2 true JP4626032B2 (en) | 2011-02-02 |
Family
ID=18745689
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2000257184A Expired - Fee Related JP4626032B2 (en) | 2000-08-28 | 2000-08-28 | Program conversion apparatus, program conversion method, and recording medium |
Country Status (3)
Country | Link |
---|---|
US (1) | US6934941B2 (en) |
JP (1) | JP4626032B2 (en) |
DE (1) | DE10141999A1 (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7725694B2 (en) * | 2004-12-21 | 2010-05-25 | Denso Corporation | Processor, microcomputer and method for controlling program of microcomputer |
CN104756138B (en) * | 2012-10-31 | 2017-08-11 | 英派尔科技开发有限公司 | Information coding method, system and equipment |
JP6366033B2 (en) * | 2014-05-09 | 2018-08-01 | インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation | Optimization method of IF statement in program |
JP6579095B2 (en) | 2016-12-22 | 2019-09-25 | トヨタ自動車株式会社 | Program writing method, apparatus control method, program writing program, and apparatus control program |
EP3428792B1 (en) * | 2017-07-10 | 2022-05-04 | Arm Ltd | Testing bit values inside vector elements |
US11662988B2 (en) * | 2020-09-29 | 2023-05-30 | Shenzhen GOODIX Technology Co., Ltd. | Compiler for RISC processor having specialized registers |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS58166443A (en) * | 1982-03-27 | 1983-10-01 | Fujitsu Ltd | Logical arithmetic control system |
JP2868122B2 (en) * | 1987-11-05 | 1999-03-10 | 富士通株式会社 | Logical expression evaluation order determination method |
US5045992A (en) | 1988-10-19 | 1991-09-03 | Hewlett-Packard Company | Apparatus for executing instruction regardless of data types and thereafter selectively branching to other instruction upon determining of incompatible data type |
JP2001202243A (en) * | 1999-04-30 | 2001-07-27 | Hitachi Ltd | Data processor |
-
2000
- 2000-08-28 JP JP2000257184A patent/JP4626032B2/en not_active Expired - Fee Related
-
2001
- 2001-08-24 US US09/935,686 patent/US6934941B2/en not_active Expired - Fee Related
- 2001-08-28 DE DE10141999A patent/DE10141999A1/en not_active Ceased
Also Published As
Publication number | Publication date |
---|---|
DE10141999A1 (en) | 2002-05-08 |
JP2002073346A (en) | 2002-03-12 |
US6934941B2 (en) | 2005-08-23 |
US20020042695A1 (en) | 2002-04-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CA2082070C (en) | Branch resolution via backward symbolic execution | |
EP0528028B1 (en) | Automatic flowgraph generation for program analysis and translation | |
JP5118745B2 (en) | Vectorization of memory access instructions | |
AU2256692A (en) | Cross-image referencing of program code | |
JPH01201729A (en) | Decoding | |
US6738966B1 (en) | Compiling device, computer-readable recording medium on which a compiling program is recorded and a compiling method | |
JP4026940B2 (en) | Program converter | |
JP4626032B2 (en) | Program conversion apparatus, program conversion method, and recording medium | |
EP0947922B1 (en) | Compiler | |
JP2004086837A (en) | Data processor | |
US20010044930A1 (en) | Loop optimization method and a compiler | |
US5694605A (en) | Program translator with selective data value amendment and processor with data extension instructions | |
JP2009020695A (en) | Information processing apparatus and system | |
JP2004038279A (en) | Compiler, arithmetic operation system and arithmetic operation method | |
JP3264901B2 (en) | Compiling device and compiling method | |
JP2002182926A (en) | Compiling method and computer readable recording medium | |
US20040064301A1 (en) | Software development system, simulator, and recording medium | |
JP3692884B2 (en) | Program processing method and recording medium | |
JP2607319B2 (en) | Programmable controller | |
JPH1165622A (en) | Programmable controller | |
Nonaka et al. | Design and Implementation of Superinstructions for JavaScript Virtual Machine Generation System for Embedded Systems eJSTK | |
JP2002182925A (en) | Compiling method and computer readable recording medium | |
JP3754222B2 (en) | assembler | |
JP5910197B2 (en) | Embedded program development apparatus, compilation method, and compiler program | |
JPH06282444A (en) | Compilation method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20070510 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20091116 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20100817 |
|
A521 | Request for written amendment filed |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20100924 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20101012 |
|
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20101025 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20131119 Year of fee payment: 3 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20131119 Year of fee payment: 3 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
R250 | Receipt of annual fees |
Free format text: JAPANESE INTERMEDIATE CODE: R250 |
|
LAPS | Cancellation because of no payment of annual fees |