<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>수성컴전자방</title>
    <description>개발 블로그 &apos;수성컴전자방&apos;입니다.</description>
    <link>https://sooseongcom.com/</link>
    <atom:link href="https://sooseongcom.com/rss" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 08 Mar 2026 13:39:42 +0000</pubDate>
    <lastBuildDate>Sun, 08 Mar 2026 13:39:42 +0000</lastBuildDate>
    <generator>Jekyll v4.3.1</generator>
    
      <item>
        <title>C++ 다익스트라 알고리즘으로 최단 경로 구하기</title>
        <description>&lt;p&gt;지도를 보면 여러 점이 있고 길마다 거리가 다릅니다. 이때 한 점에서 다른 점으로 이동하기 위한 최단 경로는 어떻게 구할 수 있을까요? &lt;strong&gt;다익스트라 알고리즘(Dijkstra Algorithm)&lt;/strong&gt;으로 구할 수 있습니다. 오늘은 C++로 다익스트라 알고리즘을 구현해 보겠습니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-파일-목록&quot;&gt;1&lt;/a&gt;. 파일 목록&lt;br /&gt;
&lt;a href=&quot;#2-class-상속-관계&quot;&gt;2&lt;/a&gt;. class 상속 관계&lt;br /&gt;
&lt;a href=&quot;#3-파일-입력&quot;&gt;3&lt;/a&gt;. 파일 입력&lt;br /&gt;
&lt;a href=&quot;#4-다익스트라-알고리즘&quot;&gt;4&lt;/a&gt;. ★★다익스트라 알고리즘&lt;br /&gt;
&lt;a href=&quot;#5-출발-지점으로부터-도착-지점까지의-최단-경로-및-최단-거리-구하기&quot;&gt;5&lt;/a&gt;. ★출발 지점으로부터 도착 지점까지의 최단 경로 및 최단 거리 구하기&lt;br /&gt;
&lt;a href=&quot;#6-나머지는-github-repository를-참고하세요&quot;&gt;6&lt;/a&gt;. 나머지는 GitHub repository를 참고하세요.&lt;br /&gt;
&lt;a href=&quot;#7-글-마무리&quot;&gt;7&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#8-참고-자료&quot;&gt;8&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-파일-목록&quot;&gt;1. 파일 목록&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;.gitignore&lt;/strong&gt;: x64(folder), *.vcxproj, *.vcxproj.filters, *.vcxproj.user, *.txt, *.o, run을 무시&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Graph.cpp&lt;/strong&gt;: Graph의 멤버 변수/함수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Graph.h&lt;/strong&gt;: 그래프를 위한 class&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LICENSE&lt;/strong&gt;: MIT License&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ListGraph.cpp&lt;/strong&gt;: ListGraph의 멤버 변수/함수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ListGraph.h&lt;/strong&gt;: list graph를 위한 class&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;main.cpp&lt;/strong&gt;: 콘솔 입출력을 담당하는 main 함수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;makefile&lt;/strong&gt;: make를 사용하여 빌드하기 위한 파일&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Manager.cpp&lt;/strong&gt;: Manager의 멤버 변수/함수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Manager.h&lt;/strong&gt;: 함수들을 작동시키기 위한 class&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MatrixGraph.cpp&lt;/strong&gt;: MatrixGraph의 멤버 변수/함수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;MatrixGraph.h&lt;/strong&gt;: matrix graph를 위한 class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;이 글은 일부 코드만 설명합니다. 전체 코드는 &lt;a href=&quot;https://github.com/sooseongcom/Dijkstra&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://github.com/sooseongcom/Dijkstra&lt;/a&gt;에서 확인하실 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;2-class-상속-관계&quot;&gt;2. class 상속 관계&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/inheritance.png&quot; alt=&quot;Inheritance&quot; /&gt;&lt;br /&gt;
ListGraph와 MatrixGraph는 Graph를 상속받습니다.&lt;/p&gt;

&lt;h2 id=&quot;3-파일-입력&quot;&gt;3. 파일 입력&lt;/h2&gt;
&lt;p&gt;그래프를 텍스트 파일(*.txt)로 작성합니다. List Graph와 Matrix Graph를 지원하며 양식은 아래와 같습니다.&lt;/p&gt;

&lt;h3 id=&quot;31-list-graph&quot;&gt;3.1. List Graph&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;L
v 0
e 1 2
e 2 5
e 3 1
v 1
e 2 3
e 3 3
v 2
e 1 3
e 5 2
v 3
e 2 4
e 4 1
v 4
e 2 2
e 5 1
v 5
e 5 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;[Line 1]&lt;br /&gt;
&lt;strong&gt;L&lt;/strong&gt;은 List Graph라는 뜻입니다.&lt;/p&gt;

&lt;p&gt;[Line 2~]&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v &amp;lt;from&amp;gt;&lt;/code&gt;: vertex를 만들고 선택합니다.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e &amp;lt;to&amp;gt; &amp;lt;weight&amp;gt;&lt;/code&gt;: 선택된 vertex(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;from&amp;gt;&lt;/code&gt;)부터 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;to&amp;gt;&lt;/code&gt;
까지 연결해 주는 edge를 작성합니다. 거리는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;weight&amp;gt;&lt;/code&gt;입니다.&lt;/li&gt;
  &lt;li&gt;선택된 vertex에서 출발하여 다른 vertex로 가는 edge가 있을 경우 자기 자신으로 가는 edge(거리가 0인 edge)는 생략할 수 있습니다. &lt;strong&gt;다만, 선택된 vertex에서 출발하여 다른 vertex로 가는 edge가 없을 경우 자기 자신으로 가는 edge를 거리 0으로 선언해 주시기 바랍니다(19행 참조).&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;32-matrix-graph&quot;&gt;3.2. Matrix Graph&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;M
6
0 2 5 1 0 0
0 0 3 3 0 0
0 3 0 0 2 0
0 0 4 0 1 0
0 0 2 0 0 1
0 0 0 0 0 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;[Line 1]&lt;br /&gt;
&lt;strong&gt;M&lt;/strong&gt;은 Matrix Graph라는 뜻입니다.&lt;/p&gt;

&lt;p&gt;[Line 2]&lt;br /&gt;
vertex 개수를 적어 줍니다.&lt;/p&gt;

&lt;p&gt;[Line 3~]&lt;br /&gt;
Matrix graph를 작성합니다. 열과 열 사이는 공백으로 구분합니다.&lt;/p&gt;

&lt;h2 id=&quot;4-다익스트라-알고리즘&quot;&gt;4. ★★다익스트라 알고리즘&lt;/h2&gt;
&lt;p&gt;다익스트라 알고리즘은 출발 지점으로부터 모든 지점까지의 최단 거리를 구하는 알고리즘입니다. 모든 선(edge)은 방향성이 있습니다. 출발 지점(&lt;span style=&quot;color: #ff5000&quot;&gt;vertex&lt;/span&gt;)을 parameter로 입력받는 dijkstra 함수와 &lt;span style=&quot;color: #ff5000&quot;&gt;vertex&lt;/span&gt;에 0을 대입한 예시로 설명 드리겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//Graph.cpp Line 12~46&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Graph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dijkstra&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vertex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;arraysInit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Init dist, prev, visited&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;getAdjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vertex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;setVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;setDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;setPrev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vertex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;setVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vertex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;setDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vertex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;choose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//choose() returns a value u such that getDistance(u) = minimum getDistance(w) where visited[w]=false&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;n&quot;&gt;setVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;getAdjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

		&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;begin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;adjacentEdges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
				&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u_dist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getVisited&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u_dist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
					&lt;span class=&quot;n&quot;&gt;setDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u_dist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
					&lt;span class=&quot;n&quot;&gt;setPrev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;위 코드블록의 행 번호를 기준으로 설명 드리겠습니다.&lt;/p&gt;

&lt;p&gt;[Line 3]&lt;br /&gt;
&lt;img src=&quot;/assets/images/20260302/1.png&quot; alt=&quot;Dijkstra init&quot; /&gt;&lt;br /&gt;
dist와 prev는 int형 배열, visited는 bool형 배열입니다.
dist의 모든 원소를 MAX(적당히 큰 숫자. 저는 0xfffffff로 했습니다.)로, visited의 모든 원소를 false로, prev의 모든 원소를 false로 초기화합니다. (함수 별도 구현)&lt;/p&gt;

&lt;p&gt;[Line 5~6]&lt;br /&gt;
&lt;strong&gt;adjacentEdges&lt;/strong&gt;는 연결된 edge를 저장하기 위한 map입니다. key는 vertex 번호이고, value는 거리입니다. &lt;strong&gt;getAdjacentEdges 함수&lt;/strong&gt;를 이용하여 vertex로부터 연결된 edge를 구합니다.(함수 별도 구현)&lt;/p&gt;

&lt;p&gt;[Line 8~12]&lt;br /&gt;
&lt;img src=&quot;/assets/images/20260302/2.png&quot; alt=&quot;Dijkstra-0&quot; /&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00b050&quot;&gt;adjacentEdges에 저장된 정보를 이용하여 dist를 최단 거리로 업데이트하고&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;0번 vertex와 edge로 연결된 vertex의 prev를 0으로 설정합니다.&lt;/span&gt;&lt;br /&gt;
그러고 나서 &lt;span style=&quot;color: #ff00ff&quot;&gt;visited[0]=true;&lt;/span&gt;를 실행합니다.&lt;/p&gt;

&lt;p&gt;[Line 17~33]&lt;br /&gt;
&lt;img src=&quot;/assets/images/20260302/3.png&quot; alt=&quot;Dijkstra-3&quot; /&gt;&lt;br /&gt;
choose() 함수를 이용하여 아직 방문하지 않은 vertex 중 가장 가까운 vertex를 선택합니다(함수 별도 구현). 이번에는 3이네요.&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;visited[3]=true;&lt;/span&gt;를 실행합니다.&lt;br /&gt;
연결된 vertex는 2와 4가 있네요. 거리를 비교해 보면&lt;br /&gt;
2: 5==1+4 ⇒ dist[2]와 prev[2] 유지&lt;br /&gt;
4: MAX&amp;gt;1+1 ⇒ &lt;span style=&quot;color: #00b050&quot;&gt;dist[4]=2;&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;prev[4]=3;&lt;/span&gt;&lt;br /&gt;
이렇게 진행됩니다.&lt;/p&gt;

&lt;p&gt;모든 vertex를 방문할 때까지 Line 20~38을 계속 반복합니다. 예시를 이어서 보겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/4.png&quot; alt=&quot;Dijkstra-1&quot; /&gt;&lt;br /&gt;
아직 방문하지 않은 vertex 중 가장 가까운 vertex는 1입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;visited[1]=true;&lt;/span&gt;를 실행합니다.&lt;br /&gt;
연결된 vertex는 2가 있습니다.(3도 있지만 이미 방문했으므로 건너뜀.)&lt;br /&gt;
거리를 비교해 보면 5==2+3이므로 dist[2]와 prev[2]를 유지합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/5.png&quot; alt=&quot;Dijkstra-4&quot; /&gt;&lt;br /&gt;
아직 방문하지 않은 vertex 중 가장 가까운 vertex는 4입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;visited[4]=true;&lt;/span&gt;를 실행합니다.&lt;br /&gt;
연결된 vertex는 2와 5가 있네요. 거리를 비교해 보면&lt;br /&gt;
2: 5&amp;gt;2+2 ⇒ &lt;span style=&quot;color: #00b050&quot;&gt;dist[2]=4;&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;prev[2]=4;&lt;/span&gt;&lt;br /&gt;
5: MAX&amp;gt;2+1 ⇒ &lt;span style=&quot;color: #00b050&quot;&gt;dist[5]=3;&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;prev[5]=4;&lt;/span&gt;&lt;br /&gt;
이렇게 진행됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/6.png&quot; alt=&quot;Dijkstra-5&quot; /&gt;&lt;br /&gt;
아직 방문하지 않은 vertex 중 가장 가까운 vertex는 5입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;visited[5]=true;&lt;/span&gt;를 실행합니다.&lt;br /&gt;
5번 vertex에는 연결된 vertex가 없네요.(2와 4는 역방향입니다.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/7.png&quot; alt=&quot;Dijkstra-2&quot; /&gt;&lt;br /&gt;
아직 방문하지 않은 vertex 중 가장 가까운 vertex는 2입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;visited[2]=true;&lt;/span&gt;를 실행합니다.&lt;br /&gt;
나머지 vertex를 이미 모두 방문하였으므로 더 이상 업데이트할 것이 없습니다.&lt;/p&gt;

&lt;p&gt;그 다음 choose() 함수를 호출하면 -1 또는 이미 방문한 vertex를 반환합니다.&lt;br /&gt;
19행 &lt;strong&gt;if (u == -1 || getVisited(u) == true) break;&lt;/strong&gt;에 의해 반복문을 탈출하게 됩니다.&lt;/p&gt;

&lt;h2 id=&quot;5-출발-지점으로부터-도착-지점까지의-최단-경로-및-최단-거리-구하기&quot;&gt;5. ★출발 지점으로부터 도착 지점까지의 최단 경로 및 최단 거리 구하기&lt;/h2&gt;
&lt;p&gt;위의 다익스트라 알고리즘 소스코드를 실행하면 dist, visited, prev를 업데이트할 뿐 최단 경로가 눈에 바로 보이지는 않습니다. 그러나 우리가 궁금한 것은 출발 지점으로부터 도착 지점까지의 &lt;strong&gt;최단 경로&lt;/strong&gt;와 최단 거리입니다. 이것을 구하기 위해서 저는 &lt;strong&gt;void Graph::shortestPath(&lt;span style=&quot;color: #ff0000&quot;&gt;int start&lt;/span&gt;, &lt;span style=&quot;color: #00ff00&quot;&gt;int dest&lt;/span&gt;, &lt;span style=&quot;color: #0000ff&quot;&gt;vector&amp;lt;int&amp;gt;* result&lt;/span&gt;)&lt;/strong&gt; 함수를 만들었습니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//Graph.cpp 48~73&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Graph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shortestPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;dijkstra&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;stack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getPrev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;curr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//No path&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 3]&lt;br /&gt;
&lt;strong&gt;dijkstra(&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;start&lt;/span&gt;&lt;strong&gt;);&lt;/strong&gt;&lt;br /&gt;
먼저 3번 문단의 &lt;strong&gt;dijkstra&lt;/strong&gt; 함수를 호출하여 다익스트라 알고리즘을 수행합니다. parameter에는 &lt;span style=&quot;color: #ff0000&quot;&gt;start&lt;/span&gt;를 넣습니다.&lt;/p&gt;

&lt;p&gt;[Line 5]&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: #ff5000&quot;&gt;stack&amp;lt;int&amp;gt; path&lt;/span&gt;;&lt;/strong&gt;&lt;br /&gt;
stack을 하나 선언합니다. stack은 후입선출(LIFO) 자료 구조이죠.&lt;br /&gt;
다익스트라 알고리즘을 수행하고 나면 prev 배열을 이용하여 이전 vertex를 알 수 있으므로, 도착 지점(dest)에서부터 prev 배열을 타고 이전 vertex로 가면서 stack에 push한 다음, 그 stack의 원소들을 꺼내면 경로가 깔끔하게 나올 것입니다.&lt;/p&gt;

&lt;p&gt;[Line 6]&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: #ff00ff&quot;&gt;int curr&lt;/span&gt; =&lt;/strong&gt; &lt;span style=&quot;color: #00ff00&quot;&gt;dest&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
현재 위치를 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt;로 표현합니다.&lt;br /&gt;
초기 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt;는 &lt;span style=&quot;color: #00ff00&quot;&gt;dest&lt;/span&gt;(도착 지점)입니다.&lt;/p&gt;

&lt;p&gt;[Line 8~11]&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt; != &lt;span style=&quot;color: #ff0000&quot;&gt;start&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt; != -1이면 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt;를 &lt;span style=&quot;color: #ff5000&quot;&gt;path&lt;/span&gt;에 push하고 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt;에는 prev 배열을 이용하여 이전 vertex를 대입합니다. 이것을 반복합니다.&lt;/p&gt;

&lt;p&gt;[Line 13~15]&lt;br /&gt;
반복문을 탈출했을 때 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt; == &lt;span style=&quot;color: #ff0000&quot;&gt;start&lt;/span&gt;라면 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt;를 &lt;span style=&quot;color: #ff5000&quot;&gt;path&lt;/span&gt;에 push합니다.&lt;/p&gt;

&lt;p&gt;[Line 16~19]&lt;br /&gt;
반복문을 탈출했을 때 &lt;span style=&quot;color: #ff00ff&quot;&gt;curr&lt;/span&gt; == -1이라면 경로가 없는 것이므로 &lt;span style=&quot;color: #0000ff&quot;&gt;result&lt;/span&gt;를 clear하고 return합니다.&lt;/p&gt;

&lt;p&gt;[Line 21~24]&lt;br /&gt;
&lt;span style=&quot;color: #ff5000&quot;&gt;path&lt;/span&gt;가 빌 때까지 &lt;span style=&quot;color: #0000ff&quot;&gt;result&lt;/span&gt;에 &lt;span style=&quot;color: #ff5000&quot;&gt;path&lt;/span&gt;.top()를 삽입하고 &lt;span style=&quot;color: #ff5000&quot;&gt;path&lt;/span&gt;를 pop하는 것을 반복합니다.&lt;/p&gt;

&lt;p&gt;참고로 console 출력은 Manager.cpp에서 구현했습니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//Manager.cpp Line 117~138&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Manager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shortestPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//distance&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;graph&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Load graph first.&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;graph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shortestPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;graph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MAX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;X&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//can&apos;t go from start to end&lt;/span&gt;
		&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

			&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;(&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;graph&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDistance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;)&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 3]&lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;vector&amp;lt;int&amp;gt; path&lt;/span&gt;;&lt;/strong&gt;&lt;br /&gt;
경로를 저장할 vector입니다. Graph.cpp 48~73의 &lt;span style=&quot;color: #0000ff&quot;&gt;result&lt;/span&gt;입니다.&lt;/p&gt;

&lt;p&gt;[Line 10]&lt;br /&gt;
&lt;strong&gt;graph-&amp;gt;shortestPath(&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;start&lt;/span&gt;, &lt;span style=&quot;color: #00ff00&quot;&gt;dest&lt;/span&gt;, &lt;span style=&quot;color: #0000ff&quot;&gt;&amp;amp;path&lt;/span&gt;&lt;strong&gt;);&lt;/strong&gt;&lt;br /&gt;
Graph.cpp 48~73의 함수를 호출합니다.&lt;/p&gt;

&lt;p&gt;[Line 12~21]&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;path&lt;/span&gt;의 원소들을 출력합니다.&lt;/p&gt;

&lt;h2 id=&quot;6-나머지는-github-repository를-참고하세요&quot;&gt;6. 나머지는 GitHub repository를 참고하세요.&lt;/h2&gt;
&lt;p&gt;이 글에서 설명하지 않은 부분(파일 입력 구현, arraysinit, choose 등)은 제가 GitHub에 올려 둔 소스코드(&lt;a href=&quot;https://github.com/sooseongcom/Dijkstra&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://github.com/sooseongcom/Dijkstra&lt;/a&gt;)를 참고하시기 바랍니다.&lt;br /&gt;
특히 GitHub에 올려 둔 소스코드를 빌드하면 아래와 같은 명령어를 사용할 수 있으니 참고하시기 바랍니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;load &amp;lt;filepath&amp;gt;&lt;/code&gt;&lt;/strong&gt;: 그래프 파일(.txt)을 불러옵니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print&lt;/code&gt;&lt;/strong&gt;: 그래프를 출력합니다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shortestPath &amp;lt;start vertex&amp;gt; &amp;lt;destination vertex&amp;gt;&lt;/code&gt;&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;start vertex&amp;gt;&lt;/code&gt;부터 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;destination vertex&amp;gt;&lt;/code&gt;까지 최단 경로를 탐색합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260302/screenshot.png&quot; alt=&quot;콘솔 예시&quot; /&gt;&lt;br /&gt;
위 이미지는 사용 예시입니다.&lt;/p&gt;

&lt;h2 id=&quot;7-글-마무리&quot;&gt;7. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;8-참고-자료&quot;&gt;8. 참고 자료&lt;/h2&gt;
&lt;p&gt;1) KWiOS. 2022. “최단경로 - 다익스트라 알고리즘”, KWiOS0101. (2026. 02. 25. 방문). &lt;a href=&quot;https://kwios0101.tistory.com/71&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://kwios0101.tistory.com/71&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 02 Mar 2026 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/dijkstra</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/dijkstra</guid>
        
        
        <category>프로그래밍</category>
        
        <category>cpp</category>
        
      </item>
    
      <item>
        <title>[Verilog]Moore FSM으로 신호등 만들기</title>
        <description>&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;오늘은 Moore FSM(Finite State Machine)으로 신호등을 만들어 보겠습니다. 보통 신호등은 색깔별로 시간이 정해져 있지만, 오늘은 차량 통행의 유무에 따라 작동하는 신호등을 만들어 보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IDE: &lt;a href=&quot;https://www.intel.com/content/www/us/en/software-kit/665990/intel-quartus-prime-lite-edition-design-software-version-18-1-for-windows.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus 18.1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Device: Cyclone V 5CSXFC6D6F31C6(밑에서 6번째)&lt;/li&gt;
  &lt;li&gt;Simulation: ModelSim-Altera, Verilog HDL&lt;/li&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: fsm_traffic_light&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-신호등-규칙-설명&quot;&gt;1&lt;/a&gt;. 신호등 규칙 설명&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-structural-design&quot;&gt;2&lt;/a&gt;. Structural Design&lt;br /&gt;
&lt;a href=&quot;#21-fsm-설계&quot;&gt;2.1&lt;/a&gt;. FSM 설계&lt;br /&gt;
&lt;a href=&quot;#22-reg2v&quot;&gt;2.2&lt;/a&gt;. reg2.v&lt;br /&gt;
&lt;a href=&quot;#23-fsm_traffic_lightv&quot;&gt;2.3&lt;/a&gt;. fsm_traffic_light.v&lt;br /&gt;
&lt;a href=&quot;#24-tb_fsm_traffic_lightv&quot;&gt;2.4&lt;/a&gt;. tb_fsm_traffic_light.v&lt;br /&gt;
&lt;a href=&quot;#25-simmulationmodelsimtv_fsm_traffic_lighttv&quot;&gt;2.5&lt;/a&gt;. simmulation\modelsim\tv_fsm_traffic_light.tv&lt;br /&gt;
&lt;a href=&quot;#26-rtl-view&quot;&gt;2.6&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#27-rtl-simulation&quot;&gt;2.7&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#28-flow-summary&quot;&gt;2.8&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#3-behavioral-design&quot;&gt;3&lt;/a&gt;. Behavioral Design&lt;br /&gt;
&lt;a href=&quot;#31-fsm-state-transition-diagram&quot;&gt;3.1&lt;/a&gt;. FSM State Transition Diagram&lt;br /&gt;
&lt;a href=&quot;#32-fsm_traffic_lightv&quot;&gt;3.2&lt;/a&gt;. fsm_traffic_light.v&lt;br /&gt;
&lt;a href=&quot;#33-tb_fsm_traffic_lightv--simmulationmodelsimtv_fsm_traffic_lighttv&quot;&gt;3.3&lt;/a&gt;. tb_fsm_traffic_light.v &amp;amp; simmulation\modelsim\tv_fsm_traffic_light.tv&lt;br /&gt;
&lt;a href=&quot;#34-rtl-view&quot;&gt;3.4&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#35-rtl-simulation&quot;&gt;3.5&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#36-flow-summary&quot;&gt;3.6&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#4-글-마무리&quot;&gt;4&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#5-참고-문헌&quot;&gt;5&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-신호등-규칙-설명&quot;&gt;1. 신호등 규칙 설명&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-rule.png&quot; alt=&quot;신호등 규칙&quot; /&gt;&lt;br /&gt;
보통 신호등은 색깔별로 시간이 정해져 있지만, 오늘은 차량 통행의 유무에 따라 작동하는 신호등을 만들어 보겠다고 말씀드렸습니다.&lt;br /&gt;
A, B 도로가 있습니다.&lt;br /&gt;
Reset이 1이 되면(rising edge) A 도로의 신호등에는 초록 불이, B 도로의 신호등에는 빨간 불이 켜집니다. A 도로에 차량 통행이 있는 동안에는 A 도로 신호등의 초록 불이 유지됩니다.&lt;br /&gt;
A 도로에 차량 통행이 더 이상 없으면 A 도로의 신호등이 노란 불로 바뀝니다.&lt;br /&gt;
그 다음 A 도로의 신호등은 빨간 불로, B 도로의 신호등은 초록 불로 바뀝니다. B 도로에 차량 통행이 있는 동안에는 B 도로 신호등의 초록 불이 유지됩니다.&lt;br /&gt;
B 도로에 차량 통행이 더 이상 없으면 B 도로의 신호등이 노란 불로 바뀝니다.&lt;br /&gt;
그 다음 A 도로의 신호등은 초록 불로, B 도로의 신호등은 빨간 불로 바뀝니다.&lt;/p&gt;

&lt;h2 id=&quot;2-structural-design&quot;&gt;2. Structural Design&lt;/h2&gt;
&lt;h3 id=&quot;21-fsm-설계&quot;&gt;2.1. FSM 설계&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-1.png&quot; alt=&quot;FSM State Transition Diagram&quot; /&gt;&lt;br /&gt;
2.1.①. FSM State Transition Diagram을 설계합니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(T_A\): A 도로의 차량 통행 여부(있으면 1, 없으면 0)&lt;/li&gt;
  &lt;li&gt;\(T_B\): B 도로의 차량 통행 여부(있으면 1, 없으면 0)&lt;/li&gt;
  &lt;li&gt;\(L_A\): A 도로의 신호등 색깔&lt;/li&gt;
  &lt;li&gt;\(L_B\): B 도로의 신호등 색깔&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1번 문단에서 설명드린 내용이 위의 이미지와 같이 설계됩니다. 신호등 색깔에 따라서 state를 S0~S3으로 나누었습니다. 이것 중에서 S0~S1만 자세히 설명을 드리고 넘어가겠습니다.&lt;br /&gt;
Reset이 1이 되면(rising edge) A 도로의 신호등에는 초록 불이(S0 상태, \(L_A\): green), B 도로의 신호등에는 빨간 불이(\(L_B\): red) 켜집니다. A 도로에 차량 통행이 있는 동안에는(\(T_A\)) A 도로 신호등의 초록 불이 유지됩니다(S0 유지).&lt;br /&gt;
A 도로에 차량 통행이 더 이상 없으면(\(\overline{T_A}\)) A 도로의 신호등이 노란 불로 바뀝니다(S1으로 변경, \(L_A\): yellow, \(L_B\): red).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-2.png&quot; alt=&quot;FSM State Transition Table&quot; /&gt;&lt;br /&gt;
2.1.②. FSM State Transition Table을 만듭니다. Current State는 &lt;em&gt;Q&lt;/em&gt;이고, Next State는 &lt;em&gt;D&lt;/em&gt;입니다.&lt;br /&gt;
흰색 1~2번째 줄(&lt;em&gt;Q&lt;/em&gt;=S0)만 설명을 드리자면,&lt;br /&gt;
&lt;em&gt;Q&lt;/em&gt;=S0, \(T_A=0\)이면 \(T_B\)에 상관없이 &lt;em&gt;D&lt;/em&gt;=S1이 됩니다.&lt;br /&gt;
&lt;em&gt;Q&lt;/em&gt;=S0, \(T_A=1\)이면 \(T_B\)에 상관없이 &lt;em&gt;D&lt;/em&gt;=S0이 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-3.png&quot; alt=&quot;FSM Encode State Transition Table&quot; /&gt;&lt;br /&gt;
2.1.③. 위의 이미지 왼쪽부터 보시면 됩니다.&lt;br /&gt;
S0~S3을 무엇으로 Encoding할지 Encoding Table을 만듭니다.&lt;br /&gt;
&lt;em&gt;S&lt;/em&gt;개의 state를 binary encoding할 때 \(\lceil \log_2 S \rceil\)비트로 encoding됩니다. 지금은 state가 4개이니 \(\lceil \log_2 4 \rceil = 2\)비트가 되네요.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;↓&lt;/span&gt;&lt;br /&gt;
앞서 만든 FSM State Transition Table과 Encoding Table을 토대로 FSM Encode State Transition Table을 만듭니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;↓&lt;/span&gt;&lt;br /&gt;
\(D_1\)과 \(D_0\) 각각의 boolean equation을 도출합니다.&lt;br /&gt;
Karnaugh Map을 그려 본 결과&lt;br /&gt;
\(D_1 = Q_1 \oplus Q_0\)&lt;br /&gt;
\(D_0 = {Q_1}’{Q_0}’{T_A}’+Q_1{Q_0}’{T_B}’\)&lt;br /&gt;
가 나왔습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-4.png&quot; alt=&quot;FSM Output Table&quot; /&gt;&lt;br /&gt;
2.1.④. 신호등 색깔별로 Encoding합니다. 신호등 색깔은 3개이므로 binary encoding하면 \(\lceil \log_2 3 \rceil = \lceil 1. \text x \text x \rceil = 2\) 비트로 encoding되네요.&lt;br /&gt;
Current State에 따라 \(L_A\)와 \(L_B\)를 어떻게 출력할 것인지 FSM Output Table을 그립니다. 가령 \(Q_1=0\), \(Q_0=0\)이면 \(L_A\)는 green, \(L_B\)는 red이므로 \(L_A=00_2\), \(L_B=10_2\)가 됩니다.&lt;br /&gt;
그러면 신호등의 boolean equation은 아래와 같이 나옵니다.&lt;br /&gt;
\(L_{A1}=Q_1\)&lt;br /&gt;
\(L_{A0}=\overline{Q_1} Q_0\)&lt;br /&gt;
\(L_{B1}=\overline{Q_1}\)&lt;br /&gt;
\(L_{B0}=Q_1 Q_0\)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-5.png&quot; alt=&quot;FSM Schematic&quot; /&gt;&lt;br /&gt;
2.1.⑤. State Register를 그립니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;2.1.⑥. Next State Logic을 만듭니다.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;2.1.⑦. Output Logic을 만듭니다.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-6.png&quot; alt=&quot;Bubble Pushing&quot; /&gt;&lt;br /&gt;
저는 추가로 bubble pushing도 해 주었습니다.&lt;/p&gt;

&lt;p&gt;2.1.⑧. Timing analysis를 합니다. 다만, 오늘 Verilog 설계를 할 때는 timing analysis를 생략하겠습니다. Intel Quartus로 timing analysis하는 방법은 지난 글을 참고하시기 바랍니다.&lt;br /&gt;
&lt;a href=&quot;/post/verilog-timing-quartus&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus로 Verilog Timing Analysis(https://sooseongcom.com/post/verilog-timing-quartus)&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;22-reg2v&quot;&gt;2.2. reg2.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;
 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;23-fsm_traffic_lightv&quot;&gt;2.3. fsm_traffic_light.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fsm_traffic_light&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//inputs and outputs&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//states&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Next State&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Current State&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//wire for NAND gate&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_nd1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_nd2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//d[1]=q[1]^q[0]&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;xor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//d[0]=~((~(~q[1]&amp;amp;~q[0]&amp;amp;~traffic_a))&amp;amp;(~(q[1]&amp;amp;~q[0]&amp;amp;~traffic_b)))&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w_nd1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w_nd2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_nd1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_nd2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;reg2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;state_reg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	
	&lt;span class=&quot;kt&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 4]&lt;br /&gt;
&lt;strong&gt;input&lt;/strong&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;, &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;는 \(T_A\)이고, &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;는 \(T_B\)입니다.&lt;/p&gt;

&lt;p&gt;[Line 5]&lt;br /&gt;
&lt;strong&gt;output [1:0]&lt;/strong&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;light_a&lt;/span&gt;, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;light_a&lt;/span&gt;는 \(L_A\)이고, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b&lt;/span&gt;는 \(L_B\)입니다.&lt;/p&gt;

&lt;p&gt;[Line 7~9 states]&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;d&lt;/span&gt;와 &lt;span style=&quot;color: #00ffff&quot;&gt;q&lt;/span&gt;를 2-bit wire로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 11~12 wire for NAND gate]&lt;br /&gt;
12행) &lt;strong&gt;wire w_nd1, w_nd2;&lt;/strong&gt;&lt;br /&gt;
NAND gate의 output을 연결할 wire를 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 14~20]&lt;br /&gt;
Next State Logic입니다.&lt;/p&gt;

&lt;p&gt;[Line 22]&lt;br /&gt;
&lt;strong&gt;reg2 state_reg(clk, reset_n,&lt;/strong&gt; &lt;span style=&quot;color: #ff00ff&quot;&gt;d&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #00ffff&quot;&gt;q&lt;/span&gt;&lt;strong&gt;);&lt;/strong&gt;&lt;br /&gt;
State Register는 reg2를 instantiation하여 구현합니다.&lt;/p&gt;

&lt;p&gt;[Line 24~28]&lt;br /&gt;
Output Logic입니다.&lt;/p&gt;

&lt;h3 id=&quot;24-tb_fsm_traffic_lightv&quot;&gt;2.4. tb_fsm_traffic_light.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_fsm_traffic_light&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//bookkeeping variables&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//array of testvectors&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instantiate device under test&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fsm_traffic_light&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//generate clock&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//at start of test, load vectors and pulse reset&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;readmemb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tv_fsm_traffic_light.tv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Put testvector file at simulation\modelsim&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//apply test vectors on rising edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//check results on falling edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//skip during reset==1&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}!=={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: inputs=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;	outputs=%b (%b expected)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
			
	&lt;span class=&quot;c1&quot;&gt;//increment array index and read next testvector&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;32&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d tests completed with %d errors.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;finish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;
 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;25-simmulationmodelsimtv_fsm_traffic_lighttv&quot;&gt;2.5. simmulation\modelsim\tv_fsm_traffic_light.tv&lt;/h3&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00_0110
01_1000
01_1000
10_1000
10_1001
11_0010
11_0010
00_0010
00_0110
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;각 줄이 &lt;span style=&quot;color: #ff0000&quot;&gt;&amp;lt;traffic_a&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;&amp;lt;traffic_b&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color: #0000ff&quot;&gt;&amp;lt;light_a_expected&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #ff8000&quot;&gt;&amp;lt;light_b_expected&amp;gt;&lt;/span&gt;입니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;&amp;lt;light_a_expected&amp;gt;와 &lt;/span&gt;&lt;span style=&quot;color: #ff8000&quot;&gt;&amp;lt;light_b_expected&amp;gt;&lt;/span&gt;는 각각 2-bit이며, Current State에 따른 출력 값을 기준으로 합니다.&lt;br /&gt;
예) &lt;span style=&quot;color: #ff0000&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;0&lt;/span&gt;_&lt;span style=&quot;color: #0000ff&quot;&gt;01&lt;/span&gt;&lt;span style=&quot;color: #ff8000&quot;&gt;10&lt;/span&gt;은 &lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a=0&lt;/span&gt;, &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b=0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff&quot;&gt;light_a_expected=01&lt;/span&gt;, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b_expected=10&lt;/span&gt;입니다.&lt;/p&gt;

&lt;h3 id=&quot;26-rtl-view&quot;&gt;2.6. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-view.png&quot; alt=&quot;Structural RTL View&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;27-rtl-simulation&quot;&gt;2.7. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-sim.png&quot; alt=&quot;Structural RTL Simulation&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;28-flow-summary&quot;&gt;2.8. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-flow.png&quot; alt=&quot;Structural Flow Summary&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Logic utilization (in ALMs): 3 / 41,910 (&amp;lt;1%)&lt;/li&gt;
  &lt;li&gt;Total registers: 3&lt;/li&gt;
  &lt;li&gt;Total pins: 8 / 499 (2%)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-behavioral-design&quot;&gt;3. Behavioral Design&lt;/h2&gt;
&lt;h3 id=&quot;31-fsm-state-transition-diagram&quot;&gt;3.1. FSM State Transition Diagram&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/1-1.png&quot; alt=&quot;FSM State Transition Diagram&quot; /&gt;&lt;br /&gt;
Behavioral Design도 FSM State Transition Diagram을 그립니다. FSM State Transition Diagram은 Structural Design과 같습니다.&lt;/p&gt;

&lt;h3 id=&quot;32-fsm_traffic_lightv&quot;&gt;3.2. fsm_traffic_light.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fsm_traffic_light&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//inputs and outputs&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//encoded states&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//encoded outputs&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GREEN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;YELLOW&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;parameter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//sequential circuit part&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Next State&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Current State&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//combinational circuit part&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;casex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traffic_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;b0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;b1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;b0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;b1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;endcase&lt;/span&gt;
		
		&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;nl&quot;&gt;S0:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GREEN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;nl&quot;&gt;S1:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;YELLOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;nl&quot;&gt;S2:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GREEN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;nl&quot;&gt;S3:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;light_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;light_b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;YELLOW&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;endcase&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 4]&lt;br /&gt;
