<?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>Thu, 02 Jul 2026 08:01:34 +0000</pubDate>
    <lastBuildDate>Thu, 02 Jul 2026 08:01:34 +0000</lastBuildDate>
    <generator>Jekyll v4.3.4</generator>
    
      <item>
        <title>Visual Studio Community 설치</title>
        <description>&lt;p&gt;Visual Studio는 Microsoft에서 배포하는 IDE(통합 개발 환경)입니다. C/C++로 Windows용 앱을 개발할 때 Visual Studio를 쓰면 편리합니다. 오늘은 개인 또는 5인 이하 단체용에 해당하는 &lt;strong&gt;Visual Studio Community&lt;/strong&gt;를 설치하고 C/C++ 프로젝트를 생성해 보겠습니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;&quot;&gt;1&lt;/a&gt;. Visual Studio와 Visual Studio Code 차이점&lt;br /&gt;
&lt;a href=&quot;&quot;&gt;2&lt;/a&gt;. Visual Studio Community 설치&lt;br /&gt;
&lt;a href=&quot;&quot;&gt;3&lt;/a&gt;. 언어 변경&lt;br /&gt;
&lt;a href=&quot;&quot;&gt;4&lt;/a&gt;. C/C++ 입문 시 프로젝트 생성&lt;/p&gt;

&lt;h2 id=&quot;1-visual-studio와-visual-studio-code-차이점&quot;&gt;1. Visual Studio와 Visual Studio Code 차이점&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/VS비교.png&quot; alt=&quot;Visual Studio vs. VS Code&quot; /&gt;&lt;br /&gt;
&lt;a href=&quot;/post/vscode-windows&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Visual Studio Code에 대해서는 지난 글에서 설명했습니다.&lt;/a&gt;&lt;br /&gt;
오늘은 Visual Studio Community를 알아보겠습니다.&lt;/p&gt;

&lt;h2 id=&quot;2-visual-studio-community-설치&quot;&gt;2. Visual Studio Community 설치&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/1.png&quot; alt=&quot;Microsoft Store Visual Studio Community&quot; /&gt;&lt;br /&gt;
2.1. Microsoft Store에서 Visual Studio Community를 내려받을 수 있습니다.&lt;br /&gt;
&lt;a href=&quot;https://apps.microsoft.com/detail/XPDCFJDKLZJLP8?hl=ko&amp;amp;gl=KR&amp;amp;ocid=pdpshare&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://apps.microsoft.com/detail/XPDCFJDKLZJLP8?hl=ko&amp;amp;gl=KR&amp;amp;ocid=pdpshare&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/2.png&quot; alt=&quot;Visual Studio Installer&quot; /&gt;&lt;br /&gt;
2.2. Visual Studio Installer 창이 뜨면 계속을 &lt;strong&gt;클릭&lt;/strong&gt;합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/3-1.png&quot; alt=&quot;워크로드&quot; /&gt;&lt;br /&gt;
2.3. &lt;strong&gt;워크로드&lt;/strong&gt; 탭이 먼저 뜰 텐데 사용할 언어를 체크합니다. 저는 C/C++ 개발을 할 것이므로 &lt;strong&gt;C++를 사용한 데스크톱 개발&lt;/strong&gt;을 체크하겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/3-2.png&quot; alt=&quot;언어 팩&quot; /&gt;&lt;br /&gt;
2.4. 저는 &lt;strong&gt;언어 탭&lt;/strong&gt;으로 이동해서 &lt;strong&gt;영어&lt;/strong&gt;를 추가 설치했습니다. 사실 독학할 때는 한국어로 공부하는 것이 훨씬 편하다고 생각하지만 제가 사용하는 전공 교재가 영어로 되어 있어서 영어를 설치한 것입니다.(원래 영어로 사용할 때의 장점은 오류 메시지를 그대로 복사해서 구글에 검색하면 해외 StackOverFlow의 도움을 받을 수 있다는 것이었지만, AI가 발전한 지금도 그 장점 때문에 영어로 Visual Studio를 써야 하는지는 잘 모르겠습니다.)&lt;br /&gt;
2.5. 이제 &lt;strong&gt;설치&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/5-ms.png&quot; alt=&quot;Visual Studio에 로그인&quot; /&gt;&lt;br /&gt;
2.6. 설치 후 Visual Studio를 실행하면 로그인 창이 뜹니다. 저는 Microsoft 계정으로 로그인했습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/6-나중에.png&quot; alt=&quot;GitHub Copilot Free&quot; /&gt;&lt;br /&gt;
2.7. 그러면 GitHub Copilot 등록 창이 뜨는데 저는 ‘나중에’를 클릭했습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/7-1.png&quot; alt=&quot;Get started&quot; /&gt;&lt;br /&gt;
2.8. 이제 Visual Studio를 사용하실 수 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;3-언어-변경&quot;&gt;3. 언어 변경&lt;/h2&gt;
&lt;p&gt;여러 언어를 설치한 경우 언어를 변경하려면 다음과 같이 합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/7-2.png&quot; alt=&quot;Get started&quot; /&gt;&lt;br /&gt;
3.1. 첫 화면에서 &lt;strong&gt;Continue without code&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/8.png&quot; alt=&quot;도구-옵션&quot; /&gt;&lt;br /&gt;
3.2. &lt;strong&gt;도구&lt;/strong&gt;→&lt;strong&gt;옵션&lt;/strong&gt;으로 들어갑니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/9.png&quot; alt=&quot;언어&quot; /&gt;&lt;br /&gt;
3.3. &lt;strong&gt;language&lt;/strong&gt;를 검색하고 언어를 원하는 것으로 설정합니다.&lt;/p&gt;

