<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ando</title>
    <description>The latest articles on DEV Community by Ando (@ikaroshunt).</description>
    <link>https://dev.to/ikaroshunt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4157951%2F1292dec2-31ff-4cfd-9cdd-491022bc2553.jpg</url>
      <title>DEV Community: Ando</title>
      <link>https://dev.to/ikaroshunt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ikaroshunt"/>
    <language>en</language>
    <item>
      <title>Automating My Stock Portfolio with Python</title>
      <dc:creator>Ando</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:25:48 +0000</pubDate>
      <link>https://dev.to/ikaroshunt/from-manual-copy-paste-to-one-command-automating-my-stock-portfolio-with-python-3nao</link>
      <guid>https://dev.to/ikaroshunt/from-manual-copy-paste-to-one-command-automating-my-stock-portfolio-with-python-3nao</guid>
      <description>&lt;p&gt;I used to update my portfolio the painful way. Open Yahoo Finance. Search BBCA.JK. Copy the price. Paste it into Excel. Repeat for BMRI, ASII, TLKM, ICBP, ANTM, BBRI, Gold, Bitcoin, and my money market fund. 10 assets. 10 tabs. Every single day. One typo and my whole ROI was wrong. One lazy day and my portfolio was already&lt;br&gt;
outdated. So I built something better: a self-updating portfolio tracker that pulls live prices with one command.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ikaroshunt" rel="noopener noreferrer"&gt;
        ikaroshunt
      &lt;/a&gt; / &lt;a href="https://github.com/ikaroshunt/analisis_portfolio" rel="noopener noreferrer"&gt;
        analisis_portfolio
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Analisa Portfolio — Auto-Update dengan yfinance&lt;/h1&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Update 10 aset portfolio dalam 1 perintah. Tanpa copy-paste manual lagi.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="https://img.shields.io/badge/Python-3.15-blue" rel="nofollow noopener noreferrer"&gt;Python&lt;/a&gt;
&lt;a href="https://img.shields.io/badge/yfinance-live-green" rel="nofollow noopener noreferrer"&gt;yfinance&lt;/a&gt;
&lt;a href="https://img.shields.io/badge/Excel-auto--update-brightgreen" rel="nofollow noopener noreferrer"&gt;Excel&lt;/a&gt;
&lt;a href="https://img.shields.io/badge/Status-VALIDATED-success" rel="nofollow noopener noreferrer"&gt;Status&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Artikel lengkap (English) ada di Dev.to &amp;amp; Codecademy Forum.&lt;/strong&gt;
&lt;strong&gt;README ini Bahasa Indonesia, biar yang buka repo ikut pusing dikit. 😅&lt;/strong&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Kenapa Repo Ini Ada?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Dulu, cara gue update portfolio tuh nyiksa:&lt;/p&gt;
&lt;p&gt;Buka Yahoo Finance → Cari BBCA.JK → Copy harga → Paste ke Excel → Ulangi buat BMRI, ASII, TLKM, ICBP, ANTM, BBRI, Emas, BTC, RDPU.&lt;/p&gt;
&lt;p&gt;10 aset. 10 tab. Tiap hari.&lt;/p&gt;
&lt;p&gt;Sekali typo, ROI langsung salah. Sekali males, portfolio langsung basi.&lt;/p&gt;
&lt;p&gt;Akhirnya gue bikin sistem ini: &lt;strong&gt;Excel buat analisa, Python buat narik harga.&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;python update.py&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Udah. Beres.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Isi Repo&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;analisis portfolio/
├── portfolio.xlsx   # Template Excel: Dashboard, Holdings, Alokasi, Performa, Harga_Historis
├── update.py        # Script Python: yfinance -&amp;gt; Excel (JANGAN DIUBAH, SUDAH VALID)
├── README.md        # File ini (Bahasa Indonesia)
└── portfolio_UPDATE.xlsx  # Hasil setelah run (auto-generate)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;…&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ikaroshunt/analisis_portfolio" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpccensp4va66jlylgspc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpccensp4va66jlylgspc.png" alt=" " width="466" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it. 9 tickers updated. Currency converted. History filled. Backup created. Here is how I did it, what broke along the way, and the exact validation output that proved it works.&lt;/p&gt;

