JPH01216429A - Microcomputer - Google Patents
MicrocomputerInfo
- Publication number
- JPH01216429A JPH01216429A JP4274588A JP4274588A JPH01216429A JP H01216429 A JPH01216429 A JP H01216429A JP 4274588 A JP4274588 A JP 4274588A JP 4274588 A JP4274588 A JP 4274588A JP H01216429 A JPH01216429 A JP H01216429A
- Authority
- JP
- Japan
- Prior art keywords
- memory
- instruction
- subroutine
- program
- stack
- 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.)
- Pending
Links
Landscapes
- Executing Machine-Instructions (AREA)
Abstract
Description
【発明の詳細な説明】
〔産業上の利用分野〕
本発明はマイクロコンピュータ夕に関し、特に複数段の
ネスティング・レベルでサブルーチン参照を行ない、そ
のサブルーチンからの復帰方式を改良したマイクロコン
ピュータに関する。DETAILED DESCRIPTION OF THE INVENTION [Field of Industrial Application] The present invention relates to a microcomputer, and more particularly to a microcomputer that references a subroutine at multiple nesting levels and has an improved method for returning from the subroutine.
通常、マイクロコンピュータ(以下、マイコンと称す)
は、プログラム内からサブルーチンを呼び出すめの命令
(以下、CALL命令と称す)およびそのサブルーチン
から復帰するための命令(以下、RET命令と称す)を
備えている。ここでは、特にかかるCALL命令および
RET命令実行時のマイコンの動作を説明する。Usually, a microcomputer (hereinafter referred to as a microcomputer)
The program includes an instruction for calling a subroutine from within a program (hereinafter referred to as a CALL instruction) and an instruction for returning from the subroutine (hereinafter referred to as a RET instruction). Here, the operation of the microcomputer when executing such a CALL instruction and a RET instruction will be explained in particular.
第4図は従来の一例を説明するためのプロゲラの流れ、
特にマイコンのサブルーチン動作とその復帰動作の一例
を示すシーケンス図である。Figure 4 shows the flow of progera to explain a conventional example.
In particular, it is a sequence diagram showing an example of a subroutine operation of a microcomputer and its return operation.
第4図に示すように、メインプログラム30を処理中の
マイコンがCALL命令をデコードすると、まずプログ
ラムを格納したROMメモリをアドレッシングするため
のカウンタ(以下、プログラム力、ウンタと称す)の値
をスタックメモリと呼ばれるランダムアクセスメモリに
格納する。その際の格納アドレスはスタックポインタと
呼ばれるカウンタレジスタにより指定される値となる。As shown in FIG. 4, when the microcomputer that is processing the main program 30 decodes the CALL instruction, it first stacks the value of a counter (hereinafter referred to as a program counter) for addressing the ROM memory that stores the program. Stored in random access memory called memory. The storage address at that time is a value specified by a counter register called a stack pointer.
このスタックポインタはフタツクメモリにプログラムカ
ウンタの値を格納していくと同時にアドレスをインクリ
メントしていく。例えば、スタックメモリが1アドレス
につき8ビツトであれば、5バイトのデータを格納した
とき、スタックポインタは(現在のアドレス)+5のア
ドレスを指す、また、同時にコールされるアドレスすな
わちサブルーチンの先頭アドレスがプログラムカウンタ
に書き込まれ、CALL命令の動作が完結する。以後、
マイコンはサブルーチンに実行を移す。第4図の例では
サブルーチン31をコールしている。This stack pointer stores the value of the program counter in the back memory and at the same time increments the address. For example, if the stack memory has 8 bits per address, when 5 bytes of data is stored, the stack pointer will point to the (current address) + 5 address, and the address that is called at the same time, that is, the start address of the subroutine, will point to the (current address) + 5 address. It is written to the program counter and the operation of the CALL instruction is completed. From then on,
The microcontroller moves execution to a subroutine. In the example shown in FIG. 4, subroutine 31 is called.
次に、RET命令の動作については、マイコンがRET
命令をデコードすると、スタックメモリよりサブルーチ
ンコール時に格納したデータを取り出し、プログラムカ
ウンタにそのデータを書き込む。取り出すデータのアド
レスは(スタックポインタの値)−1から順次下がって
いき最終的にマイコンはCALL命令直前の状態に戻る
。第4図の例ではメインプログラム30よりサブルーチ
ン31をコールし、更にサブルーチン31がらサブルー
チン32をコールし、更にサブルーチン32からサブル
ーチン33をコールした後、RET命令によりコールし
てきたサブルーチンより順次復帰しメインプログラムへ
戻っている。Next, regarding the operation of the RET command, the microcontroller
When the instruction is decoded, the data stored during the subroutine call is retrieved from the stack memory and written to the program counter. The address of the data to be taken out sequentially decreases from (the value of the stack pointer) -1, and finally the microcomputer returns to the state immediately before the CALL instruction. In the example shown in FIG. 4, the main program 30 calls the subroutine 31, the subroutine 31 calls the subroutine 32, the subroutine 32 calls the subroutine 33, and then the subroutines called by the RET command sequentially return to the main program. is returning to.
上述した従来のマイコンでは、サブルーチンが所謂入れ
子構造になっているため、サブルーチンからサブルーチ
ンをコールするようなシーケンスを行ったときに、−度
にメインプログラムに戻ることはできず、各サブルーチ
ン内にある各々のRET命令を通過しなければならない
という問題がある。In the conventional microcontrollers mentioned above, subroutines have a so-called nested structure, so when performing a sequence of calling subroutines from subroutines, it is not possible to return to the main program at once; The problem is that each RET instruction must be passed through.
しかるに、一般にはRET命令の動作は数多くの処理ス
テートを必要としているため、数マシンサイクルにかか
ってしまうためRET命令を何度も実行しながらメイン
プログラムへ戻るマイコンシーケンスではメインプログ
ラムへ戻るまでの処理効率が悪くなるという欠点がある
。However, in general, the operation of the RET instruction requires many processing states and takes several machine cycles, so in a microcomputer sequence that returns to the main program while executing the RET instruction many times, the processing until returning to the main program is delayed. The disadvantage is that it is less efficient.
本発明の目的は、かかるサブルーチンからメインプログ
ラムに復帰するまでの時間を短縮し処理効率を向上させ
るマイクロコンピュータを提供することにある。An object of the present invention is to provide a microcomputer that shortens the time required to return to the main program from such a subroutine and improves processing efficiency.
本発明のマイクロコンピュータは、サブルーチンコール
命令実行時にプログラムメモリのアドレッシングを行な
うプログラムカウンタの値を格納する第一のメモリおよ
び第二のメモリと、前記第一のメモリのアドレッシング
を行うスタックポインタと、前記第二のメモリへの前記
プログラムカウンタ値の格納許可・不許可の制御を行う
許可フラグ設定回路とを有して構成される。The microcomputer of the present invention includes a first memory and a second memory that store the value of a program counter that addresses the program memory when executing a subroutine call instruction, a stack pointer that addresses the first memory, and a stack pointer that addresses the first memory. and a permission flag setting circuit that controls permission/denial of storage of the program counter value in the second memory.
次に、本発明の実施例について図面を参照して説明する
。Next, embodiments of the present invention will be described with reference to the drawings.
第1図は本発明の第一の実施例を説明するためのマイコ
ン主要回路図である。FIG. 1 is a main circuit diagram of a microcomputer for explaining a first embodiment of the present invention.
第1図に示すように、かかるマイコンはサブルーチンコ
ール命令実行時にプログラムメモリのアドレッシングを
行うプログラムカウンタの値を格納する第一のメモリと
してのスタックメモリ1および第二のメモリとしてのス
タックメモリ2と、復帰命令RETMの有無にもとすき
動作禁止信号5を作成しアドレス線7を用いてスタック
メモリ1へのアドレッシングを行うスタックポインタ3
と、スタックメモリ2ヘプログラムカウンタ値を格納す
るか否かの制御を行うための書き込み許可信号6を形成
する許可フラグ設定回路4とを有して構成される。この
許可フラグ設定回路4はCFLAG命令によりセットさ
れ且つCALL命令によりセットされるとともに、その
出力0と制御信号線8からのCALL命令との論理積に
より書き込み許可信号6が形成される。また、スタック
メモリ1およびスタックメモリ2はそれぞれ復帰命令R
ETMおよびRET命令に基すき形成されるメモリの読
み出し禁止信号9および10により読み出しの制御が行
われる。As shown in FIG. 1, such a microcomputer includes a stack memory 1 as a first memory and a stack memory 2 as a second memory, which store the value of a program counter that addresses program memory when executing a subroutine call instruction. A stack pointer 3 generates a recess operation prohibition signal 5 depending on the presence or absence of a return command RETM, and performs addressing to the stack memory 1 using an address line 7.
and a permission flag setting circuit 4 that generates a write permission signal 6 for controlling whether or not to store the program counter value in the stack memory 2. This permission flag setting circuit 4 is set by the CFLAG command and by the CALL command, and the write permission signal 6 is formed by the AND of its output 0 and the CALL command from the control signal line 8. In addition, stack memory 1 and stack memory 2 each have a return instruction R.
Reading is controlled by memory read inhibit signals 9 and 10 which are formed based on the ETM and RET commands.
第2図は本発明におけるプログラム処理の流れの一例で
あり、第1図におけるマイコンのサブルーチン動作を説
明するための動作シーケンス図である。FIG. 2 shows an example of the flow of program processing in the present invention, and is an operation sequence diagram for explaining the subroutine operation of the microcomputer in FIG. 1.
第2図に示すように、かかるプログラム処理の流れにお
いて、メインプログラム21を実行中に第一のサブルー
チン22.第二のサブレーチン23、第三のサブルーチ
ン24を処理した後、再びメインプログラム21の実行
に戻る流れである。この動作シーケンス中、CFLAG
は第1図において許可フラグ設定回路4をセットし、ス
タックメモリ2への書き込みを許可する命令、CALL
Iは第一のサブルーチン22をコールする命令、CAL
L2は第二のサブルーチン23をコールする命令、CA
LL3は第三のサブルーチン24をコールする命令であ
り、またRETMはサブルーチンからメインプログラム
に戻るための復帰命令である。このRBTM命令は前述
のRET命令とは異なる。As shown in FIG. 2, in the flow of such program processing, while the main program 21 is being executed, the first subroutine 22. After processing the second subroutine 23 and third subroutine 24, the flow returns to execution of the main program 21 again. During this operating sequence, CFLAG
In FIG. 1, CALL is an instruction to set the permission flag setting circuit 4 and permit writing to the stack memory 2.
I is an instruction that calls the first subroutine 22, CAL
L2 is an instruction that calls the second subroutine 23, CA
LL3 is an instruction for calling the third subroutine 24, and RETM is a return instruction for returning from the subroutine to the main program. This RBTM instruction is different from the RET instruction described above.
先ずメインプログラム21上でサブルーチン22をコー
ルする前にCFLAG命令により許可フラグ設定回路4
をセットする。かかるセットを行った後、許可フラグ設
定回路4は以後最初に現われるCALL命令(CALL
l )を実行した後クリアされる。このように、CFL
AG命令を実行した後、最初のCALL命令であるCA
LLlをデコードすると、制御信号線8がアクティブと
なり、スタックメモリ2への書き込みが許可される。以
後の動作は前述したCALL命令の動作と同一であるが
、本発明においては、プログラムカウンタの値はスタッ
クメモリ1とスタックメモリ2の双方のメモリに書き込
まれることになる。更に、CALL命令実行後は許可フ
ラグ設定回路4がクリアされるために以後再びCFLA
G命令を行って許可フラグ設定回路4をアクティブにし
ない限り、CALL命令を実行してもスタックメモリ2
にデータが書き込まれることはない。第2図における例
では、CALLI命令実行によりプログラム処理がサブ
ルーチン22に移行するが、この中でCALL2命令を
実行しても動作は従来のマイコンと何ら変わることはな
い、CALL3命令の実行についても同様である。First, before calling the subroutine 22 on the main program 21, the permission flag setting circuit 4 is set using the CFLAG command.
Set. After performing such setting, the permission flag setting circuit 4 receives the first CALL instruction (CALL
1) is cleared after execution. In this way, CFL
After executing the AG instruction, the first CALL instruction, CA
When LLl is decoded, the control signal line 8 becomes active and writing to the stack memory 2 is permitted. The subsequent operation is the same as that of the CALL instruction described above, but in the present invention, the value of the program counter is written to both stack memory 1 and stack memory 2. Furthermore, after the CALL instruction is executed, the permission flag setting circuit 4 is cleared, so the CFLA is set again.
Unless the permission flag setting circuit 4 is activated by executing the G instruction, even if the CALL instruction is executed, the stack memory 2
No data is written to . In the example shown in FIG. 2, program processing moves to subroutine 22 by executing the CALLI instruction, but even if the CALL2 instruction is executed within this, the operation is no different from that of conventional microcontrollers, and the same applies to the execution of the CALL3 instruction. It is.
一方、マイコンがサブルーチン24を処理中のとき、メ
インプログラム21への復帰命令であるRETM命令を
デコードすると、マイコンはスタックポインタ3の動作
禁止信号5をアクティブにし、スタックポインタ3の動
作を禁止すると同時に、スタックメモリ1への読み出し
禁止信号9もアクティブにしてスタックメモリ1へのア
クセスを禁止する。従って、復帰処理はスタックメモリ
2をアクセスして行なわれるようになる。すなわち、ス
タックメモリ2にはCALLI命令実行直前の状態を格
納しであるので、メインプログラムへの復帰を1命令で
行ったことになる。一方、前述した通常のRET命令の
処理に対してはスタックメモリ2への読み出し禁止信号
10がアクティブとなるためにスタックメモリ1のみを
アクセスして従来通りの処理が行なわれる。On the other hand, when the microcomputer is processing the subroutine 24 and decodes the RETM instruction, which is an instruction to return to the main program 21, the microcomputer activates the stack pointer 3 operation inhibit signal 5, and at the same time inhibits the operation of the stack pointer 3. , the read prohibition signal 9 to the stack memory 1 is also activated to prohibit access to the stack memory 1. Therefore, the restoration process is performed by accessing the stack memory 2. That is, since the stack memory 2 stores the state immediately before the execution of the CALLI instruction, the return to the main program is performed with one instruction. On the other hand, for processing of the above-mentioned normal RET command, since the read prohibition signal 10 to the stack memory 2 becomes active, only the stack memory 1 is accessed and the conventional processing is performed.
尚、これまでの説明においては第2図のプログラムの流
れを例にとったが、この他に例えばCFLAG命令をサ
ブルーチン22の中のCALL2命令の前に実行させれ
ばサブルーチン24においてRETM命令を実行するこ
とによりサブルーチン22に復帰でき、サブルーチンの
ネスティングレベルを意識することなく1命令で希望の
場所に復帰させることができる。In the explanation so far, the program flow shown in FIG. 2 has been taken as an example, but in addition to this, for example, if the CFLAG instruction is executed before the CALL2 instruction in the subroutine 22, the RETM instruction can be executed in the subroutine 24. By doing this, it is possible to return to the subroutine 22, and it is possible to return to the desired location with one command without being aware of the nesting level of the subroutine.
第3図は本発明の第二の実施例を説明するためのマイコ
ン主要回路図である。FIG. 3 is a main circuit diagram of a microcomputer for explaining a second embodiment of the present invention.
第3図に示すように、この第二の実施例における基本構
成は第1図と同じであるため、スタックメモリ1とこと
スタックメモリ1に付随する制御信号線とスタックポイ
ンタ3については第3図では省略している。前述した第
一の実施例との相違点はスタックメモリ11への書き込
み許可信号13.16が二通りあることにある。すなわ
ち、第1図におけるスタックメモリ2はユーザが直接使
用できないが、この第二の実施例ではスタックメモリ1
をメモリ空間にマツピングし、書き込み許可信号16を
設はユーザが自由にアクセスできるようにしたことにあ
る0例えば、ユーザが自由に第二のスタックメモリ11
をアクセスできれば、プログラムカウンタの値を書き換
えることによりRETM命令の実行時に任意のアドレス
1命令で復帰することができるという大きな利点がある
。As shown in FIG. 3, the basic configuration of this second embodiment is the same as that in FIG. It is omitted here. The difference from the first embodiment described above is that there are two types of write permission signals 13 and 16 to the stack memory 11. That is, the stack memory 2 in FIG. 1 cannot be used directly by the user, but in this second embodiment, the stack memory 1
For example, the user can freely access the second stack memory 11 by mapping it into the memory space and setting the write permission signal 16.
If access is possible, there is a great advantage that by rewriting the value of the program counter, it is possible to return to an arbitrary address with a single instruction when executing a RETM instruction.
以上説明したように、本発明のマイコンは内蔵した二稚
類のスタックメモリを切り換えることにより、サブルー
チンのネスティンダレベルを意識することなく1命令、
すなわちどの位置からも同じ時間で所望の場所へ復帰で
きるので、処理時間を短縮して処理効率を向上させるこ
とができるという効果がある。また、従来のマイコンに
比べ付加するハードウェアは少量で済むという大きな利
点もある。As explained above, the microcontroller of the present invention can execute a single instruction without being aware of the subroutine nesting level by switching the built-in secondary stack memory.
That is, since it is possible to return to a desired location from any location in the same amount of time, it is possible to shorten processing time and improve processing efficiency. Another big advantage is that it requires less hardware than conventional microcontrollers.
第1図は本発明の第一の実施例を説明するためのマイク
ロコンピュータの主要回路図、第2図は第1図における
マイクロコンピュータのサブルーチン動作を説明するた
めの動作シーケンス図、第3図は本発明の第二の実施例
を説明するためのマイクロコンピュータの主要回路図、
第4図は従来の一例を説明するためのマイクロコンピュ
ータのサブルーチン動作シーケンス図である。
1.2.11・・・スタックメモリ、3・・・スタック
ポインタ、4,12・・・許可フラグ設定回路、5・・
・スタックポインタの動作禁止信号、6.13゜16・
・・スタックメモリ書き込み許可信号、7・・・スタッ
クメモリへのアドレス線、8,14・・・スタックメモ
リへの制御信号線、9.10.15・・・スタックメモ
リ読み出し禁止信号、21・・・メインプログラム、2
2.23.24・・・サブルーチン。FIG. 1 is a main circuit diagram of a microcomputer for explaining the first embodiment of the present invention, FIG. 2 is an operation sequence diagram for explaining the subroutine operation of the microcomputer in FIG. 1, and FIG. A main circuit diagram of a microcomputer for explaining a second embodiment of the present invention,
FIG. 4 is a subroutine operation sequence diagram of a microcomputer to explain a conventional example. 1.2.11... Stack memory, 3... Stack pointer, 4, 12... Permission flag setting circuit, 5...
・Stack pointer operation prohibition signal, 6.13゜16・
...Stack memory write enable signal, 7...Address line to stack memory, 8,14...Control signal line to stack memory, 9.10.15...Stack memory read prohibition signal, 21...・Main program, 2
2.23.24... Subroutine.
Claims (1)
ドレッシングを行うプログラムカウンタの値を格納する
第一のメモリおよび第二のメモリと、前記第一のメモリ
のアドレッシングを行うスタック・ポインタと、前記第
二のメモリへの前記プログラムカウンタ値の格納許可・
不許可の制御を行う許可フラグ設定回路とを有すること
を特徴とするマイクロコンピュータ。A first memory and a second memory for storing the value of a program counter for addressing program memory when a subroutine call instruction is executed, a stack pointer for addressing the first memory, and a stack pointer for addressing the first memory; Permission to store the program counter value
1. A microcomputer comprising a permission flag setting circuit for controlling permission disapproval.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP4274588A JPH01216429A (en) | 1988-02-24 | 1988-02-24 | Microcomputer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP4274588A JPH01216429A (en) | 1988-02-24 | 1988-02-24 | Microcomputer |
Publications (1)
Publication Number | Publication Date |
---|---|
JPH01216429A true JPH01216429A (en) | 1989-08-30 |
Family
ID=12644552
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP4274588A Pending JPH01216429A (en) | 1988-02-24 | 1988-02-24 | Microcomputer |
Country Status (1)
Country | Link |
---|---|
JP (1) | JPH01216429A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH03257629A (en) * | 1990-03-08 | 1991-11-18 | Matsushita Electric Ind Co Ltd | Interruption restoring device |
JPH04245543A (en) * | 1990-09-04 | 1992-09-02 | American Teleph & Telegr Co <Att> | Method and device for executing subprogram calling and compiler device |
JP2008530712A (en) * | 2005-02-18 | 2008-08-07 | クゥアルコム・インコーポレイテッド | Method and apparatus for managing a return stack |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS60105046A (en) * | 1983-11-11 | 1985-06-10 | Nec Corp | Address stack control system |
-
1988
- 1988-02-24 JP JP4274588A patent/JPH01216429A/en active Pending
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS60105046A (en) * | 1983-11-11 | 1985-06-10 | Nec Corp | Address stack control system |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH03257629A (en) * | 1990-03-08 | 1991-11-18 | Matsushita Electric Ind Co Ltd | Interruption restoring device |
JPH04245543A (en) * | 1990-09-04 | 1992-09-02 | American Teleph & Telegr Co <Att> | Method and device for executing subprogram calling and compiler device |
US5522072A (en) * | 1990-09-04 | 1996-05-28 | At&T Corp. | Arrangement for efficiently transferring program execution between subprograms |
US5530870A (en) * | 1990-09-04 | 1996-06-25 | At&T Corp. | Arrangement for efficiently transferring program execution between subprograms |
EP0474425B1 (en) * | 1990-09-04 | 1998-06-03 | AT&T Corp. | Arrangement for efficiently transferring program execution between subprograms |
JP2008530712A (en) * | 2005-02-18 | 2008-08-07 | クゥアルコム・インコーポレイテッド | Method and apparatus for managing a return stack |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US6868505B2 (en) | Memory exchange | |
JPH01216429A (en) | Microcomputer | |
WO2003019385A1 (en) | Cache memory control in a multi-tasking environment | |
IE61306B1 (en) | Method and device to execute two instruction sequences in an order determined in advance | |
WO2019237865A1 (en) | Data protection method and computing device | |
JP2000207203A (en) | Micro controller | |
US5450587A (en) | Expanded memory addressing scheme | |
JPS6220583B2 (en) | ||
US20050144408A1 (en) | Memory protection unit, memory protection method, and computer-readable record medium in which memory protection program is recorded | |
JPH0855204A (en) | Ic card with cpu and accessible address limiting method of ic card with cpu | |
JPS58107963A (en) | Interruption processor | |
JPS6074033A (en) | Instruction reading method | |
WO2000022531A1 (en) | System and method for improving memory access | |
JPH0731608B2 (en) | Information processing equipment | |
JPS6231382B2 (en) | ||
JPS6155694B2 (en) | ||
JPH05257807A (en) | Cache memory controller | |
JPS6161139B2 (en) | ||
JP2504151B2 (en) | Data processing device | |
JP2002544619A (en) | Object-oriented processing using dedicated pointer memory | |
JPS6126701B2 (en) | ||
JPH04311895A (en) | IC memory | |
JPH02165358A (en) | Program loading method with learning function | |
JPH04111031A (en) | Primary memory information implementation processing method | |
JPS6361333A (en) | Instruction control device |