&lt;h2 id=&quot;4-cc-입문-시-프로젝트-생성&quot;&gt;4. C/C++ 입문 시 프로젝트 생성&lt;/h2&gt;
&lt;p&gt;Visual Studio로 C/C++ 기반 CUI 앱을 만드는 방법입니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/11.png&quot; alt=&quot;Get started&quot; /&gt;&lt;br /&gt;
4.1. 첫 화면에서 &lt;strong&gt;Create a new project(새 프로젝트 만들기)&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/12.png&quot; alt=&quot;Create a new project&quot; /&gt;&lt;br /&gt;
4.2. &lt;span style=&quot;color: #ff0000&quot;&gt;Windows Desktop Wizard&lt;/span&gt;를 선택하고 &lt;span style=&quot;color: #0000ff&quot;&gt;Next&lt;/span&gt;를 클릭합니다.&lt;br /&gt;
주의: Windows Desktop Application 아닙니다!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/13.png&quot; alt=&quot;Configure your new project&quot; /&gt;&lt;br /&gt;
4.3. &lt;strong&gt;Project name&lt;/strong&gt;과 &lt;strong&gt;Location&lt;/strong&gt;을 설정합니다. Solution name은 Project name을 입력하면 자동으로 반영됩니다.&lt;br /&gt;
원래 이런 것 설정할 때는 한글을 포함시키지 않고 영어로만 작성하는 것이 국룰이지만, Visual Studio는 한글도 잘 지원하니, 한글로 쓰셔도 상관없습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/14.png&quot; alt=&quot;Windows Desktop Project&quot; /&gt;&lt;br /&gt;
4.4. &lt;strong&gt;OK&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/15.png&quot; alt=&quot;HelloWorld.cpp&quot; /&gt;&lt;br /&gt;
4.5. 그러면 &lt;em&gt;프로젝트명&lt;/em&gt;.cpp 파일에 기본적인 코드가 나와 있는데, C++ 프로그래밍을 하실 것이라면 그냥 코드 작성하시면 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/16.png&quot; alt=&quot;rename&quot; /&gt;&lt;br /&gt;
4.6. C 프로그래밍을 하실 것이라면 Solution Explorer에서 Source Files 안에 있는 *.cpp를 *&lt;strong&gt;.c&lt;/strong&gt;로 바꿉니다.(파일 클릭 후 &lt;strong&gt;F2&lt;/strong&gt;. 또는 파일 오른쪽 클릭→&lt;strong&gt;Rename&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/17.png&quot; alt=&quot;C언어&quot; /&gt;&lt;br /&gt;
4.7. 이제 C언어로 코드를 작성하시면 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/18.png&quot; alt=&quot;빌드 터미널&quot; /&gt;&lt;br /&gt;
4.8. Ctrl+F5를 누르면 빌드가 진행되며, 터미널 창에 출력 결과가 나타납니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/19.png&quot; alt=&quot;화면상단&quot; /&gt;&lt;br /&gt;
4.9. 화면 상단에서 Debug/Release, architecture(x64/x86) 등을 설정할 수 있습니다.&lt;br /&gt;
참고) &lt;a href=&quot;https://sooseongcom.com/post/visual-studio-build-debug-release&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Visual Studio로 빌드 시 Debug와 Release의 차이점(https://sooseongcom.com/post/visual-studio-build-debug-release)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260626/빌드과정.png&quot; alt=&quot;빌드 과정&quot; /&gt;&lt;br /&gt;
Visual Studio는 GCC/G++와 달리 목적 코드의 확장명이 .obj입니다.(cf. GCC/G++는 .o)&lt;br /&gt;
목적 코드는 프로젝트폴더\프로젝트명\x64\Debug에서, 실행 파일(.exe)은 프로젝트폴더\x64\Debug에서 보실 수 있습니다.&lt;br /&gt;
(단, Release 모드로 빌드했다면 Release 폴더에서 보실 수 있습니다.)&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;
        필자(수성컴)의 노트북은 LG 그램 Pro AI 360입니다.
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Fri, 26 Jun 2026 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/vscommunity-windows</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/vscommunity-windows</guid>
        
        
        <category>정보</category>
        
        <category>Windows</category>
        
      </item>
    
      <item>
        <title>Visual Studio Code 설치 및 한국어 설정</title>
        <description>&lt;p&gt;코딩(특히 웹개발)을 하다 보면 코드 편집기가 필요할 때가 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/0-1.png&quot; alt=&quot;메모장으로 index.html&quot; /&gt;&lt;br /&gt;