&lt;strong&gt;input&lt;/strong&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;, &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;는 \(T_A\)이고, &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;는 \(T_B\)입니다.&lt;/p&gt;

&lt;p&gt;[Line 5]&lt;br /&gt;
&lt;strong&gt;output reg [1:0]&lt;/strong&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;light_a&lt;/span&gt;, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;light_a&lt;/span&gt;는 \(L_A\)이고, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b&lt;/span&gt;는 \(L_B\)입니다. reg로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 7~11 encoded states]&lt;br /&gt;
S0부터 S3까지를 parameter로 선언하고 각각의 binary encoding으로 초기화합니다. parameter 이름은 일반적으로 대문자로 짓습니다.&lt;/p&gt;

&lt;p&gt;[Line 13~16 encoded outputs]&lt;br /&gt;
신호등 색깔을 parameter로 선언하고 각각의 binary encoding으로 초기화합니다. 7~11행의 states와 마찬가지로 이름은 대문자로 짓습니다.&lt;/p&gt;

&lt;p&gt;[Line 19~20]&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;d&lt;/span&gt;와 &lt;span style=&quot;color: #00ffff&quot;&gt;q&lt;/span&gt;를 2-bit reg로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 21~25]&lt;br /&gt;
State Register입니다.&lt;/p&gt;

&lt;p&gt;[Line 21]&lt;br /&gt;
&lt;strong&gt;always @ (posedge clk or negedge reset_n)&lt;/strong&gt;&lt;br /&gt;
clk가 0→1 상승하거나(posedge) reset_n이 1→0 하강할 때(negedge) 출력 값을 업데이트합니다.&lt;/p&gt;

&lt;p&gt;[Line 23]&lt;br /&gt;
&lt;strong&gt;if(reset_n==0)	q&amp;lt;=S0;&lt;/strong&gt;&lt;br /&gt;
reset_n==0이면 즉시 q&amp;lt;=S0;을 수행합니다.&lt;/p&gt;

&lt;p&gt;[Line 24]&lt;br /&gt;
&lt;strong&gt;else	q&amp;lt;=d;&lt;/strong&gt;&lt;br /&gt;
reset_n!=0이면(즉, reset_n==1이면) q&amp;lt;=d;를 수행합니다.&lt;/p&gt;

&lt;p&gt;[Line 29]&lt;br /&gt;
&lt;strong&gt;always @ (&lt;/strong&gt;&lt;span style=&quot;color: #5000ff&quot;&gt;*&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
Next State Logic과 Output Logic은 combinational circuit이므로 always문의 조건을 &lt;span style=&quot;color: #5000ff&quot;&gt;*&lt;/span&gt;로 합니다.&lt;/p&gt;

&lt;p&gt;[Line 31~38]&lt;br /&gt;
Next State Logic입니다.&lt;/p&gt;

&lt;p&gt;[Line 31]&lt;br /&gt;
&lt;strong&gt;casex(&lt;/strong&gt;&lt;span style=&quot;color: #705050&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #00ffff&quot;&gt;q&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;&lt;span style=&quot;color: #705050&quot;&gt;}&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
x 기호를 don’t care로 사용하기 위해서 case 대신 case&lt;u&gt;x&lt;/u&gt;를 사용합니다.&lt;br /&gt;
&lt;span style=&quot;color: #705050&quot;&gt;중괄호&lt;/span&gt;는 concatenation으로서 어떤 두 signal을 연결해 줍니다.&lt;br /&gt;
&lt;span style=&quot;color: #705050&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #00ffff&quot;&gt;q&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;traffic_a&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #00ff00&quot;&gt;traffic_b&lt;/span&gt;&lt;span style=&quot;color: #705050&quot;&gt;}&lt;/span&gt;의 값에 따라 case문이 작동하게 됩니다.&lt;br /&gt;
32~37행 코드를 보시면 어떤 원리로 작동되는지 아실 것 같습니다.&lt;/p&gt;

&lt;p&gt;[Line 40~45]&lt;br /&gt;
Output Logic입니다.&lt;/p&gt;

&lt;p&gt;[Line 41~44]&lt;br /&gt;
41행) &lt;span style=&quot;color: #00ffff&quot;&gt;S0&lt;/span&gt;&lt;strong&gt;:&lt;/strong&gt; &lt;span style=&quot;color: #705050&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;light_a&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #ff8000&quot;&gt;light_b&lt;/span&gt;&lt;span style=&quot;color: #705050&quot;&gt;}&lt;/span&gt;=&lt;span style=&quot;color: #705050&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;GREEN&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #ff8000&quot;&gt;RED&lt;/span&gt;&lt;span style=&quot;color: #705050&quot;&gt;}&lt;/span&gt;;&lt;br /&gt;
concatenation은 값을 대입할 때도 사용 가능합니다. 41행 코드는 &lt;span style=&quot;color: #00ffff&quot;&gt;q==S0&lt;/span&gt;일 때 &lt;span style=&quot;color: #0000ff&quot;&gt;light_a에는 GREEN을&lt;/span&gt;, &lt;span style=&quot;color: #ff8000&quot;&gt;light_b에는 RED를&lt;/span&gt; 대입합니다.&lt;/p&gt;

&lt;h3 id=&quot;33-tb_fsm_traffic_lightv--simmulationmodelsimtv_fsm_traffic_lighttv&quot;&gt;3.3. tb_fsm_traffic_light.v &amp;amp; simmulation\modelsim\tv_fsm_traffic_light.tv&lt;/h3&gt;
&lt;p&gt;testbench와 testvector는 Structural Design에서 사용한 것과 동일합니다.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#24-tb_fsm_traffic_lightv&quot;&gt;2.4&lt;/a&gt;. tb_fsm_traffic_light.v&lt;br /&gt;
&lt;a href=&quot;#25-simmulationmodelsimtv_fsm_traffic_lighttv&quot;&gt;2.5&lt;/a&gt;. simmulation\modelsim\tv_fsm_traffic_light.tv&lt;/p&gt;

&lt;h3 id=&quot;34-rtl-view&quot;&gt;3.4. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/2-view.png&quot; alt=&quot;Behavioral RTL View&quot; /&gt;&lt;br /&gt;
Decoder가 사용되었습니다. Concatenation을 사용한 것들이 다 decoder로 변환된 듯 보입니다.&lt;/p&gt;

&lt;h3 id=&quot;35-rtl-simulation&quot;&gt;3.5. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/2-sim.png&quot; alt=&quot;Behavioral RTL Simulation&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;36-flow-summary&quot;&gt;3.6. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251215/2-flow.png&quot; alt=&quot;Behavioral Flow Summary&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Logic utilization (in ALMs): 3 / 41,910 (&amp;lt;1%)&lt;/li&gt;
  &lt;li&gt;Total registers: 3&lt;/li&gt;
  &lt;li&gt;Total pins: 8 / 499 (2%)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Structural Design과 똑같이 나왔습니다.&lt;/p&gt;

&lt;h2 id=&quot;4-글-마무리&quot;&gt;4. 글 마무리&lt;/h2&gt;
&lt;p&gt;오늘은 이렇게 신호등 Moore FSM을 Structural Design과 Behavioral Design으로 각각 구현해 보았습니다.&lt;br /&gt;
제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;5-참고-문헌&quot;&gt;5. 참고 문헌&lt;/h2&gt;
&lt;p&gt;1) David Money Harris, Sarah L. Harris. 2013. Digital Design and Computer Architecture. 2nd Edition. Elsevier Korea L.L.C.&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Mon, 15 Dec 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/verilog-fsm-traffic-light</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/verilog-fsm-traffic-light</guid>
        
        
        <category>프로그래밍</category>
        
        <category>Verilog</category>
        
      </item>
    
      <item>
        <title>Intel Quartus로 Verilog Timing Analysis</title>
        <description>&lt;p&gt;Combinational circuit과 sequential circuit이 섞인 회로를 구성할 때는 delay를 고려하여 클럭의 frequency를 정해야 합니다. 오늘은 Intel Quartus로 timing analysis하는 방법을 알아보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IDE: &lt;a href=&quot;https://www.intel.com/content/www/us/en/software-kit/665990/intel-quartus-prime-lite-edition-design-software-version-18-1-for-windows.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus 18.1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Device: Cyclone V 5CSXFC6D6F31C6(밑에서 6번째)&lt;/li&gt;
  &lt;li&gt;Simulation: ModelSim-Altera, Verilog HDL&lt;/li&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: cla32_clk&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-예제-코드&quot;&gt;1&lt;/a&gt;. 예제 코드&lt;br /&gt;