&lt;p&gt;The Problem&lt;/p&gt;

&lt;p&gt;My portfolio is mixed, and that's what made it painful:&lt;br&gt;
Indonesian stocks: BBCA, BMRI, ASII, TLKM, ICBP, ANTM, BBRI — priced in IDR&lt;/p&gt;

&lt;p&gt;Gold: Antam gold — priced in USD per troy ounce on Yahoo&lt;/p&gt;

&lt;p&gt;No single app handled all of them well. Excel could handle the math, but not the live prices. Python could fetch live prices, but I didn't want to live in a Jupyter notebook. &lt;br&gt;
I wanted the best of both: Excel for analysis, Python for fetching.&lt;/p&gt;

&lt;p&gt;The Architecture&lt;br&gt;
Two files. Same folder. Nothing else.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65zmmgevxb1bwi6p85ph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65zmmgevxb1bwi6p85ph.png" alt=" " width="800" height="103"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;portfolio.xlsx — The Brain
The Excel file is not just a table. It does the analysis:
python update.py
Dashboard: Total value, total gain/loss, ROI, CAGR, Volatility, Sharpe Ratio, Top 5
holdings
Holdings: The single source of truth. Each row has a Ticker Yahoo column
Alokasi: Actual vs target allocation + rebalance calculator
Performa: Monthly return tracking + risk metrics
Harga_Historis: Daily history per ticker, used for volatility and drawdown
Config: USD/IDR rate, risk-free rate, gold premium
The key design decision: Column C in Holdings is Ticker Yahoo .&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffsz1q0odnbh47ht3xg7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffsz1q0odnbh47ht3xg7w.png" alt=" " width="799" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;update.py — The Muscle
The Python script does 4 things:&lt;/li&gt;
&lt;li&gt;Fetches USD/IDR from USDIDR=X&lt;/li&gt;
&lt;li&gt;Fetches the latest price for each ticker&lt;/li&gt;
&lt;li&gt;Converts everything to IDR&lt;/li&gt;
&lt;li&gt;Writes it back to Excel + fills history + creates a backup
The core conversion logic is where most people get stuck:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fugugtooak4jle7b86hd7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fugugtooak4jle7b86hd7.png" alt=" " width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gold is the tricky one. Yahoo gives you $3,863.70 per troy ounce . My portfolio&lt;br&gt;
is in grams, in IDR, with Antam's premium. So: price * USDIDR / 31.1035 * premium .&lt;/p&gt;

&lt;p&gt;And it has safety features I learned to add:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3njcdogq7z9uo93vbm7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3njcdogq7z9uo93vbm7r.png" alt=" " width="797" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every real run also creates an automatic backup:&lt;br&gt;
portfolio_BACKUP_20261116_1633.xlsx . I never lose my old data.&lt;/p&gt;

&lt;p&gt;What Broke (And What I Learned)&lt;br&gt;
This was not smooth. Three bugs ate my afternoon:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;File Not Found — But The File Was There
I ran:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx312z8unmyzs6jpecdzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx312z8unmyzs6jpecdzs.png" alt=" " width="772" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Error: No such file or directory .&lt;/p&gt;

&lt;p&gt;The real file was Update-Portofolio-Yfinance-FIX.py — with dashes - , not&lt;br&gt;
underscores _ . My browser had converted _ to - on download. Windows treats&lt;br&gt;
them as different characters.&lt;br&gt;
Fix: I renamed everything to simple names with no confusion: update.py and&lt;br&gt;
portfolio.xlsx .&lt;br&gt;
Lesson: If your filename has both _ and - , you will typo it. Keep it simple.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;VS Code's Run Button Added Double Quotes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When I clicked Run in VS Code, it executed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxvaatq0mzuu0acoxw14q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxvaatq0mzuu0acoxw14q.png" alt=" " width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the '"...\"' — double quotes inside double quotes. Python threw Errno&lt;br&gt;
22 Invalid argument .&lt;br&gt;
Fix: Don't use the Run button. Type it manually in the terminal. Or use Tab&lt;br&gt;
completion: type python Up + Tab and let PowerShell complete the name.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Virtual Environment Gotcha
My prompt showed (.venv-1) , meaning I was in a venv. I had installed yfinance globally, but the venv couldn't see it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fix:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fova6e2ruh6daqv9sjnps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fova6e2ruh6daqv9sjnps.png" alt=" " width="662" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...while the venv is active.&lt;/p&gt;