프로그래밍 서적을 보면 간혹 메모장으로 작성하라고 안내하는 경우가 있는데, 메모장은 코딩하기에는 불편합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/0-2.png&quot; alt=&quot;VS Code로 index.html&quot; /&gt;&lt;br /&gt;
Visual Studio Code(VS Code)를 사용하면 IDE처럼 줄 번호도 띄워 주고 코딩 문법에 맞게 색깔도 표시됩니다. VS Code는 Microsoft에서 배포하는 &lt;strong&gt;오픈 소스&lt;/strong&gt;(소스 코드: MIT License) 소프트웨어이며, &lt;u&gt;사적 이용 및 &lt;strong&gt;상업적 이용이 무료&lt;/strong&gt;&lt;/u&gt;입니다. 확장 기능을 설치하여 프로그래밍 언어에 맞게 설정할 수도 있습니다. 오늘은 VS Code를 설치하고 한국어 설정까지 해 보겠습니다.&lt;/p&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#1-visual-studio-code-설치&quot;&gt;1&lt;/a&gt;. Visual Studio Code 설치&lt;br /&gt;
&lt;a href=&quot;#2-한국어-확장-설치-및-적용&quot;&gt;2&lt;/a&gt;. 한국어 확장 설치 및 적용&lt;br /&gt;
&lt;a href=&quot;#3-설정-동기화&quot;&gt;3&lt;/a&gt;. 설정 동기화&lt;br /&gt;
&lt;a href=&quot;#4-참고-vs-code에서-터미널-사용&quot;&gt;4&lt;/a&gt;. 참고) VS Code에서 터미널 사용&lt;/p&gt;

