private void EvalInitialize ptr Eval Stack0 ptr Name

  • Slides: 15
Download presentation

(2)スタックマシンエミュレータの例 初期化 private void Eval_Initialize() { ptr. Eval. Stack=0; ptr. Name. Table=0; ptr. Prog.

(2)スタックマシンエミュレータの例 初期化 private void Eval_Initialize() { ptr. Eval. Stack=0; ptr. Name. Table=0; ptr. Prog. Stack=0; }

トップレベルのみの概要(1) private void Eval() { Name. Data P 1, P 2; int i=0; push.

トップレベルのみの概要(1) private void Eval() { Name. Data P 1, P 2; int i=0; push. Eval. Stack(new Name. Data("*Function*")); while(i<num. Statement) { next. IP =i+1; if (All. Statement[i]. operation=="end") { Message. Box. Show(“プログラムの終了です。カウンタ=” + i. To. String()); break; } switch (All. Statement[i]. operation) { case "+" : Eval_add(); break; case "-" : Eval_sub(); break; case "%" : Eval_mod(); break;

トップレベルのみの概要(2) case case case case case "*" "mod" "/" "^" "=" "++" "--" "++$"

トップレベルのみの概要(2) case case case case case "*" "mod" "/" "^" "=" "++" "--" "++$" "--$" "+$" "+=" "-=" "*=" "/=" "==" "!=" ">" : Eval_mult(); break; : Eval_mod(); break; : Eval_dev(); break; : Eval_exp(); break; : Eval_set(); break; : Eval_PPset(); break; : Eval_MMset(); break; : Eval_Befor. PPset(); break; : Eval_Befor. MMset(); break; : Eval_minus(); break; : Eval_plus(); break; : Eval_Asign. Pset(); break; : Eval_Asign. Multset(); break; : Eval_Asign. Divset(); break; : Eval_equal(); break; : Eval_not_equal(); break; : Eval_greater_than(); break;

トップレベルのみの概要(3) case case case case ">" ">=" "<=" "||" "&&" "%%" "!" "Arg. End"

トップレベルのみの概要(3) case case case case ">" ">=" "<=" "||" "&&" "%%" "!" "Arg. End" "Func" : Eval_greater_than(); break; : Eval_greater_than_equal(); break; : Eval_less_than_equal(); break; : Eval_or(); break; : Eval_and(); break; : Eval_exclusive_or(); break; : Eval_not(); break; : Eval_Arg(); break; : Eval_func(All. Statement[i]. str); break; "*dim. Start" : Eval_dim. Start(All. Statement[i]. str); break; "dim" : Eval_dim(); break; "*PStart*" : Eval_PStart(); break; "*Parm*" : Eval_Param(All. Statement[i]. str); break; "return" : Eval_return(); break;

トップレベルのみの概要(4) case "St. No" : Statement. No=int. Parse(All. Statement[i]. str); ptr. Eval. Stack=0; break;

トップレベルのみの概要(4) case "St. No" : Statement. No=int. Parse(All. Statement[i]. str); ptr. Eval. Stack=0; break; case "goto" : P 1=Eval(pop. Eval. Stack()); next. IP=(int)P 1. Val; break; case "then" : P 2=Eval(pop. Eval. Stack()); P 1=Eval(pop. Eval. Stack()); if(P 1. Type=="Number" && P 2. Type=="Number" ) { if(P 1. Val ==0) next. IP=(int)P 2. Val; } else Message. Box. Show("評価エラーです"); break; default : push. Eval. Stack(All. Statement[i]); break; } i=next. IP; } }

以下VB6による例 初期化 Private Sub 初期化() SVC_Call = 0 Exec. Address = 0 End Sub

以下VB6による例 初期化 Private Sub 初期化() SVC_Call = 0 Exec. Address = 0 End Sub

1命令の実行 Private Sub Command 2_Click() 命令取出 アドレス計算 命令実行 If SVC_Flag Then If SVC_Call =

1命令の実行 Private Sub Command 2_Click() 命令取出 アドレス計算 命令実行 If SVC_Flag Then If SVC_Call = 0 Then CRLF = Chr(13) & Chr(10) Text 3. Text = Right(Text 3. Text, 5000) & CRLF & _ "プログラムの終了です. " Exec. Address = 0 命令表示 End If End Sub

命令取出し Private Sub 命令取出() A = MCode(Exec. Address): MPart(0) = A  &H 100:

命令取出し Private Sub 命令取出() A = MCode(Exec. Address): MPart(0) = A &H 100: A 2 = A Mod &H 100 If MPart(0) >= &H 80 Then MPart(1) = A 2 &H 10: MPart(2) = A 2 Mod &H 10 MPart(3) = MCode(Exec. Address + 1) Exec. Address = Exec. Address + 2 Else. If MPart(0) = &H 50 Then MPart(1) = A 2 &H 10: MPart(2) = A 2 Mod &H 10 Exec. Address = Exec. Address + 1 Else MPart(1) = 0: MPart(2) = 0: MPart(3) = A 2 Exec. Address = Exec. Address + 1 End If End Sub

アドレス計算 Private Sub アドレス計算() If MPart(0) >= &H 80 Then If MPart(2) = 0

アドレス計算 Private Sub アドレス計算() If MPart(0) >= &H 80 Then If MPart(2) = 0 Then Effect. Address = MPart(3) Else ID = MPart(2) Effect. Address = Register(ID) + MPart(3) End If Else Effect. Address = MPart(3) End If End Sub

命令実行直後の状態フラグ設定 Private Sub 状態フラグ設定(Rno) Status(0) = 0: Status(1) = 0: Status(2) = 0 If

命令実行直後の状態フラグ設定 Private Sub 状態フラグ設定(Rno) Status(0) = 0: Status(1) = 0: Status(2) = 0 If Register(Rno) > 0 Then Status(0) = 1 Else. If Register(Rno) = 0 Then Status(1) = 1 Else Status(2) = 1 End If End Sub

命令実行(その1) Private Sub 命令実行() SVC_Flag = False Select Case MPart(0) Case &HA 0: Register(MPart(1))

命令実行(その1) Private Sub 命令実行() SVC_Flag = False Select Case MPart(0) Case &HA 0: Register(MPart(1)) = MCode(Effect. Address) 'Load 状態フラグ設定 MPart(1) Case &HA 2: MCode(Effect. Address) = Register(MPart(1)) 'Store 状態フラグ設定 MPart(1) Case &HB 0: Register(MPart(1)) = Effect. Address 'LI (Load Imediate) 状態フラグ設定 MPart(1) Case &H 81: Register(MPart(1)) = Register(MPart(1)) + _ MCode(Effect. Address) 'ADD 状態フラグ設定 MPart(1) Case &H 82: Register(MPart(1)) = Register(MPart(1)) - _ MCode(Effect. Address) 'SUB 状態フラグ設定 MPart(1) Case &H 83: Register(MPart(1)) = Register(MPart(1)) * _ MCode(Effect. Address) 'MULT 状態フラグ設定 MPart(1)

命令実行(その2) Case &H 84: Register(MPart(1)) = Register(MPart(1))  _ MCode(Effect. Address) 'DIV 状態フラグ設定 MPart(1)

命令実行(その2) Case &H 84: Register(MPart(1)) = Register(MPart(1)) _ MCode(Effect. Address) 'DIV 状態フラグ設定 MPart(1) ・ ・ (中略) ・ Case &HE 0: Exec. Address = Effect. Address 'JMP Case &HE 1: If Status(0) <> 0 Then Exec. Address = Effect. Address 'JP (Jump Plus) Case &HE 2: If Status(1) <> 0 Then Exec. Address = Effect. Address 'JZ (Jump Zero) Case &HE 3: If Status(2) <> 0 Then Exec. Address = Effect. Address 'JM (Jump Minus) ・ ・ (中略) ・

命令実行(その3) ・ ・ (中略) ・ Case &H 61: Register(MPart(1)) = Val(Input. Box("データ入力")) Case &H

命令実行(その3) ・ ・ (中略) ・ Case &H 61: Register(MPart(1)) = Val(Input. Box("データ入力")) Case &H 1: SVC_Call = MPart(1): SVC_Flag = True 'SVC_Call End Select End Sub