&lt;p&gt;How To Use It&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz8lpqvh1r5jl5nx6xqj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz8lpqvh1r5jl5nx6xqj.png" alt=" " width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open portfolio_UPDATE.xlsx . Dashboard, Holdings, and History are all updated.&lt;br&gt;
To add a new stock, just add a row in Holdings:&lt;/p&gt;

&lt;p&gt;Kode: GOTO&lt;br&gt;
Ticker Yahoo: GOTO.JK&lt;/p&gt;

&lt;p&gt;Run again. Done.&lt;br&gt;
What's Next&lt;br&gt;
This version is manual — I run it when I want. The next version I'm thinking about:&lt;br&gt;
Schedule it with Task Scheduler / cron every Monday 08:00&lt;br&gt;
Send a Telegram summary: "Portfolio today: +1.2%, Top mover ASII +3.64%"&lt;br&gt;
Add dividend tracking from yfinance&lt;br&gt;
But even as-is, it already saved me hours. No more copy-paste. No more stale&lt;br&gt;
prices.&lt;/p&gt;

&lt;p&gt;Final Thought&lt;br&gt;
The most valuable part is not the Excel formulas. It's the validation log.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install once pip install yfinance openpyxl pandas&lt;/li&gt;
&lt;li&gt;Put both files in the same folder portfolio.xlsx and update.py&lt;/li&gt;
&lt;li&gt;Run python update.py&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Anyone can claim their portfolio is up to date. I can prove it in 10 seconds with one&lt;br&gt;
command and one log that shows every ticker, every price, every conversion, and&lt;br&gt;
every change.&lt;/p&gt;

&lt;p&gt;That's why I built it. And that's why I'm sharing it.&lt;/p&gt;

&lt;p&gt;Disclaimer: This is not financial advice. This is a personal automation tool for tracking,&lt;br&gt;
not for recommending buys/sells. Always do your own research.&lt;br&gt;
Built on Windows 10, Python 3.15, yfinance, openpyxl, and a lot of patience with&lt;br&gt;
dashes vs underscores.&lt;/p&gt;

</description>
      <category>python</category>
      <category>yfinance</category>
      <category>finance</category>
    </item>
    <item>
      <title>Pipeline panic game</title>
      <dc:creator>Ando</dc:creator>
      <pubDate>Sat, 03 Oct 2026 11:03:03 +0000</pubDate>
      <link>https://dev.to/ikaroshunt/a-5th-stage-game-1bjl</link>
      <guid>https://dev.to/ikaroshunt/a-5th-stage-game-1bjl</guid>
      <description>&lt;p&gt;I Built a 5-Stage Pipeline Game in Python — And Finally Lost to My Own Branch Predictor&lt;/p&gt;

&lt;p&gt;When I started CS101: Introduction to Programming on Codecademy, the portfolio project sounded simple: "Build a basic terminal game."&lt;br&gt;
Everyone was making Blackjack and Tic-Tac-Toe. I wanted something that actually teaches how computers really think. So I remembered my previous project - building a CPU from scratch - and thought: what if I turn the CPU's biggest enemy into a game?&lt;/p&gt;

&lt;p&gt;Introducing PIPELINE PANIC - CPU Hazard Defender. You're a Pipeline Engineer and your job is to keep a 5-stage pipeline alive while hazards try to kill it.&lt;/p&gt;