&lt;a href=&quot;#11-cla32v&quot;&gt;1.1&lt;/a&gt;. cla32.v&lt;br /&gt;
&lt;a href=&quot;#12-reg32v&quot;&gt;1.2&lt;/a&gt;. reg32.v&lt;br /&gt;
&lt;a href=&quot;#13-_dff_rv&quot;&gt;1.3&lt;/a&gt;. _dff_r.v&lt;br /&gt;
&lt;a href=&quot;#14-cla32_clkv&quot;&gt;1.4&lt;/a&gt;. cla32_clk.v&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-timing-analysis&quot;&gt;2&lt;/a&gt;. Timing Analysis&lt;br /&gt;
&lt;a href=&quot;#3-글-마무리&quot;&gt;3&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#4-참고-자료&quot;&gt;4&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-예제-코드&quot;&gt;1. 예제 코드&lt;/h2&gt;
&lt;p&gt;32-bit Carry Look-Ahead(CLA) Adder with clock을 만들겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/rtl-view.png&quot; alt=&quot;RTL View&quot; /&gt;&lt;br /&gt;
참고로 합성 후 RTL View는 위와 같이 나옵니다.&lt;/p&gt;

&lt;h3 id=&quot;11-cla32v&quot;&gt;1.1. cla32.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cla32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//32-bit Carry Look-Ahead Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U4_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U5_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U6_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U7_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//full adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Ripple Carry Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;carry4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Carry Look-Ahead Carry&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Carry Look-Ahead Block&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;carry4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_carry4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;CLA Adder에 대한 설명은 &lt;a href=&quot;https://sooseongcom.com/post/adder-subtractor#2-carry-look-ahead-adder&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://sooseongcom.com/post/adder-subtractor#2-carry-look-ahead-adder&lt;/a&gt;를 참고하시기 바랍니다.&lt;/p&gt;

&lt;h3 id=&quot;12-reg32v&quot;&gt;1.2. reg32.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reg32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;32-bit register입니다.&lt;/p&gt;

&lt;h3 id=&quot;13-_dff_rv&quot;&gt;1.3. _dff_r.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;
 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;D Flip-flop입니다.&lt;/p&gt;

&lt;h3 id=&quot;14-cla32_clkv&quot;&gt;1.4. cla32_clk.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cla32_clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//outputs of registers&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;//output of D Flip-flop&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//input of register&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;//input of D Flip-flop&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//input registers&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;reg32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_reg32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;reg32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_reg32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//output registers&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;reg32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_reg32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U4_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//combinational circuit&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;cla32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U5_cla32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w_co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;input인 a, b, ci와 output인 s, co를 모두 register 또는 D Flip-flop로 할 것입니다.&lt;br /&gt;
Clock의 이름은 &lt;span style=&quot;color: #ff00ff&quot;&gt;clk&lt;/span&gt;로 했습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/rtl-view-wire.png&quot; alt=&quot;RTL View with 빨간 글씨&quot; /&gt;&lt;br /&gt;
이해하기 쉽도록 빨간 글씨로 표시해 드렸으니 참고하세요.^^&lt;/p&gt;

&lt;h2 id=&quot;2-timing-analysis&quot;&gt;2. Timing Analysis&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/1.png&quot; alt=&quot;Tools&quot; /&gt;&lt;br /&gt;
2.1. &lt;strong&gt;Tools&lt;/strong&gt;→&lt;strong&gt;Timing Analyzer&lt;/strong&gt;로 들어갑니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/2.png&quot; alt=&quot;Welcome to the Quartus Prime Timing Analyzer&quot; /&gt;&lt;br /&gt;
2.2. &lt;strong&gt;Create Timing Netlist&lt;/strong&gt;, &lt;strong&gt;Read SDC File&lt;/strong&gt;, &lt;strong&gt;Update Timing Netlist&lt;/strong&gt;를 각각 더블클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/3.png&quot; alt=&quot;Timing Analyzer Summary&quot; /&gt;&lt;br /&gt;
2.3. &lt;strong&gt;Report Setup Summary&lt;/strong&gt;를 더블클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/4.png&quot; alt=&quot;Slow 1100mV 85C Model&quot; /&gt;&lt;br /&gt;
2.4. Top module에 있는 clock이 창의 Clock 항목에 나타납니다. 예제 코드대로 하면 &lt;span style=&quot;color: #ff00ff&quot;&gt;clk&lt;/span&gt;가 있을 것입니다. &lt;span style=&quot;color: #ff00ff&quot;&gt;clk&lt;/span&gt;를 오른쪽 클릭하고 &lt;strong&gt;Report Timing&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/5.png&quot; alt=&quot;Report Timing&quot; /&gt;&lt;br /&gt;
2.5. &lt;strong&gt;Report Timing&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/6.png&quot; alt=&quot;오른쪽 아래 빨간색 보임&quot; /&gt;&lt;br /&gt;
2.6. 오른쪽 아래를 보면 Slack이 -4.27 ns로 음수인 것을 볼 수 있습니다. 이는 clock 주기 안에 데이터가 전달되지 않았다는 뜻이므로 clock 주기를 늘려야 합니다.&lt;br /&gt;
참고) 초기 clock 주기는 1ns입니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/7.png&quot; alt=&quot;Constraints&quot; /&gt;&lt;br /&gt;
2.7. &lt;strong&gt;Constraints&lt;/strong&gt;→&lt;strong&gt;Create Clock...&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/8.png&quot; alt=&quot;Create Clock&quot; /&gt;&lt;br /&gt;
2.8. Clock name은 &lt;span style=&quot;color: #ff00ff&quot;&gt;Top module에서 사용하는 clock의 이름(예제 기준: clk)&lt;/span&gt;을 입력합니다.&lt;br /&gt;
2.9. Period는 적당히 큰 숫자를 입력합니다. 저는 기본값인 10.000 그대로 두었습니다.&lt;br /&gt;
2.10. Targets는 &lt;span style=&quot;color: #ff00ff&quot;&gt;Top module에서 사용하는 clock의 이름(예제 기준: clk)&lt;/span&gt;을 입력합니다.&lt;br /&gt;
2.11. &lt;span style=&quot;color: #0000ff&quot;&gt;Run&lt;/span&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/9.png&quot; alt=&quot;Write SDC File&quot; /&gt;&lt;br /&gt;
2.12. 왼쪽 Tasks를 아래로 스크롤하면 &lt;strong&gt;Write SDC File...&lt;/strong&gt;이 있습니다. 더블클릭합니다.&lt;br /&gt;
2.13. SDC file name을 확인하고 &lt;strong&gt;OK&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/10.png&quot; alt=&quot;Assignments&quot; /&gt;&lt;br /&gt;
2.14. 다시 Quartus 메인 창으로 돌아와서 &lt;strong&gt;Assignments&lt;/strong&gt;→&lt;strong&gt;Settings...&lt;/strong&gt;로 들어갑니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/11.png&quot; alt=&quot;Settings&quot; /&gt;&lt;br /&gt;
2.15. &lt;strong&gt;Timing Analyzer&lt;/strong&gt; 카테고리로 들어가서 File name &lt;strong&gt;...&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/12.png&quot; alt=&quot;cla32_clk.out.sdc 선택&quot; /&gt;&lt;br /&gt;
2.16. 방금 만든 SDC 파일을 선택합니다.(확장명이 .sdc인 것을 선택하세요.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/13.png&quot; alt=&quot;SDC 추가 완료&quot; /&gt;&lt;br /&gt;
2.17. &lt;strong&gt;OK&lt;/strong&gt;를 클릭합니다.&lt;br /&gt;
2.18. 다시 컴파일합니다.(&lt;strong&gt;Ctrl+L&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/15.png&quot; alt=&quot;Timing Analyzer 복귀&quot; /&gt;&lt;br /&gt;
2.19. Timing Analyzer 창으로 다시 돌아갑니다.&lt;br /&gt;
2.20. &lt;strong&gt;Create Timing Netlist&lt;/strong&gt;, &lt;strong&gt;Read SDC File&lt;/strong&gt;, &lt;strong&gt;Update Timing Netlist&lt;/strong&gt;, &lt;strong&gt;Report Setup Summary&lt;/strong&gt;를 각각 더블클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/16.png&quot; alt=&quot;Slow 1100mV 85C Model&quot; /&gt;&lt;br /&gt;
2.21. &lt;span style=&quot;color: #ff00ff&quot;&gt;clk&lt;/span&gt;를 오른쪽 클릭하고 &lt;strong&gt;Report Timing&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/17.png&quot; alt=&quot;Report Timing&quot; /&gt;&lt;br /&gt;
2.22. &lt;strong&gt;OK&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/18.png&quot; alt=&quot;오른쪽 아래 초록색 보임&quot; /&gt;&lt;br /&gt;
2.23. 오른쪽 아래를 보면 Slack이 3.337 ns로 양수인 것을 볼 수 있습니다. 그러면 성공입니다. 그렇다고 clock 주기를 10ns로 계속 사용할 수는 없으니 clock 주기의 최솟값을 찾아 봅시다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/19.png&quot; alt=&quot;Datasheet 아래 Report Fmax Summary&quot; /&gt;&lt;br /&gt;
2.24. 왼쪽 Tasks에서 &lt;strong&gt;Report Fmax Summary&lt;/strong&gt;를 더블클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251206/20.png&quot; alt=&quot;Fmax와 Restricted Fmax&quot; /&gt;&lt;br /&gt;
2.25. &lt;span style=&quot;color: #0000ff&quot;&gt;Fmax&lt;/span&gt;와 &lt;span style=&quot;color: #ff0000&quot;&gt;Restricted Fmax&lt;/span&gt;를 확인할 수 있습니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;Fmax&lt;/span&gt;는 회로가 작동할 수 있는 최대 frequency입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;Restricted Fmax&lt;/span&gt;는 FGPA device limit을 고려한 최대 frequency로써, Fmax보다 클 수 있습니다.&lt;br /&gt;
일단 오늘 회로는 둘 다 150.08MHz가 나왔네요. 최대 frequency는 150.08MHz가 되겠습니다. 최소 주기는 150.08MHz의 역수가 되겠지요.&lt;/p&gt;

&lt;h2 id=&quot;3-글-마무리&quot;&gt;3. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;4-참고-자료&quot;&gt;4. 참고 자료&lt;/h2&gt;
&lt;p&gt;1) Intel Corporation. n. d. “fmax Definition”, Intel® Quartus® Prime Pro Edition Help version 22.1. (2025. 12. 06. 방문). &lt;a href=&quot;https://www.intel.la/content/www/xl/es/programmable/quartushelp/22.1/index.htm#reference/glossary/def_fmax.htm&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://www.intel.la/content/www/xl/es/programmable/quartushelp/22.1/index.htm#reference/glossary/def_fmax.htm&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 06 Dec 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/verilog-timing-quartus</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/verilog-timing-quartus</guid>
        
        
        <category>프로그래밍</category>
        
        <category>Verilog</category>
        
      </item>
    
      <item>
        <title>[Verilog]RCA, CLA Adder, Subtractor</title>
        <description>&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;오늘은 Verilog로 32-bit 덧셈기(가산기, adder)와 뺄셈기(감산기, subtractor)를 구현해 보겠습니다. 덧셈기는 Ripple Carry Adder 방식과 Carry Look-Ahead Adder 방식으로 구현해 보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IDE: &lt;a href=&quot;https://www.intel.com/content/www/us/en/software-kit/665990/intel-quartus-prime-lite-edition-design-software-version-18-1-for-windows.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus 18.1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Device: Cyclone V 5CSXFC6D6F31C6(밑에서 6번째)&lt;/li&gt;
  &lt;li&gt;Simulation: ModelSim-Altera, Verilog HDL&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-ripple-carry-adder&quot;&gt;1&lt;/a&gt;. Ripple Carry Adder&lt;br /&gt;
&lt;a href=&quot;#11-half-adder&quot;&gt;1.1&lt;/a&gt;. Half Adder&lt;br /&gt;
&lt;a href=&quot;#12-full-adder&quot;&gt;1.2&lt;/a&gt;. Full Adder&lt;br /&gt;
&lt;a href=&quot;#13-ripple-carry-adder-구현-방법&quot;&gt;1.3&lt;/a&gt;. Ripple Carry Adder 구현 방법&lt;br /&gt;
&lt;a href=&quot;#14-rca32v&quot;&gt;1.4&lt;/a&gt;. rca32.v&lt;br /&gt;
&lt;a href=&quot;#15-tb_rca32v&quot;&gt;1.5&lt;/a&gt;. tb_rca32.v&lt;br /&gt;
&lt;a href=&quot;#16-rtl-view&quot;&gt;1.6&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#17-rtl-simulation&quot;&gt;1.7&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#18-flow-summary&quot;&gt;1.8&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-carry-look-ahead-adder&quot;&gt;2&lt;/a&gt;. Carry Look-Ahead Adder&lt;br /&gt;
&lt;a href=&quot;#21-carry-look-ahead-adder는-무엇인가&quot;&gt;2.1&lt;/a&gt;. Carry Look-Ahead Adder는 무엇인가?&lt;br /&gt;
&lt;a href=&quot;#22-cla-adder-delay&quot;&gt;2.2&lt;/a&gt;. CLA Adder Delay&lt;br /&gt;
&lt;a href=&quot;#23-cla32v&quot;&gt;2.3&lt;/a&gt;. cla32.v&lt;br /&gt;
&lt;a href=&quot;#24-tb_cla32v&quot;&gt;2.4&lt;/a&gt;. tb_cla32.v&lt;br /&gt;
&lt;a href=&quot;#25-rtl-view&quot;&gt;2.5&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#26-rtl-simulation&quot;&gt;2.6&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#27-flow-summary&quot;&gt;2.7&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#3-subtractor&quot;&gt;3&lt;/a&gt;. Subtractor&lt;br /&gt;
&lt;a href=&quot;#31-subtractor-구현-방법&quot;&gt;3.1&lt;/a&gt;. Subtractor 구현 방법&lt;br /&gt;
&lt;a href=&quot;#32-sub32v&quot;&gt;3.2&lt;/a&gt;. sub32.v&lt;br /&gt;
&lt;a href=&quot;#33-tb_sub32v&quot;&gt;3.3&lt;/a&gt;. tb_sub32.v&lt;br /&gt;
&lt;a href=&quot;#34-rtl-view&quot;&gt;3.4&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#35-rtl-simulation&quot;&gt;3.5&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#36-flow-summary&quot;&gt;3.6&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#4-글-마무리&quot;&gt;4&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#5-참고-문헌&quot;&gt;5&lt;/a&gt;. 참고 문헌&lt;/p&gt;

&lt;h2 id=&quot;1-ripple-carry-adder&quot;&gt;1. Ripple Carry Adder&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: rca32&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;11-half-adder&quot;&gt;1.1. Half Adder&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-ha.png&quot; alt=&quot;Half Adder&quot; /&gt;&lt;br /&gt;
Half Adder는 &lt;em&gt;A&lt;/em&gt;와 &lt;em&gt;B&lt;/em&gt;를 input으로 하고, &lt;em&gt;S&lt;/em&gt;와 \(C_{out}\)을 output으로 합니다.&lt;br /&gt;
S는 A와 B의 합이고, \(C_{out}\)은 받아올림(carry out)을 나타냅니다.&lt;br /&gt;
Boolean eqation은 아래와 같습니다.&lt;br /&gt;
\(S=A \oplus B\)&lt;br /&gt;
\(C_{out}=AB\)&lt;/p&gt;

&lt;h3 id=&quot;12-full-adder&quot;&gt;1.2. Full Adder&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-fa-truth.png&quot; alt=&quot;Full Adder Truth Table&quot; /&gt;&lt;br /&gt;
Full Adder는 Half Adder에 \(C_{in}\)이 input으로 추가된 형태입니다.&lt;br /&gt;
즉 &lt;em&gt;A&lt;/em&gt;, &lt;em&gt;B&lt;/em&gt;, \(C_{in}\)을 input으로 하고, &lt;em&gt;S&lt;/em&gt;와 \(C_{out}\)을 output으로 합니다.&lt;br /&gt;
\(C_{in}\)은 carry in으로, 이전 bit에서 받아올림된 것을 더하는 데 사용됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-fa-s.png&quot; alt=&quot;Full Adder S K-Map&quot; /&gt;&lt;br /&gt;
&lt;em&gt;S&lt;/em&gt;를 도출하기 위해 Karnaugh Map을 그려 보면&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
S &amp;amp;= \bar{A} \bar{B} C_{in} + \bar{A} B \overline{C_{in}} + A B C_{in} + A \bar{B} \overline{C_{in}} \\&lt;br /&gt;
&amp;amp;= C_{in} (\bar{A} \bar{B} + A B) + \overline{C_{in}}(\bar{A} B + A \bar{B}) \\&lt;br /&gt;
&amp;amp;= C_{in} \oplus A \oplus B&lt;br /&gt;
\end{align}\)&lt;br /&gt;
가 나옵니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-fa-co.png&quot; alt=&quot;Full Adder C_out K-Map&quot; /&gt;&lt;br /&gt;
\(C_{out}=AB+BC_{in}+AC_{in}\)입니다.&lt;/p&gt;

&lt;h3 id=&quot;13-ripple-carry-adder-구현-방법&quot;&gt;1.3. Ripple Carry Adder 구현 방법&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-rca.png&quot; alt=&quot;Ripple Carry Adder&quot; /&gt;&lt;br /&gt;
Full Adder 1개는 1-bit 덧셈밖에 못하지만 Full Adder를 여러 개 연결하여 &lt;strong&gt;Ripple Carry Adder&lt;/strong&gt;를 만들면 여러 bit 덧셈을 할 수 있습니다.&lt;br /&gt;
i번째 bit의 carry out이 i+1번째 bit의 carry in이 됩니다.&lt;br /&gt;
사실 LSB(Least Significant Bit)는 Half Adder를 써도 덧셈을 수행할 수 있지만 어차피 Subtractor를 만들 때 LSB의 carry in도 써야 하므로 Full Adder로 만들겠습니다.&lt;/p&gt;

&lt;h3 id=&quot;14-rca32v&quot;&gt;1.4. rca32.v&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-rca32-block.png&quot; alt=&quot;Ripple Carry Adder Block Diagram&quot; /&gt;&lt;br /&gt;
32-bit Ripple Carry Adder를 만들어 보겠습니다. Full Adder를 그냥 32개 연달아 작성하려면 힘드니까 &lt;span style=&quot;color: #ff0000&quot;&gt;rca32&lt;/span&gt;, &lt;span style=&quot;color: #7030a0&quot;&gt;rca16&lt;/span&gt;, &lt;span style=&quot;color: #0000ff&quot;&gt;rca4&lt;/span&gt;, fa(Full Adder)로 나누어서 &lt;span style=&quot;color: #0000ff&quot;&gt;rca4&lt;/span&gt;는 fa를 4개 instantiation하고, &lt;span style=&quot;color: #7030a0&quot;&gt;rca16&lt;/span&gt;은 &lt;span style=&quot;color: #0000ff&quot;&gt;rca4&lt;/span&gt;를 4개 instantiation하고, &lt;span style=&quot;color: #ff0000&quot;&gt;rca32&lt;/span&gt;는 &lt;span style=&quot;color: #7030a0&quot;&gt;rca16&lt;/span&gt;을 2개 instantiation하겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rca32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//32-bit Ripple Carry Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;rca16&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_rca16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;rca16&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_rca16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//full adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Ripple Carry Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rca16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//16-bit Ripple Carry Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;15-tb_rca32v&quot;&gt;1.5. tb_rca32.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_rca32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;rca32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;61&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;62&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;이번에는 변수를 10진수로 다루는 것이 편할 것 같아서 a와 b를 10진수로 입력하고 콘솔 창에 모든 결과를 띄우도록 했습니다.&lt;/p&gt;

&lt;p&gt;[Line 13]&lt;br /&gt;
&lt;strong&gt;if(s==0)	$display(“&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;%d&lt;/span&gt;&lt;strong&gt;+&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;%d&lt;/span&gt;&lt;strong&gt;=&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;%d&lt;/span&gt;&lt;strong&gt;, co=&lt;/strong&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;%b&lt;/span&gt; &lt;strong&gt;(when ci=&lt;/strong&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;%b&lt;/span&gt;&lt;strong&gt;)”, a, b, s, co, ci);&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;%d&lt;/span&gt;는 10진수로, &lt;span style=&quot;color: #0000ff&quot;&gt;%b&lt;/span&gt;는 2진수로 출력합니다.&lt;/p&gt;

&lt;h3 id=&quot;16-rtl-view&quot;&gt;1.6. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-view.png&quot; alt=&quot;rca32 RTL View&quot; /&gt;&lt;br /&gt;
rca32는 rca16을 2개 instantiation합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-view-rca16.png&quot; alt=&quot;rca16 RTL View&quot; /&gt;&lt;br /&gt;
rca16은 rca4를 4개 instantiation합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-view-rca4.png&quot; alt=&quot;rca4 RTL View&quot; /&gt;&lt;br /&gt;
rca4는 fa를 4개 instantiation합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-view-fa.png&quot; alt=&quot;fa RTL View&quot; /&gt;&lt;br /&gt;
fa는 AND Gate 3개, OR Gate 1개, XOR Gate 1개로 구성되었습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-fa-bubble-pushing.png&quot; alt=&quot;fa Bubble Pushing&quot; /&gt;&lt;br /&gt;
그러나 실제로 회로를 만들 때는 AND와 OR 대신 NAND를 쓰는 것이 더 저렴하기 때문에 Bubble Pushing을 해야 할 것입니다.&lt;/p&gt;