&lt;h2 id=&quot;1-visual-studio-code-설치&quot;&gt;1. Visual Studio Code 설치&lt;/h2&gt;
&lt;p&gt;Visual Studio Code를 Microsoft Store에서도 설치하면 자동 업데이트가 된다는 점이 좋을 수 있지만, 최초 설치할 때 탐색기 연결 설정 등을 못한다는 단점이 있습니다. 그래서 이 글에서는 EXE 파일로 설치(사이드로딩)하도록 하겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/1-1.png&quot; alt=&quot;Visual Studio Code 누리집&quot; /&gt;&lt;br /&gt;
1.1. &lt;a href=&quot;https://code.visualstudio.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://code.visualstudio.com&lt;/a&gt;로 접속합니다.&lt;br /&gt;
1.2. &lt;span style=&quot;color: #ff0000&quot;&gt;Download for Windows&lt;/span&gt;를 클릭하여 설치 파일을 바로 내려받거나 오른쪽 위 &lt;span style=&quot;color: #0000ff&quot;&gt;Download&lt;/span&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/1-2.png&quot; alt=&quot;Download 페이지&quot; /&gt;&lt;br /&gt;
1.3. &lt;span style=&quot;color: #0000ff&quot;&gt;Download&lt;/span&gt;를 클릭했다면 Download 페이지로 넘어옵니다. 본인 운영체제와 아키텍처에 맞는 버전을 선택하여 내려받습니다.(이 글은 Windows Installer 기준으로 진행됩니다.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/2.png&quot; alt=&quot;사용권 계약&quot; /&gt;&lt;br /&gt;
1.4. 내려받은 설치 파일을 실행하고 사용권 계약에 &lt;strong&gt;동의합니다&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/3.png&quot; alt=&quot;설치 위치 선택&quot; /&gt;&lt;br /&gt;
1.5. &lt;strong&gt;다음&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/4.png&quot; alt=&quot;시작 메뉴 폴더 선택&quot; /&gt;&lt;br /&gt;
1.6. &lt;strong&gt;다음&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/5.png&quot; alt=&quot;추가 작업 선택&quot; /&gt;&lt;br /&gt;
1.7. 이 부분에서 원하시는 대로 설정합니다. 위의 스크린샷은 제가 필요하다고 생각하는 것들을 체크한 것입니다.\&lt;/p&gt;
&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; checked=&quot;checked&quot; /&gt;“Code(으)로 열기” 작업을 Windows 탐색기 파일의 상황에 맞는 메뉴에 추가:&lt;br /&gt;
&lt;img src=&quot;/assets/images/20260523/11-2.png&quot; alt=&quot;파일의 상황에 맞는 메뉴&quot; /&gt;&lt;br /&gt;
파일 탐색기에서 파일을 오른쪽 클릭하면 “Code(으)로 열기” 메뉴가 나옵니다.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; checked=&quot;checked&quot; /&gt;“Code(으)로 열기” 작업을 Windows 탐색기 디렉터리의 상황에 맞는 메뉴에 추가:&lt;br /&gt;
&lt;img src=&quot;/assets/images/20260523/11-1.png&quot; alt=&quot;디렉터리의 상황에 맞는 메뉴&quot; /&gt;&lt;br /&gt;
파일 탐색기에서 오른쪽 클릭하면 “Code(으)로 열기” 메뉴가 나오며, 그 메뉴를 클릭하면 VS Code에서 해당 디렉터리가 열립니다.(강력추천)&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;Code을(를) 지원되는 파일 형식에 대한 편집기로 등록합니다.: “Code(으)로 열기” 작업을 Windows 탐색기 파일의 상황에 맞는 메뉴에 추가로 대체 가능하므로 체크하지 않았습니다.&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; checked=&quot;checked&quot; /&gt;PATH에 추가(다시 시작한 후 사용 가능): 터미널에서 &lt;strong&gt;code&lt;/strong&gt;를 실행하면 Visual Studio Code가 열립니다. &lt;strong&gt;code .&lt;/strong&gt;을 실행하면 터미널의 현재 작업 경로가 VS Code로 열리므로 유용합니다. 나중에 수동으로 추가하려면 번거로우니 VS Code 설치할 때 체크해 놓는 것이 좋습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/6.png&quot; alt=&quot;설치 준비 완료&quot; /&gt;&lt;br /&gt;
1.8. &lt;strong&gt;설치&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/7.png&quot; alt=&quot;Visual Studio Code 설치 마법사 완료&quot; /&gt;&lt;br /&gt;
1.9. 설치가 완료되었습니다.&lt;/p&gt;

&lt;h2 id=&quot;2-한국어-확장-설치-및-적용&quot;&gt;2. 한국어 확장 설치 및 적용&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/8.png&quot; alt=&quot;VS Code 영어&quot; /&gt;&lt;br /&gt;
VS Code를 처음 설치하면 영어로 나옵니다. 프로그래밍 툴은 영어로 쓰면 모르는 것이 있을 때 구글 검색하기 좋다는 장점이 있지만, VS Code는 어차피 컴파일을 별도 프로그램으로 하기도 하고 독학할 때는 익숙한 언어로 보면 이점이 있기 때문에 한국어 설정을 해 보겠습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/9.png&quot; alt=&quot;확장&quot; /&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;2.1. 확장 탭을 클릭합니다.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #ff0000&quot;&gt;2.2. &lt;strong&gt;Korean&lt;/strong&gt;을 검색하면 &lt;strong&gt;Korean Language Pack for Visual Studio Code&lt;/strong&gt;가 나올 것입니다.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #c080ff&quot;&gt;2.3. &lt;strong&gt;Korean Language Pack for Visual Studio Code&lt;/strong&gt;를 설치합니다.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/10.png&quot; alt=&quot;Would you&quot; /&gt;&lt;br /&gt;
2.4. 오른쪽 아래에 “Would you like to change Visual Studio Code’s display language to Korean and restart?”라는 창이 뜨면 &lt;strong&gt;Change Language and Restart&lt;/strong&gt;를 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/14.png&quot; alt=&quot;톱니바퀴 아이콘&quot; /&gt;&lt;br /&gt;
2.5. 혹시 그 창을 놓쳤거나 나중에 언어를 다시 변경하고 싶어진다면 &lt;strong&gt;Ctrl+Shift+P&lt;/strong&gt;를 누르고 &lt;strong&gt;Configure Display Language&lt;/strong&gt;를 검색하여 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/15.png&quot; alt=&quot;한국어 설정&quot; /&gt;&lt;br /&gt;
2.6. 언어를 선택합니다.&lt;/p&gt;