&lt;p&gt;The Result (Proof it Works)&lt;br&gt;
Here's my game running a real program with RAW hazards and branch&lt;br&gt;
mispredictions: ![&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fusmo0gj35bd0opj8mirs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fusmo0gj35bd0opj8mirs.jpg" alt=" " width="800" height="533"&gt;&lt;/a&gt; - Pipeline Panic running Cycle 5 with forwarding and stall detection]&lt;/p&gt;

&lt;p&gt;This is actual terminal output from python main.py (Menu 2 - PLAY): It loads instructions from program.asm or from interactive input: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It runs a full IF → ID → EX → MEM → WB simulation&lt;/li&gt;
&lt;li&gt;It shows Stalls, Flushes, Forwarding in real-time&lt;/li&gt;
&lt;li&gt;It tracks Branch Predictor Accuracy live - in this run, 75.0%!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ytrwdg04se7up6qzrsv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ytrwdg04se7up6qzrsv.png" alt=" " width="797" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, I tied with a 2-bit saturating counter. That's humbling.&lt;/p&gt;

&lt;p&gt;How My Python Code Works&lt;br&gt;
I split the game into 5 core OOP modules to meet the Codecademy requirement for clean architecture - just like real hardware:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AssemblyParser (The File Parser)
A 3-pass parser pipeline - yes, a pipeline inside a pipeline simulator:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Pass 1: Collect all labels ( LOOP: , TARGET: )&lt;/li&gt;
&lt;li&gt;Pass 2: Tokenize with strict Regex for R-type ( ADD R1,R2,R3 ), I-type ( LW R5,R2,100 ), B-type ( BEQ ), J-type&lt;/li&gt;
&lt;li&gt;Pass 3: Resolve label → instruction index, with nice error reporting:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhknim2mxesxcr5afchdy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhknim2mxesxcr5afchdy.png" alt=" " width="800" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It supports # comments , empty lines, and both file and text input.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HazardDetectionUnit + ForwardingUnit (The Brains)
This is the part that makes decisions by itself - the "otak" I wanted:
Two Big-O implementations for education:
detect_naive() - O(n²) - checks every pair in the 3-instruction window
detect_optimized() - O(n) - uses a last_write hashmap
Benchmark in Menu 1 shows O(n) is ~40% faster even for 7 instructions. Imagine for
1000.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fse1099vg3en506d9cl3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fse1099vg3en506d9cl3c.png" alt=" " width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ForwardingUnit automatically decides if it can forward EX→EX or MEM→EX or must insert a bubble.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;BranchPredictor (The One That Beat Me)&lt;br&gt;
This is the "nebak cabang" brain. It implements 3 strategies:&lt;br&gt;
always_taken&lt;br&gt;
always_not_taken&lt;br&gt;
2-bit - 4-state FSM: Strong NT (00) → Weak NT (01) → Weak T (10) → Strong T (11)&lt;br&gt;
It learns from history and tracks its own accuracy. In Battle Mode, you play against it.&lt;br&gt;
Spoiler: it's good.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CPUPipeline (The 5-Stage Pipeline)&lt;br&gt;
Classic RISC pipeline:&lt;br&gt;
1 IF (Fetch) → ID (Decode) → EX (Execute) → MEM → WB&lt;br&gt;
Each step() moves pipeline registers. It handles stalls and flushes:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49tv4n2tkpafidk6mdit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49tv4n2tkpafidk6mdit.png" alt=" " width="766" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GameEngine (The Terminal Game)
Meets Codecademy's input() requirement with 5 modes:&lt;/li&gt;
&lt;li&gt;LEARN - Big-O demo + hazard visualization&lt;/li&gt;
&lt;li&gt;PLAY - Live pipeline visualization&lt;/li&gt;
&lt;li&gt;CHALLENGE - Compiler optimization puzzle: reorder instructions to minimize
stalls (my favorite - you have ADD R1,R2,R3 / SUB R4,R1,R5 / ADD R6,R7,R8
and you must move the independent one up!)&lt;/li&gt;
&lt;li&gt;BATTLE - You vs 2-bit predictor&lt;/li&gt;
&lt;li&gt;PARSER - Load your own .asm file&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check Out The Code&lt;br&gt;
All the code is open source and ready to run. I fixed the Git case from last time, but&lt;br&gt;
this time I fought with program.asm not being found - classic Windows PowerShell&lt;br&gt;
moment!&lt;br&gt;
GitHub: &lt;a href="https://github.com/ikaroshunt/pipeline_panic.git" rel="noopener noreferrer"&gt;https://github.com/ikaroshunt/pipeline_panic.git&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;To run it yourself:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftp3z8ms6amiw4x5q63h4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftp3z8ms6amiw4x5q63h4.png" alt=" " width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Files:&lt;br&gt;
main.py - All-in-one game (OOP, Pipeline, Brains, Parser)&lt;br&gt;
program.asm - Sample program with intentional hazards&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
My first CPU simulator taught me why cache exists. This one taught me why pipelines are hard. I finally understand:&lt;br&gt;
Why a simple ADD can stall the whole CPU (RAW hazard)&lt;br&gt;
Why branch prediction is 30% of CPU performance&lt;br&gt;
Why O(n) vs O(n²) matters when you check hazards for thousands of&lt;br&gt;
instructions&lt;br&gt;
Why forwarding is cheaper than stalling&lt;/p&gt;

&lt;p&gt;It was frustrating at first - ParseError: Undefined label LOOP (yes, I forgot to&lt;br&gt;
define my own label!), fatal: pathspec did not match , and tying with my own&lt;br&gt;
AI. But each error was a lesson.&lt;br&gt;
If you're taking CS101, don't just make Blackjack. Make something that makes you&lt;br&gt;
lose to your own code. There's no better feeling than seeing === Cycle 10 ===&lt;br&gt;
Stalls=2 and knowing you built that logic.&lt;br&gt;
This project was built as part of Codecademy's Computer Science Career Path&lt;br&gt;
(CS101: Python Terminal Game Portfolio Project) - Level 2 of my CPU series.&lt;/p&gt;

&lt;p&gt;Tools: Python 3, Git, VS Code, PowerShell, OOP, Big-O Analysis, 2-bit Branch&lt;br&gt;
Prediction&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzagoiztq8e3guj06j3nu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzagoiztq8e3guj06j3nu.jpg" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F470pnjgictsfjllhrbad.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F470pnjgictsfjllhrbad.jpg" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>gamedev</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Why I Built This</title>
      <dc:creator>Ando</dc:creator>
      <pubDate>Fri, 02 Oct 2026 16:00:15 +0000</pubDate>
      <link>https://dev.to/ikaroshunt/why-i-built-this-68p</link>
      <guid>https://dev.to/ikaroshunt/why-i-built-this-68p</guid>
      <description>&lt;p&gt;I Built a CPU From Scratch in Python — And Finally Understood How Computers Think&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ikaroshunt/cpu_simulator.git" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I started CS104: Computer Architecture on Codecademy, I realized I had been using computers for years without actually understanding what happens inside. We type &lt;code&gt;print("hello")&lt;/code&gt; and it works — but how?&lt;/p&gt;

&lt;p&gt;The portfolio project challenge was: &lt;em&gt;"Research, design, and build a Python program that simulates the functionalities of a CPU."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So I decided to stop being a user and start being a builder. Instead of just reading about registers and memory buses, I built them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Result (Proof it Works)
&lt;/h2&gt;

&lt;p&gt;Here's my CPU simulator running a real program that adds two numbers, stores them to memory, and tests branching:&lt;/p&gt;

&lt;p&gt;![My CPU simulator running in terminal - showing Fetch Decode Execute cycles]&lt;/p&gt;

&lt;p&gt;This is my actual terminal output after fixing the import errors (you can see the full journey in my GitHub commits!):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It loads instructions from &lt;code&gt;instruction_input.txt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It loads initial memory values from &lt;code&gt;data_input.txt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It runs 11 cycles of FETCH → DECODE → EXECUTE → WRITEBACK&lt;/li&gt;
&lt;li&gt;It even tracks Cache Hits/Misses — in this run, 100% hit rate!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here's the architecture I designed:&lt;/p&gt;

&lt;p&gt;![CPU Architecture Diagram]&lt;br&gt;
&lt;em&gt;(Diagram: Instruction and Data flow from input files through CPU → Cache → MemoryBus)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How My Python Code Works
&lt;/h2&gt;

&lt;p&gt;I split the simulator into 3 classes to mimic real hardware, just like Codecademy suggested:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. MemoryBus (The RAM)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;256 addressable locations&lt;/li&gt;
&lt;li&gt;Methods &lt;code&gt;read(address)&lt;/code&gt; and &lt;code&gt;write(address, value)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Can load initial values from a CSV file like &lt;code&gt;10,100&lt;/code&gt; meaning MEM[10] = 100&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Cache (The Speed Bridge)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple direct-mapped cache with 8 blocks&lt;/li&gt;
&lt;li&gt;Write-through policy&lt;/li&gt;
&lt;li&gt;Tracks hits and misses — crucial for understanding why cache matters in real CPUs&lt;/li&gt;
&lt;li&gt;If data is not in cache (MISS), it fetches from MemoryBus&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. CPU (The Brain)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;8 registers R0-R7 (R0 is hardwired to 0, just like in MIPS)&lt;/li&gt;
&lt;li&gt;Program Counter (PC) to track next instruction&lt;/li&gt;
&lt;li&gt;Full Fetch-Decode-Execute loop:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="n"&gt;instr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PC&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[FETCH] PC=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PC&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; | &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;instr&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instr&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;ISA I implemented:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ADD Rd,Rs,Rt&lt;/code&gt; → Rd = Rs + Rt&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SUB, MUL, ADDI&lt;/code&gt; (with immediate)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;LW Rd,Addr&lt;/code&gt; → Load Word using cache&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SW Rs,Addr&lt;/code&gt; → Store Word&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BEQ Rs,Rt,Offset&lt;/code&gt; → Branch if equal&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;J Target&lt;/code&gt; → Jump&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HALT&lt;/code&gt; → Stop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each cycle prints its stage, so you can literally watch the CPU think. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[FETCH] PC=2 | ADD,R3,R1,R2
[DECODE] Operation: ADD, Args: ['R3', 'R1', 'R2']
[EXECUTE] R3 = R1(10) + R2(20) = 30
[WRITEBACK] Registers: {'R1':10, 'R2':20, 'R3':30}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check Out The Code
&lt;/h2&gt;

&lt;p&gt;All the code is open source and ready to run. I struggled with Git case-sensitivity on Windows (Cpu.py vs cpu.py) and missing input files — you can see the fix in my commit history!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/ikaroshunt/cpu_simulator" rel="noopener noreferrer"&gt;https://github.com/ikaroshunt/cpu_simulator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To run it yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/ikaroshunt/cpu_simulator.git
&lt;span class="nb"&gt;cd &lt;/span&gt;cpu_simulator
python main.py
&lt;span class="c"&gt;# or if import fails: python main_single.py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building this CPU simulator taught me more than any textbook could. I finally understand why cache exists (CPU is fast, memory is slow), why R0 is always 0, and how a simple ADD instruction actually travels through fetch, decode, execute.&lt;/p&gt;

&lt;p&gt;It was frustrating at first — ModuleNotFoundError, FileNotFoundError, Git saying "not a git repository" — but each error taught me something about real-world development: file structure matters, case matters, and Git is strict.&lt;/p&gt;

&lt;p&gt;If you're taking CS104, don't skip this project. Don't just copy a solution. Build it, break it, fix the imports, and watch your own CPU print "SIMULATION FINISHED". There's no better feeling.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This project was built as part of Codecademy's Computer Science Career Path (CS104: Computer Architecture Portfolio Project).&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Tools: Python 3, Git, VS Code, Terminal / PowerShell&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzyi8u284ryifso1n9fv1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzyi8u284ryifso1n9fv1.jpg" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F13gsyz61ki7fq3c2mc96.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F13gsyz61ki7fq3c2mc96.jpg" alt=" " width="800" height="516"&gt;&lt;/a&gt;&lt;a href="https://dev.tourl"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>computerscience</category>
      <category>learning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
