1
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?

circuitjsの作法 その48

Last updated at Posted at 2025-01-16

概要

circuitjsを調査してみた。
練習問題やってみた。

練習問題

elixirで論理回路アセンブラをコンパイルして、ネットリストを高位合成せよ。

論理回路アセンブラの仕様

  • make
    回路を作る。ビットを指定する。
    inputが2つで、outputが2つ、なら4。make 4

  • in
    inputを作る。
    0,1,2がinputならば、in 0 2

  • out
    outputを作る。
    3,4,5がoutputならば、out 3 5

  • xor
    xorを作る。
    0,1が入力で、2が出力ならば、xor 0 1 2

  • and
    andを作る。
    0,1が入力で、2が出力ならば、and 0 1 2

  • or
    orを作る。
    0,1が入力で、2が出力ならば、or 0 1 2

投入するソース

make 3
in 0 1
out 2 2
or 0 1 2

生成したネットリスト

$ 1 0.000005 10.20027730826997 50 5 50 5e-11
L 224 128 176 128 2 0 false 5 0
L 224 160 176 160 2 0 false 5 0
M 368 144 416 144 2 2.5
152 224 144 368 144 0 2 0 5

写真

image.png

ネットリスト読み込み手順

を開く。

ファイル>テキストデータからインポートをクリック

成果物

サンプルコード


defmodule Asm do
	def start_link do
		Agent.start_link(fn ->
			%{in0: "", in1: "", make0: "", u: ""}
		end, name: __MODULE__)
	end
    def make0(a) do
	end
    def in0(a, b) do
    end
    def out0(a, b) do
    end
    def and0(a, b, c) do
		Agent.update(__MODULE__, fn v ->
            str = "150 224 144 368 144 0 2 0 5"
            %{v | u: v.u <> str}
		end)
    end
    def xor0(a, b, c) do
		Agent.update(__MODULE__, fn v ->
            str = "154 224 144 368 144 0 2 0 5"
            %{v | u: v.u <> str}
		end)
    end
    def or0(a, b, c) do
		Agent.update(__MODULE__, fn v ->
            str = "152 224 144 368 144 0 2 0 5"
            %{v | u: v.u <> str}
		end)
    end
    def print() do
		Agent.get(__MODULE__, fn v ->
            IO.puts "$ 1 0.000005 10.20027730826997 50 5 50 5e-11"
            IO.puts "L 224 128 176 128 2 0 false 5 0"
            IO.puts "L 224 160 176 160 2 0 false 5 0"
            IO.puts "M 368 144 416 144 2 2.5"
            IO.puts v.u
		end)
	end
end

defmodule Main do
	def run(str) do
    	Enum.map(String.split(str, "\n"), fn l ->
		    #IO.puts l
		    s = String.split(l, " ")
		    #IO.puts Enum.at(s, 0)
		    cond do
			Enum.at(s, 0) == "make" ->
				Asm.make0(Enum.at(s, 1))
			Enum.at(s, 0) == "in" ->
				Asm.in0(Enum.at(s, 1), Enum.at(s, 2))
			Enum.at(s, 0) == "out" ->
				Asm.out0(Enum.at(s, 1), Enum.at(s, 2))
			Enum.at(s, 0) == "and" ->
				Asm.and0(Enum.at(s, 1), Enum.at(s, 2), Enum.at(s, 3))
			Enum.at(s, 0) == "nand" ->
				Asm.nand0(Enum.at(s, 1), Enum.at(s, 2), Enum.at(s, 3))
			Enum.at(s, 0) == "nor" ->
				Asm.nor0(Enum.at(s, 1), Enum.at(s, 2), Enum.at(s, 3))
			Enum.at(s, 0) == "xor" ->
				Asm.xor0(Enum.at(s, 1), Enum.at(s, 2), Enum.at(s, 3))
			Enum.at(s, 0) == "or" ->
				Asm.or0(Enum.at(s, 1), Enum.at(s, 2), Enum.at(s, 3))
			true ->
				IO.puts ""
			end
	    end)
	    Asm.print
	end
end

Asm.start_link

Main.run("""
make 3
in 0 1
out 2 2
or 0 1 2
""")








以上。

1
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
1
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?