&lt;h3 id=&quot;17-rtl-simulation&quot;&gt;1.7. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-sim.png&quot; alt=&quot;rca32 RTL Simulation&quot; /&gt;&lt;br /&gt;
어째선지 콘솔 창에 음수가 제대로 뜨지 않지만, 일단 회로 자체는 오류가 없습니다.&lt;br /&gt;
Waveform에서 a, b, s는 10진수(decimal)로 표시하도록 설정을 변경해 주었습니다.&lt;/p&gt;

&lt;h3 id=&quot;18-flow-summary&quot;&gt;1.8. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/1-flow.png&quot; alt=&quot;rca32 Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 43, Total registers는 0, Total pins는 98이 나옵니다.&lt;/p&gt;

&lt;h2 id=&quot;2-carry-look-ahead-adder&quot;&gt;2. Carry Look-Ahead Adder&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: cla32&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;21-carry-look-ahead-adder는-무엇인가&quot;&gt;2.1. Carry Look-Ahead Adder는 무엇인가?&lt;/h3&gt;
&lt;p&gt;Ripple Carry Adder는 덧셈을 하기 위해서 그 전 bit의 carry out을 알아야 하기 때문에 속도가 느립니다. Full Adder의 delay를 \(t_{FA}\)라고 하면 &lt;em&gt;N&lt;/em&gt;-bit Ripple Carry Adder의 delay는 \(t_{ripple}=Nt_{FA}\)가 됩니다.&lt;br /&gt;
이 단점을 보완하고자 쓰는 것이 &lt;strong&gt;Carry Look-Ahead(CLA) Adder&lt;/strong&gt;입니다. CLA block을 나눠서 일정 bit마다 carry만 빠르게 연산하여 delay를 단축합니다.&lt;/p&gt;

&lt;p&gt;이를 위하여 generate signal(\(G_i\))과 propagate signal(\(P_i\))을 정의합니다.&lt;br /&gt;
\(G_i = A_i B_i\)&lt;br /&gt;
\(P_i = A_i + B_i\)&lt;/p&gt;

&lt;p&gt;1.2절에서 \(C_{out}=AB+BC_{in}+AC_{in}\)이었으므로&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
C_i &amp;amp;= A_i B_i + B_i C_{i-1} + A C_{i-1} \\&lt;br /&gt;
&amp;amp;= A_i B_i + (A_i + B_i) C_{i-1} \\&lt;br /&gt;
&amp;amp;= G_i + P_i C_{i-1}&lt;br /&gt;
\end{align}\)&lt;br /&gt;
이 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;i&lt;/em&gt;=0을 대입하면&lt;br /&gt;
\(C_0 = G_0 + P_0 C_{-1}\)&lt;br /&gt;
인데 \(C_{-1}=C_{in}\)입니다.&lt;br /&gt;
따라서 \(C_0 = G_0 + P_0 C_{in}\)이 됩니다.&lt;/p&gt;

&lt;p&gt;이어서 &lt;em&gt;i&lt;/em&gt;에 1부터 3까지 대입하면&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
C_1 &amp;amp;= G_1 + P_1 C_0 \\&lt;br /&gt;
&amp;amp;= G_1 + P_1 (G_0 + P_0 C_{in}) \\&lt;br /&gt;
&amp;amp;= G_1 + P_1 G_0 + P_1 P_0 C_{in}&lt;br /&gt;
\end{align}\)&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
C_2 &amp;amp;= G_2 + P_2 C_1 \\&lt;br /&gt;
&amp;amp;= G_2 + P_2 (G_1 + P_1 G_0 + P_1 P_0 C_{in}) \\&lt;br /&gt;
&amp;amp;= G_2 + P_2 (G_1 + P_1 G_0) + P_2 P_1 P_0 C_{in}&lt;br /&gt;
\end{align}\)&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
C_3 &amp;amp;= G_3 + P_3 C_2 \\&lt;br /&gt;
&amp;amp;= G_3 + P_3 (G_2 + P_2 (G_1 + P_1 G_0) + P_2 P_1 P_0 C_{in}) \\&lt;br /&gt;
&amp;amp;= G_3 + P_3 (G_2 + P_2 (G_1 + P_1 G_0)) + P_3 P_2 P_1 P_0 C_{in}&lt;br /&gt;
\end{align}\)&lt;br /&gt;
입니다.&lt;/p&gt;

&lt;p&gt;마지막 식에서&lt;br /&gt;
\(G_3 + P_3 (G_2 + P_2 (G_1 + P_1 G_0)) = G_{3:0}\),&lt;br /&gt;
\(P_3 P_2 P_1 P_0 C_{in} = P_{3:0}\)&lt;br /&gt;
으로 치환하겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-cla-expansion.png&quot; alt=&quot;Carry Look-Ahead Adder&quot; /&gt;&lt;br /&gt;
회로도로 나타내면 위와 같습니다. 이것만 가지고는 carry만 구할 수 있을 뿐 덧셈 결과를 알 수 없기 때문에 4-bit Ripple Carry Adder를 함께 사용해야 합니다.&lt;/p&gt;

&lt;h3 id=&quot;22-cla-adder-delay&quot;&gt;2.2. CLA Adder Delay&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-cla-delay.png&quot; alt=&quot;CLA Delay&quot; /&gt;&lt;br /&gt;
CLA Adder Delay는 위의 이미지와 같습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(t_{pg}\): generate and propagate gates의 delay. AND 또는 OR Gate 1개의 delay와 같습니다.&lt;/li&gt;
  &lt;li&gt;\(t_{pg\_block}\): the block generate and propagate gates의 delay. 그러나 \(P_{3:0}\) 쪽은 \(G_{3:0}\) 쪽과 동시 진행되면서 \(P_{3:0}\) 쪽이 \(G_{3:0}\) 쪽보다 빨리 끝나기 때문에, 제가 빨간색으로 표시한 \(G_{3:0}\) 쪽만 생각하시면 됩니다.&lt;/li&gt;
  &lt;li&gt;\(t_{AND\_OR}\): \(C_{in}\)에서 \(C_{out}\)까지 거치는 AND/OR Gate에서 발생하는 delay&lt;/li&gt;
  &lt;li&gt;\(t_{FA}\): Full Adder의 delay&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;N&lt;/em&gt;-bit CLA Adder는 &lt;em&gt;N&lt;/em&gt;&amp;gt;16일 때 Ripple Carry Adder보다 훨씬 빨라집니다.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;그런데 공식만 봐서는 무슨 말인지 잘 모르겠죠?&lt;br /&gt;
32-bit CLA Adder with 4-bit blocks 예제로 살펴보겠습니다.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Compare the delays of a 32-bit ripple-carry adder and a 32-bit carry-lookahead adder with 4-bit blocks. Assume that each two-input gate delay is 100 ps and that a full adder delay is 300 ps.&lt;br /&gt;
(출처: David Money Harris, Sarah L. Harris. 2013. Digial Design and Computer Architecture. 2nd Edition. Elsevier Korea L.L.C. Example 5.1(p. 243).)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;위의 이미지와 아래의 해설을 함께 보시기 바랍니다.&lt;/p&gt;

&lt;p&gt;“two-input gate delay is 100 ps”라는 것은 AND Gate delay와 OR Gate delay가 100ps라는 것입니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(t_{pg}=100\textnormal{ps}\)&lt;/li&gt;
  &lt;li&gt;\(t_{pg\_block} = 6 \times 100 \textnormal{ps} = 600 \textnormal{ps}\)&lt;/li&gt;
  &lt;li&gt;\(t_{AND\_OR} = 2 \times 100 \textnormal{ps} = 200 \textnormal{ps}\)&lt;/li&gt;
  &lt;li&gt;\(t_{FA}=300\textnormal{ps}\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;\(\begin{align}&lt;br /&gt;
\therefore t_{CLA} &amp;amp;= 100\textnormal{ps} + 600\textnormal{ps} + (32/4-1) \times 200\textnormal{ps} + 4 \times 300\textnormal{ps} \\&lt;br /&gt;
&amp;amp;= 3300\textnormal{ps} \\&lt;br /&gt;
&amp;amp;= 3.3\textnormal{ns}&lt;br /&gt;
\end{align}\)&lt;/p&gt;

&lt;p&gt;여기까지 하면 일단 32-bit CLA Adder with 4-bit blocks의 delay는 구한 것입니다.&lt;br /&gt;
그런데 예제에서 32-bit Ripple Carry Adder와 비교하라고 했으니 문제를 끝까지 풀어 보면&lt;br /&gt;
\(\begin{align}&lt;br /&gt;
t_{ripple} &amp;amp;= 32 \times 300 \textnormal{ps} \\&lt;br /&gt;
&amp;amp;= 9600 \textnormal{ps} \\&lt;br /&gt;
&amp;amp;= 9.6 \textnormal{ns}&lt;br /&gt;
\end{align} \\&lt;br /&gt;
\therefore t_{CLA} &amp;lt; t_{ripple}\)&lt;br /&gt;
이 되겠습니다.&lt;/p&gt;

&lt;h3 id=&quot;23-cla32v&quot;&gt;2.3. cla32.v&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-cla-block.png&quot; alt=&quot;32-bit CLA Block Diagram&quot; /&gt;&lt;br /&gt;
32-bit CLA Adder with 4-bit blocks를 Verilog로 구현하겠습니다.&lt;br /&gt;
&lt;span style=&quot;color: #7030a0&quot;&gt;clb4(4-bit CLA Block)&lt;/span&gt;는 &lt;span style=&quot;color: #0000ff&quot;&gt;rca4&lt;/span&gt;와 &lt;span style=&quot;color: #00b050&quot;&gt;carry&lt;/span&gt;를 instantiation합니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;cla32&lt;/span&gt;는 &lt;span style=&quot;color: #7030a0&quot;&gt;clb4&lt;/span&gt;를 8개 instantiation합니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cla32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//32-bit Carry Look-Ahead Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U4_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U5_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U6_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U7_clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//full adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Ripple Carry Adder&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fa&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_fa&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;carry4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Carry Look-Ahead Carry&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry in&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;assign&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clb4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//4-bit Carry Look-Ahead Block&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;rca4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_rca4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;carry4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_carry4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 49]&lt;br /&gt;
&lt;strong&gt;rca4 U0_rca4(a, b, ci, s,);&lt;/strong&gt;&lt;br /&gt;
carry out은 CLA로 따로 구하기 때문에 rca4 module에서 co port는 비워 둡니다.&lt;/p&gt;

&lt;h3 id=&quot;24-tb_cla32v&quot;&gt;2.4. tb_cla32.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_cla32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;cla32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;61&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;62&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed (when ci=%b)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ci&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;사실 1.5절의 tb_rca32.v에서 모듈명만 바꾼 것입니다.&lt;/p&gt;

&lt;h3 id=&quot;25-rtl-view&quot;&gt;2.5. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-view.png&quot; alt=&quot;cla32 RTL View&quot; /&gt;&lt;br /&gt;
cla32는 clb4를 8개 instantiation합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-view-clb4.png&quot; alt=&quot;clb4 RTL View&quot; /&gt;&lt;br /&gt;
clb4는 rca4와 carry4를 instantiation합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-view-carry4.png&quot; alt=&quot;carry4 RTL View&quot; /&gt;&lt;br /&gt;
carry4는 이렇게 생겼습니다.&lt;/p&gt;

&lt;h3 id=&quot;26-rtl-simulation&quot;&gt;2.6. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-sim.png&quot; alt=&quot;cla32 RTL Simulation&quot; /&gt;&lt;br /&gt;
Waveform에서 a, b, s는 10진수(decimal)로 표시하도록 설정을 변경해 주었습니다.&lt;/p&gt;

&lt;h3 id=&quot;27-flow-summary&quot;&gt;2.7. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/2-flow.png&quot; alt=&quot;cla32 Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 52, Total registers는 0, Total pins는 98이 나옵니다.&lt;br /&gt;
Logic utiliazation은 CLA Adder가 Ripple Carry Adder보다 9개 더 많다는 것을 알 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;3-subtractor&quot;&gt;3. Subtractor&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: sub32&lt;/li&gt;
  &lt;li&gt;Add file: cla32.v
    &lt;ul&gt;
      &lt;li&gt;cf) Ripple Carry Subtractor를 만들려면 rca32.v를 추가하세요.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;31-subtractor-구현-방법&quot;&gt;3.1. Subtractor 구현 방법&lt;/h3&gt;
&lt;p&gt;\(\begin{align}&lt;br /&gt;
A-B &amp;amp;= A+(-B) \\&lt;br /&gt;
&amp;amp;= A+(\bar{B}+1)&lt;br /&gt;
\end{align}\)&lt;br /&gt;
라는 점을 이용합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/3-sub.png&quot; alt=&quot;Subtractor&quot; /&gt;&lt;br /&gt;
Adder에서 B를 invert하고, carry in에 1을 넣습니다.&lt;br /&gt;
Adder는 Ripple Carry Adder, CLA Adder 상관없습니다.&lt;/p&gt;

&lt;h3 id=&quot;32-sub32v&quot;&gt;3.2. sub32.v&lt;/h3&gt;
&lt;p&gt;CLA로 Subtractor를 만들어 보겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sub32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//32-bit Carry Look-Ahead Subtractor&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	    &lt;span class=&quot;c1&quot;&gt;//operand&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;		&lt;span class=&quot;c1&quot;&gt;//sum&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//carry out&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b_inv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;				&lt;span class=&quot;c1&quot;&gt;//b inverted&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;cla32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_cla32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 1]&lt;br /&gt;
&lt;strong&gt;module sub32(a, b, s, co);&lt;/strong&gt;&lt;br /&gt;
carry in은 1로 고정이기 때문에 sub32의 port에서 빠졌습니다.&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;cla32 U0_cla32(a, ~b, &lt;span style=&quot;color: #ff0000&quot;&gt;1&lt;/span&gt;, s, co);&lt;/strong&gt;&lt;br /&gt;
cla32를 instantiation할 때 ci에는 &lt;span style=&quot;color: #ff0000&quot;&gt;1&lt;/span&gt;을 넣습니다.&lt;/p&gt;

&lt;h3 id=&quot;33-tb_sub32v&quot;&gt;3.3. tb_sub32.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_sub32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;sub32&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;41&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d+%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		
		&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;51&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;83&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;		&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d-%d=%d, co=%b failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;sub32 dut(a, b, s, co);&lt;/strong&gt;&lt;br /&gt;
carry in은 1로 고정이기 때문에 sub32의 port에서 빠졌다는 것을 잊지 마세요.&lt;/p&gt;

&lt;h3 id=&quot;34-rtl-view&quot;&gt;3.4. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/3-view.png&quot; alt=&quot;sub32 RTL View&quot; /&gt;&lt;br /&gt;
cla32의 ci에는 1이 들어갔습니다.&lt;/p&gt;

&lt;h3 id=&quot;35-rtl-simulation&quot;&gt;3.5. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/3-sim.png&quot; alt=&quot;sub32 RTL Simulation&quot; /&gt;&lt;br /&gt;
Waveform에서 a, b, s는 10진수(decimal)로 표시하도록 설정을 변경해 주었습니다.&lt;/p&gt;

&lt;h3 id=&quot;36-flow-summary&quot;&gt;3.6. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251202/3-flow.png&quot; alt=&quot;sub32 Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 51, Total registers는 0, Total pins는 97이 나옵니다.&lt;/p&gt;

&lt;h2 id=&quot;4-글-마무리&quot;&gt;4. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;5-참고-문헌&quot;&gt;5. 참고 문헌&lt;/h2&gt;
&lt;p&gt;1) David Money Harris, Sarah L. Harris. 2013. Digital Design and Computer Architecture. 2nd Edition. Elsevier Korea L.L.C.&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 02 Dec 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/adder-subtractor</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/adder-subtractor</guid>
        
        
        <category>프로그래밍</category>
        
        <category>Verilog</category>
        
      </item>
    
      <item>
        <title>Quine-McCluskey Algorithm 자동화 프로그램</title>
        <description>&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;진리표(truth table)를 보고 boolean equation을 만들 때 변수가 4개 이하이면 Karnaugh Map을 이용할 수 있습니다. 그러나 변수가 5개 이상으로 늘어나면 Karnaugh Map을 사용하기 힘들어집니다. 그러므로 &lt;strong&gt;Quine-McCluskey Algorithm&lt;/strong&gt;을 사용하면 변수 개수가 많아도 boolean equation을 쉽게 도출할 수 있게 됩니다. 다만, Quine-McCluskey Algorithm은 사람이 직접 수행하기에 따분한 작업이므로 자동화 프로그램을 만들었습니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-사용자-설명서&quot;&gt;1&lt;/a&gt;. 사용자 설명서&lt;br /&gt;
&lt;a href=&quot;#11-시스템-요구사항&quot;&gt;1.1&lt;/a&gt;. 시스템 요구사항&lt;br /&gt;
&lt;a href=&quot;#12-파일-내려받기&quot;&gt;1.2&lt;/a&gt;. &lt;a href=&quot;https://github.com/sooseongcom/Quine-McCluskey?tab=readme-ov-file#12-download&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;파일 내려받기&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;#13-프로그램-사용법&quot;&gt;1.3&lt;/a&gt;. 프로그램 사용법&lt;br /&gt;
&lt;a href=&quot;#14-qunie-mccluskey-algorithm이란&quot;&gt;1.4&lt;/a&gt;. Qunie-McCluskey Algorithm이란?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-개발자-설명서&quot;&gt;2&lt;/a&gt;. 개발자 설명서&lt;br /&gt;
&lt;a href=&quot;#21-how-to-build&quot;&gt;2.1&lt;/a&gt;. How To Build&lt;br /&gt;
&lt;a href=&quot;#22-files&quot;&gt;2.2&lt;/a&gt;. Files&lt;br /&gt;
&lt;a href=&quot;#23-implicant-table-column-1-step-1&quot;&gt;2.3&lt;/a&gt;. Implicant Table Column 1 (Step 1)&lt;br /&gt;
&lt;a href=&quot;#24-combining-variables-step-23&quot;&gt;2.4&lt;/a&gt;. Combining variables (Step 2~3)&lt;br /&gt;
&lt;a href=&quot;#25-construct-a-pi-table-step-4&quot;&gt;2.5&lt;/a&gt;. Construct a PI table (Step 4)&lt;br /&gt;
&lt;a href=&quot;#26-identify-essential-pis-step-56&quot;&gt;2.6&lt;/a&gt;. Identify essential PIs (Step 5~6)&lt;br /&gt;
&lt;a href=&quot;#27-find-minimum-set-of-pispetricks-method-step-7&quot;&gt;2.7&lt;/a&gt;. Find minimum set of PIs(Petrick’s Method) (Step 7)&lt;br /&gt;
&lt;a href=&quot;#28-cost--of-transistors&quot;&gt;2.8&lt;/a&gt;. Cost (# of transistors)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#3-글-마무리&quot;&gt;3&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#4-참고-자료&quot;&gt;4&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-사용자-설명서&quot;&gt;1. 사용자 설명서&lt;/h2&gt;
&lt;h3 id=&quot;11-시스템-요구사항&quot;&gt;1.1. 시스템 요구사항&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;운영체제: Windows&lt;/li&gt;
  &lt;li&gt;아키텍처: x64(AMD64, Intel64)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;12-파일-내려받기&quot;&gt;1.2. 파일 내려받기&lt;/h3&gt;
&lt;p&gt;1.2.1. &lt;a href=&quot;https://github.com/sooseongcom/Quine-McCluskey?tab=readme-ov-file#12-download&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://github.com/sooseongcom/Quine-McCluskey?tab=readme-ov-file#12-download&lt;/a&gt;로 접속하셔서 본인 PC에 맞는 버전의 설치 파일을 내려받습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20240928/1.png&quot; alt=&quot;차단 경고&quot; /&gt;&lt;br /&gt;
1.2.2. 웹 브라우저(MS Edge 기준)에서 차단 경고가 뜰 경우 &lt;strong&gt;···&lt;/strong&gt; 클릭 후 &lt;strong&gt;유지&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20240928/2.png&quot; alt=&quot;열기 전에 신뢰할 수 있는지 확인합니다.&quot; /&gt;&lt;br /&gt;
1.2.3. &lt;strong&gt;더 보기 v&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20240928/3.png&quot; alt=&quot;그래도 계속&quot; /&gt;&lt;br /&gt;
1.2.4. &lt;strong&gt;그래도 계속&lt;/strong&gt;을 클릭합니다.
1.2.5. 그러면 설치 파일을 내려받으실 수 있습니다. 내려받으신 후 실행합니다.&lt;br /&gt;
1.2.6. Windows에서 SmartScreen 경고가 뜰 경우 &lt;strong&gt;추가 정보&lt;/strong&gt; 클릭 후 &lt;strong&gt;실행&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;h3 id=&quot;13-프로그램-사용법&quot;&gt;1.3. 프로그램 사용법&lt;/h3&gt;
&lt;p&gt;1.3.1. 실행 파일이 있는 경로(예: Windows의 경우 exe 파일이 있는 폴더와 같은 폴더)에 &lt;strong&gt;input_minterm.txt&lt;/strong&gt;를 생성합니다.&lt;/p&gt;

&lt;p&gt;1.3.2. 예를 들어 설명해 드리겠습니다. &lt;em&gt;f(A, B, C, D)=Σm(0, 1, 2, 5, 7, 10, 12, 13)+Σd(3, 8, 15)&lt;/em&gt;를 구하려면 &lt;strong&gt;input_minterm.txt&lt;/strong&gt;의 내용은 아래와 같습니다.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;4
m 0000
m 0001
m 0010
d 0011
m 0101
m 0111
d 1000
m 1010
m 1100
m 1101
d 1111
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;[Line 1]&lt;br /&gt;
첫 줄 숫자는 input bit length를 나타냅니다.&lt;/p&gt;