&lt;h2 id=&quot;3-설정-동기화&quot;&gt;3. 설정 동기화&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/12.png&quot; alt=&quot;계정 단추&quot; /&gt;&lt;br /&gt;
왼쪽 아래 &lt;span style=&quot;color: #ff0000&quot;&gt;계정 단추&lt;/span&gt;를 클릭하고 로그인하면 다른 PC의 VS Code에서도 동일한 확장과 설정이 적용되도록 &lt;span style=&quot;color: #ff0000&quot;&gt;설정 동기화&lt;/span&gt;를 켤 수 있습니다.&lt;br /&gt;
상단의 &lt;span style=&quot;color: #0000ff&quot;&gt;로그인&lt;/span&gt; 단추는 AI agent를 사용하기 위한 것입니다. 동기화를 위해 로그인하는 것과 별개입니다.&lt;/p&gt;

&lt;h2 id=&quot;4-참고-vs-code에서-터미널-사용&quot;&gt;4. 참고) VS Code에서 터미널 사용&lt;/h2&gt;
&lt;p&gt;참고로 Visual Studio Code 안에서 터미널을 사용할 수 있습니다. VS Code 내장 터미널을 사용하면 gcc, node.js, icarus verilog 등 터미널에서 사용하는 컴파일러를 사용할 때 편리합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/16.png&quot; alt=&quot;터미널-새터미널&quot; /&gt;&lt;br /&gt;
&lt;strong&gt;터미널&lt;/strong&gt;→&lt;strong&gt;새 터미널&lt;/strong&gt;을 클릭합니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/17.png&quot; alt=&quot;터미널 생김&quot; /&gt;&lt;br /&gt;
VS Code 창 하단에 터미널이 열립니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/18.png&quot; alt=&quot;터미널 창 추가&quot; /&gt;&lt;br /&gt;
터미널 창을 추가할 때 PC에 설치된 셸 중에서 원하는 것을 선택할 수 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/19.png&quot; alt=&quot;터미널 드래그&quot; /&gt;&lt;br /&gt;
터미널 창 이름을 텍스트 편집기 영역으로 드래그하면&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260523/20.png&quot; alt=&quot;터미널 커짐&quot; /&gt;&lt;br /&gt;
터미널을 더 넓게 사용할 수 있습니다. 터미널 출력 결과가 많을 때는 왼쪽에 코드 편집기를 띄우고, 오른쪽에 터미널을 띄우면 편리할 것입니다.&lt;/p&gt;

&lt;p&gt;그 외 터미널 설정 방법은 아래 글을 참고하시기 바랍니다.&lt;br /&gt;
&lt;a href=&quot;https://sooseongcom.com/post/vscode-terminal&quot; target=&quot;_blank&quot;&gt;VS Code 터미널 설정 방법(프로필, 실행 파일 등) - https://sooseongcom.com/post/vscode-terminal&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;오늘은-여기까지&quot;&gt;오늘은 여기까지!&lt;/h2&gt;
&lt;p&gt;이 블로그의 &lt;a href=&quot;https://sooseongcom.com/category/vscode/&quot;&gt;VS Code 카테고리&lt;/a&gt;로 들어가면 Visual Studio Code의 다양한 설정 방법을 보실 수 있습니다.&lt;br /&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;
        필자(수성컴)의 노트북은 LG 그램 Pro AI 360입니다.
    &lt;/a&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 23 May 2026 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/vscode-windows</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/vscode-windows</guid>
        
        
        <category>프로그래밍</category>
        
        <category>vscode</category>
        
      </item>
    
      <item>
        <title>수성컴의 LG 그램 Pro AI 360 사양(스펙)</title>
        <description>&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/1.png&quot; alt=&quot;LG gram Pro AI 360&quot; /&gt;&lt;br /&gt;
(저에게 맞게 설정한 후 사진을 찍었기 때문에 기본 바탕화면이 아닙니다.)&lt;/p&gt;

&lt;p&gt;전에 쓰던 갤럭시 북 Flex2가 고장나서 새 노트북을 구매했습니다. 요즘은 국산 노트북이 거의 다 16인치 이상이더라고요. 삼성 2in1 노트북을 16인치로 쓰면 무거울 것 같아서 &lt;strong&gt;LG 그램 Pro AI 360&lt;/strong&gt;를 구입했습니다. 요즘 노트북 값이 올라서 신제품 대신 2025년 제품을 구입했습니다. 제 노트북의 사양과 제가 선택한 옵션들을 알려드립니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;모델명: 16T90TP-GD7BK&lt;/li&gt;
  &lt;li&gt;크기: 357mm×254mm (디스플레이 40.6cm)&lt;/li&gt;
  &lt;li&gt;무게: 약 1399g&lt;/li&gt;
  &lt;li&gt;색상: 옵시디안 블랙&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;목차&quot;&gt;목차&lt;/h2&gt;
