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?

More than 1 year has passed since last update.

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

Last updated at Posted at 2023-12-11

概要

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

練習問題

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

真理値表を書く。

lutで書く。

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

説明

  • lut 4
    ルックアップテーブルの列4を宣言
  • lin 3
    入力を3bit
  • lout 1
    出力を1bit
  • code 3 1
    入力0x3で出力0x1を設定

写真

image.png

サンプルコード


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

class LUT {
	constructor(n) {
	  this.h = "";
	  this.n = n;
		this.s = [];
		this.a = 0;
		this.b = 0;
    this.bin = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512];
		return this;
	}
	in(a) {
		this.a = a;
		return this;
	}
	out(a) {
		this.b = a;
		return this;
	}
	code(a, b) {
		var t = new Array(this.n);
    var i,
      j,
      k;
		for (i = 0; i < this.a; i++)
		{
      j = this.a - i - 1;
      k = a >> j;
      k = k & 1;
      if (k == 1) t[i] = 1;
      else t[i] = 0;
		}
    for (i = 0; i < this.b; i++)
		{
      j = this.b - i - 1;
      k = b >> j;
      k = k & 1;
      if (k == 1) t[this.a + i] = 1;
      else t[this.a + i] = 0;
		}
		this.s.push(t);
	  return this;
	}
	table() {
    this.h += '<table>';
    this.h += '<tr>';
		for (var a = 0; a < this.a; a++)
    {
			this.h += '<th>' + this.bin[this.a - a - 1] + '</th>';
		}
    for (var b = 0; b < this.b; b++)
    {
			this.h += '<th>' + this.bin[this.b - b - 1] + '</th>';
		}
		this.h += '</tr>';
		for (var row = 0; row < this.s.length; row++)
    {
    	this.h += '<tr>';
    	for (var col = 0; col < this.n; col++)
    	{
	    	var v = this.s[row][col];
		    this.h += '<td>' + v + '</td>';
	    }
	    this.h += '</tr>';
    }
    this.h += '</table>';
    out.innerHTML = this.h;
	}
}

function run() {
  var str = src.value;
  var codes = str.split("\n");  
  var len = codes.length;
  var i;
  for (i = 0; i < len; i++)
  {
    var code = codes[i].split(" ");
    switch (code[0])
    {
    case "":
    break;
    case "lut":
      var a = parseInt(code[1]);
      c0 = new LUT(a);
    break;
    case "lin":
      var a = parseInt(code[1]);
      c0.in(a);
    break;
    case "lout":  
      var a = parseInt(code[1]);
      c0.out(a);
    break;
    case "code":  
      var a = parseInt("0x" + code[1]);
      var b = parseInt("0x" + code[2]);
      c0.code(a, b);
    break;
    default:
      alert(code[0]);
    break;
    }
  }
  c0.table();
}




成果物

以上。

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?