&lt;p&gt;[Line 2]&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;m&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;0000&lt;/span&gt;&lt;br /&gt;
둘째 줄부터는 &lt;span style=&quot;color: #ff0000&quot;&gt;true minterm인지 don’t care minterm인지 구분하는 문자와&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;minterm 값(implicant)&lt;/span&gt;을 작성합니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;m은 true minterm을, d는 don’t care minterm을 나타냅니다.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;1.3.3. 실행 파일(Quine-McCluskey-Algorithm-&lt;em&gt;버전&lt;/em&gt;.exe)을 실행합니다.&lt;br /&gt;
1.3.4. &lt;strong&gt;result.txt&lt;/strong&gt;를 확인합니다.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-0-0
110-
0--1

Cost (# of transistors): 28

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 1~3]&lt;br /&gt;
이 term들은 결과적으로 나온 essential Prime Implicant입니다. 이것들을 조합하면&lt;br /&gt;
\(f(A, B, C, D)=\bar{B}\bar{D}+AB\bar{C}+\bar{A}D\)&lt;br /&gt;
가 됩니다.&lt;br /&gt;
그러나 실제로는 보통 bubble pushing을 하여 NAND Gate를 사용하실 테니 모든 gate를 NAND로 사용하시면 되겠습니다.&lt;/p&gt;

&lt;p&gt;[Line 5]&lt;br /&gt;
Cost는 트랜지스터 개수입니다. Bubble pushing을 고려하여 계산된 결과입니다.&lt;/p&gt;

&lt;h3 id=&quot;14-qunie-mccluskey-algorithm이란&quot;&gt;1.4. Qunie-McCluskey Algorithm이란?&lt;/h3&gt;
&lt;p&gt;Qunie-McCluskey Algorithm은 logic function을 minimize하기 위한 tabular algorithm입니다.&lt;/p&gt;

&lt;p&gt;예제로 &lt;strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;f(A, B, C, D)&lt;/span&gt;=&lt;span style=&quot;color: #006000&quot;&gt;Σm(0, 1, 2, 5, 7, 10, 12, 13)&lt;/span&gt;+&lt;span style=&quot;color: #0000ff&quot;&gt;Σd(3, 8, 15)&lt;/span&gt;&lt;/strong&gt;를 사용하겠습니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;f(A, B, C, D)&lt;/span&gt;는 boolean equation의 변수가 &lt;span style=&quot;color: #ff0000&quot;&gt;A, B, C, D&lt;/span&gt;라는 뜻입니다.&lt;br /&gt;
&lt;span style=&quot;color: #006000&quot;&gt;Σm(0, 1, 2, 5, 7, 10, 12, 13)&lt;/span&gt;은 &lt;span style=&quot;color: #006000&quot;&gt;0, 1, 2, 5, 7, 10, 12, 13&lt;/span&gt;이 true minterm이라는 뜻입니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;Σd(3, 8, 15)&lt;/span&gt;는 &lt;span style=&quot;color: #0000ff&quot;&gt;3, 8, 15&lt;/span&gt;가 don’t care minterm이라는 뜻입니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/1.png&quot; alt=&quot;Step 1&quot; /&gt;&lt;br /&gt;
1.4.1. true minterm들과 don’t care minterm들을 Implicant table의 Column 1에 작성합니다. 이때 1의 개수에 따라 그룹을 나눕니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/2.png&quot; alt=&quot;Step 2&quot; /&gt;&lt;br /&gt;
1.4.2. 인접한 두 그룹에서 Hamming distance가 1이 되도록 minterm을 하나씩 고릅니다. 변수가 다른 자리는 ‘-‘로 바꾸어 Column 2에 작성합니다. ‘-‘는 don’t care를 의미합니다. Column 1→2로 합쳐진 minterm은 Column 1에서 v 표시를 합니다. 이러한 과정을 모든 변수에 대해서 진행합니다.(v 표시가 되었다고 해서 더 이상 안 보는 것이 아니라, 두 그룹을 비교할 때는 모든 변수에 대해서 확인해야 합니다.) Column 1의 모든 변수를 순회했음에도 v 표시가 되지 않은 것은 * 표시를 합니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;예1) 0000과 0001 → 000-&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;예2) 0000과 0010 → 00-0&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/3.png&quot; alt=&quot;Step 3&quot; /&gt;&lt;br /&gt;
1.4.3. 앞에서 한 것처럼 Column 2의 implicant들을 합쳐서 Column 3에 작성합니다. 이때 ‘-‘가 있으면 ‘-‘의 자리는 일치해야 합니다. Column &lt;em&gt;N&lt;/em&gt;의 implicant들을 합쳐서 Column &lt;em&gt;N&lt;/em&gt;+1에 작성하기를 모든 implicant들이 v 또는 * 표시가 될 때까지(즉, 더 이상 combining을 할 수 없을 때까지) 진행합니다.&lt;br /&gt;
이제 * 표시가 된 implicant들이 prime implicant가 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/4.png&quot; alt=&quot;Step 4&quot; /&gt;&lt;br /&gt;
1.4.4. PI table을 만듭니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;열: true minterms&lt;/li&gt;
  &lt;li&gt;행: PIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PI가 minterm을 cover하는 곳에 ‘X’ 표시합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/5.png&quot; alt=&quot;Step 5&quot; /&gt;&lt;br /&gt;
1.4.5. 이제 essential PI를 찾을 것입니다.&lt;br /&gt;
‘X’가 1개밖에 없는 열을 찾습니다. 예제에서는 True Minterms가 1010인 열이군요.&lt;br /&gt;
그 열의 ‘X’를 동그라미 합니다. 그리고 그 ‘X’를 기준으로 세로줄과 가로줄을 긋습니다.&lt;br /&gt;
예제에서는 가로줄이 &lt;strong&gt;-0-0&lt;/strong&gt;에 닿았습니다. -0-0이 essential PI가 됩니다.&lt;br /&gt;
참고) 만약 ‘X’가 1개밖에 없는 열이 여러 개 있으면 essential PI가 여러 개 나올 것입니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/6.png&quot; alt=&quot;Step 6&quot; /&gt;&lt;br /&gt;
1.4.6. essential PI에 의해 cover되는 열들을 지울 것입니다. 가로줄 위에 있는 ‘X’에서 각각 세로줄을 그어 주면 됩니다.&lt;/p&gt;

&lt;p&gt;어떨 때는 이 과정까지 하고 나면 모든 ‘X’들이 지워져서 최종 식이 도출되지만, 오늘의 예제는 ‘X’가 남게 되었습니다. 그러므로 남은 ‘X’들끼리 PI table을 새로 만들어 주겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/7.png&quot; alt=&quot;Step 7&quot; /&gt;&lt;br /&gt;
1.4.7. 이것이 새로 만든 PI table입니다. 열들을 보니 모든 열에 ‘X’가 2개씩 있습니다.&lt;br /&gt;
이때는 &lt;strong&gt;Petrick’s Method&lt;/strong&gt;를 사용합니다.&lt;br /&gt;
편의상 PI마다 \(P_0\)부터 \(P_4\)까지 기호를 매겨 주었습니다.&lt;br /&gt;
그러면 이 PI table의 모든 ‘X’를 cover하는 식은 \(P=(P_2+P_3)(P_3+P_4)(P_0+P_1)(P_1+P_4)\)가 됩니다.&lt;br /&gt;
전개하면&lt;br /&gt;
\(\begin{align}
P &amp;amp;= (P_2+P_3)(P_3+P_4)(P_0+P_1)(P_1+P_4) \\&lt;br /&gt;
&amp;amp;= (P_3 + P_2 P_4)(P_1 + P_0 P_4) \\&lt;br /&gt;
&amp;amp;= P_1 P_3 + P_0 P_3 P_4 + P_1 P_2 P_4 + P_0 P_2 P_4&lt;br /&gt;
\end{align}\)&lt;br /&gt;
가 됩니다.&lt;br /&gt;
이것 중에서 PI 개수가 가장 적은 항인 \(P_1 P_3\)을 택합니다.&lt;/p&gt;

&lt;p&gt;만약 PI 개수가 가장 적은 항이 여러 개라면 트랜지스터 개수를 비교하여 가장 저렴한 것을 택합니다.&lt;/p&gt;

&lt;h2 id=&quot;2-개발자-설명서&quot;&gt;2. 개발자 설명서&lt;/h2&gt;
&lt;h3 id=&quot;21-how-to-build&quot;&gt;2.1. How To Build&lt;/h3&gt;
&lt;p&gt;(추후 작성 예정)&lt;/p&gt;

&lt;h3 id=&quot;22-files&quot;&gt;2.2. Files&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;.gitignore&lt;/strong&gt;: Git add 시 x64(folder), *.vcxproj, *.vcxproj.filters, *.vcxproj.user, input_minterm.txt, result.txt를 제외&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ImpTable.cpp&lt;/strong&gt;: ImpTable의 멤버 함수/변수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ImpTable.h&lt;/strong&gt;: implicant table를 위한 class&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LICENSE&lt;/strong&gt;: MIT License&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;main.cpp&lt;/strong&gt;: main function&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minterm.cpp&lt;/strong&gt;: Minterm의 멤버 함수/변수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minterm.h&lt;/strong&gt;: implicant table을 위한 minterm을 위한 class&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PetrickTable.cpp&lt;/strong&gt;: PetrickTable의 멤버 함수/변수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PetrickTable.h&lt;/strong&gt;: Petrick’s Method를 위한 PI Table&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PITable.cpp&lt;/strong&gt;: PITable의 멤버 함수/변수&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;PITable.h&lt;/strong&gt;: PI Table를 위한 class&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;23-implicant-table-column-1-step-1&quot;&gt;2.3. Implicant Table Column 1 (Step 1)&lt;/h3&gt;
&lt;p&gt;Implicant Table은 &lt;strong&gt;ImpTable&lt;/strong&gt; class에서 담당합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p1.png&quot; alt=&quot;Step 1 데이터 구조&quot; /&gt;&lt;br /&gt;
전체 implicant table의 자료형은 vector입니다.&lt;br /&gt;
table의 각 원소는 multimap입니다.&lt;br /&gt;
multimap의 key는 1의 개수이고, value는 implicant입니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//ImpTable.h Line 13~18&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;/**	the type of table
* vector
* multimap&amp;lt;int, Minterm*&amp;gt;*: vector 확장 시 multimap을 재생성하므로 dynamic allocation해야 함.
* Minterm*: 생성 편의를 위해 dynamic allocation해야 함.
*/&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;multimap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Minterm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&amp;gt;*&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;24-combining-variables-step-23&quot;&gt;2.4. Combining variables (Step 2~3)&lt;/h3&gt;
&lt;p&gt;Step 2~3는 &lt;strong&gt;int ImpTable::combine(int a)&lt;/strong&gt; 함수가 공통적으로 담당합니다. a는 implicant table의 column 번호입니다. int ImpTable::combine(int a) 함수는 combining에 성공하면 1을, 아무것도 combining하지 못하면 0을 return합니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//main.cpp Line 34~38&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//Step 2~3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;combined&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;combined&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;imp_table&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;imp_table&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;따라서 위 코드와 같이 함수의 return 값이 0이 될 때까지 for문을 돌려 주면 PI를 구할 수 있습니다.&lt;/p&gt;

&lt;p&gt;Minterm의 멤버 변수 marked의 초기 값은 0입니다.&lt;br /&gt;
v 표시를 하는 경우 Minterm의 멤버 변수 marked를 1로 설정합니다.&lt;br /&gt;
모든 combining 과정을 마친 후에도 marked가 0인 Minterm이 stared(*) minterm입니다.&lt;/p&gt;

&lt;h3 id=&quot;25-construct-a-pi-table-step-4&quot;&gt;2.5. Construct a PI table (Step 4)&lt;/h3&gt;
&lt;p&gt;PI table은 &lt;strong&gt;PITable&lt;/strong&gt; class에서 담당합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p4.png&quot; alt=&quot;Step 4 programming&quot; /&gt;&lt;br /&gt;
PI table은 2차원 vector로 만듭니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&lt;/code&gt;로 선언할 것이며, 위의 이미지에서 흰색 칸만 만들었습니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//PITable.cpp Line 3~12&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;PITable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PITable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpTM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;/**
* Row: PIs
* Column: true minterms
* 
* -1: deleted
* 0: blank
* 1: PI covers the minterm
* 2: only 1 in the column
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;vector는 선언하면 0으로 초기화됩니다.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//PITable.cpp Line 129~137&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;piCoverTm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpTM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inpPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;-&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inpTM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;PI가 minterm을 cover하는 곳에 1을 넣습니다.&lt;/p&gt;

&lt;h3 id=&quot;26-identify-essential-pis-step-56&quot;&gt;2.6. Identify essential PIs (Step 5~6)&lt;/h3&gt;
&lt;p&gt;Step 5~6는 &lt;strong&gt;int PITable::identifyEPI()&lt;/strong&gt; 함수가 담당합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p5.png&quot; alt=&quot;Step 5 Programming&quot; /&gt;&lt;br /&gt;
1이 1개밖에 없는 열을 찾습니다. 예제에서는 True Minterms가 1010인 열입니다.&lt;br /&gt;
그 열의 1을 2로 바꿉니다(빨간 동그라미를 쳤다는 뜻). 그리고 그 1을 기준으로 세로줄과 가로줄을 긋습니다. 세로줄은 모두 -1로 바꾸고, 가로줄은 1만 -1로 바꿉니다.&lt;br /&gt;
예제에서는 가로줄이 &lt;strong&gt;-0-0&lt;/strong&gt;에 닿았습니다. -0-0가 epi에 없는지 확인하고 없다면 push합니다.&lt;br /&gt;
1이 1개밖에 없는 열을 찾을 때마다 complete이라는 변수를 1 증가시킵니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p6.png&quot; alt=&quot;Step 6 Programming&quot; /&gt;&lt;br /&gt;
가로줄의 1을 -1로 바꿀 때 그 -1이 있는 열을 -1로 바꿉니다(단, 2는 그대로 유지). 그때마다 complete을 1씩 증가시킵니다.&lt;/p&gt;

&lt;p&gt;int PITable::identifyEPI() 함수는 tm.size() - complete을 return합니다.&lt;br /&gt;
모든 열이 지워진 상태라면 return 값은 0이 될 것입니다.&lt;br /&gt;
1이 남아 있는 열이 있다면 return 값은 0보다 클 것이며, Step 7을 진행해야 합니다.&lt;/p&gt;

&lt;h3 id=&quot;27-find-minimum-set-of-pispetricks-method-step-7&quot;&gt;2.7. Find minimum set of PIs(Petrick’s Method) (Step 7)&lt;/h3&gt;
&lt;p&gt;Petrick’s Method를 위한 PI table을 새로 만들어야 하는데, 이는 &lt;strong&gt;PetrickTable&lt;/strong&gt; class에서 담당합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p7.png&quot; alt=&quot;Step 7 Programming&quot; /&gt;&lt;br /&gt;
구조는 PITable과 유사합니다. True Minterms는 -1만 있는 열이 있어도 무시하면 그만이기에 그냥 남겨 두었습니다. 다만, PI는 essential PI가 포함되면 식 도출할 때 오류가 발생할 수 있기에 삭제해 주었습니다.&lt;br /&gt;
이제 여기서 식을 어떻게 도출할 것이냐가 문제입니다. 일단 식은 \(P=(P_2+P_3)(P_3+P_4)(P_0+P_1)(P_1+P_4)\)로 잘 나옵니다.&lt;br /&gt;
다만, 이것을 전개하기가 어려우므로 \(P_0\)부터 \(P_4\)까지를 int형 p[0]부터 p[4]로 동적 할당했습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;전체 식: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vector&amp;lt;set&amp;lt;int*&amp;gt;&amp;gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;각 괄호: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&amp;lt;int*&amp;gt;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;괄호 안의 각 항: int*&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;p[0]부터 p[4]까지를 0 또는 1을 넣어 보면서 전체 식 결과가 1이 되는 조합을 찾습니다. 중복순열 알고리즘을 차용했습니다.&lt;br /&gt;
괄호 안에서는 여러 항 중 하나만 1이어도 그 괄호 전체가 1이 되므로 set 안에서 int 값이 1인 것이 있는지 찾아보면 됩니다.&lt;br /&gt;
전체 식은 괄호의 곱으로 연결되어 있어서 각 괄호가 모두 1이어야 전체 식의 결과도 1이 됩니다. 그러므로 모든 set 안에 int 값이 1인 것이 있는지 찾아봐야 합니다.&lt;br /&gt;
그렇게 전체 식이 1인 것을 찾으면 그 p 조합이 바로 minimum set of PIs의 후보가 됩니다.&lt;/p&gt;

&lt;p&gt;minimum set of PIs의 후보 중에서는 PI 개수가 가장 적은 항을 택합니다.&lt;br /&gt;
만약 PI 개수가 가장 적은 항이 여러 개라면(PetrickTable.cpp Line 179~190 else문) 트랜지스터 개수를 비교하여 가장 저렴한 것을 택합니다(PetrickTable.cpp Line 195~231 int PetrickTable::cost(int* pterms) 함수).&lt;/p&gt;

&lt;h3 id=&quot;28-cost--of-transistors&quot;&gt;2.8. Cost (# of transistors)&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;-0-0
110-
0--1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;essential PI가 위와 같이 나왔다면 \(f(A, B, C, D)=\bar{B}\bar{D}+AB\bar{C}+\bar{A}D\)입니다. 언뜻 보면 AND, OR, NOT으로 구현하면 될 것 같지만 실제로는 NAND Gate를 이용하는 것이 더 저렴하기 때문에 bubble pushing을 합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251118/p8.png&quot; alt=&quot;Bubble Pushing&quot; /&gt;&lt;br /&gt;
따라서 AND와 OR이 모두 NAND로 바뀐다고 생각하시면 됩니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;N&lt;/em&gt;-input NAND Gate의 트랜지스터 개수: 2&lt;em&gt;N&lt;/em&gt;개&lt;/li&gt;
  &lt;li&gt;NOT Gate의 트랜지스터 개수: 2개&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-글-마무리&quot;&gt;3. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 프로그램을 사용해 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;4-참고-자료&quot;&gt;4. 참고 자료&lt;/h2&gt;
&lt;p&gt;1) novs. 2022. “[C++] STL map vs multimap (feat. multimap equal_range)”, nov.Zip. (2025. 11. 28. 방문). &lt;a href=&quot;https://novlog.tistory.com/entry/C-STL-map-vs-multimap-feat-multimap-equalrange&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://novlog.tistory.com/entry/C-STL-map-vs-multimap-feat-multimap-equalrange&lt;/a&gt;&lt;br /&gt;
2) Jihan. 2023. “C++로 Quine-McCluskey 구현하기”, bbbjihan.log. (2025. 11. 28. 방문). &lt;a href=&quot;https://velog.io/@bbbjihan/C로-Quine-McCluskey-구현하기&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://velog.io/@bbbjihan/C로-Quine-McCluskey-구현하기&lt;/a&gt;&lt;br /&gt;
3) SCRIPTS BY. 2023. “vector VS list 뭘 써야 하지?”, SCRIPTS BY. (2025. 11. 28. 방문). &lt;a href=&quot;https://nx006.tistory.com/20&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://nx006.tistory.com/20&lt;/a&gt;&lt;br /&gt;
4) BlockDMask. 2017. “[C++] multimap container 정리 및 사용법”, 가면 뒤의 기록. (2025. 11. 28. 방문). &lt;a href=&quot;https://blockdmask.tistory.com/88&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://blockdmask.tistory.com/88&lt;/a&gt;&lt;br /&gt;
5) horang. n. d. “C++ std::string::erase 정리”, Code by horang. (2025. 11. 18. 방문). &lt;a href=&quot;https://hoho325.tistory.com/317&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://hoho325.tistory.com/317&lt;/a&gt;&lt;br /&gt;
6) BLASTIC. 2012. “[Quine-McCluskey Method] Petrick’s Method”, BLASTIC. (2025. 11. 18. 방문). &lt;a href=&quot;https://blastic.tistory.com/204&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://blastic.tistory.com/204&lt;/a&gt;&lt;br /&gt;
7) 젠니. 2023. “[논리회로설계] Petrick’s Method”, Jenvelop log. (2025. 11. 18. 방문). &lt;a href=&quot;https://velog.io/@tmdtmdqorekf/논리회로설계-Patricks-Method&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://velog.io/@tmdtmdqorekf/논리회로설계-Patricks-Method&lt;/a&gt;&lt;br /&gt;
8) 공부하는 식빵맘. 2020. “(C++) 중복 순열(Repeated Permutation) 구현하기”, 평생 공부 블로그 : Today I Learned. (2025. 11. 18. 방문). &lt;a href=&quot;https://ansohxxn.github.io/algorithm/repeated-permutation/#google_vignette&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://ansohxxn.github.io/algorithm/repeated-permutation/#google_vignette&lt;/a&gt;&lt;br /&gt;
9) Song 전자공학. 2025. “CMOS Logic Gates: CMOS 논리 게이트”, Song 전자공학. (2025. 11. 18. 방문). &lt;a href=&quot;https://blog.naver.com/songsite123/223712874895&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://blog.naver.com/songsite123/223712874895&lt;/a&gt;&lt;br /&gt;
10) spring. 2020. “[c++] std::vector”, springkim.log. (2025. 11. 18. 방문). &lt;a href=&quot;https://velog.io/@springkim/c-stdvector&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://velog.io/@springkim/c-stdvector&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Tue, 18 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/qm-algorithm</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/qm-algorithm</guid>
        
        
        <category>포트폴리오</category>
        
        <category>포트폴리오-기타</category>
        
      </item>
    
      <item>
        <title>[모닝PPT 2.0]아침에 일어나기 힘들다면 PPT로 잠을 깨 보자!</title>
        <description>&lt;p&gt;아침에 일어나기 힘드신가요? 알람을 맞춰 놓아도 끄고 다시 주무시나요?&lt;br /&gt;