&lt;p&gt;* 모델명, 크기, 무게, 색상은 서론을 참고하시기 바랍니다.&lt;/p&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;/p&gt;

&lt;p&gt;&lt;a href=&quot;#2-운영체제-windows-11-home&quot;&gt;2&lt;/a&gt;. 운영체제: Windows 11 Home&lt;br /&gt;
&lt;a href=&quot;#3-프로세서-intel-core-ultra-7-프로세서-255h&quot;&gt;3&lt;/a&gt;. CPU: Intel® Core™ Ultra 7 프로세서 255H&lt;br /&gt;
&lt;a href=&quot;#4-메모리ram-32gb&quot;&gt;4&lt;/a&gt;. 메모리(RAM): 32GB&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;br /&gt;
&lt;a href=&quot;#8-입력-장치&quot;&gt;8&lt;/a&gt;. 입력 장치&lt;br /&gt;
&lt;a href=&quot;#9-파워-및-배터리&quot;&gt;9&lt;/a&gt;. 파워 및 배터리&lt;br /&gt;
&lt;a href=&quot;#10-네트워크&quot;&gt;10&lt;/a&gt;. 네트워크&lt;br /&gt;
&lt;a href=&quot;#11-보안-얼굴-인식&quot;&gt;11&lt;/a&gt;. 보안: 얼굴 인식&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#12-우측&quot;&gt;12&lt;/a&gt;. 제공 S/W&lt;br /&gt;
&lt;a href=&quot;#121-무료-sw&quot;&gt;12.1&lt;/a&gt;. 무료 S/W&lt;br /&gt;
&lt;a href=&quot;#122-체험판-sw&quot;&gt;12.2&lt;/a&gt;. 체험판 S/W&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;p&gt;&lt;img src=&quot;/assets/images/20260505/2.jpg&quot; alt=&quot;포트-좌측&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;HDMI&lt;/li&gt;
  &lt;li&gt;USB Type-C 포트 2개
    &lt;ul&gt;
      &lt;li&gt;USB4 Gen 3x2&lt;/li&gt;
      &lt;li&gt;USB PD&lt;/li&gt;
      &lt;li&gt;Thunderbolt 4&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;12-우측&quot;&gt;1.2. 우측&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/3.jpg&quot; alt=&quot;포트-우측&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;헤드폰 출력&lt;/li&gt;
  &lt;li&gt;USB 3.0 Type-A 포트 2개&lt;/li&gt;
  &lt;li&gt;우측 하단에 스타일러스 펜 부착(충전) 부위가 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-운영체제-windows-11-home&quot;&gt;2. 운영체제: Windows 11 Home&lt;/h2&gt;
&lt;p&gt;Windows 11 Home이 선탑재되어 있습니다.&lt;/p&gt;

&lt;h2 id=&quot;3-프로세서-intel-core-ultra-7-프로세서-255h&quot;&gt;3. 프로세서: Intel® Core™ Ultra 7 프로세서 255H&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;시리즈: Series 2&lt;/li&gt;
  &lt;li&gt;코드 이름: Products formerly Arrow Lake&lt;/li&gt;
  &lt;li&gt;전체 최대 TOPS(Int8): 96&lt;/li&gt;
  &lt;li&gt;CPU
    &lt;ul&gt;
      &lt;li&gt;코어: 총 16코어
        &lt;ul&gt;
          &lt;li&gt;Performance-core(P-코어): 6코어(기본 2GHz ~ 최대 터보 5.1GHz)&lt;/li&gt;
          &lt;li&gt;Efficient-core(E-코어): 8코어(기본 1.5GHz ~ 최대 터보 4.4GHz)&lt;/li&gt;
          &lt;li&gt;저전력 Efficient-cores(저전력 E-코어): 2코어(기본 1.5GHz ~ 최대 터보 2.5GHz)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;스레드: 16스레드&lt;/li&gt;
      &lt;li&gt;캐시 메모리: 24MB Intel® Smart Cache&lt;/li&gt;
      &lt;li&gt;Intel® 딥 러닝 부스트&lt;/li&gt;
      &lt;li&gt;CPU에서 지원하는 AI 소프트웨어 프레임워크: OpenVINO™, WindowsML, DirectML, ONNX RT, WebNN&lt;/li&gt;
      &lt;li&gt;CPU 리소그래피: TSMC N3B&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;GPU: Intel® Arc™ 140T GPU
    &lt;ul&gt;
      &lt;li&gt;GPU에서 지원하는 AI 소프트웨어 프레임워크: OpenVINO™, WindowsML, DirectML, ONNX RT, WebGPU&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;NPU: Intel® AI Boost (13TOPS)
    &lt;ul&gt;
      &lt;li&gt;NPU에서 지원하는 AI 소프트웨어 프레임워크: OpenVINO™, WindowsML, DirectML, ONNX RT, WebNN&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;4-메모리ram-32gb&quot;&gt;4. 메모리(RAM): 32GB&lt;/h2&gt;
