21 |
BSVの設計トライアル (11) |
BSVコード
nextStep()関数は以下のとおりです。
function nextStep;
case (state.step)
S0: nextStep = S1;
S1: nextStep = S2;
S2: nextStep = S3;
S3: nextStep = S4;
endcase
endfunction: nextStep
以下に4段のスタックとスタックポインタの実装(インスタンシエーション)を示します。
// return stack
RegFile#(UInt#(2), State_t) rs <- mkRegFile(0, 3);
// stack pointer
Reg#(UInt#(2)) sp <- mkReg(0);
検証用FSMの設計
これらのステート遷移の検証用FSMを設計します。全部でL1~L4の4レベルのコールネスティング関係を持ち、各ステートでは、主にステート変数の表示を行います。図244.1~図244.4に、レベル1からレベル4のステート遷移図を図示します。




検証結果の作成
expectedというファイル名で実行結果を作成しておきます。レベルとステートをサイクル毎に表示するFSMの動きを示します。
L1 S0
L1 S1
L2 S0
L2 S1
L2 S2
L3 S0
L3 S1
L4 S0
L4 S1
L3 S2
L2 S3
L2 S4
L1 S2
L1 S2
Leave a Comment