&lt;strong&gt;모닝PPT&lt;/strong&gt;와 &lt;strong&gt;알라미&lt;/strong&gt;를 함께 사용한다면 좀 더 잘 일어날 수 있습니다.&lt;br /&gt;
참고) 모닝PPT는 수성컴 본인이 만들었으며, 알라미는 제가 아닌 Delightroom이 제작한 앱입니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-모닝ppt-내려받기&quot;&gt;1&lt;/a&gt;. &lt;a href=&quot;https://cafe.naver.com/gameppt/165632&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;모닝PPT 내려받기&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;#2-알라미-설치&quot;&gt;2&lt;/a&gt;. 알라미 설치&lt;br /&gt;
&lt;a href=&quot;#3-알라미-qr-미션-알람-설정&quot;&gt;3&lt;/a&gt;. 알라미 QR 미션 알람 설정&lt;br /&gt;
&lt;a href=&quot;#4-기상-시-알람-끄는-방법&quot;&gt;4&lt;/a&gt;. 기상 시 알람 끄는 방법&lt;br /&gt;
&lt;a href=&quot;#5-절정3에-모닝ppt-설치하기&quot;&gt;5&lt;/a&gt;. 절정3에 모닝PPT 설치하기&lt;/p&gt;

&lt;h2 id=&quot;1-모닝ppt-내려받기&quot;&gt;1. 모닝PPT 내려받기&lt;/h2&gt;
&lt;p&gt;모닝PPT는 파워포인트게임마을에서 배포합니다. 비회원도 내려받을 수 있게 해 놓았으니 &lt;a href=&quot;https://cafe.naver.com/gameppt/165632&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://cafe.naver.com/gameppt/165632&lt;/a&gt;로 접속하셔서 모닝PPT를 내려받으시길 바랍니다.&lt;/p&gt;

&lt;h2 id=&quot;2-알라미-설치&quot;&gt;2. 알라미 설치&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/a.jpg&quot; alt=&quot;Google Play 알라미&quot; /&gt;&lt;br /&gt;
휴대전화에 &lt;strong&gt;알라미&lt;/strong&gt;를 설치합니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;안드로이드 Google Play Store: &lt;a href=&quot;https://play.google.com/store/apps/details?id=droom.sleepIfUCan&amp;amp;pcampaignid=web_share&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://play.google.com/store/apps/details?id=droom.sleepIfUCan&amp;amp;pcampaignid=web_share&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;iOS 앱스토어: &lt;a href=&quot;https://apps.apple.com/kr/app/알라미-알람-시계-수면-분석-루틴-습관/id1163786766&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://apps.apple.com/kr/app/알라미-알람-시계-수면-분석-루틴-습관/id1163786766&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;이 글은 안드로이드를 기준으로 작성되었습니다.&lt;/p&gt;

&lt;h2 id=&quot;3-알라미-qr-미션-알람-설정&quot;&gt;3. 알라미 QR 미션 알람 설정&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/b~c편집.PNG&quot; alt=&quot;알람 추가&quot; /&gt;&lt;br /&gt;
3.1. 알라미를 실행하고 오른쪽 아래 &lt;strong&gt;+&lt;/strong&gt;를 터치합니다.&lt;br /&gt;
3.2. &lt;strong&gt;알람&lt;/strong&gt;을 터치합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/d편집.PNG&quot; alt=&quot;기상 알람&quot; /&gt;&lt;br /&gt;
3.3. 알람 이름을 설정합니다. 저는 대충 요일 이름으로 설정했습니다.&lt;br /&gt;
3.4. 알람 시간을 정합니다.&lt;br /&gt;
3.5. 요일을 선택합니다. &lt;strong&gt;이때 &amp;lt;주일, 화, 목, 토&amp;gt;와 &amp;lt;월, 수, 금&amp;gt;을 구분하여 따로 만들어야 합니다!&lt;/strong&gt; 일단 저는 월, 수, 금을 먼저 설정해 보겠습니다.&lt;br /&gt;
3.6. 기상 미션의 &lt;strong&gt;+&lt;/strong&gt;를 터치합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/e~f편집.PNG&quot; alt=&quot;QR/바코드&quot; /&gt;&lt;br /&gt;
3.7. QR/바코드를 선택합니다.&lt;br /&gt;
3.8. &lt;strong&gt;+ 추가&lt;/strong&gt;를 터치합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/주화목토.png&quot; alt=&quot;주일, 화, 목, 토&quot; /&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/images/20251103/월수금.png&quot; alt=&quot;월, 수, 금&quot; /&gt;&lt;br /&gt;
3.9. 요일에 맞는 QR 코드를 스캔합니다. 요일별로 다르니 주의하여 등록하세요.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/h~i편집.PNG&quot; alt=&quot;QR/바코드 이름&quot; /&gt;&lt;br /&gt;
3.10. QR 코드 이름을 등록합니다.&lt;br /&gt;
3.11. 등록한 QR 코드가 선택되었는지 확인하고 &lt;strong&gt;완료&lt;/strong&gt;를 터치합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/j.jpg&quot; alt=&quot;나머지 설정&quot; /&gt;&lt;br /&gt;
3.12. 이어서 알람 소리, 부드럽게 깨우기 여부(기본값은 켜져 있는데 저는 껐습니다.) 등을 설정합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/k.jpg&quot; alt=&quot;설정 완료&quot; /&gt;&lt;br /&gt;
3.13. 주일, 화, 목, 토도 똑같이 설정합니다. 저는 토요일은 일찍 일어날 필요가 없어서 뺐습니다.&lt;/p&gt;

&lt;h2 id=&quot;4-기상-시-알람-끄는-방법&quot;&gt;4. 기상 시 알람 끄는 방법&lt;/h2&gt;
&lt;p&gt;4.1. 알라미 앱에서 자명종이 울립니다.&lt;br /&gt;
4.2. PC를 부팅합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/5.png&quot; alt=&quot;모닝PPT 첫화면&quot; /&gt;&lt;br /&gt;
4.3. 모닝PPT를 실행합니다.&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;4.4. 작업 표시줄의 주일~토 중 그날의 요일을 선택합니다.&lt;/span&gt;&lt;br /&gt;
4.5. 화면에 뜨는 QR 코드를 알라미 앱으로 촬영합니다.&lt;br /&gt;
4.6. 인식에 성공하면 &lt;strong&gt;인식시켰어요&lt;/strong&gt;를 클릭하고, 실패하면 요일을 재선택합니다.&lt;br /&gt;
4.7. 좋은 하루를 보냅니다.&lt;/p&gt;

&lt;h2 id=&quot;5-절정3에-모닝ppt-설치하기&quot;&gt;5. 절정3에 모닝PPT 설치하기&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;/post/jeoljeong3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;절정3&lt;/a&gt;을 사용하시는 분이라면 절정3에 모닝PPT를 설치할 수도 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/1.png&quot; alt=&quot;파일 탐색기 external&quot; /&gt;&lt;br /&gt;
5.1. 절정3을 설치할 때 &lt;strong&gt;external&lt;/strong&gt; 폴더가 있었을 것입니다. &lt;strong&gt;external&lt;/strong&gt; 폴더 안에 &lt;strong&gt;모닝PPT.pptx&lt;/strong&gt;를 넣습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/2.png&quot; alt=&quot;모닝PPT 편집 사용&quot; /&gt;&lt;br /&gt;
5.2. &lt;strong&gt;모닝PPT.pptx&lt;/strong&gt;를 실행하고 &lt;strong&gt;편집 사용&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/3.png&quot; alt=&quot;단추들&quot; /&gt;&lt;br /&gt;
5.3. 1슬라이드 왼쪽을 잘 보면 &lt;span style=&quot;color: #ff0000&quot;&gt;절정 메뉴에 넣을 모닝PPT 단추&lt;/span&gt;와 &lt;span style=&quot;color: #0000ff&quot;&gt;작업 표시줄에 넣을 모닝PPT 단추&lt;/span&gt;가 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/4-1.png&quot; alt=&quot;절정 메뉴&quot; /&gt;&lt;br /&gt;
5.4. &lt;span style=&quot;color: #ff0000&quot;&gt;절정 메뉴에 넣을 모닝PPT 단추&lt;/span&gt;를 복사한 후 &lt;strong&gt;절정3&lt;/strong&gt;을 실행하여 절정3의 절정 메뉴에 붙여넣습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251103/4-2.png&quot; alt=&quot;작업 표시줄&quot; /&gt;&lt;br /&gt;
5.5. 작업 표시줄은 원하시는 분만 하셔도 됩니다. &lt;span style=&quot;color: #0000ff&quot;&gt;작업 표시줄에 넣을 모닝PPT 단추&lt;/span&gt; 복사한 것을 절정3의 &lt;strong&gt;슬라이드 마스터&lt;/strong&gt;로 들어가서 작업 표시줄에 붙여넣습니다.&lt;/p&gt;

&lt;h2 id=&quot;제-ppt를-사용해-주셔서-감사합니다&quot;&gt;제 PPT를 사용해 주셔서 감사합니다.&lt;/h2&gt;
&lt;p&gt;다음에 만나요!&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxys25plus&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 휴대전화는 갤럭시 S25+입니다.
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Mon, 03 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/morningppt2</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/morningppt2</guid>
        
        
        <category>포트폴리오</category>
        
        <category>절정-및-오피스</category>
        
      </item>
    
      <item>
        <title>[Verilog]Multiplexer(Mux)</title>
        <description>&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;디지털논리회로에서 여러 신호 중 하나를 선택할 때 Multiplexer(Mux)를 사용합니다. 오늘은 4-to-1 Mux를 structural design과 if문, case문으로 구현해 보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IDE: &lt;a href=&quot;https://www.intel.com/content/www/us/en/software-kit/665990/intel-quartus-prime-lite-edition-design-software-version-18-1-for-windows.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus 18.1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Device: Cyclone V 5CSXFC6D6F31C6(밑에서 6번째)&lt;/li&gt;
  &lt;li&gt;Simulation: ModelSim-Altera, Verilog HDL&lt;/li&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: mx4&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-structural-design&quot;&gt;1&lt;/a&gt;. Structural Design&lt;br /&gt;
&lt;a href=&quot;#11-mx2v&quot;&gt;1.1&lt;/a&gt;. mx2.v&lt;br /&gt;
&lt;a href=&quot;#12-mx4v&quot;&gt;1.2&lt;/a&gt;. mx4.v&lt;br /&gt;
&lt;a href=&quot;#13-tb_mx4v&quot;&gt;1.3&lt;/a&gt;. tb_mx4.v&lt;br /&gt;
&lt;a href=&quot;#14-simulationmodelsimtv_tv_mx4v&quot;&gt;1.4&lt;/a&gt;. simulation\modelsim\tv_tv_mx4.v&lt;br /&gt;
&lt;a href=&quot;#15-rtl-view&quot;&gt;1.5&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#16-rtl-simulation&quot;&gt;1.6&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#17-flow-summary&quot;&gt;1.7&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-if문을-사용하는-방법&quot;&gt;2&lt;/a&gt;. if문을 사용하는 방법&lt;br /&gt;
&lt;a href=&quot;#21-mx4v&quot;&gt;2.1&lt;/a&gt;. mx4.v&lt;br /&gt;
&lt;a href=&quot;#22-tb_mx4v--simulationmodelsimtv_tv_mx4v&quot;&gt;2.2&lt;/a&gt;. tb_mx4.v &amp;amp; simulation\modelsim\tv_tv_mx4.v&lt;br /&gt;
&lt;a href=&quot;#23-rtl-view&quot;&gt;2.3&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#24-rtl-simulation&quot;&gt;2.4&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#25-flow-summary&quot;&gt;2.5&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#3-case문을-사용하는-방법&quot;&gt;3&lt;/a&gt;. case문을 사용하는 방법&lt;br /&gt;
&lt;a href=&quot;#31-mx4v&quot;&gt;3.1&lt;/a&gt;. mx4.v&lt;br /&gt;
&lt;a href=&quot;#32-tb_mx4v--simulationmodelsimtv_tv_mx4v&quot;&gt;3.2&lt;/a&gt;. tb_mx4.v &amp;amp; simulation\modelsim\tv_tv_mx4.v&lt;br /&gt;
&lt;a href=&quot;#33-rtl-view&quot;&gt;3.3&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#34-rtl-simulation&quot;&gt;3.4&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#35-flow-summary&quot;&gt;3.5&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#4-글-마무리&quot;&gt;4&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#5-참고-문헌&quot;&gt;5&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-structural-design&quot;&gt;1. Structural Design&lt;/h2&gt;
&lt;h3 id=&quot;11-mx2v&quot;&gt;1.1. mx2.v&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-1-k-map.png&quot; alt=&quot;2:1 Mux Karnaugh Map&quot; /&gt;&lt;br /&gt;
mx2.v에서는 2-to-1 Mux를 만듭니다.&lt;br /&gt;
Karnaugh Map을 그려 보면 2-to-1 Mux의 boolean eqation은 \(Y=D_0\bar{S}+D_1S\)임을 알 수 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-1-bubble-pushing.png&quot; alt=&quot;2:1 Mux Bubble Pushing&quot; /&gt;&lt;br /&gt;
그러나 AND, OR Gate보다 NAND Gate가 더 저렴하므로 forward로 bubble pushing을 하겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mx2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//select signal&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//data&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;kt&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;nand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;12-mx4v&quot;&gt;1.2. mx4.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mx4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//select signal&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//data&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instance MAB: Bth mux whose select signal is s[A]&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;mx2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;M00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;mx2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;M01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;mx2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;M10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;[Line 2]&lt;br /&gt;
&lt;strong&gt;input [1:0] s;&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;N&lt;/em&gt;-to-1 Mux의 s의 비트 길이는 \(\log_2 N\)입니다. 우리는 지금 4-to-1 Mux를 만들려고 하므로 s의 길이는 \(\log_2 4=2\)입니다.&lt;/p&gt;

&lt;p&gt;[Line 6~9 instance 이름 규칙]&lt;br /&gt;
M&lt;span style=&quot;color: #ff00ff&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #00ffff&quot;&gt;B&lt;/span&gt;는 select signal이 s[&lt;span style=&quot;color: #ff00ff&quot;&gt;A&lt;/span&gt;]인 &lt;span style=&quot;color: #00ffff&quot;&gt;B&lt;/span&gt;번째 Mux입니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-4-to-1-mux.png&quot; alt=&quot;4-to-1 Mux&quot; /&gt;&lt;br /&gt;
[Line 7]&lt;br /&gt;
&lt;strong&gt;mx2 M00(w00, &lt;span style=&quot;color: #ff0000&quot;&gt;s[0]&lt;/span&gt;, d0, d1);&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;s[0]&lt;/span&gt;==0이면 d0을,&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;s[0]&lt;/span&gt;==1이면 d1을 출력합니다.&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;mx2 M01(w01, &lt;span style=&quot;color: #00b050&quot;&gt;s[0]&lt;/span&gt;, d2, d3);&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00b050&quot;&gt;s[0]&lt;/span&gt;==0이면 d2을,&lt;br /&gt;
&lt;span style=&quot;color: #00b050&quot;&gt;s[0]&lt;/span&gt;==1이면 d3을 출력합니다.&lt;/p&gt;

&lt;p&gt;[Line 9]&lt;br /&gt;
&lt;strong&gt;mx2 M10(y, &lt;span style=&quot;color: #0000ff&quot;&gt;s[1]&lt;/span&gt;, w00, w01);&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00b050&quot;&gt;s[1]&lt;/span&gt;==0이면 w00을,&lt;br /&gt;
&lt;span style=&quot;color: #00b050&quot;&gt;s[1]&lt;/span&gt;==1이면 w01을 출력합니다.&lt;/p&gt;

&lt;h3 id=&quot;13-tb_mx4v&quot;&gt;1.3. tb_mx4.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_mx4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//bookkeeping variables&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//array of testvectors&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instantiate device under test&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;mx4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//generate clock&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//at start of test, load vectors and pulse reset&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;readmemb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tv_mx4.tv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Put testvector file at simulation\modelsim&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//apply test vectors on rising edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//check results on falling edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//skip during reset==1&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: inputs=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;	outputs=%b (%b expected)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
			
	&lt;span class=&quot;c1&quot;&gt;//increment array index and read next testvector&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;32&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d tests completed with %d errors.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;finish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;14-simulationmodelsimtv_tv_mx4v&quot;&gt;1.4. simulation\modelsim\tv_tv_mx4.v&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00_0000_0
01_0000_0
10_0000_0
11_0000_0
00_0001_0
01_0001_0
10_0001_0
11_0001_1
00_0010_0
01_0010_0
10_0010_1
11_0010_0
00_0011_0
01_0011_0
10_0011_1
11_0011_1
00_0100_0
01_0100_1
10_0100_0
11_0100_0
00_0101_0
01_0101_1
10_0101_0
11_0101_1
00_0110_0
01_0110_1
10_0110_1
11_0110_0
00_0111_0
01_0111_1
10_0111_1
11_0111_1
00_1000_1
01_1000_0
10_1000_0
11_1000_0
00_1001_1
01_1001_0
10_1001_0
11_1001_1
00_1010_1
01_1010_0
10_1010_1
11_1010_0
00_1011_1
01_1011_0
10_1011_1
11_1011_1
00_1100_1
01_1100_1
10_1100_0
11_1100_0
00_1101_1
01_1101_1
10_1101_0
11_1101_1
00_1110_1
01_1110_1
10_1110_1
11_1110_0
00_1111_1
01_1111_1
10_1111_1
11_1111_1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;각 줄이 &lt;span style=&quot;color: #ff5000&quot;&gt;&amp;lt;s&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color: #008060&quot;&gt;&amp;lt;d0&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008080&quot;&gt;&amp;lt;d1&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0080a0&quot;&gt;&amp;lt;d2&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0080c0&quot;&gt;&amp;lt;d3&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;&amp;lt;y_expected&amp;gt;&lt;/span&gt;입니다.&lt;br /&gt;
&lt;span style=&quot;color: #ff5000&quot;&gt;&amp;lt;s&amp;gt;&lt;/span&gt;는 2-bit입니다.&lt;br /&gt;
예) &lt;span style=&quot;color: #ff5000&quot;&gt;10&lt;/span&gt;_&lt;span style=&quot;color: #008060&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #008080&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #0080a0&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #0080c0&quot;&gt;1&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;0&lt;/span&gt;은 &lt;span style=&quot;color: #ff5000&quot;&gt;s=10&lt;/span&gt;, d=&lt;span style=&quot;color: #008060&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #008080&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #0080a0&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #0080c0&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #00ffff&quot;&gt;y=0&lt;/span&gt;입니다.&lt;/p&gt;

&lt;h3 id=&quot;15-rtl-view&quot;&gt;1.5. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-view.png&quot; alt=&quot;Structural mx4 RTL View&quot; /&gt;&lt;br /&gt;
의도한 대로 mx2가 instantiation되었습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-view-mx2.png&quot; alt=&quot;Structural mx2 RTL View&quot; /&gt;&lt;br /&gt;
mx2를 확대해 보면 이렇게 되어 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;16-rtl-simulation&quot;&gt;1.6. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-sim.png&quot; alt=&quot;Structural mx4 RTL Simulation&quot; /&gt;&lt;br /&gt;
vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.&lt;/p&gt;

&lt;h3 id=&quot;17-flow-summary&quot;&gt;1.7. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/1-flow.png&quot; alt=&quot;Structural mx4 Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 2, Total registers는 0, Total pins는 7이 나옵니다.&lt;/p&gt;

&lt;h2 id=&quot;2-if문을-사용하는-방법&quot;&gt;2. if문을 사용하는 방법&lt;/h2&gt;
&lt;h3 id=&quot;21-mx4v&quot;&gt;2.1. mx4.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mx4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//select signal&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//data&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;2&apos;b11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 4]&lt;br /&gt;
&lt;strong&gt;output reg y;&lt;/strong&gt;&lt;br /&gt;
Combinational circuit이지만 always문을 사용하기 위해 y를 output &lt;strong&gt;reg&lt;/strong&gt;로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 6]&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;always&lt;/span&gt; &lt;strong&gt;@ (&lt;/strong&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;*&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;어떤 변수든 변화가 있으면&lt;/span&gt; begin과 end 사이의 내용을 &lt;span style=&quot;color: #ff0000&quot;&gt;반복한다는&lt;/span&gt; 뜻입니다.&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;if(s==2’b00)	y=d0;&lt;/strong&gt;&lt;br /&gt;
s==2’b00이면 y=d0;을 수행합니다.&lt;/p&gt;

&lt;p&gt;[Line 9~11]&lt;br /&gt;
&lt;strong&gt;else if(s==2’b&lt;/strong&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;s값&lt;/span&gt;&lt;strong&gt;)	y=&lt;/strong&gt;&lt;span style=&quot;color: #ff00ff&quot;&gt;데이터&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
s가 &lt;span style=&quot;color: #00ff00&quot;&gt;01, 10, 11&lt;/span&gt; 중 무엇이냐에 따라 y에 &lt;span style=&quot;color: #ff00ff&quot;&gt;d1, d2, d3&lt;/span&gt;을 대입합니다.&lt;/p&gt;

&lt;p&gt;[Line 12]&lt;br /&gt;
&lt;strong&gt;else y=1’bx;&lt;/strong&gt;&lt;br /&gt;
s가 00, 01, 10, 11 모두 아닐 때는 y=1’bx;를 수행합니다.&lt;/p&gt;

&lt;h3 id=&quot;22-tb_mx4v--simulationmodelsimtv_tv_mx4v&quot;&gt;2.2. tb_mx4.v &amp;amp; simulation\modelsim\tv_tv_mx4.v&lt;/h3&gt;
&lt;p&gt;testbench와 testvector는 Structural Design에서 사용한 것과 동일합니다.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#13-tb_mx4v&quot;&gt;1.3&lt;/a&gt;. tb_mx4.v&lt;br /&gt;
&lt;a href=&quot;#14-simulationmodelsimtv_tv_mx4v&quot;&gt;1.4&lt;/a&gt;. simulation\modelsim\tv_tv_mx4.v&lt;/p&gt;

&lt;h3 id=&quot;23-rtl-view&quot;&gt;2.3. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/2-view.png&quot; alt=&quot;Mux by if RTL View&quot; /&gt;&lt;br /&gt;
if문을 회로로 구현해 놓은 듯 보입니다.&lt;br /&gt;
2-to-1 Mux가 3개, Equal이 3개 있습니다.&lt;br /&gt;
각 Equal의 output은 2-to-1 Mux의 select signal로 들어갑니다.&lt;/p&gt;

&lt;h3 id=&quot;24-rtl-simulation&quot;&gt;2.4. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/2-sim.png&quot; alt=&quot;Mux by if RTL Simulation&quot; /&gt;&lt;br /&gt;
Structural Design과 똑같습니다.&lt;br /&gt;
vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.&lt;/p&gt;

&lt;h3 id=&quot;25-flow-summary&quot;&gt;2.5. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/2-flow.png&quot; alt=&quot;Mux by if Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 2, Total registers는 0, Total pins는 7이 나옵니다. Structural Design과 똑같네요.&lt;/p&gt;

&lt;h2 id=&quot;3-case문을-사용하는-방법&quot;&gt;3. case문을 사용하는 방법&lt;/h2&gt;
&lt;h3 id=&quot;31-mx4v&quot;&gt;3.1. mx4.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mx4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//select signal&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//data&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;mb&quot;&gt;2&apos;b00&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;mb&quot;&gt;2&apos;b01&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;mb&quot;&gt;2&apos;b10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;mb&quot;&gt;2&apos;b11&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;nl&quot;&gt;default:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;1&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;endcase&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 4]&lt;br /&gt;
&lt;strong&gt;output reg y;&lt;/strong&gt;
if문을 사용할 때와 마찬가지로 case문도 always문 안에서 작동합니다. always문을 사용하기 위해 y를 output &lt;strong&gt;reg&lt;/strong&gt;로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 6]&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;always&lt;/span&gt; &lt;strong&gt;@ (&lt;/strong&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;*&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;어떤 변수든 변화가 있으면&lt;/span&gt; begin과 end 사이의 내용을 &lt;span style=&quot;color: #ff0000&quot;&gt;반복한다는&lt;/span&gt; 뜻입니다.&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;case(s)&lt;/strong&gt;&lt;br /&gt;
s 값에 따라 case문이 작동하게 됩니다.&lt;/p&gt;

&lt;p&gt;[Line 9~12]&lt;br /&gt;
&lt;strong&gt;2’b&lt;/strong&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;s값&lt;/span&gt;&lt;strong&gt;: y=&lt;/strong&gt;&lt;span style=&quot;color: #ff00ff&quot;&gt;데이터&lt;/span&gt;&lt;strong&gt;;&lt;/strong&gt;&lt;br /&gt;
s가 &lt;span style=&quot;color: #00ff00&quot;&gt;00, 01, 10, 11&lt;/span&gt; 중 무엇이냐에 따라 y에 &lt;span style=&quot;color: #ff00ff&quot;&gt;d1, d2, d3&lt;/span&gt;을 대입합니다.&lt;/p&gt;

&lt;p&gt;[Line 13]&lt;br /&gt;
&lt;strong&gt;default: y=1’bx;&lt;/strong&gt;&lt;br /&gt;
s가 00, 01, 10, 11 모두 아닐 때는 y=1’bx;를 수행합니다.&lt;/p&gt;

&lt;p&gt;[Line 14]&lt;br /&gt;
&lt;strong&gt;endcase&lt;/strong&gt;&lt;br /&gt;
case문을 닫습니다.&lt;/p&gt;

&lt;h3 id=&quot;32-tb_mx4v--simulationmodelsimtv_tv_mx4v&quot;&gt;3.2. tb_mx4.v &amp;amp; simulation\modelsim\tv_tv_mx4.v&lt;/h3&gt;
&lt;p&gt;testbench와 testvector는 Structural Design에서 사용한 것과 동일합니다.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#13-tb_mx4v&quot;&gt;1.3&lt;/a&gt;. tb_mx4.v&lt;br /&gt;
&lt;a href=&quot;#14-simulationmodelsimtv_tv_mx4v&quot;&gt;1.4&lt;/a&gt;. simulation\modelsim\tv_tv_mx4.v&lt;/p&gt;

&lt;h3 id=&quot;33-rtl-view&quot;&gt;3.3. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/3-view.png&quot; alt=&quot;Mux by case RTL View&quot; /&gt;&lt;br /&gt;
case문을 사용하니 RTL View가 Mux 기호로 구현되었습니다. RTL View는 case문이 제일 간결한 것 같네요.&lt;/p&gt;

&lt;h3 id=&quot;34-rtl-simulation&quot;&gt;3.4. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/3-sim.png&quot; alt=&quot;Mux by case RTL Simulation&quot; /&gt;&lt;br /&gt;
Structural Design과 똑같습니다.&lt;br /&gt;
vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.&lt;/p&gt;

&lt;h3 id=&quot;35-flow-summary&quot;&gt;3.5. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251101/3-flow.png&quot; alt=&quot;Mux by case Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 2, Total registers는 0, Total pins는 7이 나옵니다. 이것도 Structural Design과 똑같네요.&lt;/p&gt;

&lt;h2 id=&quot;4-글-마무리&quot;&gt;4. 글 마무리&lt;/h2&gt;
&lt;p&gt;Mux를 구현할 때는 case문이 가장 좋아 보이네요.&lt;br /&gt;
제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;5-참고-문헌&quot;&gt;5. 참고 문헌&lt;/h2&gt;
&lt;p&gt;1) David Money Harris, Sarah L. Harris. 2013. Digital Design and Computer Architecture. 2nd Edition. Elsevier Korea L.L.C.&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 01 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/verilog-mux</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/verilog-mux</guid>
        
        
        <category>프로그래밍</category>
        
        <category>Verilog</category>
        
      </item>
    
      <item>
        <title>[Verilog]D Flip-Flop, Register</title>
        <description>&lt;p&gt;오늘은 Verilog로 기억 소자인 D Flip-Flop과 Register를 만들어 보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IDE: &lt;a href=&quot;https://www.intel.com/content/www/us/en/software-kit/665990/intel-quartus-prime-lite-edition-design-software-version-18-1-for-windows.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus 18.1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Device: Cyclone V 5CSXFC6D6F31C6(밑에서 6번째)&lt;/li&gt;
  &lt;li&gt;Simulation: ModelSim-Altera, Verilog HDL&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-d-flip-flop&quot;&gt;1&lt;/a&gt;. D Flip-Flop&lt;br /&gt;
