<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emu8086</title>
	<atom:link href="https://emu8086emulator.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://emu8086emulator.com</link>
	<description>Download Emu8086, Step-by-Step Installation &#38; 8086 Opcode Reference</description>
	<lastBuildDate>Sat, 24 Oct 2026 10:37:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>

<image>
	<url>https://emu8086emulator.com/wp-content/uploads/2026/06/favicon-150x150.png</url>
	<title>Emu8086</title>
	<link>https://emu8086emulator.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>First Program Checklist: From Code to a Running Emu8086 Program</title>
		<link>https://emu8086emulator.com/emu8086-first-program-checklist/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:37:59 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-first-program-checklist/</guid>

					<description><![CDATA[This is the checklist to run through every time you start a new program, until the steps are automatic. It gathers the lessons of the whole tutorial series into one page. If you have not installed Emu8086 yet, start with the install guide; the download there is through the community mirror linked from this site,...]]></description>
										<content:encoded><![CDATA[<p>This is the checklist to run through every time you start a new program, until the steps are automatic. It gathers the lessons of the whole tutorial series into one page. If you have not installed Emu8086 yet, start with the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>; the download there is through the community mirror linked from this site, and the mirror may ask you to sign in.</p>
<h2>Before you type anything</h2>
<ul>
<li>Choose the template first: .COM for a short exercise, .EXE for a multi-segment program. The <a href="https://emu8086emulator.com/emu8086-com-vs-exe/">.COM vs .EXE guide</a> explains the choice.</li>
<li>Decide which registers hold your inputs and which one will hold the answer, before you write the first instruction.</li>
<li>If you plan to use <code>PRINT</code>, <code>PUTC</code> or <code>PRINTN</code>, the include line for <code>emu8086.inc</code> must be in the file. If you use none of them, leave it out.</li>
</ul>
<h2>While you write</h2>
<ul>
<li>A .COM program starts with <code>ORG 100h</code> and ends with <code>RET</code>; an .EXE program sets DS and exits with function 4Ch.</li>
<li>Every <code>CALL</code> needs a matching <code>RET</code>, and every <code>PUSH</code> needs a matching <code>POP</code>.</li>
<li>Strings for function 09h end with <code>$</code>; strings walked by hand end with a zero byte. Do not mix the two terminators.</li>
<li>No placeholder gaps: a program with a missing middle section cannot be assembled or tested, so write each part completely, even if it is short.</li>
</ul>
<h2>Assemble, then step before you run</h2>
<p>Assemble first and read any error message literally: an unknown symbol usually means a missing include line or a misspelled label, and a segment-directive error usually means the wrong template. Then single-step the program once, as described in the <a href="https://emu8086emulator.com/emu8086-step-debugging/">step debugging tutorial</a>, watching the registers and flags at each instruction. Only run at full speed after the single-step behaved as expected.</p>
<h2>A complete final example</h2>
<p>The program below combines several series lessons: it uses macros, so it includes <code>emu8086.inc</code>; it does a small calculation; and it converts the numeric result to a printable character by adding the character code for zero. Run it, step it, and confirm each expectation before moving on.</p>
<pre>include &#x27;emu8086.inc&#x27;
ORG 100h

PRINT &#x27;2 + 3 = &#x27;
MOV AL, 2
ADD AL, 3
ADD AL, &#x27;0&#x27;
PUTC
PRINTN
RET</pre>
<h2>What you should see</h2>
<p>The emulator window should show <code>2 + 3 = 5</code>. The digit appears because adding the character code for <code>'0'</code> to the value 5 gives the character code for <code>'5'</code>, which is what <code>PUTC</code> prints. This only works for single digits from 0 to 9; larger results need a proper number-to-string conversion, which is a good second project once this checklist feels easy.</p>
<h2>When it does not work</h2>
<ul>
<li>Nothing prints: check the template, the include line, and whether the program reached a <code>RET</code> before the printing code.</li>
<li>Wrong digit: check whether the value in AL was still the sum when <code>PUTC</code> ran, or whether an instruction in between overwrote it.</li>
<li>Assembler error on the first line: check the include line spelling and that the file is a .COM template.</li>
<li>Program runs past the end: check that every path through the code reaches a <code>RET</code> or a proper exit.</li>
</ul>
<h2>Where to go next</h2>
<p>For deeper reading, the buying guide at <a href="https://emu8086emulator.com/best-books-learning-8086-assembly/">best books for learning 8086 assembly</a> collects book suggestions for continued study. The tutorial series itself continues from here into larger programs; revisit <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Hello World</a> and <a href="https://emu8086emulator.com/emu8086-registers-segments/">registers and segments</a> whenever a new program surprises you, and keep the <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> open while you work.</p>
<h2>Next steps</h2>
<p>That is the whole first-program workflow in one place. Return to the <a href="https://emu8086emulator.com/">home page</a> for the full series, and use <a href="https://emu8086emulator.com/emu8086-step-debugging/">step debugging</a> whenever a new program misbehaves.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Step Debugging in Emu8086: Single-Step, Breakpoints, Memory and Flags</title>
		<link>https://emu8086emulator.com/emu8086-step-debugging/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:37:44 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-step-debugging/</guid>

					<description><![CDATA[Most beginner programs are not wrong in a big way; they are wrong in one register, one flag, or one address. The emulator&#8217;s debugging tools exist to find that one thing. This tutorial walks through them with a small program you can break on purpose. It assumes you can already write and run a program;...]]></description>
										<content:encoded><![CDATA[<p>Most beginner programs are not wrong in a big way; they are wrong in one register, one flag, or one address. The emulator&#8217;s debugging tools exist to find that one thing. This tutorial walks through them with a small program you can break on purpose. It assumes you can already write and run a program; the <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Hello World tutorial</a> is the starting point, and Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>A program to practise on</h2>
<p>Assemble the program below. It counts CX down from 3 to 0, jumping back while CX is not zero. You will practise watching it, then change the starting value and confirm the loop runs a different number of times.</p>
<pre>ORG 100h

MOV CX, 3
count_down:
DEC CX
JNZ count_down
RET</pre>
<h2>Single-stepping</h2>
<p>Single-step executes one instruction at a time. Step through the program and watch CX fall from 3 to 2 to 1, then to 0. The jump should be taken twice and not taken on the third pass, when CX reaches zero. If you see the loop exit early, check whether an instruction between the decrement and the jump changed the flags: <code>DEC</code> sets the zero flag, and the jump reads it, so nothing may sit between them that also sets flags. The <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops tutorial</a> explains this flag discipline.</p>
<h2>What you should see</h2>
<p>In this version, the jump should be taken twice and not taken on the third pass. If you still see the loop exit early, check whether an instruction between the decrement and the jump changed the flags: <code>DEC</code> sets the zero flag, and the jump reads it, so nothing may sit between them that also sets flags. The <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops tutorial</a> explains this flag discipline.</p>
<h2>Breakpoints</h2>
<p>A breakpoint pauses execution when it reaches a chosen line, so you do not have to step through a long program to reach the interesting part. Set a breakpoint on the <code>DEC CX</code> line, run at full speed, and the program should pause there on every pass. Inspect CX at each pause: it should read 3 on the first pause, then 2, then 1, counting the pauses as you go. Remove the breakpoint when you are done, or the program will keep pausing there on later runs.</p>
<h2>Memory and flags</h2>
<p>Use the memory window to check variables and arrays directly, rather than inferring them from registers. The <a href="https://emu8086emulator.com/emu8086-sorting-numbers/">sorting tutorial</a> is a good place to practise this: pause after each pass and read the array from memory. For flags, watch the zero flag after comparisons, the carry flag after subtraction, and the sign flag after operations that produce a negative-looking result. A jump that misbehaves is almost always a flag that is not what you assumed, and the flag display tells you in one glance.</p>
<h2>A debugging checklist</h2>
<ul>
<li>Reproduce the fault with the smallest program that still shows it.</li>
<li>Single-step the first few instructions before assuming the later ones are at fault.</li>
<li>Check the flags at the jump, not just the registers.</li>
<li>Check that pushes and pops balance, so a <code>RET</code> returns to the right address.</li>
<li>When memory looks wrong, check the address the program actually used, not the one you meant it to use.</li>
</ul>
<h2>Next steps</h2>
<p>Apply these tools to the <a href="https://emu8086emulator.com/emu8086-sorting-numbers/">sorting example</a> and the <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutine example</a> next; both reward careful tracing. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> helps you predict each instruction&#8217;s flag effects, and the <a href="https://emu8086emulator.com/">home page</a> links the series.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>.COM vs .EXE in Emu8086: Which Template to Choose</title>
		<link>https://emu8086emulator.com/emu8086-com-vs-exe/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:37:29 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-com-vs-exe/</guid>

					<description><![CDATA[Emu8086 offers two templates for a new program, and choosing the wrong one is a common first error: the directives that are correct in one template are rejected in the other. This tutorial compares them directly, with a minimal working example of each, so you can choose confidently. Emu8086 setup is in the install guide....]]></description>
										<content:encoded><![CDATA[<p>Emu8086 offers two templates for a new program, and choosing the wrong one is a common first error: the directives that are correct in one template are rejected in the other. This tutorial compares them directly, with a minimal working example of each, so you can choose confidently. Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>.COM: small, simple, one segment</h2>
<p>A .COM program is a single segment of at most 64 KB. It starts with <code>ORG 100h</code>, because the first 256 bytes of the segment hold the program segment prefix, and it ends with <code>RET</code>. All segment registers start out pointing at the same segment, so you do not set DS yourself. This is the right template for almost every beginner exercise in this series, including the <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Hello World program</a>.</p>
<pre>ORG 100h

LEA DX, msg
MOV AH, 09h
INT 21h
RET

msg DB &#x27;Hello from a .COM program!$&#x27;</pre>
<h2>.EXE: segments you control</h2>
<p>A .EXE program has separate code, data and stack segments, and can be larger than 64 KB in total. You declare them with the simplified segment directives <code>.MODEL</code>, <code>.STACK</code>, <code>.DATA</code> and <code>.CODE</code>, and you must set DS to your data segment at the start, because the loader does not do it for you. The program ends with function 4Ch rather than a plain <code>RET</code>.</p>
<pre>.MODEL SMALL
.STACK 100h
.DATA
msg DB &#x27;Hello from an .EXE program!$&#x27;
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, msg
MOV AH, 09h
INT 21h
MOV AX, 4C00h
INT 21h
MAIN ENDP
END MAIN</pre>
<h2>What you should see</h2>
<p>Both programs should print their greeting and stop. The visible difference is in the setup, not the output: the .COM version needs no segment setup and ends with <code>RET</code>, while the .EXE version sets DS, uses a named procedure, and exits through function 4Ch with a return code of zero in AL. If the .EXE version prints garbage, the usual cause is a missing <code>MOV DS, AX</code> pair, so DS still points somewhere unrelated to your string.</p>
<h2>Which template to choose</h2>
<ul>
<li>Choose .COM for short exercises, single-file examples, and anything in this tutorial series unless it says otherwise.</li>
<li>Choose .EXE when a program needs more than one segment, a larger stack, or a structure that mirrors a real multi-segment program.</li>
<li>Never mix the two conventions in one file: <code>ORG 100h</code> with <code>.MODEL SMALL</code>, or a .COM program that tries to set DS with <code>@DATA</code>, will not assemble cleanly.</li>
</ul>
<h2>Converting between them</h2>
<p>To convert a small .COM program to .EXE, move its data after the code into a <code>.DATA</code> section, add the <code>.MODEL</code>, <code>.STACK</code> and <code>.CODE</code> directives, add the DS setup at the start, and replace the final <code>RET</code> with the 4Ch exit. To go the other way, remove the segment directives, add <code>ORG 100h</code>, drop the DS setup, and end with <code>RET</code>. Doing one conversion by hand is the best way to fix the difference in your memory.</p>
<h2>Next steps</h2>
<p>Both templates appear throughout the series: most tutorials use .COM, and the <a href="https://emu8086emulator.com/emu8086-registers-segments/">registers and segments tutorial</a> explains why DS matters. For input and output details, see <a href="https://emu8086emulator.com/emu8086-int-21h-input-output/">INT 21h input and output</a>. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> and the <a href="https://emu8086emulator.com/">home page</a> complete the picture.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>INT 21h Input and Output in Emu8086</title>
		<link>https://emu8086emulator.com/emu8086-int-21h-input-output/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:37:14 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-int-21h-input-output/</guid>

					<description><![CDATA[Underneath the friendly macros in emu8086.inc sits a plain mechanism: interrupt 21h, the DOS service call. You set a function number in AH, set up any other registers the function needs, and execute INT 21h. This tutorial covers the four functions a beginner program uses most. Emu8086 setup is in the install guide. The four...]]></description>
										<content:encoded><![CDATA[<p>Underneath the friendly macros in <a href="https://emu8086emulator.com/emu8086-macros-emu8086-inc/">emu8086.inc</a> sits a plain mechanism: interrupt 21h, the DOS service call. You set a function number in AH, set up any other registers the function needs, and execute <code>INT 21h</code>. This tutorial covers the four functions a beginner program uses most. Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>The four functions</h2>
<ul>
<li>Function 09h: print a string. DX points at the string, which must end with <code>$</code>.</li>
<li>Function 02h: print one character. DL holds the character.</li>
<li>Function 01h: read one key, with echo. The character comes back in AL.</li>
<li>Function 4Ch: exit a .EXE program with a return code in AL. A .COM program normally just uses <code>RET</code> instead.</li>
</ul>
<h2>A complete program: ask, read, echo</h2>
<p>The program below prints a prompt, waits for a keypress, then prints the key on a new line. It uses no macros, so it needs no include line. Watch the order of the newline: the carriage return (13) and line feed (10) are printed as two separate characters through function 02h, before the echoed character is printed.</p>
<pre>ORG 100h

LEA DX, prompt
MOV AH, 09h
INT 21h

MOV AH, 01h
INT 21h
MOV BL, AL

MOV AH, 02h
MOV DL, 13
INT 21h
MOV DL, 10
INT 21h

MOV DL, BL
INT 21h
RET

prompt DB &#x27;Press a key: $&#x27;</pre>
<h2>What you should see</h2>
<p>After you press a key, say <code>k</code>, the emulator window should show the prompt, the echoed key, and then the same key again on the next line. The first appearance is the echo from function 01h; the second is your own function 02h print. If the key appears only once, the echo may have been consumed differently by your emulator settings; the important check is that the character on the new line matches the key you pressed.</p>
<h2>Why the key is saved in BL</h2>
<p>Function 01h returns the character in AL, but the very next function call needs AH set to 02h, which overwrites the high half of AX. Saving AL into BL first protects the character. This is the same register-preservation idea as the <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">stack tutorial</a>, done here with a spare register instead of the stack. Forgetting to save it is the classic INT 21h beginner bug: the printed character comes out as something unrelated to the key pressed.</p>
<h2>Choosing macros or raw INT 21h</h2>
<p>Macros are shorter to write and easier to read. Raw INT 21h calls show what is really happening and work in programs that do not include <code>emu8086.inc</code>. A good rule is to learn both: write your first programs with macros, then rewrite one of them with raw services, as in the Hello World comparison in the <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">first tutorial</a>, so you understand what the macros were doing for you.</p>
<h2>Next steps</h2>
<p>Next, <a href="https://emu8086emulator.com/emu8086-step-debugging/">step debugging</a> shows how to watch AH and AL change at each service call, and <a href="https://emu8086emulator.com/emu8086-com-vs-exe/">.COM vs .EXE</a> explains where function 4Ch fits. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> covers <code>INT</code> itself, and the <a href="https://emu8086emulator.com/">home page</a> links the series.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Macros and emu8086.inc: PUTC, PRINT and Friends</title>
		<link>https://emu8086emulator.com/emu8086-macros-emu8086-inc/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:37:00 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-macros-emu8086-inc/</guid>

					<description><![CDATA[Beginner Emu8086 programs often start with a line that looks like magic: include 'emu8086.inc'. It is not magic. It pulls in a file of macro definitions, small text templates that the assembler expands before assembling your program. This tutorial explains the macros you will actually use and shows you how to write one of your...]]></description>
										<content:encoded><![CDATA[<p>Beginner Emu8086 programs often start with a line that looks like magic: <code>include 'emu8086.inc'</code>. It is not magic. It pulls in a file of macro definitions, small text templates that the assembler expands before assembling your program. This tutorial explains the macros you will actually use and shows you how to write one of your own. It follows the <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Hello World tutorial</a>, and Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>The three macros you will use most</h2>
<ul>
<li><code>PUTC</code> prints the single character in AL.</li>
<li><code>PRINT 'text'</code> prints a string of text.</li>
<li><code>PRINTN</code> prints a new line.</li>
</ul>
<h2>A complete program using all three</h2>
<p>This program prints a word, a new line, and then a single character. It needs the include line, because without it the assembler has no definition of <code>PRINT</code> or <code>PUTC</code> and will report them as unknown symbols. That error message is the usual sign that the include line was deleted by accident.</p>
<pre>include &#x27;emu8086.inc&#x27;
ORG 100h

PRINT &#x27;Hello&#x27;
PRINTN
MOV AL, &#x27;!&#x27;
PUTC
RET</pre>
<h2>What you should see</h2>
<p>The emulator window should show <code>Hello</code> on one line and <code>!</code> on the next. Note the order in the character case: <code>PUTC</code> reads AL, so AL must be loaded after the <code>PRINTN</code>, not before, if any macro in between changes AL. When a character prints wrong, check what AL held at the exact moment <code>PUTC</code> ran.</p>
<h2>Defining your own macro</h2>
<p>A macro is defined once and expanded everywhere it is used. The definition below prints a fixed greeting. Every time <code>SAY_HI</code> appears in the code, the assembler replaces it with the two macro lines before assembling. That is the key difference from a subroutine: a macro costs no <code>CALL</code> at run time, but it does make the assembled program longer each time it is used.</p>
<pre>include &#x27;emu8086.inc&#x27;
ORG 100h

SAY_HI
SAY_HI
RET

SAY_HI MACRO
PRINT &#x27;Hi from a macro!&#x27;
PRINTN
ENDM</pre>
<h2>What you should see</h2>
<p>The greeting should appear twice, on two lines. If it appears only once, check that the macro definition comes after the code that uses it in your file layout, or that you have not placed the definition after the final <code>RET</code> in a way that the assembler treats as unreachable data; the layout above, definition after the main code, is the standard Emu8086 arrangement.</p>
<h2>Macros are not subroutines</h2>
<p>A subroutine, covered in <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutines and the stack</a>, exists once in the assembled program and is jumped to. A macro exists only in the source: the assembler copies its body to every use. Use macros for short, repeated text output and similar conveniences. Use subroutines for longer logic that you want to keep in one place and debug in one place.</p>
<h2>One rule to remember</h2>
<p>Only include <code>emu8086.inc</code> when your program actually uses one of its macros. Including it in a program that uses none of them is harmless but pointless, and it can confuse a reader who goes looking for a macro call that never comes. Conversely, never delete the include line from a program that uses <code>PRINT</code>, <code>PUTC</code> or <code>PRINTN</code>.</p>
<h2>Next steps</h2>
<p>Input and output without macros are covered in <a href="https://emu8086emulator.com/emu8086-int-21h-input-output/">INT 21h input and output</a>, and the subroutine alternative is <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutines and the stack</a>. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> lists the underlying instructions, and the <a href="https://emu8086emulator.com/">home page</a> is the series index.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Subroutines and the Stack in 8086 Assembly (CALL, RET, PUSH, POP)</title>
		<link>https://emu8086emulator.com/emu8086-subroutines-stack/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:36:43 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-subroutines-stack/</guid>

					<description><![CDATA[As programs grow, the same block of code is needed in several places. Copying it everywhere is error-prone; calling it as a subroutine is not. This tutorial explains the two mechanisms that make subroutines work: CALL and RET for the jump there and back, and PUSH and POP for saving values on the stack. It...]]></description>
										<content:encoded><![CDATA[<p>As programs grow, the same block of code is needed in several places. Copying it everywhere is error-prone; calling it as a subroutine is not. This tutorial explains the two mechanisms that make subroutines work: <code>CALL</code> and <code>RET</code> for the jump there and back, and <code>PUSH</code> and <code>POP</code> for saving values on the stack. It builds on <a href="https://emu8086emulator.com/emu8086-mov-add-sub/">MOV, ADD and SUB</a>, and Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>CALL and RET are a matched pair</h2>
<p><code>CALL</code> jumps to a subroutine and, crucially, pushes the return address onto the stack first. <code>RET</code> at the end of the subroutine pops that address back and jumps to it, so execution continues just after the <code>CALL</code>. Every <code>CALL</code> must be matched by a <code>RET</code> on every path through the subroutine. A subroutine that falls off the end without a <code>RET</code> will jump to whatever value happens to sit on the stack, which is one of the most confusing bugs in assembly language.</p>
<h2>PUSH and POP save values</h2>
<p>The stack is a last-in, first-out store. <code>PUSH</code> puts a value on it and moves the stack pointer; <code>POP</code> takes the most recently pushed value back. That is how a routine protects a register it needs to use, and how the sorting example in this series protects CX across an inner loop. Pushes and pops must balance: an extra push without a matching pop leaves the stack pointer wrong, and the next <code>RET</code> will return to the wrong address.</p>
<h2>The complete program</h2>
<p>The program below adds 7 and 5 in a subroutine, saves that result on the stack while AX is reused, then adds it to 3. Follow the stack pointer in the emulator while single-stepping: it should move on the <code>CALL</code>, the <code>PUSH</code> and the <code>POP</code>, and return to its starting value by the final <code>RET</code>.</p>
<pre>ORG 100h

MOV AX, 7
MOV BX, 5
CALL add_two
MOV CX, AX
PUSH CX
MOV AX, 3
POP BX
ADD AX, BX
RET

add_two PROC
ADD AX, BX
RET
add_two ENDP</pre>
<h2>What you should see</h2>
<p>After the <code>CALL</code>, AX should hold 12, because the subroutine added BX (5) to AX (7). CX then holds 12, and after the push, reuse of AX and pop, BX holds 12 again while AX holds 3. The final <code>ADD</code> gives AX equal to 15. If AX ends up as something else, the most likely cause is an unbalanced push and pop, so watch the stack pointer value at the start and at the end: in a correct run it is the same.</p>
<h2>Passing values in registers</h2>
<p>This example passes its inputs in AX and BX and returns its answer in AX. That convention, inputs in named registers and the result in a named register, is the simplest calling convention and the right one for beginner programs. Larger programs sometimes pass values on the stack instead, but the principle is the same: the caller and the subroutine must agree, in advance, on where each value lives.</p>
<h2>Next steps</h2>
<p>Macros look similar but work differently: <a href="https://emu8086emulator.com/emu8086-macros-emu8086-inc/">macros and emu8086.inc</a> explain the difference. For the debugging techniques that catch unbalanced stacks, see <a href="https://emu8086emulator.com/emu8086-step-debugging/">step debugging</a>. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> covers <code>CALL</code>, <code>RET</code>, <code>PUSH</code> and <code>POP</code>, and the <a href="https://emu8086emulator.com/">home page</a> links the whole series.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Sorting Numbers in 8086 Assembly: A Worked Example</title>
		<link>https://emu8086emulator.com/emu8086-sorting-numbers/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:36:28 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-sorting-numbers/</guid>

					<description><![CDATA[Sorting is the classic first array algorithm, and bubble sort is the easiest to trace by hand. It works by repeatedly comparing neighbouring numbers and swapping any pair that is out of order. After enough passes, the smallest values have bubbled to the front. You should already be comfortable with arrays and strings and loops...]]></description>
										<content:encoded><![CDATA[<p>Sorting is the classic first array algorithm, and bubble sort is the easiest to trace by hand. It works by repeatedly comparing neighbouring numbers and swapping any pair that is out of order. After enough passes, the smallest values have bubbled to the front. You should already be comfortable with <a href="https://emu8086emulator.com/emu8086-arrays-strings/">arrays and strings</a> and <a href="https://emu8086emulator.com/emu8086-branches-loops/">loops</a> before this one. Emu8086 setup is in the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>The idea, in one paragraph</h2>
<p>Each pass walks the array from left to right, comparing each pair of neighbours. Whenever the left number is larger than the right one, the two are swapped. After one full pass, the largest number has reached the end. Repeating the pass for the remaining elements eventually leaves the whole array in ascending order. The code below uses four passes for a five-element array, which is more than strictly necessary but keeps the loop structure simple and easy to trace.</p>
<h2>The complete program</h2>
<p>Read the inner loop first: it compares the two bytes SI points at, swaps them if they are out of order, then moves SI on. The outer loop repeats that walk. CX is saved on the stack around the inner loop because both loops need CX; the stack handling is explained in full in the <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutines and stack tutorial</a>.</p>
<pre>ORG 100h

MOV CX, 4
outer_loop:
PUSH CX
LEA SI, arr
MOV CX, 4
inner_loop:
MOV AL, [SI]
MOV BL, [SI+1]
CMP AL, BL
JBE no_swap
MOV [SI], BL
MOV [SI+1], AL
no_swap:
INC SI
LOOP inner_loop
POP CX
LOOP outer_loop
RET

arr DB 5, 2, 8, 1, 9</pre>
<h2>Trace it by hand</h2>
<p>Start: 5, 2, 8, 1, 9. First pass: 5 and 2 swap to 2, 5; 5 and 8 stay; 8 and 1 swap to 1, 8; 8 and 9 stay. After pass one the array is 2, 5, 1, 8, 9. Second pass gives 2, 1, 5, 8, 9. Third pass gives 1, 2, 5, 8, 9. The fourth pass changes nothing, which is how you know the array is sorted. You should see exactly those intermediate states if you set a breakpoint at the <code>POP CX</code> line and inspect memory after each pass.</p>
<h2>What you should see at the end</h2>
<p>After the program finishes, the five bytes at <code>arr</code> should read 1, 2, 5, 8, 9 in order. If the last element looks wrong, check the inner-loop count: with five elements there are four neighbouring pairs per pass, so the inner loop must run four times, not five. Running it five times reads one byte past the end of the array and can corrupt the byte that follows it.</p>
<h2>Ways to break it on purpose</h2>
<ul>
<li>Change the array to 9, 8, 7, 6, 5 and trace the worst case: every pair swaps.</li>
<li>Change the array to an already-sorted list and confirm that no swaps happen but the passes still run.</li>
<li>Try a duplicate value, such as 3, 3, 1, and check that equal neighbours are left alone by the <code>JBE</code> test.</li>
</ul>
<h2>Next steps</h2>
<p>Bubble sort uses the stack to protect CX; <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutines and the stack</a> explain that mechanism properly. To revisit the basics, see <a href="https://emu8086emulator.com/emu8086-arrays-strings/">arrays and strings</a>. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> covers <code>CMP</code> and the conditional jumps, and the <a href="https://emu8086emulator.com/">home page</a> is the series index.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Arrays and Strings in 8086 Assembly</title>
		<link>https://emu8086emulator.com/emu8086-arrays-strings/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:36:13 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-arrays-strings/</guid>

					<description><![CDATA[An array is just a row of bytes (or words) in memory, and a string is an array of characters. Both are handled the same way in 8086 assembly: point an index register at the first element and step through it. This tutorial assumes you know branches and loops and have Emu8086 installed; see the...]]></description>
										<content:encoded><![CDATA[<p>An array is just a row of bytes (or words) in memory, and a string is an array of characters. Both are handled the same way in 8086 assembly: point an index register at the first element and step through it. This tutorial assumes you know <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops</a> and have Emu8086 installed; see the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>Defining an array</h2>
<p>The <code>DB</code> directive lays bytes down one after another. The label in front of it is the address of the first byte, and the following bytes sit at the next addresses. There is no length stored anywhere: your program has to know, or count, how many elements there are.</p>
<h2>Summing an array</h2>
<p>The program below adds the five numbers in <code>numbers</code> and leaves the total in AX. SI starts at the first element, CX counts the elements, and each pass adds the byte SI points at, then moves SI on by one. Note the order: the value is added before SI is incremented, so the first element is not skipped.</p>
<pre>ORG 100h

LEA SI, numbers
MOV CX, 5
XOR AX, AX
add_next:
ADD AL, [SI]
INC SI
LOOP add_next
RET

numbers DB 3, 1, 4, 1, 5</pre>
<h2>What you should see</h2>
<p>AX should end at 14, which is 3 + 1 + 4 + 1 + 5. If you get a different total, the usual cause is an off-by-one error: either SI was incremented before the first add, so the first element was missed, or CX was loaded with the wrong count. Single-step the first two passes and check SI and AL after each one.</p>
<h2>Printing a string character by character</h2>
<p>A string printed with DOS function 02h needs one character at a time in DL. The loop below walks a string that ends with a zero byte, printing each character until it reaches that terminator. The zero byte itself is never printed, because the loop tests for it first. This version uses no macros, so it needs no include line.</p>
<pre>ORG 100h

LEA SI, text
print_next:
MOV DL, [SI]
CMP DL, 0
JE finished
MOV AH, 02h
INT 21h
INC SI
JMP print_next
finished:
RET

text DB &#x27;Hi, 8086!&#x27;, 0</pre>
<h2>What you should see</h2>
<p>The emulator window should show <code>Hi, 8086!</code> and nothing after it. If extra characters appear, the string probably has no zero terminator, so the loop ran on into whatever bytes followed it. If nothing appears, check that SI was loaded with the address of the string and that DL, not AL, carries each character into function 02h.</p>
<h2>Arrays of words, briefly</h2>
<p>A word array uses <code>DW</code> instead of <code>DB</code>, and each element is two bytes, so SI must advance by two per element instead of one. The pattern is identical; only the step size changes. Mixing the two up, stepping by one through a word array, reads the high byte of one element as if it were the next element, and the results look mysteriously halved or doubled.</p>
<h2>Next steps</h2>
<p>Sorting is the natural next exercise: <a href="https://emu8086emulator.com/emu8086-sorting-numbers/">sorting numbers</a> rearranges an array in place. For the ideas behind the loop, revisit <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops</a>. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> covers the addressing modes used here, and the <a href="https://emu8086emulator.com/">home page</a> links the full series.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Branches and Loops in 8086 Assembly (JMP, conditional jumps, LOOP)</title>
		<link>https://emu8086emulator.com/emu8086-branches-loops/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:35:59 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-branches-loops/</guid>

					<description><![CDATA[So far every program in this series has run straight from top to bottom. Real programs branch: they choose a path, repeat a block, or skip one. This tutorial covers the three mechanisms that make that possible. It builds on MOV, ADD and SUB and the flags they set, and it assumes Emu8086 is installed;...]]></description>
										<content:encoded><![CDATA[<p>So far every program in this series has run straight from top to bottom. Real programs branch: they choose a path, repeat a block, or skip one. This tutorial covers the three mechanisms that make that possible. It builds on <a href="https://emu8086emulator.com/emu8086-mov-add-sub/">MOV, ADD and SUB</a> and the flags they set, and it assumes Emu8086 is installed; see the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>Unconditional jumps</h2>
<p><code>JMP</code> always goes to its label. It is the simplest branch and also the easiest to misuse: a program full of unconditional jumps quickly becomes hard to follow, so use it for a clear purpose, such as skipping over a block or jumping to a shared ending.</p>
<h2>Conditional jumps read the flags</h2>
<p>Instructions such as <code>JE</code>, <code>JNE</code>, <code>JG</code> and <code>JL</code> jump only when the flags say so. They are almost always paired with a <code>CMP</code>, which subtracts without storing the result, purely to set the flags. The example below sets BL to 1 when AL equals 10 and to 0 otherwise. Step through it twice: once with AL equal to 10, once with a different value, by editing the first instruction.</p>
<pre>ORG 100h

MOV AL, 10
CMP AL, 10
JE is_ten
MOV BL, 0
JMP done
is_ten:
MOV BL, 1
done:
RET</pre>
<h2>What you should see</h2>
<p>With AL equal to 10, the jump is taken, the <code>MOV BL, 0</code> line is skipped, and BL ends up as 1. With AL equal to anything else, the jump is not taken, BL is set to 0, and the <code>JMP done</code> skips over the <code>is_ten</code> block. If BL ends up wrong, check that no <code>MOV</code> sits between the <code>CMP</code> and the jump and accidentally hides the flags you meant to test; <code>MOV</code> itself does not change the flags, but a stray arithmetic instruction between them would.</p>
<h2>Counted loops with LOOP</h2>
<p>The <code>LOOP</code> instruction decrements CX and jumps back while CX is not zero. It is made for counted repetition. The program below adds 5, 4, 3, 2 and 1, so the total should be 15. Watch CX fall on each pass and AX grow.</p>
<pre>ORG 100h

MOV CX, 5
XOR AX, AX
add_next:
ADD AX, CX
LOOP add_next
RET</pre>
<h2>What you should see</h2>
<p>AX should end at 15 and CX at 0. Two details are worth noting. First, <code>LOOP</code> itself does not set the flags, so do not test the zero flag right after a loop expecting it to reflect CX. Second, if CX starts at 0, <code>LOOP</code> wraps it to a very large value and the loop runs a very long time, so always check that CX is loaded before the loop starts.</p>
<h2>Choosing between the three</h2>
<ul>
<li>Use <code>JMP</code> when the path is unconditional, such as skipping a block.</li>
<li>Use a <code>CMP</code> plus a conditional jump when the path depends on a value.</li>
<li>Use <code>LOOP</code> with CX when you know in advance how many times a block must run.</li>
</ul>
<h2>Next steps</h2>
<p>Loops over data are next in <a href="https://emu8086emulator.com/emu8086-arrays-strings/">arrays and strings</a>, and <a href="https://emu8086emulator.com/emu8086-subroutines-stack/">subroutines and the stack</a> show how a repeated block becomes a callable routine. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> covers every jump condition, and the <a href="https://emu8086emulator.com/">home page</a> is the series index.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MOV, ADD and SUB in 8086 Assembly: A Practical Guide</title>
		<link>https://emu8086emulator.com/emu8086-mov-add-sub/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:35:41 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-mov-add-sub/</guid>

					<description><![CDATA[Three instructions carry most beginner programs: MOV copies a value, ADD adds to it and SUB subtracts from it. They look trivial, and that is exactly why they deserve a careful tutorial: almost every later bug is a misunderstanding of one of these three. You need Emu8086 installed first; see the install guide. MOV copies,...]]></description>
										<content:encoded><![CDATA[<p>Three instructions carry most beginner programs: <code>MOV</code> copies a value, <code>ADD</code> adds to it and <code>SUB</code> subtracts from it. They look trivial, and that is exactly why they deserve a careful tutorial: almost every later bug is a misunderstanding of one of these three. You need Emu8086 installed first; see the <a href="https://emu8086emulator.com/how-to-install-emu8086/">install guide</a>.</p>
<h2>MOV copies, it does not move</h2>
<p>Despite its name, <code>MOV</code> leaves the source unchanged and overwrites the destination. <code>MOV AX, BX</code> makes AX equal to BX, and BX keeps its old value. There is one famous restriction: you cannot move one memory location directly to another. At least one side of a <code>MOV</code> must be a register.</p>
<h2>Adding and subtracting with numbers in memory</h2>
<p>The program below adds two numbers stored after the code and leaves the answer in a third variable. Because the program ends with <code>RET</code>, the data after it is never executed as code. Step through it and watch AL change at each arithmetic instruction.</p>
<pre>ORG 100h

MOV AL, num1
ADD AL, num2
MOV result, AL
RET

num1   DB 10
num2   DB 25
result DB 0</pre>
<h2>What you should see</h2>
<p>After the program runs, the <code>result</code> byte should hold 35. In the register window, AL should also hold 35 at the moment <code>RET</code> executes. If you change <code>num1</code> and <code>num2</code> and re-run, the result should follow: for example 20 and 7 give 27.</p>
<h2>Flags: the part beginners skip</h2>
<p><code>ADD</code> and <code>SUB</code> update the flags; <code>MOV</code> does not. That matters as soon as you branch: a conditional jump after a <code>MOV</code> tests the flags left by some earlier instruction, not the move you just did. If a jump behaves oddly, check whether a <code>MOV</code> sits between the comparison and the jump. The <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops tutorial</a> builds on exactly this point.</p>
<h2>Subtraction and borrowing</h2>
<p>The program below subtracts 3 from 10, then subtracts a larger number from a smaller one so you can see the borrow in action. The second result wraps around in unsigned arithmetic, which is normal 8-bit behaviour, not an error in the emulator.</p>
<pre>ORG 100h

MOV AL, 10
SUB AL, 3
MOV BL, AL
MOV AL, 3
SUB AL, 10
RET</pre>
<h2>What you should see</h2>
<p>BL should hold 7 after the first subtraction. After the second subtraction, AL should hold the wrapped-around value for 3 minus 10 in 8 bits, and the carry flag should be set, signalling the borrow. That flag is what a later <code>JB</code> or <code>JAE</code> instruction would test.</p>
<h2>Next steps</h2>
<p>Continue with <a href="https://emu8086emulator.com/emu8086-branches-loops/">branches and loops</a>, where these flag effects decide which path a program takes, and <a href="https://emu8086emulator.com/emu8086-registers-segments/">registers and segments</a> if any register behaviour above surprised you. The <a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">opcode reference</a> lists the flag effects of each instruction, and the <a href="https://emu8086emulator.com/">home page</a> links the whole series.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
