<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mandip Chhetri on Medium]]></title>
        <description><![CDATA[Stories by Mandip Chhetri on Medium]]></description>
        <link>https://medium.com/@mandipchhetri?source=rss-934fe1591493------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*451c6xgWoR7zzlD-YQg87g.png</url>
            <title>Stories by Mandip Chhetri on Medium</title>
            <link>https://medium.com/@mandipchhetri?source=rss-934fe1591493------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:24:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mandipchhetri/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding and Implementing 1D Convolution from Scratch in Python]]></title>
            <link>https://medium.com/@mandipchhetri/understanding-and-implementing-1d-convolution-from-scratch-in-python-c435701105dc?source=rss-934fe1591493------2</link>
            <guid isPermaLink="false">https://medium.com/p/c435701105dc</guid>
            <category><![CDATA[convolution]]></category>
            <category><![CDATA[python-implementation]]></category>
            <dc:creator><![CDATA[Mandip Chhetri]]></dc:creator>
            <pubDate>Fri, 03 Jul 2026 18:59:34 GMT</pubDate>
            <atom:updated>2026-07-03T18:59:34.520Z</atom:updated>
            <content:encoded><![CDATA[<p>Convolution is one of the most important operations in Digital Signal Processing (DSP). At first glance, the convolution formula can look intimidating , a summation sign, an unfamiliar index like n - k, and a lot of subscripts. But once you understand what each symbol actually represents and work through a real example by hand, the whole thing becomes surprisingly intuitive.</p><p>In this article, we’ll start from the mathematical definition of convolution, solve an example completely by hand, spot the repeating pattern hidden inside the calculation, and finally translate that exact pattern into a working Python function.</p><p>The goal isn’t just to get the right answer, it’s to understand <em>why</em> every step works, so that the code at the end feels obvious rather than magical.</p><h3>Problem Statement</h3><p>Consider two discrete-time signals:</p><pre>x[n] = {1, 2, 3, 4}<br>h[n] = {1, 2}</pre><p>The first signal has four samples:</p><pre>x[0] = 1,  x[1] = 2,  x[2] = 3,  x[3] = 4</pre><p>The second signal has two samples:</p><pre>h[0] = 1,  h[1] = 2</pre><p>Our goal is to compute the discrete convolution of x[n] and h[n].</p><h3>The Convolution Formula</h3><p>The discrete-time convolution of two signals is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*_wf2DRSekAHKvsjONCl2Yw.png" /></figure><p>This formula has a few symbols that are worth unpacking before we touch any numbers.</p><h3>What does y[n] represent?</h3><p>y[n] is the <strong>output signal</strong> produced by convolving x[n] with h[n]. Since the output is itself a discrete-time signal, we compute it one sample at a time:</p><pre>y[0], y[1], y[2], ...</pre><p>Each value of y[n] is calculated independently, using its own little formula.</p><h3>What does x[k] represent?</h3><p>x[k] simply steps through every sample of the first signal:</p><pre>x[k] = 1  when k = 0<br>     = 2  when k = 1<br>     = 3  when k = 2<br>     = 4  when k = 3</pre><p>As the summation runs, k moves through all the available samples of x.</p><h4>What does h[n — k] mean?</h4><p>This is usually the part that confuses people the first time they see it.</p><p>Instead of indexing h directly with k, convolution indexes it with the expression n - k. There are two variables involved:</p><ul><li><strong>n</strong> — the output sample we’re currently computing</li><li><strong>k</strong> — the index that runs through the summation</li></ul><p>As k changes, the index n - k changes too , which means for every single output sample, we&#39;re pulling from a <em>different</em> set of positions in h.</p><p>For example, when computing y[2], the index becomes 2 - k. Substituting every possible value of k gives:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RCNIZ8IhdGSLaMvLhA2U-Q.png" /></figure><p>Notice how the index counts <em>down</em>: 2, 1, 0, −1. That downward slide is exactly what h[n - k] is doing, it&#39;s the mathematical way of describing one signal being &quot;flipped and slide&quot; across the other, which is the classic visual explanation of convolution.</p><h3>Why doesn’t the summation actually go from −∞ to +∞?</h3><p>The general definition is written for signals of any length, including infinitely long ones. But our signal x[n] = {1, 2, 3, 4} only has four samples. There&#39;s nothing before x[0] and nothing after x[3],every value of x[k] outside the range 0 ≤ k ≤ 3 is simply zero.</p><p>Since anything multiplied by zero contributes nothing to the sum, we can safely shrink the summation to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpLj5GdrtoiOL9xS-ef78g.png" /></figure><p>This is mathematically identical to the infinite version, just without wasting effort adding a string of zeros.</p><h3>How many output samples will we get?</h3><p>If the first signal has Lx samples and the second has Lh samples, the length of the convolution output is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*9XfyvxaFrERFEpqY08-TTg.png" /></figure><p>For our signals, Lx = 4 and Lh = 2, so:</p><pre>L = 4 + 2 - 1 = 5</pre><p>That means our output will contain exactly five samples: y[0], y[1], y[2], y[3], y[4].</p><h3>Manual Calculation : Step by Step</h3><p>Now let’s actually compute each of those five values by hand, using the formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpLj5GdrtoiOL9xS-ef78g.png" /></figure><h4>y[0]</h4><pre>y[0] = x[0]h[0] + x[1]h[-1] + x[2]h[-2] + x[3]h[-3]</pre><p>h[-1], h[-2], and h[-3] don&#39;t exist (h only has indices 0 and 1), so those terms are zero:</p><pre>y[0] = 1(1) + 2(0) + 3(0) + 4(0) = 1</pre><p><strong>y[0] = 1</strong></p><h4>y[1]</h4><pre>y[1] = x[0]h[1] + x[1]h[0] + x[2]h[-1] + x[3]h[-2]</pre><p>Only h[1] and h[0] are valid:</p><pre>y[1] = 1(2) + 2(1) + 3(0) + 4(0) = 2 + 2 = 4</pre><p><strong>y[1] = 4</strong></p><h4>y[2]</h4><pre>y[2] = x[0]h[2] + x[1]h[1] + x[2]h[0] + x[3]h[-1]</pre><p>h[2] and h[-1] don&#39;t exist:</p><pre>y[2] = 1(0) + 2(2) + 3(1) + 4(0) = 4 + 3 = 7</pre><p><strong>y[2] = 7</strong></p><h4>y[3]</h4><pre>y[3] = x[0]h[3] + x[1]h[2] + x[2]h[1] + x[3]h[0]</pre><p>h[3] and h[2] don&#39;t exist:</p><pre>y[3] = 1(0) + 2(0) + 3(2) + 4(1) = 6 + 4 = 10</pre><p><strong>y[3] = 10</strong></p><h4>y[4]</h4><pre>y[4] = x[0]h[4] + x[1]h[3] + x[2]h[2] + x[3]h[1]</pre><p>Only h[1] is valid:</p><pre>y[4] = 1(0) + 2(0) + 3(0) + 4(2) = 8</pre><p><strong>y[4] = 8</strong></p><h3>Putting it all together</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q682YK-SCPoap2ByA8VQsQ.png" /></figure><pre>y[n] = {1, 4, 7, 10, 8}</pre><p>That’s the complete convolution of x[n] and h[n], computed entirely by hand.</p><h3>Spotting the Pattern</h3><p>Let’s line up all five expansions together and look for a pattern:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6VQMM9s_a7IUGRitWiUEw.png" /></figure><p>Instead of writing each equation separately, we can observe that the index of <strong><em>x</em></strong> always follows the sequence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CUQtme5QQWtz2tAayMrpmA.png" /></figure><p>while the index of <strong><em>h</em></strong> is always the output index minus the current summation index:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gsr9vQc6FlAnz0xarFHe6A.png" /></figure><p>This allows us to express every equation using one general expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J23tunSPePgxnFkk5b09GQ.png" /></figure><p>Two things stand out:</p><ol><li>The index of x[k] never changes across a row ,it always runs 0,1,2,3.</li><li>The index of h[n - k] changes with n. As n increases from 0 to 4, the whole set of h indices shifts one step to the right.</li></ol><p>Whenever the index of h lands outside its valid range (negative, or greater than 1), that term simply doesn&#39;t exist and contributes zero. That&#39;s the entire reason so many terms vanished during the manual computation above, here was never anything special happening, just an out-of-range index being treated as zero.</p><p>This observation is the key that turns a page of hand-written algebra into a two-line rule:</p><p>For a given n, only keep the term x[k] * h[n — k] when</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiw0t94J9jl07pjZwfpkKg.png" /></figure><p>Everything else can be skipped entirely.</p><h3>Turning the Pattern into an Algorithm</h3><p>The manual process we just did is really just a repeating recipe:</p><ol><li>Pick an output sample y[n] to compute.</li><li>Try every element x[k] of the first signal.</li><li>Work out the matching index n - k for the second signal.</li><li>If that index actually exists inside h, multiply x[k] by h[n - k].</li><li>Add that product to a running total for y[n].</li><li>Move on to the next output sample and repeat.</li></ol><h3>Python Implementation</h3><pre>import numpy as np<br><br>def myconv(x, h):<br>    &quot;&quot;&quot;<br>    Compute the linear convolution of two input signals.<br><br>    Parameters:<br>        x (numpy.ndarray): First input signal as a NumPy array.<br>        h (numpy.ndarray): Second input signal as a NumPy array.<br><br>    Returns:<br>        numpy.ndarray: A NumPy array containing the linear convolution<br>        of the input signals x and h.<br>    &quot;&quot;&quot;<br><br>    # Length of input signals<br>    xl = len(x)<br>    hl = len(h)<br><br>    # Length of output signal: L = Lx + Lh - 1<br>    cl = xl + hl - 1<br><br>    # Initialize output with zeros<br>    y = np.zeros(cl)<br><br>    # Compute each output sample<br>    for n in range(cl):<br>        # Try every sample of x<br>        for k in range(xl):<br>            # Check whether h[n-k] is a valid index<br>            if 0 &lt;= n - k &lt; hl:<br>                # Accumulate the product<br>                y[n] += x[k] * h[n - k]<br>    return y</pre><h3>Code walkthrough</h3><p><strong>1. Lengths of the input signals</strong></p><pre>xl = len(x)<br>hl = len(h)</pre><p>For our example, xl = 4 and hl = 2.</p><p><strong>2. Output length</strong></p><pre>cl = xl + hl - 1</pre><p>This gives cl = 5, matching what we calculated by hand earlier.</p><p><strong>3. Output array initialization</strong></p><pre>y = np.zeros(cl)</pre><p>At the start, y = [0, 0, 0, 0, 0]. Each slot will be filled in as we accumulate products into it.</p><p><strong>4. Outer loop , one output sample at a time</strong></p><pre>for n in range(cl):</pre><p>This computes y[0] through y[4], one row of our manual table at a time.</p><p><strong>5. Inner loop, trying every sample of x</strong></p><pre>for k in range(xl):</pre><p>For each output sample, the code checks every element of x: x[0], x[1], x[2], x[3].</p><p><strong>6. The validity check</strong></p><pre>if 0 &lt;= n - k &lt; hl:</pre><p>This line is doing exactly what we did by hand when we crossed out terms like h[-1] or h[3]. It only allows a term through if n - k actually falls inside the valid index range of h (here, indices 0 and 1). Everything outside that range is silently skipped, which has the same effect as treating it as zero, but without wasting a multiplication.</p><p><strong>7. Accumulating the result</strong></p><pre>y[n] += x[k] * h[n - k]</pre><p>+= means &quot;add this new product to whatever is already stored in y[n].&quot; For example, while computing y[2]:</p><pre>Start:                  y[2] = 0<br>After x[1]*h[1] = 2*2:  y[2] = 0 + 4 = 4<br>After x[2]*h[0] = 3*1:  y[2] = 4 + 3 = 7</pre><p>This is the exact same addition we performed by hand:</p><pre>y[2] = 2(2) + 3(1) = 4 + 3 = 7</pre><h3>Testing the Function</h3><pre>x = np.array([1, 2, 3, 4])<br>h = np.array([1, 2])</pre><pre>result = myconv(x, h)<br>print(result)</pre><p><strong>Output:</strong></p><pre>[ 1.  4.  7. 10.  8.]</pre><p>This matches our hand-computed result exactly: {1, 4, 7, 10, 8}.</p><h3>What We Learned</h3><ul><li>Convolution computes one output sample at a time, using its own version of the formula.</li><li>The index k walks through every sample of the first signal.</li><li>The expression n - k determines which sample of the second signal lines up with each sample of the first , this is the mathematical version of &quot;flipping and sliding&quot; one signal across the other.</li><li>Invalid indices of h simply contribute zero, which is why so many terms disappeared during the manual computation.</li><li>The nested loops in the Python implementation perform <em>exactly</em> the same operations as the hand calculations, nothing more, nothing hidden.</li></ul><p>Once you can see the repeating pattern inside the hand calculation, writing the code stops being a translation exercise and starts feeling like the obvious next step. That, more than memorizing the formula, is what actually makes convolution click.</p><h3>Further Reading</h3><p>If you’d like a deeper, more visual and more rigorous treatment of convolution, these two resources are excellent follow-ups:</p><ul><li><a href="https://youtu.be/KuXjwB4LzSA"><strong>3Blue1Brown — “But what is a convolution?”</strong></a>: An outstanding visual walkthrough of convolution, covering discrete convolutions, moving averages, image processing, and how convolution connects to the Fast Fourier Transform.</li><li><a href="https://ocw.mit.edu/courses/res-6-007-signals-and-systems-spring-2011/resources/lecture-4-convolution/"><strong>MIT OpenCourseWare — Signals and Systems (Prof. Alan V. Oppenheim), Lecture 4: Convolution</strong>: </a>The classic rigorous treatment of the convolution sum for discrete-time LTI systems and the convolution integral for continuous-time systems, along with its commutative, associative, and distributive properties.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c435701105dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bayesian Thinking: The Art of Changing Your Mind]]></title>
            <link>https://medium.com/@mandipchhetri/bayesian-thinking-the-art-of-changing-your-mind-242404ced192?source=rss-934fe1591493------2</link>
            <guid isPermaLink="false">https://medium.com/p/242404ced192</guid>
            <category><![CDATA[bayesian-thinking]]></category>
            <category><![CDATA[bayesian-intuition]]></category>
            <category><![CDATA[probability]]></category>
            <dc:creator><![CDATA[Mandip Chhetri]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 18:29:51 GMT</pubDate>
            <atom:updated>2026-06-03T18:29:51.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*92F5BC8mkN5SGZag" /><figcaption>Photo by <a href="https://unsplash.com/@rocinante_11?utm_source=medium&amp;utm_medium=referral">Mick Haupt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most people think probability is just for coin flips, rolling dice, or playing board games. But what if probability is actually a superpower for your brain?</p><p>To a Bayesian thinker, probability isn’t just about games. It is a way to measure how sure you are about something.</p><p>The big question a Bayesian asks is:</p><p><strong><em>With what I know right now, how much should I believe this? And when I see new clues, how much should I change my mind?</em></strong></p><p>This simple idea helps scientists make discoveries, keeps self-driving cars on the road, and helps you make better choices every single day.</p><h3>The Detective Trap: Guessing Too Fast</h3><p>Imagine you walk onto a giant school campus. On this campus, there are two kinds of students:</p><ul><li>100 Math PhDs</li><li>1,000 Business PhDs</li></ul><p>You meet a student named Tom. He is super shy, mumbles a bit, and looks down at his shoes.</p><p>If you had to guess , Is Tom a Math PhD or a Business PhD?</p><p>Almost everyone instantly shouts: “Math PhD!”</p><p>Why? Because “shy” fits our mental picture of a math nerd. But our brains are tripping over a huge trap. We forgot to look at the map of the school. There are ten times more Business PhDs on campus than Math PhDs.</p><p>Let’s look at the actual numbers:</p><p>Out of the 100 Math PhDs, 75 of them are shy that gives us 75 shy math students.</p><p>Out of the 1,000 Business PhDs, only 15% are shy. But 15% of 1,000 is 150 shy business students.</p><p>Look at that. If you gather all the shy students on campus into one room, you have 75 math students and 150 business students. Since 150 is twice as big as 75, Tom is actually much more likely to be a Business PhD.</p><p>When we ignore how common something was to begin with, we make a big logic mistake. Remembering the “starting numbers” is your first step to thinking like a Bayesian.</p><h3>The Secret Recipe: Bayes’ Theorem</h3><p>We can turn this detective work into a math formula. Think of it as a secret code for your brain.</p><p>H is your Hypothesis -&gt; the thing you think is happening, like “Tom is a Math PhD.”</p><p>E is your Evidence → the new clue you found, like “Tom is shy.”</p><p>The formula looks like this:</p><blockquote><strong><em>P(H | E) = P(E | H) · P(H) / P(E)</em></strong></blockquote><p>Let’s break down what each piece means:</p><p><strong>The Starting Guess P(H).</strong> How likely was this true before you found the new clue? Math students are rare, so this starts low.</p><p><strong>The Likelihood P(E | H).</strong> If your guess were true, how common would this clue be? Math students are very often shy, so this is high.</p><p><strong>The Total Clues P(E).</strong> How common is this clue everywhere, across the whole school?</p><p><strong>The Final Answer P(H | E).</strong> Your brand-new, updated score of how sure you are.</p><p>Instead of doing hard math in your head all day, you can use the Golden Rule of Updating:</p><p><strong>New Belief = Old Belief × How Surprising the Clue Is</strong></p><h3>Two Rules to Live By</h3><p>You don’t need a calculator to use Bayesian thinking in real life. You just need to ask yourself two questions whenever you see something new.</p><h4><strong>Rule 1: Ask “What if I am wrong?”</strong></h4><p>When we believe something, our brains love to look for clues that prove we are right.</p><p>Imagine you think a friend is mad at you. They walk past you in the hallway without saying hi. Your brain shouts: “Aha! Proof!”</p><p><strong>A Bayesian stops and asks a different question: <em>If my friend were NOT mad at me, how likely is it that they would still walk past without saying hi?</em></strong></p><p>The answer? Very likely. Maybe they were listening to music, running late, or lost in thought about a hard exam. Because the clue makes sense in both worlds, it doesn’t actually prove anything. It’s weaker evidence than it first appeared.</p><h4><strong>Rule 2: Collect the Snowflakes</strong></h4><p>Beliefs don’t have to be just ON or OFF. Think of your confidence like a volume slider from 0 to 100.</p><p>If you think a new food is going to taste terrible and you try a tiny bite that tastes okay, you don’t have to instantly declare it your favorite food. Instead, you just move your slider a little bit.</p><p>Think of small clues like snowflakes. A single snowflake doesn’t weigh much. But if you keep your mind open and let the snowflakes pile up, eventually they become heavy enough to completely change your mind.</p><h3>The Ultimate Superpower</h3><p>The coolest thing about Bayesian thinking is what it does to your relationship with being wrong.</p><p>Being wrong isn’t a failure. Changing your mind isn’t a sign of weakness. Your beliefs are just guesses you are testing out, and new clues are just helpful data for making your mental map of the world more accurate.</p><p>The goal of a rational mind is simple:</p><blockquote><strong><em>Take what you believed yesterday, add what you learned today, and make your mind a little bit smarter for tomorrow.</em></strong></blockquote><h3>References</h3><p>[1] “<em>Bayesian Thinking</em>” — YouTube, h<a href="https://youtu.be/55L7w2Vwkuk?si=3IT4DI_HQVYbQeCP">ttps://youtu.be/55L7w2Vwkuk?si=3IT4DI_HQVYbQeCP</a></p><p>[2] Julia Galef, “<em>A Visual Guide to Bayesian Thinking</em>” — YouTube, <a href="https://youtu.be/BrK7X_XlGB8?si=s41nYkVw6tdTMd6h">https://youtu.be/BrK7X_XlGB8?si=s41nYkVw6tdTMd6h</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=242404ced192" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8086 Guide: Finding “Hidden” Variables in DOSBox]]></title>
            <link>https://medium.com/@mandipchhetri/8086-guide-finding-hidden-variables-in-dosbox-fba69aeebacb?source=rss-934fe1591493------2</link>
            <guid isPermaLink="false">https://medium.com/p/fba69aeebacb</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[assembly-languagex]]></category>
            <category><![CDATA[dosbox]]></category>
            <category><![CDATA[x86]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Mandip Chhetri]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 12:16:21 GMT</pubDate>
            <atom:updated>2026-02-18T12:17:50.640Z</atom:updated>
            <content:encoded><![CDATA[<p>When writing Assembly, you’ll often find that your program runs perfectly but displays <strong>nothing</strong> on the screen. This is because the CPU stores the result in a memory location (a variable), but it doesn’t automatically send that data to the monitor.</p><p>This guide teaches you how to “interrogate” the RAM to see your results using the DEBUG utility.</p><h3>1. The Challenge: Adding 1 to 255</h3><p>We want to add 01H (1) and FFH (255).</p><ul><li><strong>The Math:</strong> $01H + FFH = 0100H$ (Decimal 256).</li><li><strong>The Problem:</strong> Our variable SUM is 16-bit (DW). How do we confirm it holds 0100H?</li></ul><h3>The Source Code (ADDER.ASM)</h3><pre>TITLE Add two numbers<br>.MODEL SMALL<br>.STACK 32<br>.DATA<br>    VAL1 DW 0001H<br>    VAL2 DW 00FFH<br>    SUM  DW ?        ; We want to check this!<br>.CODE<br>MAIN PROC<br>    MOV AX, @DATA    ; Initialize Data Segment<br>    MOV DS, AX<br>    MOV AX, VAL1<br>    ADD AX, VAL2     ; AX now holds 0100H<br>    MOV SUM, AX      ; Store result in memory<br>    MOV AX, 4C00H    ; Exit<br>    INT 21H<br>MAIN ENDP<br>END MAIN</pre><h3>2. Step-by-Step Debugging Process</h3><h3>Step A: Start the Debugger</h3><p>After assembling and linking your code, load it into the debugger:</p><p>Bash</p><pre>DEBUG ADDER.EXE</pre><h3>Step B: Point to the Data Segment</h3><p>Before the computer can find your variables, the DS (Data Segment) register must be set.</p><ul><li>Type -t (Trace) and press Enter.</li><li>The first instruction MOV AX, @DATA executes.</li><li>Type -t again.</li><li>The second instruction MOV DS, AX executes.</li><li><strong>Now, your program is looking at the correct part of the memory.</strong></li></ul><h3>Step C: Find the Variable’s Address</h3><p>We need to know exactly where SUM lives in the RAM.</p><ul><li>Type -u (Unassemble).</li><li>Look for the line: MOV [XXXX], AX (where XXXX is a hex number).</li><li>In our data segment, if VAL1 is at 0000 and VAL2 is at 0002, then SUM is likely at <strong>0004</strong>.</li></ul><h3>Step D: Execute the Math</h3><p>You can either keep typing -t to step through line-by-line, or simply type:</p><pre>-g</pre><p>This runs the program until the end (INT 21H).</p><h3>Step E: Dump the Memory (The Result)</h3><p>Now we look at the address we found in Step C.</p><p><strong>Syntax:</strong> -d ds:address</p><pre>-d ds:0004</pre><p>You will see a display similar to this:</p><p>076B:0000 01 00 FF 00 00 01 00 00</p><h3>3. How to Read the Output</h3><p>Assembly uses <strong>Little Endian</strong> format. This means the “Small end” of the number is stored first.</p><p><strong>Memory HexInterpretationActual Value</strong>00 010100H<strong>256</strong> (Our Sum!)01 000001H<strong>1</strong> (VAL1)FF 0000FFH<strong>255</strong> (VAL2)</p><h3>💡 Pro Tips</h3><ul><li><strong>The Hyphen:</strong> If you see the - prompt, the debugger is waiting for you.</li><li><strong>The </strong><strong>q command:</strong> To exit the debugger and go back to the DOS prompt, just type q.</li><li><strong>Segment check:</strong> Always make sure your DS register matches the segment shown in the -d command.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fba69aeebacb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>