&lt;a href=&quot;#11-_dff_rv&quot;&gt;1.1&lt;/a&gt;. _dff_r.v&lt;br /&gt;
&lt;a href=&quot;#12-tb_dff_rv&quot;&gt;1.2&lt;/a&gt;. tb_dff_r.v&lt;br /&gt;
&lt;a href=&quot;#13-simulationmodelsimtv_dff_rtv&quot;&gt;1.3&lt;/a&gt;. simulation\modelsim\tv_dff_r.tv&lt;br /&gt;
&lt;a href=&quot;#14-rtl-view&quot;&gt;1.4&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#15-rtl-simulation&quot;&gt;1.5&lt;/a&gt;. RTL Simulation&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-registerd-flip-flop을-instantiation하여-구현&quot;&gt;2&lt;/a&gt;. Register(D Flip-Flop을 instantiation하여 구현)&lt;br /&gt;
&lt;a href=&quot;#21-_register8_dffv&quot;&gt;2.1&lt;/a&gt;. _register8_dff.v&lt;br /&gt;
&lt;a href=&quot;#22-_register32_dffv&quot;&gt;2.2&lt;/a&gt;. _register32_dff.v&lt;br /&gt;
&lt;a href=&quot;#23-tb_register32_dffv&quot;&gt;2.3&lt;/a&gt;. tb_register32_dff.v&lt;br /&gt;
&lt;a href=&quot;#24-simulationmodelsimtv_register32tv&quot;&gt;2.4&lt;/a&gt;. simulation\modelsim\tv_register32.tv&lt;br /&gt;
&lt;a href=&quot;#25-rtl-view&quot;&gt;2.5&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#26-rtl-simulation&quot;&gt;2.6&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#27-flow-summary&quot;&gt;2.7&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#3-registerreg-변수를-사용하여-구현&quot;&gt;3&lt;/a&gt;. Register(reg 변수를 사용하여 구현)&lt;br /&gt;
&lt;a href=&quot;#31-_register32_regv&quot;&gt;3.1&lt;/a&gt;. _register32_reg.v&lt;br /&gt;
&lt;a href=&quot;#32-tb_register32_regv&quot;&gt;3.2&lt;/a&gt;. tb_register32_reg.v&lt;br /&gt;
&lt;a href=&quot;#33-simulationmodelsimtv_register32tv&quot;&gt;3.3&lt;/a&gt;. simulation\modelsim\tv_register32.tv&lt;br /&gt;
&lt;a href=&quot;#34-rtl-view&quot;&gt;3.4&lt;/a&gt;. RTL View&lt;br /&gt;
&lt;a href=&quot;#35-rtl-simulation&quot;&gt;3.5&lt;/a&gt;. RTL Simulation&lt;br /&gt;
&lt;a href=&quot;#36-flow-summary&quot;&gt;3.6&lt;/a&gt;. Flow Summary&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#34-rtl-view&quot;&gt;4&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#5-참고-자료&quot;&gt;5&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-d-flip-flop&quot;&gt;1. D Flip-Flop&lt;/h2&gt;
&lt;p&gt;clk와 reset_n이 있는 &lt;strong&gt;Asynchronous D Flip-Flop&lt;/strong&gt;을 만들어 보겠습니다.&lt;br /&gt;
clk는 클럭입니다. clk가 0에서 1로 올라갈 때(rising edge, posedge) q=d가 됩니다.&lt;br /&gt;
reset_n은 active low로 작동합니다. 즉, reset_n==0이면 d의 값에 상관없이 즉시 q=0이 됩니다.&lt;br /&gt;
cf) Synchronous D Flip-Flop: reset_==0이 된 후 다음 clk의 rising edge에 q=0이 됨.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: _dff_r&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;11-_dff_rv&quot;&gt;1.1. _dff_r.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 5]&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;always&lt;/span&gt; &lt;strong&gt;@ (&lt;/strong&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;posedge clk&lt;/span&gt; &lt;strong&gt;or&lt;/strong&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;negedge reset_n&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00ff00&quot;&gt;clk가 0→1 상승하거나&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;reset_n이 1→0 하강할 때&lt;/span&gt; begin과 end 사이의 내용을 &lt;span style=&quot;color: #ff0000&quot;&gt;반복합니다.&lt;/span&gt;&lt;br /&gt;
cf) Synchronous D Flip-Flop: &lt;span style=&quot;color: #ff0000&quot;&gt;always&lt;/span&gt; @ (&lt;span style=&quot;color: #00ff00&quot;&gt;posedge clk&lt;/span&gt;)&lt;/p&gt;

&lt;p&gt;[Line 7]&lt;br /&gt;
&lt;strong&gt;if(reset_n==0)	q&amp;lt;=0;&lt;/strong&gt;&lt;br /&gt;
reset_n==0이면 즉시 q&amp;lt;=0;을 수행합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/blocking.png&quot; alt=&quot;Blocking vs Non-blocking&quot; /&gt;&lt;br /&gt;
&amp;lt;=는 non-blocking assignment입니다.&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;else	q&amp;lt;=d;&lt;/strong&gt;&lt;br /&gt;
reset_n!=0이면(즉, reset_n==1이면) q&amp;lt;=d;를 수행합니다.&lt;/p&gt;

&lt;h3 id=&quot;12-tb_dff_rv&quot;&gt;1.2. tb_dff_r.v&lt;/h3&gt;
&lt;p&gt;testvector를 사용하겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//bookkeeping variables&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//array of testvectors&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instantiate device under test&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//generate clock&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//at start of test, load vectors and pulse reset&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;readmemb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tv_dff_r.tv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Put testvector file at simulation\modelsim&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//apply test vectors on rising edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//check results on falling edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//skip during reset==1&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: inputs=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;	outputs=%b (%b expected)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
			
	&lt;span class=&quot;c1&quot;&gt;//increment array index and read next testvector&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;32&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d tests completed with %d errors.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;finish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 1~2]&lt;br /&gt;
clk는 testbench와 D Flip-Flop에서 공용으로 사용하겠습니다.&lt;br /&gt;
reset은 testbench에서 단독으로 사용하겠습니다.&lt;br /&gt;
reset_n은 D Flip-Flop에서 단독으로 사용하겠습니다.&lt;/p&gt;

&lt;p&gt;[Line 30]&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;#2;&lt;/span&gt; &lt;strong&gt;{&lt;/strong&gt;&lt;span style=&quot;color: #ff5000&quot;&gt;reset_n&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #008060&quot;&gt;d&lt;/span&gt;&lt;strong&gt;,&lt;/strong&gt; &lt;span style=&quot;color: #00ffff&quot;&gt;q_expected&lt;/span&gt;&lt;strong&gt;}=testvectors[vectornum];&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff00ff&quot;&gt;#2;&lt;/span&gt;를 쓰지 않으면 D Flip-Flop이 다음 클럭에 작동하므로 &lt;span style=&quot;color: #ff00ff&quot;&gt;#2;&lt;/span&gt;를 써서 지연 시간을 줄였습니다. #1이 아니고 하필 &lt;span style=&quot;color: #ff00ff&quot;&gt;#2;&lt;/span&gt;인 이유는 36행에서 negedge clk에 #6;이 붙는 것이 겹치지 않게 하기 위해서입니다.&lt;/p&gt;

&lt;p&gt;[Line 36]&lt;br /&gt;
&lt;strong&gt;#6;&lt;/strong&gt;&lt;br /&gt;
clk의 rising edge(posedge)가 일어난 후 값을 측정하도록 합니다.&lt;/p&gt;

&lt;p&gt;Testbench를 작성했으면 Simulation 설정에서 추가해 주어야 합니다. 여기서는 설명하지 않겠습니다. Testbench를 Intel Quartus에서 추가하는 방법을 모르신다면 &lt;a href=&quot;https://sooseongcom.com/post/verilog-testbench-quartus#2-simple-testbenchtestbench1v%EC%99%80-intel-quartus-%EC%97%B0%EA%B2%B0&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Intel Quartus에서 Verilog testbench 사용하기 2번 문단&lt;/a&gt;을 참고하시길 바랍니다.&lt;/p&gt;

&lt;h3 id=&quot;13-simulationmodelsimtv_dff_rtv&quot;&gt;1.3. simulation\modelsim\tv_dff_r.tv&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00_0
01_0
00_0
01_0
10_0
11_1
10_0
11_1
00_0
01_0
00_0
01_0
10_0
11_1
10_0
11_1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;각 줄이 &lt;span style=&quot;color: #ff5000&quot;&gt;&amp;lt;reset_n&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008060&quot;&gt;&amp;lt;d&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;&amp;lt;q_expected&amp;gt;&lt;/span&gt;입니다.&lt;br /&gt;
예) &lt;span style=&quot;color: #ff5000&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #008060&quot;&gt;0&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;0&lt;/span&gt;은 &lt;span style=&quot;color: #ff5000&quot;&gt;reset_n=1&lt;/span&gt;, &lt;span style=&quot;color: #008060&quot;&gt;d=0&lt;/span&gt;, &lt;span style=&quot;color: #00ffff&quot;&gt;q_expected=0&lt;/span&gt;을 의미합니다.&lt;/p&gt;

&lt;h3 id=&quot;14-rtl-view&quot;&gt;1.4. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/1-view.png&quot; alt=&quot;D Flip-Flop RTL View&quot; /&gt;&lt;br /&gt;
D Flip-Flop이 그려져 있고, D에 d가, CLK에 clk가, Q에 q가 연결되어 있으며, CLRN에 reset_n이 invert되어 들어가는 것으로 되어 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;15-rtl-simulation&quot;&gt;1.5. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/1-sim.png&quot; alt=&quot;D Flip-Flop RTL Simulation&quot; /&gt;&lt;br /&gt;
vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.
q 값의 변화는 clk의 rising edge(posedge)에만 일어나는 것을 보실 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;2-registerd-flip-flop을-instantiation하여-구현&quot;&gt;2. Register(D Flip-Flop을 instantiation하여 구현)&lt;/h2&gt;
&lt;p&gt;Register는 D Flip-Flop을 연결하여 만듭니다. 앞서 D Flip-Flop을 구현했으므로 그것을 instantiation하여 32-bit register를 구현해 보겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: _register32_dff&lt;/li&gt;
  &lt;li&gt;Add files: _dff_r.v(&lt;a href=&quot;#11-_dff_rv&quot;&gt;1.1절&lt;/a&gt; 파일 활용)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;21-_register8_dffv&quot;&gt;2.1. _register8_dff.v&lt;/h3&gt;
&lt;p&gt;한 번에 D Flip-Flop 32개를 instantiation하는 것은 번거로우므로 8-bit register를 먼저 만들겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U4_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U5_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U6_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dff_r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U7_dff_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;22-_register32_dffv&quot;&gt;2.2. _register32_dff.v&lt;/h3&gt;
&lt;p&gt;8-bit register 4개를 연결하여 32-bit register를 만듭니다.&lt;/p&gt;

&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register32_dff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register8&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U0_register8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register8&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U1_register8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register8&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U2_register8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register8&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;U3_register8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;23-tb_register32_dffv&quot;&gt;2.3. tb_register32_dff.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_register32_dff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//bookkeeping variables&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//array of testvectors&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instantiate device under test&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register32_dff&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//generate clock&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//at start of test, load vectors and pulse reset&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;readmemh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tv_register32.tv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Put testvector file at simulation\modelsim&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//apply test vectors on rising edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//check results on falling edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//skip during reset==1&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: inputs=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;	outputs=%b (%b expected)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
			
	&lt;span class=&quot;c1&quot;&gt;//increment array index and read next testvector&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;128&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d tests completed with %d errors.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;finish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;[Line 23]&lt;br /&gt;
&lt;strong&gt;$readmem&lt;span style=&quot;color: #ff0000&quot;&gt;h&lt;/span&gt;(“./tv_register32.tv”, testvectors);&lt;/strong&gt;&lt;br /&gt;
1.2절 tb_dff_r.v에서는 $readmem&lt;span style=&quot;color: #0000ff&quot;&gt;b&lt;/span&gt;를 썼지만, 여기 tb_register32_dff.v에서는 &lt;strong&gt;$readmem&lt;span style=&quot;color: #ff0000&quot;&gt;h&lt;/span&gt;&lt;/strong&gt;를 씁니다.&lt;br /&gt;
$readmem&lt;u&gt;b&lt;/u&gt;는 파일을 2진수로 읽어서 배열에 저장하고, $readmem&lt;span style=&quot;color: #ff0000&quot;&gt;h&lt;/span&gt;는 파일을 16진수로 읽어서 배열에 저장합니다.&lt;br /&gt;
testvector를 작성할 때 32bit를 2진수로 쓰면 너무 길기 때문에 16진수로 했습니다. 참고로 16진수 1자리는 2진수로 변환하면 4자리가 됩니다.&lt;/p&gt;

&lt;h3 id=&quot;24-simulationmodelsimtv_register32tv&quot;&gt;2.4. simulation\modelsim\tv_register32.tv&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;000000000_00000000
000000001_00000000
000000020_00000000
00000a003_00000000
100000000_00000000
100000001_00000001
100000020_00000020
10000a003_0000a003
000000000_00000000
000000001_00000000
000000020_00000000
00000a003_00000000
100000000_00000000
100000001_00000001
100000020_00000020
10000a003_0000a003
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;각 줄이 &lt;span style=&quot;color: #ff5000&quot;&gt;&amp;lt;reset_n&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #008060&quot;&gt;&amp;lt;d&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;&amp;lt;q_expected&amp;gt;&lt;/span&gt;입니다.&lt;br /&gt;
&lt;span style=&quot;color: #008060&quot;&gt;d&lt;/span&gt;와 &lt;span style=&quot;color: #00ffff&quot;&gt;q_expected&lt;/span&gt;는 16진수로 8자리씩 됩니다.&lt;br /&gt;
예) &lt;span style=&quot;color: #ff5000&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #008060&quot;&gt;0000a003&lt;/span&gt;_&lt;span style=&quot;color: #00ffff&quot;&gt;0000a003&lt;/span&gt;은 &lt;span style=&quot;color: #ff5000&quot;&gt;reset_n=1&lt;/span&gt;, &lt;span style=&quot;color: #008060&quot;&gt;d=0000a003&lt;/span&gt;, &lt;span style=&quot;color: #00ffff&quot;&gt;q=0000a003&lt;/span&gt;입니다.&lt;/p&gt;

&lt;h3 id=&quot;25-rtl-view&quot;&gt;2.5. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/2-view1.png&quot; alt=&quot;_register32_dff RTL View&quot; /&gt;&lt;br /&gt;
d가 _register8 4개로 나뉘어 들어갑니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/2-view2.png&quot; alt=&quot;_register8 RTL View&quot; /&gt;&lt;br /&gt;
_register8을 확대해 보면 이렇게 생겼습니다.&lt;/p&gt;

&lt;h3 id=&quot;26-rtl-simulation&quot;&gt;2.6. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/1-sim.png&quot; alt=&quot;_register32_dff RTL Simulation&quot; /&gt;&lt;br /&gt;
d와 q_expected와 q는 16진수(Hexadecimal)로, vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.&lt;br /&gt;
D Flip-Flop과 마찬가지로 q 값의 변화는 clk의 rising edge(posedge)에만 일어나는 것을 보실 수 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;27-flow-summary&quot;&gt;2.7. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/2-flow.png&quot; alt=&quot;_register32_dff Flow Summary&quot; /&gt;&lt;br /&gt;
Logic utiliazation은 9, Total registers는 32, Total pins는 66이 나오네요.&lt;/p&gt;

&lt;h2 id=&quot;3-registerreg-변수를-사용하여-구현&quot;&gt;3. Register(reg 변수를 사용하여 구현)&lt;/h2&gt;
&lt;p&gt;이번에는 그냥 32-bit reg 변수를 선언하여 Register를 구현해 보겠습니다. 물론 그렇다고 해서 그냥 “reg 변수 선언, 끝!”은 아니고 input과 output, always문 등을 사용하도록 하겠습니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Project Name &amp;amp; the name of Top-level: _register32_reg&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;31-_register32_regv&quot;&gt;3.1. _register32_reg.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register32_reg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;[Line 3~4]&lt;br /&gt;
d와 q를 각각 [31:0]으로 선언합니다.&lt;/p&gt;

