LoginSignup
0
0

More than 1 year has passed since last update.

概要

順序回路を理解する。
gtkwaveのvcdファイルを利用する。
練習問題やってみた。

練習問題

フリップフロップをシミュレートして、vcdファイルを作れ。

方針

plunkerでやる。

写真

image.png

サンプルコード



function wave(i, w) {
  out.value += "#" + i + "\n";
  out.value += w[0] + "!\n";
  out.value += w[1] + "\"\n";
  out.value += w[2] + "#\n";
  out.value += w[3] + "$\n";
}

class B {
	constructor(n) {
	  this.n = n;
		this.w = [0, 0, 0, 0];
		this.p0 = [];
		this.p1 = [];
		this.p2 = [];
		this.p3 = [];
		this.op = 0;
	}
	in0(a) {
	  this.w[0] = a;
	}
	in1(a) {
	  this.w[1] = a;
	}
	nor(a, b, c) {
	  this.p0[this.op] = 4;
	  this.p1[this.op] = a;
	  this.p2[this.op] = b;
	  this.p3[this.op] = c;
	  this.op++;
	}
	exec() {
	  var i;
	  var j = this.op;
	  while (j > 0)
	  {
  	  for (i = 0; i < j; i++)
      {
        if (this.p0[i] == 4) 
        {
          var s = this.w[this.p1[i]] | this.w[this.p2[i]];
          if (s == 0)
          {
            this.w[this.p3[i]] = 1;
          }
          else
          {
            this.w[this.p3[i]] = 0;
          }
        }
      }
      j--;
	  }
	  return this.w;
	}
}

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

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 "out":
    break;
    case "make":
      var a = parseInt(code[1]);
      c0 = new B(a);
    break;
    case "in":
      var a = parseInt(code[1]);
      var b = parseInt(code[2]);
    break;
    case "nor":  
      var a = parseInt(code[1]);
      var b = parseInt(code[2]);
      var c = parseInt(code[3]);
      c0.nor(a, b, c);
    break;
    default:
      alert(code[0]);
    break;
    }
  }
  var s = [];
  var t = [0, 1, 0, 0, 0, 0, 0, 1, 0];
	var u = [0, 0, 0, 1, 0, 1, 0, 0, 0];
  for (i = 0; i < 9; i++)
  {
    c0.in0(t[i]);
    c0.in1(u[i]);
    var c = c0.exec();
    s.push([c[0], c[1], c[2], c[3]]);
  }
  var v = [];
  for (i = 1; i < 9; i++)
  {
    wave(i, s[i]);
  }
  out.value += "#" + 9;
}






成果物

以上。

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