&lt;p&gt;LPDDR5x 온보드 RAM이며, 32GB입니다.&lt;/p&gt;

&lt;h2 id=&quot;5-디스플레이-및-스타일러스-펜&quot;&gt;5. 디스플레이 및 스타일러스 펜&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;화면 크기: 40.6cm(≒16inch)&lt;/li&gt;
  &lt;li&gt;해상도: WQXGA(2560×1600)
    &lt;ul&gt;
      &lt;li&gt;16:10 화면비입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;패널 형태: IPS LCD 터치 디스플레이(Gorilla Glass / Anti-Reflective / ~144Hz VRR)
    &lt;ul&gt;
      &lt;li&gt;스타일러스 펜(충전식)을 지원&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/4-1.png&quot; alt=&quot;스타일러스 펜 충전&quot; /&gt;&lt;br /&gt;
LG 그램 Pro AI 360의 스타일러스 펜은 충전식입니다. 펜의 ‘gram’이라고 적힌 면이 노트북에 붙도록 부착하면 펜이 충전됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/4-2.png&quot; alt=&quot;스타일러스 펜 충전 표시&quot; /&gt;&lt;br /&gt;
제대로 붙으면 화면에 충전 중이라는 표시가 뜹니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/5.jpg&quot; alt=&quot;스타일러스 펜&quot; /&gt;&lt;br /&gt;
펜의 ‘gram’이라고 적힌 면의 펜촉 쪽(스티커에 표시된 부분)을 2번 두드린 채 유지하면 오른쪽 클릭이 됩니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/6-1.png&quot; alt=&quot;My gram 키보드 및 펜&quot; /&gt;&lt;br /&gt;
노트북에 선탑재된 &lt;strong&gt;My gram&lt;/strong&gt;이라는 앱을 실행하셔서 &lt;strong&gt;PC 관리&lt;/strong&gt;→&lt;strong&gt;키보드 및 펜&lt;/strong&gt;으로 들어간 뒤 스크롤을 내리면&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/6-2.png&quot; alt=&quot;My gram 펜 설정&quot; /&gt;&lt;br /&gt;
펜 설정을 하실 수 있습니다. 원래 기본 펜촉 감도(최대 필압 도달 수준)는 3인데 저는 2로 줄였습니다.&lt;br /&gt;
2번 두드린 채 유지할 때의 동작도 오른쪽 클릭 말고 다른 것으로 바꿀 수 있는데, 저는 이 기능이 불편에서 그냥 ‘사용 안 함’으로 설정했습니다.&lt;/p&gt;

&lt;p&gt;펜의 위쪽(펜촉의 반대 방향) 단추를 누르면 지우개 모드가 됩니다. MPP 2.0을 지원하여 Microsoft 365, Drawboard PDF 등의 앱에서 지우개 버튼을 사용할 수 있습니다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/20260505/7.png&quot; alt=&quot;팜리젝션&quot; /&gt;&lt;br /&gt;
설정(Windows+I)→&lt;strong&gt;Bluetooth 및 장치&lt;/strong&gt;→&lt;strong&gt;펜 및 Windows Ink&lt;/strong&gt;로 들어가셔서 &lt;span style=&quot;color: #0000ff&quot;&gt;왼손/오른손&lt;/span&gt; 선택하고 &lt;strong&gt;추가 펜 설정&lt;/strong&gt; 메뉴를 펼쳐서 &lt;span style=&quot;color: #ff0000&quot;&gt;펜을 사용하는 동안 터치 입력 무시&lt;/span&gt;를 체크해 주시면 펜이 화면 가까이 있을 때(펜 커서 활성화 상태) 손터치는 인식하지 않고 펜터치만 인식합니다(=팜리젝션).&lt;/p&gt;

&lt;p&gt;필기감은 갤럭시보다 좀 떨어지는 것 같습니다. 초점이 미세하게 벗어난 것 같은데, 제가 공장보다 터치 보정을 잘할 자신이 없어서 그냥 그러려니 하고 쓰는 중입니다.&lt;/p&gt;