&lt;p&gt;[Line 6]&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;always&lt;/span&gt; &lt;strong&gt;@ (&lt;/strong&gt;&lt;span style=&quot;color: #00ff00&quot;&gt;posedge clk&lt;/span&gt; &lt;strong&gt;or&lt;/strong&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;negedge reset_n&lt;/span&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;color: #00ff00&quot;&gt;clk가 0→1 상승하거나&lt;/span&gt; &lt;span style=&quot;color: #0000ff&quot;&gt;reset_n이 1→0 하강할 때&lt;/span&gt; begin과 end 사이의 내용을 &lt;span style=&quot;color: #ff0000&quot;&gt;반복합니다.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;[Line 8]&lt;br /&gt;
&lt;strong&gt;if(reset_n==0)	q&amp;lt;=0;&lt;/strong&gt;&lt;br /&gt;
reset_n==0이면 즉시 q&amp;lt;=0;을 수행합니다.&lt;/p&gt;

&lt;p&gt;[Line 9]&lt;br /&gt;
&lt;strong&gt;else	q&amp;lt;=d;&lt;/strong&gt;&lt;br /&gt;
reset_n!=0이면(즉, reset_n==1이면) q&amp;lt;=d;를 수행합니다.&lt;/p&gt;

&lt;h3 id=&quot;32-tb_register32_regv&quot;&gt;3.2. tb_register32_reg.v&lt;/h3&gt;
&lt;div class=&quot;language-verilog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;`timescale&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tb_register32_reg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;wire&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//bookkeeping variables&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;reg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;127&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//array of testvectors&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//instantiate device under test&lt;/span&gt;
	&lt;span class=&quot;mi&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register32_reg&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//generate clock&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
	
	&lt;span class=&quot;c1&quot;&gt;//at start of test, load vectors and pulse reset&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;initial&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;readmemh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;./tv_register32.tv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//Put testvector file at simulation\modelsim&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//apply test vectors on rising edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;posedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		
	&lt;span class=&quot;c1&quot;&gt;//check results on falling edge of clk&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;negedge&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//skip during reset==1&lt;/span&gt;
			&lt;span class=&quot;p&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error: inputs=%b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reset_n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;	outputs=%b (%b expected)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q_expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
			
	&lt;span class=&quot;c1&quot;&gt;//increment array index and read next testvector&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testvectors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mb&quot;&gt;128&apos;bx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%d tests completed with %d errors.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vectornum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
				&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;finish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;endmodule&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;33-simulationmodelsimtv_register32tv&quot;&gt;3.3. simulation\modelsim\tv_register32.tv&lt;/h3&gt;
&lt;p&gt;2.4절과 똑같이 했습니다. 스크롤 올리기 귀찮으신 분들을 위해 한 번 더 써 드리겠습니다.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;000000000_00000000
000000001_00000000
000000020_00000000
00000a003_00000000
100000000_00000000
100000001_00000001
100000020_00000020
10000a003_0000a003
000000000_00000000
000000001_00000000
000000020_00000000
00000a003_00000000
100000000_00000000
100000001_00000001
100000020_00000020
10000a003_0000a003
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;34-rtl-view&quot;&gt;3.4. RTL View&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/3-view.png&quot; alt=&quot;_register32_reg RTL View&quot; /&gt;&lt;br /&gt;
register가 사각형 하나에 그려져 있고, D에 d[31..0]이, CLK에 clk가, Q에 q[31..0]이 연결되어 있으며, CLRN에 reset_n이 invert되어 들어가는 것으로 되어 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;35-rtl-simulation&quot;&gt;3.5. RTL Simulation&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/3-sim.png&quot; alt=&quot;_register32_reg RTL Simulation&quot; /&gt;&lt;br /&gt;
d와 q_expected와 q는 16진수(Hexadecimal)로, vectornum과 errors는 10진수(Decimal)로 표시하도록 설정했습니다.&lt;br /&gt;
q 값의 변화는 clk의 rising edge(posedge)에만 일어나는 것을 보실 수 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;36-flow-summary&quot;&gt;3.6. Flow Summary&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251018/3-flow.png&quot; alt=&quot;_register32_reg Flow Summary&quot; /&gt;&lt;br /&gt;
D Flip-Flop을 instantiation했을 때와 마찬가지로 Logic utiliazation은 9, Total registers는 32, Total pins는 66이 나옵니다.&lt;/p&gt;

&lt;h2 id=&quot;4-글-마무리&quot;&gt;4. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;5-참고-자료&quot;&gt;5. 참고 자료&lt;/h2&gt;
&lt;p&gt;1) David Money Harris, Sarah L. Harris. 2013. Digital Design and Computer Architecture. 2nd Edition. Elsevier Korea L.L.C.&lt;br /&gt;
2) @SEMICIRCUIT. 2025. “[Verilog] “=”(blocking)과 “&amp;lt;=”(non-blocking) 할당의 차이”, SEMICIRCUIT. (2025. 10. 18. 방문). &lt;a href=&quot;https://semicircuit.tistory.com/199&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://semicircuit.tistory.com/199&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 18 Oct 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/verilog-dff-register</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/verilog-dff-register</guid>
        
        
        <category>프로그래밍</category>
        
        <category>Verilog</category>
        
      </item>
    
      <item>
        <title>[WinFsp]Windows 파일 탐색기에 SFTP 네트워크 드라이브 연결</title>
        <description>&lt;p&gt;Windows의 파일 탐색기는 원래 SFTP 연결이 안 됩니다. 그래서 FileZilla를 쓰고 있었는데요, 파일을 편집할 때 업로드 버튼을 눌러야 하는 것이 불편하더라고요. 그냥 파일 탐색기에 네트워크 드라이브로 연결해서 USB 파일 수정하듯이 수정하는 것이 훨씬 편할 것 같았습니다. &lt;strong&gt;WinFsp&lt;/strong&gt;와 &lt;strong&gt;SSHFS-Win&lt;/strong&gt;를 설치하면 Windows의 파일 탐색기에서 SFTP 연결이 가능해집니다. WinFsp는 커널 프로그래밍 지식 없이도 Windows에서 유저 모드 파일 시스템을 만들 수 있게 해주는 오픈소스라고 합니다. SSHFS-Win은 WinFsp의 확장 같은 것으로써 SFTP 연결을 할 수 있게 해 줍니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-httpswinfspdev에서-설치-파일-내려받기&quot;&gt;1&lt;/a&gt;. &lt;a href=&quot;https://winfsp.dev&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://winfsp.dev&lt;/a&gt;에서 설치 파일 내려받기&lt;br /&gt;
&lt;a href=&quot;#2-winfsp-설치&quot;&gt;2&lt;/a&gt;. WinFsp 설치&lt;br /&gt;
&lt;a href=&quot;#3-sshfs-win-설치&quot;&gt;3&lt;/a&gt;. SSHFS-Win 설치&lt;br /&gt;
&lt;a href=&quot;#4-파일-탐색기에서-sftp-네트워크-드라이브-연결&quot;&gt;4&lt;/a&gt;. 파일 탐색기에서 SFTP 네트워크 드라이브 연결&lt;br /&gt;
&lt;a href=&quot;#5-네트워크-드라이브-이름-바꾸기&quot;&gt;5&lt;/a&gt;. 네트워크 드라이브 이름 바꾸기&lt;br /&gt;
&lt;a href=&quot;#6-글-마무리&quot;&gt;6&lt;/a&gt;. 글 마무리&lt;br /&gt;
&lt;a href=&quot;#7-참고-자료&quot;&gt;7&lt;/a&gt;. 참고 자료&lt;/p&gt;

&lt;h2 id=&quot;1-httpswinfspdev에서-설치-파일-내려받기&quot;&gt;1. &lt;a href=&quot;https://winfsp.dev&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://winfsp.dev&lt;/a&gt;에서 설치 파일 내려받기&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/0.png&quot; alt=&quot;Windows File System Proxy&quot; /&gt;&lt;br /&gt;
1.1. &lt;a href=&quot;https://winfsp.dev&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://winfsp.dev&lt;/a&gt;로 접속합니다.&lt;br /&gt;
1.2. &lt;strong&gt;Download&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/1.png&quot; alt=&quot;Download&quot; /&gt;&lt;br /&gt;
1.3. &lt;strong&gt;Download WinFsp Installer&lt;/strong&gt;를 클릭하여 WinFsp 설치 프로그램을 내려받습니다.&lt;br /&gt;
1.4. 요즘은 대부분 64-bit 컴퓨터를 쓰실 테니 &lt;strong&gt;SSHFS-Win (x64)&lt;/strong&gt;를 클릭하여 SSHFS-Win 설치 프로그램을 내려받습니다. 혹시 32-bit 컴퓨터를 쓰신다면 SSHFS-Win (x86)을 클릭하세요.&lt;/p&gt;

&lt;h2 id=&quot;2-winfsp-설치&quot;&gt;2. WinFsp 설치&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/2.png&quot; alt=&quot;Welcome to the WinFsp 2023 Setup Wizard&quot; /&gt;&lt;br /&gt;
2.1. WinFsp 설치 프로그램을 실행합니다.&lt;br /&gt;
2.2. &lt;strong&gt;Next&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/3.png&quot; alt=&quot;Custom Setup&quot; /&gt;&lt;br /&gt;
2.3. &lt;strong&gt;Next&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/4.png&quot; alt=&quot;Ready to install WinFsp 2023&quot; /&gt;&lt;br /&gt;
2.4. &lt;strong&gt;Install&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/5.png&quot; alt=&quot;Completed the WinFsp 2023 Setup Wizard&quot; /&gt;&lt;br /&gt;
2.5. &lt;strong&gt;Finish&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;h2 id=&quot;3-sshfs-win-설치&quot;&gt;3. SSHFS-Win 설치&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/6.png&quot; alt=&quot;Welcome to the SSHFS-Win 2021 (x64) Setup Wizard&quot; /&gt;&lt;br /&gt;
3.1. SSHFS-Win 설치 프로그램을 실행합니다.&lt;br /&gt;
3.2. &lt;strong&gt;Next&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/7.png&quot; alt=&quot;Custom Setup&quot; /&gt;&lt;br /&gt;
3.3. &lt;strong&gt;Next&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/8.png&quot; alt=&quot;Ready to install SSHFS-Win 2021 (x64)&quot; /&gt;&lt;br /&gt;
3.4. &lt;strong&gt;Install&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/9.png&quot; alt=&quot;Completed the SSHFS-Win 2021 (x64) Setup Wizard&quot; /&gt;&lt;br /&gt;
3.5. &lt;strong&gt;Finish&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;h2 id=&quot;4-파일-탐색기에서-sftp-네트워크-드라이브-연결&quot;&gt;4. 파일 탐색기에서 SFTP 네트워크 드라이브 연결&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/10.png&quot; alt=&quot;내 PC&quot; /&gt;&lt;br /&gt;
4.1. &lt;span style=&quot;color: #0000ff&quot;&gt;···&lt;/span&gt;를 클릭합니다.&lt;br /&gt;
4.2. &lt;span style=&quot;color: #ff0000&quot;&gt;네트워크 드라이브 연결&lt;/span&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/11.png&quot; alt=&quot;네트워크 드라이브 연결&quot; /&gt;&lt;br /&gt;
4.3. 원하는 드라이브 문자를 선택합니다.(보통 Z:를 많이 쓰지만 저는 이미 Z:가 SMB에 연결되어 있어서 X:를 선택했습니다.)&lt;br /&gt;
4.4. 폴더에 &lt;strong&gt;\\sshfs\&lt;/strong&gt;&lt;span style=&quot;color: #ff00ff&quot;&gt;SFTP계정명&lt;/span&gt;&lt;strong&gt;@&lt;/strong&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;IP또는DDNS주소&lt;/span&gt;&lt;span style=&quot;color: #32be6d&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #7000ff&quot;&gt;포트번호&lt;/span&gt;를 입력합니다.&lt;br /&gt;
주의1) DDNS 사용 시 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://&lt;/code&gt;를 붙이지 &lt;u&gt;않습니다&lt;/u&gt;(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://&lt;/code&gt;를 폴더 경로로 오해하기 때문).&lt;br /&gt;
주의2) &lt;span style=&quot;color: #7000ff&quot;&gt;포트번호&lt;/span&gt; 앞에 :가 아닌 &lt;span style=&quot;color: #32be6d&quot;&gt;!&lt;/span&gt;를 붙입니다.&lt;br /&gt;
4.5. &lt;strong&gt;마침&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/12.png&quot; alt=&quot;Windows 보안&quot; /&gt;&lt;br /&gt;
4.6. &lt;strong&gt;암호&lt;/strong&gt;를 입력하고 &lt;span style=&quot;color: #0000ff&quot;&gt;기억&lt;/span&gt;에 체크한 뒤 &lt;span style=&quot;color: #ff0000&quot;&gt;확인&lt;/span&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/13.png&quot; alt=&quot;X드라이브 추가됨&quot; /&gt;&lt;br /&gt;
4.7. 네트워크 드라이브가 추가되었습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/14.png&quot; alt=&quot;X드라이브 내부&quot; /&gt;&lt;br /&gt;
4.8. 이제 SFTP 서버의 파일을 로컬처럼 쉽게 추가/삭제/수정할 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;5-네트워크-드라이브-이름-바꾸기&quot;&gt;5. 네트워크 드라이브 이름 바꾸기&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/15.png&quot; alt=&quot;우클릭&quot; /&gt;&lt;br /&gt;
5.1. 네트워크 드라이브를 오른쪽 클릭하고 &lt;strong&gt;이름 바꾸기&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251011/16.png&quot; alt=&quot;이름 바꾸기&quot; /&gt;&lt;br /&gt;
5.2. 원하는 이름으로 설정합니다.&lt;/p&gt;

&lt;h2 id=&quot;6-글-마무리&quot;&gt;6. 글 마무리&lt;/h2&gt;
&lt;p&gt;제 글을 읽어 주셔서 감사합니다. 다음에 만나요!&lt;/p&gt;

&lt;h2 id=&quot;7-참고-자료&quot;&gt;7. 참고 자료&lt;/h2&gt;
&lt;p&gt;1) Ratatou2. 2024. “윈도우 탐색기에 SFTP 연결하기(feat. NAS 바로가기 설정)”, nok-z. (2025. 10. 09. 방문). &lt;a href=&quot;https://ratatou2.tistory.com/41&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://ratatou2.tistory.com/41&lt;/a&gt;&lt;br /&gt;
2) 제이스핀. 2022. “[Windows] 외부 ssh 서버 폴더 연결”, J.Spin. (2025. 10. 09. 방문). &lt;a href=&quot;https://nuggy875.tistory.com/160&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://nuggy875.tistory.com/160&lt;/a&gt;&lt;br /&gt;
3) xguru. 2021. “WinFsp - Windows File System Proxy”, GeekNews. (2025. 10. 09. 방문). &lt;a href=&quot;https://news.hada.io/topic?id=4871&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://news.hada.io/topic?id=4871&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 11 Oct 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/WinFsp-sshfs</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/WinFsp-sshfs</guid>
        
        
        <category>정보</category>
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>[DistroAV]OBS Studio에 NDI 소스 추가, NDI 송출 방법</title>
        <description>&lt;p&gt;영상 소스는 보통 HDMI로 전송한다고 생각하실 것입니다. 전문적으로 일하시는 분은 SDI를 쓰시기도 하겠죠. 그런데 혹시 &lt;strong&gt;IP 기반&lt;/strong&gt;으로도 영상을 전송할 수 있다는 것을 알고 계셨나요? 바로 &lt;strong&gt;NDI&lt;/strong&gt;라는 프로토콜을 사용하면 가능합니다. 오늘은 OBS Studio에 NDI 소스 추가하거나 반대로 NDI로 송출하는 방법을 알아보겠습니다.&lt;/p&gt;

&lt;p&gt;※ OBS Studio는 이미 설치되어 있다고 가정하겠습니다. OBS Studio가 아직 설치되어 있지 않다면 &lt;a href=&quot;https://obsproject.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://obsproject.com&lt;/a&gt;에서 설치하세요.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-distroav-설치&quot;&gt;1&lt;/a&gt;. DistroAV 설치&lt;br /&gt;
&lt;a href=&quot;#2-번외-ndi-camera-앱&quot;&gt;2&lt;/a&gt;. 번외) NDI Camera 앱&lt;br /&gt;
&lt;a href=&quot;#3-네트워크-구성&quot;&gt;3&lt;/a&gt;. 네트워크 구성&lt;br /&gt;
&lt;a href=&quot;#4-obs-studio에-ndi-소스-추가&quot;&gt;4&lt;/a&gt;. OBS Studio에 NDI 소스 추가&lt;br /&gt;
&lt;a href=&quot;#5-obs-studio-화면을-ndi로-송출&quot;&gt;5&lt;/a&gt;. OBS Studio 화면을 NDI로 송출&lt;/p&gt;

&lt;h2 id=&quot;1-distroav-설치&quot;&gt;1. DistroAV 설치&lt;/h2&gt;
&lt;p&gt;GitHub에는 DistroAV repository(&lt;a href=&quot;https://github.com/DistroAV/DistroAV&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://github.com/DistroAV/DistroAV&lt;/a&gt;)가 있습니다. 다만 터미널에서 설치할 수 있으므로 GitHub로 들어가지 않고 그냥 아래 설명대로 설치하셔도 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/2.png&quot; alt=&quot;시작 우클릭&quot; /&gt;&lt;br /&gt;
1.1. 시작을 오른쪽 클릭(Windows+X)합니다.&lt;br /&gt;
1.2. &lt;strong&gt;터미널&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/3.png&quot; alt=&quot;터미널&quot; /&gt;&lt;br /&gt;
1.3. &lt;strong&gt;winget install --exact --id DistroAV.DistroAV&lt;/strong&gt; 명령을 실행합니다. 설치가 완전히 끝날 때까지 기다린 후, 설치가 완료되면 터미널을 닫습니다.&lt;/p&gt;

&lt;h2 id=&quot;2-번외-ndi-camera-앱&quot;&gt;2. 번외) NDI Camera 앱&lt;/h2&gt;
&lt;p&gt;이제 NDI 카메라를 켜면 되는데, 저는 카메라가 없어서 스마트폰 앱을 사용하겠습니다.&lt;br /&gt;
&lt;strong&gt;다른 카메라로 NDI 설정을 하신 분은 3번 문단으로 넘어가시기 바랍니다.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/a.jpg&quot; alt=&quot;NDI Camera 설치&quot; /&gt;&lt;br /&gt;
2.1. Google Play Store에서 NDI Camera를 설치합니다.&lt;br /&gt;
&lt;a href=&quot;https://play.google.com/store/apps/details?id=com.specialprojects.stream&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://play.google.com/store/apps/details?id=com.specialprojects.stream&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/b.jpg&quot; alt=&quot;NDI STREAM NAME&quot; /&gt;&lt;br /&gt;
2.2. &lt;strong&gt;▶&lt;/strong&gt;를 터치합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/c.jpg&quot; alt=&quot;사진을 촬영하고 동영상을 녹화하도록&quot; /&gt;&lt;br /&gt;
2.3. 허용합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/d.jpg&quot; alt=&quot;오디오를 녹음하도록&quot; /&gt;&lt;br /&gt;
2.4. 허용합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/e.jpg&quot; alt=&quot;카메라 화면&quot; /&gt;&lt;br /&gt;
2.5. 이제 카메라 화면이 나옵니다.&lt;/p&gt;

&lt;h2 id=&quot;3-네트워크-구성&quot;&gt;3. 네트워크 구성&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/network.png&quot; alt=&quot;네트워크 예시&quot; /&gt;&lt;br /&gt;
NDI 송출하는 소스 카메라(2번 문단의 예시는 스마트폰)와 그 소스를 받아들일 PC(OBS Studio)는 같은 네트워크에 있어야 합니다. 쉽게 말하면 같은 공유기에 연결되어 있어야 한다는 뜻입니다.&lt;/p&gt;

&lt;h2 id=&quot;4-obs-studio에-ndi-소스-추가&quot;&gt;4. OBS Studio에 NDI 소스 추가&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/4.png&quot; alt=&quot;OBS Studio&quot; /&gt;&lt;br /&gt;
4.1. OBS Studio를 실행합니다.&lt;br /&gt;
4.2. 소스 목록의 &lt;strong&gt;+&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/5.png&quot; alt=&quot;소스 추가 메뉴&quot; /&gt;&lt;br /&gt;
4.3. &lt;strong&gt;NDI® 소스&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/6.png&quot; alt=&quot;NDI® 소스 속성&quot; /&gt;&lt;br /&gt;
4.4. &lt;strong&gt;소스이름&lt;/strong&gt;에서 NDI 소스를 선택하고 원하는 대로 설정한 다음 &lt;strong&gt;확인&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/8.png&quot; alt=&quot;OBS Studio에 휴대전화 카메라 화면이 뜸&quot; /&gt;&lt;br /&gt;
4.5. 휴대전화로 촬영되는 장면이 OBS Studio에 추가된 것을 보실 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;5-obs-studio-화면을-ndi로-송출&quot;&gt;5. OBS Studio 화면을 NDI로 송출&lt;/h2&gt;
&lt;p&gt;4번 문단과 반대로 OBS Studio 화면을 NDI로 송출하여 다른 기기에서 볼 수도 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/9.png&quot; alt=&quot;OBS Studio 도구&quot; /&gt;&lt;br /&gt;
5.1. &lt;strong&gt;도구&lt;/strong&gt;→&lt;strong&gt;구성 마법사&lt;/strong&gt;로 들어갑니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20251004/10.png&quot; alt=&quot;DistroAV NDI® 설정&quot; /&gt;&lt;br /&gt;
5.2. 주 출력 또는 미리보기 출력을 원하는 대로 설정, 체크한 뒤 &lt;strong&gt;확인&lt;/strong&gt;을 클릭합니다.&lt;br /&gt;
5.3. 이제 다른 기기(또는 이 OBS Studio에서) NDI® 소스를 추가할 때 이 OBS PGM(또는 OBS Preview 또는 설정한 이름)을 보실 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;제-글을-읽어-주셔서-감사합니다&quot;&gt;제 글을 읽어 주셔서 감사합니다.&lt;/h2&gt;
&lt;p&gt;다음에 만나요!&lt;/p&gt;

&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxybookflex2&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 노트북은 갤럭시 북 Flex2입니다.(Windows 11)
    &lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;div class=&quot;phrase&quot;&gt;
    &lt;a href=&quot;/post/galaxys25plus&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
        필자(수성컴)의 휴대전화는 갤럭시 S25+입니다.
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 04 Oct 2025 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/DistroAV</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/DistroAV</guid>
        
        
        <category>정보</category>
        
        <category>Windows</category>
        
      </item>
    
  </channel>
</rss>