0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

高位合成言語アセンブラを作る。 その28

Last updated at Posted at 2023-12-11

概要

高位合成言語アセンブラを作る。
練習問題、やってみる。
ルックアップテーブル方式をやってみる。
論理式は書かない。

練習問題

3 の正の倍数検出回路を作れ。

高位合成する。

写真

image.png

投入したソース

lut 4
lin 3
lout 1
code 0 0
code 1 0
code 2 0
code 3 1
code 4 0
code 5 0
code 6 1
code 7 0

サンプルコード


var src = document.getElementById("src");
var out = document.getElementById("out");

function run() {
  var in0 = "";
  var in1 = "";
  var out0 = "";
  var out1 = "";
  var m = "";
  var u = "";
  var str = src.value;
  var codes = str.split("\n");  
  var len = codes.length;
  var i, 
    j;
  for (i = 0; i < len; i++)
  {
    var code = codes[i].split(" ");
    switch (code[0])
    {
    case "":
    break;
    case "lut":
    break;
    case "lin":
      var a = parseInt(code[1]) - 1;
      in0 = "input wire [" + a + ":0] data,";
      in1 = "\treg [" + a + ":0] data;\n";
    break;
    case "lout":
      var a = parseInt(code[1]) - 1;
      out0 = " output reg [" + a + ":0] code";
      out1 = "\twire [" + a + ":0] code;\n";
    break;
    case "code":  
      var a = code[1];
      var b = code[2];
      u += "\t\t4'h" + a + ":\n\t\t\tcode = 8'h" + b + ";\n";
      m += "\t\tdata = 4'h" + a + "; #10;\n";
    break;
    default:
      alert(code[0]);
    break;
    }
  }
  out.value = "module lut(" + in0 + out0 + ");\n" +
  	"\talways @(data)\n" +
	  "\tbegin\n" +
		"\t\tcase(data)\n" +
    u +
    "\t\tendcase\n" +
	  "\tend\n" +
    "endmodule\n\n" +
    "module testbench;\n" +
    in1 + 
    out1 +
    "\tlut u(.data(data), .code(code));\n" +
	  "\tinitial\n" +
	  "\tbegin\n" +
		'\t\t$display("data code");\n' +
		'\t\t$monitor("%h  %b", data, code);\n' +
    m +
    "\t\t$finish;\n" +
    "\tend\n" +
    "endmodule";
}


成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?