&lt;h2 id=&quot;6-멀티미디어&quot;&gt;6. 멀티미디어&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;오디오&amp;amp;사운드: Dolby Atmos, Stereo speakers, Smart Amp (Max 3.0W x2)&lt;/li&gt;
  &lt;li&gt;웹캠: FHD IR 웹캠 (듀얼 마이크)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;7-저장-장치&quot;&gt;7. 저장 장치&lt;/h2&gt;
&lt;p&gt;1TB NVMe SSD가 탑재되어 있으며, 확장 슬롯이 1개 더 있습니다.(PCIe 4.0×4)&lt;/p&gt;

&lt;h2 id=&quot;8-입력-장치&quot;&gt;8. 입력 장치&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;키보드: 백라이트 키보드 풀 사이즈 97키 (3열 숫자 전용키 포함)&lt;/li&gt;
  &lt;li&gt;터치패드&lt;/li&gt;
  &lt;li&gt;터치스크린 및 스타일러스 펜&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;스타일러스 펜에 대한 설명은 &lt;a href=&quot;#5-디스플레이-및-스타일러스-펜&quot;&gt;5번 ‘디스플레이 및 스타일러스 펜’ 항목&lt;/a&gt;을 참고하세요.&lt;/p&gt;

&lt;h2 id=&quot;9-파워-및-배터리&quot;&gt;9. 파워 및 배터리&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;파워: 65W&lt;/li&gt;
  &lt;li&gt;배터리: 77Wh 리튬 이온 배터리&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;10-네트워크&quot;&gt;10. 네트워크&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;무선랜: Intel® Wi-Fi7 BE201 (Wi-Fi 7, 2x2, BT Combo)&lt;/li&gt;
  &lt;li&gt;Bluetooth 5.4&lt;/li&gt;
  &lt;li&gt;유선랜: Gigabit(랜젠더 별매. 저는 Thunderbolt dock이 있어서 그걸로 사용하고 있습니다.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;11-보안-얼굴-인식&quot;&gt;11. 보안: 얼굴 인식&lt;/h2&gt;
&lt;p&gt;Windows Hello와 호환되는 얼굴 인식을 지원합니다.&lt;/p&gt;

&lt;h2 id=&quot;12-제공-sw&quot;&gt;12. 제공 S/W&lt;/h2&gt;
&lt;h3 id=&quot;121-무료-sw&quot;&gt;12.1. 무료 S/W&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;My gram: LG 그램에 대한 설정을 할 수 있는 앱입니다. 배터리 충전 설정, 스타일러스 펜 설정 등이 여기 있습니다.&lt;/li&gt;
  &lt;li&gt;LG Update &amp;amp; Renew&lt;/li&gt;
  &lt;li&gt;LG Easy Guide&lt;/li&gt;
  &lt;li&gt;LG On Screen Display&lt;/li&gt;
  &lt;li&gt;LG Glance by Mirametrix&lt;/li&gt;
  &lt;li&gt;LG gram Link&lt;/li&gt;
  &lt;li&gt;gram chat On-Device&lt;/li&gt;
  &lt;li&gt;Dolby Atmos&lt;/li&gt;
  &lt;li&gt;Google Quick Share&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;122-체험판-sw&quot;&gt;12.2. 체험판 S/W&lt;/h3&gt;
&lt;p&gt;사실 체험판 S/W를 공식 홈페이지에 있는 스펙에서 마치 자기들이 제공하는 S/W처럼 써 놓은 것이 어이없긴 하네요.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Good Notes(90 Days Trial)&lt;/li&gt;
  &lt;li&gt;Microsoft 365(30 Days Trial)&lt;/li&gt;
  &lt;li&gt;McAfee Live Safe(30 Days Trial): &lt;u&gt;백신(안티바이러스) 프로그램&lt;/u&gt;. McAfee를 유료 결제할 것이 아니라면 제거하고 다른 백신 프로그램(&lt;strong&gt;Windows Defender를 추천&lt;/strong&gt;합니다.)을 켜야 합니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;제-글을-읽어-주셔서-감사합니다&quot;&gt;제 글을 읽어 주셔서 감사합니다.&lt;/h2&gt;
&lt;p&gt;다음에 만나요!&lt;/p&gt;
</description>
        <pubDate>Tue, 05 May 2026 00:00:00 +0000</pubDate>
        <link>https://sooseongcom.com/post/lg-gram-pro-ai-360</link>
        <guid isPermaLink="true">https://sooseongcom.com/post/lg-gram-pro-ai-360</guid>
        
        
        <category>정보</category>
        
        <category>Windows</category>
        
      </item>
    
      <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>
    
  </channel>
</rss>