<?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>Reference &#8211; Emu8086</title>
	<atom:link href="https://emu8086emulator.com/reference/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:27:39 +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>Reference &#8211; Emu8086</title>
	<link>https://emu8086emulator.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Robot Arm Simulation in Emu8086: A Worked Example</title>
		<link>https://emu8086emulator.com/emu8086-robot-arm-simulation/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:25:35 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-robot-arm-simulation/</guid>

					<description><![CDATA[Emu8086 ships with a built-in Robot virtual device, and it is the device students usually mean when they search for a robot simulation in the emulator. A note on the name first: the built-in device is called Robot, and it is a small mobile robot moving around a map, turning, examining objects and switching lamps...]]></description>
										<content:encoded><![CDATA[<p>Emu8086 ships with a built-in Robot virtual device, and it is the device students usually mean when they search for a robot simulation in the emulator. A note on the name first: the built-in device is called Robot, and it is a small mobile robot moving around a map, turning, examining objects and switching lamps on and off. It is not a jointed arm with shoulder and elbow joints. This post covers the device the emulator actually provides, with its real commands, so the code here runs as written.</p>
<h2>How the device is controlled</h2>
<p>Open the device from the emulator&#8217;s virtual devices menu before you run your program. You can edit its map from the device&#8217;s toolbox: place the robot, walls and lamps, and the map is saved automatically when the device closes. The robot uses three ports:</p>
<table>
<thead>
<tr>
<th>Port</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>9</td>
<td>Command register: write a command byte here.</td>
</tr>
<tr>
<td>10</td>
<td>Data register: read the result of an examine command here.</td>
</tr>
<tr>
<td>11</td>
<td>Status register: read the robot&#8217;s state here.</td>
</tr>
</tbody>
</table>
<h2>The command set</h2>
<table>
<thead>
<tr>
<th>Value</th>
<th>Command</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>Do nothing.</td>
</tr>
<tr>
<td>1</td>
<td>Move forward one step.</td>
</tr>
<tr>
<td>2</td>
<td>Turn left.</td>
</tr>
<tr>
<td>3</td>
<td>Turn right.</td>
</tr>
<tr>
<td>4</td>
<td>Examine: sense the object in front and report it in the data register.</td>
</tr>
<tr>
<td>5</td>
<td>Switch on a lamp.</td>
</tr>
<tr>
<td>6</td>
<td>Switch off a lamp.</td>
</tr>
</tbody>
</table>
<p>The examine results reported in the data register are 255 for a wall, 0 for nothing, 7 for a switched-on lamp, and 8 for a switched-off lamp. The status register reports three things in its low bits: bit 0 is set when new data is waiting in the data register, bit 1 is set while the robot is busy, and bit 2 is set when the last command ended in an error, for example trying to move into a wall.</p>
<h2>The rule you must not skip: wait until it is ready</h2>
<p>The robot is a mechanical creature in the simulation and takes time to finish each task. Always check bit 1 of the status register before sending the next command, or the robot rejects the command and reports busy. The standard wait loop polls port 11:</p>
<pre>wait_ready PROC
wait_loop:
IN AL, 11
TEST AL, 00000010b   ; bit 1: 1 means busy
JNZ wait_loop        ; still busy: keep waiting
RET
wait_ready ENDP</pre>
<h2>Worked example: move, turn, examine</h2>
<p>This example moves forward, turns right, moves forward again, turns left, and then examines what is in front of the robot. After the examine command, it reads the data register; a program that went further would compare that value with 255, 0, 7 or 8 and branch accordingly, using the comparison and jump techniques from the <a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP</a> and <a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP</a> posts.</p>
<pre>ORG 100h

CALL wait_ready
MOV AL, 1            ; move forward
OUT 9, AL
CALL wait_ready
MOV AL, 3            ; turn right
OUT 9, AL
CALL wait_ready
MOV AL, 1            ; move forward
OUT 9, AL
CALL wait_ready
MOV AL, 2            ; turn left
OUT 9, AL
CALL wait_ready
MOV AL, 4            ; examine what is in front
OUT 9, AL
CALL wait_ready

; The examine result is now in the data register.
IN AL, 10
; AL = 255 (wall), 0 (nothing), 7 (lamp on) or 8 (lamp off).
RET

wait_ready PROC
wait_loop:
IN AL, 11
TEST AL, 00000010b
JNZ wait_loop
RET
wait_ready ENDP</pre>
<p>If a command is rejected, check the two usual causes: the previous command had not finished and the wait loop was skipped, or the map has no robot placed on it, in which case the device places one at a random position and the robot&#8217;s starting direction is not the one you assumed. Place the robot deliberately in the map editor before running, and the example behaves predictably.</p>
<p>For the simpler devices that lead up to this one, see the <a href="https://emu8086emulator.com/emu8086-traffic-light-simulation/">traffic light simulation</a> and the <a href="https://emu8086emulator.com/emu8086-stepper-motor-simulation/">stepper motor simulation</a>. For what changes when the robot stops being virtual, read <a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">from simulation to real hardware</a>.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-traffic-light-simulation/">Traffic Light Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/emu8086-stepper-motor-simulation/">Stepper Motor Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">From Simulation to Real Hardware: A Kit Guide</a></li>
<li><a href="https://emu8086emulator.com/emu8086-interrupt-table-10h-16h-21h/">8086 Interrupt Table: INT 10h, INT 16h and INT 21h</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Stepper Motor Simulation in Emu8086: A Worked Example</title>
		<link>https://emu8086emulator.com/emu8086-stepper-motor-simulation/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:25:23 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-stepper-motor-simulation/</guid>

					<description><![CDATA[Emu8086 ships with a built-in Stepper Motor virtual device: a simple three-phase motor that turns through a precise angle each time it receives a pulse pattern. It is the standard next step after the traffic lights, because it adds direction, speed and a status read to the output-only pattern you already know. How the device...]]></description>
										<content:encoded><![CDATA[<p>Emu8086 ships with a built-in Stepper Motor virtual device: a simple three-phase motor that turns through a precise angle each time it receives a pulse pattern. It is the standard next step after the traffic lights, because it adds direction, speed and a status read to the output-only pattern you already know.</p>
<h2>How the device is controlled</h2>
<p>Open the device from the emulator&#8217;s virtual devices menu before you run your program. The motor is controlled by sending a byte to <strong>I/O port 7</strong>. Only bits 0, 1 and 2 of the byte are used; they drive the motor&#8217;s three magnets, and bits 3 to 7 are unused. When a magnet is energised it is shown in red, and an arrow shows the direction of the last move. The motor turns by varying the rate at which pulse patterns are sent, so speed is controlled by the delay between outputs, exactly as with the traffic lights.</p>
<p>The emulator&#8217;s documentation gives the starting sequence for three clockwise half-steps, and it is the right place to begin:</p>
<pre>MOV AL, 001b ; initialize.
OUT 7, AL
MOV AL, 011b ; half step 1.
OUT 7, AL
MOV AL, 010b ; half step 2.
OUT 7, AL
MOV AL, 110b ; half step 3.
OUT 7, AL</pre>
<p>The same documentation points to the bundled example file stepper_motor.asm in the emulator&#8217;s examples folder. Open it alongside this post: it shows the sequence extended into continuous rotation, and it is the reference to check any pattern against.</p>
<h2>Reading readiness: the top bit of port 7</h2>
<p>The motor also talks back. Reading port 7 with IN returns a byte whose topmost bit is set when the motor is ready for the next pattern. A careful program checks that bit before sending the next step, rather than assuming a fixed delay was long enough:</p>
<pre>wait_ready:
IN AL, 7
TEST AL, 10000000b   ; is the top bit set?
JZ wait_ready        ; no: keep waiting</pre>
<p>TEST sets the flags without changing AL, so this polling loop is a clean use of the flag behaviour covered in the <a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP</a> post.</p>
<h2>Worked example: rotate, then reverse</h2>
<p>This example steps through the documented half-step patterns in a loop, then runs the same patterns in reverse order to turn the motor the other way. Reversing the sequence is how direction is controlled: there is no separate direction command, the order of the patterns is the direction.</p>
<pre>ORG 100h

MOV CX, 20           ; twenty steps forward
forward:
MOV AL, 001b
OUT 7, AL
CALL delay
MOV AL, 011b
OUT 7, AL
CALL delay
MOV AL, 010b
OUT 7, AL
CALL delay
MOV AL, 110b
OUT 7, AL
CALL delay
LOOP forward

MOV CX, 20           ; twenty steps back, patterns reversed
backward:
MOV AL, 110b
OUT 7, AL
CALL delay
MOV AL, 010b
OUT 7, AL
CALL delay
MOV AL, 011b
OUT 7, AL
CALL delay
MOV AL, 001b
OUT 7, AL
CALL delay
LOOP backward
RET

delay PROC
PUSH CX
MOV CX, 0FFFFh
wait_loop:
LOOP wait_loop
POP CX
RET
delay ENDP</pre>
<p>Two details matter here. First, the delay procedure saves and restores CX, because the outer loop also uses CX as its counter; without the PUSH and POP, the delay would destroy the step count. Second, speed is the delay length: a longer delay means slower, more visible steps, and a shorter delay means faster rotation, up to the point where the motor cannot keep up and steps are missed.</p>
<h2>Common mistakes</h2>
<ul>
<li>Sending patterns too fast without a delay, so the motor appears not to move at all.</li>
<li>Changing only one bit at a time in the wrong order, which produces vibration instead of rotation. Follow the documented half-step order.</li>
<li>Letting a delay routine overwrite CX, SI or another register the caller is using. Save what you use.</li>
</ul>
<p>For the wider picture, compare this output-only-plus-status device with the <a href="https://emu8086emulator.com/emu8086-traffic-light-simulation/">traffic light simulation</a>, and read <a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">from simulation to real hardware</a> for what changes when a real motor, driver circuit and power supply replace the simulated window.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-traffic-light-simulation/">Traffic Light Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/emu8086-robot-arm-simulation/">Robot Arm Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">From Simulation to Real Hardware: A Kit Guide</a></li>
<li><a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP in 8086 Assembly</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Traffic Light Simulation in Emu8086: A Worked Example</title>
		<link>https://emu8086emulator.com/emu8086-traffic-light-simulation/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:25:09 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-traffic-light-simulation/</guid>

					<description><![CDATA[Emu8086 ships with a built-in Traffic Lights virtual device: a four-way junction with twelve lamps, four green, four yellow and four red. It is the standard first virtual-hardware exercise because the whole interface is a single output instruction, yet it forces you to think about bit patterns, timing loops and sequencing, the same skills real...]]></description>
										<content:encoded><![CDATA[<p>Emu8086 ships with a built-in Traffic Lights virtual device: a four-way junction with twelve lamps, four green, four yellow and four red. It is the standard first virtual-hardware exercise because the whole interface is a single output instruction, yet it forces you to think about bit patterns, timing loops and sequencing, the same skills real embedded code needs.</p>
<h2>How the device is controlled</h2>
<p>Open the device from the emulator&#8217;s virtual devices menu before you run your program, so the lamps are visible while the code executes. The device is controlled by sending a word to <strong>I/O port 4</strong>. Only the low twelve bits of the word are used, one bit per lamp: a bit set to 1 turns its lamp on, and a bit set to 0 turns it off. The top four bits are unused. You write the word with the OUT instruction:</p>
<pre>MOV AX, 0000001011110100b
OUT 4, AX</pre>
<p>That example pattern comes from the emulator&#8217;s own documentation for the device. The same documentation points to the bundled example file traffic_lights.asm in the emulator&#8217;s examples folder, which is worth opening alongside this post: it shows a full junction sequence, and watching its patterns change is the fastest way to learn which bit drives which lamp in your copy of the device. Run a pattern, look at the lamps, and write down the mapping you observe rather than memorising a table from a web page.</p>
<h2>Worked example: two states, alternating with a delay</h2>
<p>A traffic light program is a loop of three steps: output a pattern, wait, output the next pattern. The delay is a nested counting loop, because the emulator has no sleep call for this device. This example alternates two patterns so you can see the mechanism clearly before building a full junction cycle:</p>
<pre>ORG 100h

cycle:
; State 1: one pattern of lamps on.
MOV AX, 0000001011110100b
OUT 4, AX
CALL delay

; State 2: a different pattern of lamps on.
MOV AX, 0000000100001011b
OUT 4, AX
CALL delay

JMP cycle            ; run the junction forever
RET

; A simple delay: two nested counters.
delay PROC
PUSH CX
PUSH DX
MOV CX, 0FFFFh
wait_outer:
MOV DX, 0FFFFh
wait_inner:
DEC DX
JNZ wait_inner
DEC CX
JNZ wait_outer
POP DX
POP CX
RET
delay ENDP</pre>
<p>The delay length is set by the counter values, not by seconds, so the same code runs at different visible speeds on different machines. Shorten the counters if the cycle changes too slowly, lengthen them if it changes too fast. If the lamps never change, the usual causes are that the device window was not opened before running, or that the program was assembled as a different template that never reaches the OUT instruction.</p>
<h2>Building a full junction cycle</h2>
<p>Once the two-state example runs, extend it one state at a time: one direction green while the others are red, then yellow as a warning, then red, then the next direction. Keep each state as one OUT followed by one delay call, and keep a written list of which pattern means which state, because twelve bits are easy to confuse once you have six or eight states. Test each new state on its own before adding it to the cycle, so a wrong pattern is caught when it appears rather than after the whole sequence is built.</p>
<h2>From simulation to real hardware</h2>
<p>The ideas transfer directly: a real junction controller also outputs bit patterns to lamps and waits between states, except that its outputs drive real circuits through driver hardware instead of a simulated window. The companion guide <a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">from simulation to real hardware</a> covers what changes when the lamps stop being virtual. For the instruction set behind OUT, see the <a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV</a> and <a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP</a> posts, and for the bit-level thinking, see <a href="https://emu8086emulator.com/emu8086-addressing-modes-flags/">addressing modes and flags</a>.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-stepper-motor-simulation/">Stepper Motor Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/emu8086-robot-arm-simulation/">Robot Arm Simulation in Emu8086</a></li>
<li><a href="https://emu8086emulator.com/simulation-to-real-hardware-kit-guide/">From Simulation to Real Hardware: A Kit Guide</a></li>
<li><a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP in 8086 Assembly</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>8086 Addressing Modes and Flags Explained</title>
		<link>https://emu8086emulator.com/emu8086-addressing-modes-flags/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:24:57 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-addressing-modes-flags/</guid>

					<description><![CDATA[Two ideas sit underneath almost every 8086 instruction: how an operand names its data, and what the flags record about the last result. Addressing modes answer the first question. The flags register answers the second. This post covers both, because they are constantly used together: a comparison uses an addressing mode to fetch its operands,...]]></description>
										<content:encoded><![CDATA[<p>Two ideas sit underneath almost every 8086 instruction: how an operand names its data, and what the flags record about the last result. Addressing modes answer the first question. The flags register answers the second. This post covers both, because they are constantly used together: a comparison uses an addressing mode to fetch its operands, and a jump reads the flags the comparison left behind.</p>
<h2>Segmented addresses: segment times sixteen plus offset</h2>
<p>An 8086 address has two parts, a segment and an offset, and the physical address is the segment multiplied by 16 plus the offset. DS:1234h with DS equal to 1000h therefore addresses physical address 11234h. By default, BX, SI and DI use DS, while BP uses SS; a segment override prefix such as ES: or CS: changes the default for that one instruction. Forgetting the default segment of BP is a reliable source of bugs in stack-based code.</p>
<h2>The addressing modes</h2>
<table>
<thead>
<tr>
<th>Mode</th>
<th>Example</th>
<th>What it means</th>
</tr>
</thead>
<tbody>
<tr>
<td>Immediate</td>
<td><code>MOV AX, 1234h</code></td>
<td>The value is in the instruction.</td>
</tr>
<tr>
<td>Register</td>
<td><code>MOV AX, BX</code></td>
<td>The value is in a register.</td>
</tr>
<tr>
<td>Direct</td>
<td><code>MOV AX, [1234h]</code></td>
<td>The value is at a fixed memory address.</td>
</tr>
<tr>
<td>Register indirect</td>
<td><code>MOV AX, [BX]</code></td>
<td>The register holds the address.</td>
</tr>
<tr>
<td>Based</td>
<td><code>MOV AX, [BX+10]</code></td>
<td>Base register plus a displacement.</td>
</tr>
<tr>
<td>Indexed</td>
<td><code>MOV AX, [SI+10]</code></td>
<td>Index register plus a displacement.</td>
</tr>
<tr>
<td>Base plus index</td>
<td><code>MOV AX, [BX+SI+10]</code></td>
<td>Base plus index plus displacement, the form used for arrays and tables.</td>
</tr>
<tr>
<td>Implied</td>
<td><code>STOSB</code>, <code>LOOP</code></td>
<td>The operand is fixed by the instruction itself.</td>
</tr>
</tbody>
</table>
<h2>Worked example: walking an array with base plus index</h2>
<pre>ORG 100h

LEA BX, table        ; BX = base address of the table
MOV SI, 0            ; SI = index into the table
MOV CX, 5            ; five entries to add
MOV AX, 0            ; running total
add_next:
ADD AL, [BX+SI]      ; fetch table[SI] and add it
INC SI               ; move to the next entry
LOOP add_next
; AL now holds the sum of the five bytes.
RET

table DB 10, 20, 30, 40, 50</pre>
<p>The same [BX+SI] pattern works for any table: change BX to point at a different table, or change SI to pick a different entry, and the instruction does not change. That separation of base and index is the whole point of the mode.</p>
<h2>The flags register, bit by bit</h2>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Bit</th>
<th>Set when</th>
</tr>
</thead>
<tbody>
<tr>
<td>CF (carry)</td>
<td>0</td>
<td>An arithmetic result carries out of, or borrows into, the top bit.</td>
</tr>
<tr>
<td>PF (parity)</td>
<td>2</td>
<td>The low byte of the result has an even number of set bits.</td>
</tr>
<tr>
<td>AF (auxiliary carry)</td>
<td>4</td>
<td>There is a carry out of bit 3, used by decimal adjust instructions.</td>
</tr>
<tr>
<td>ZF (zero)</td>
<td>6</td>
<td>The result is zero.</td>
</tr>
<tr>
<td>SF (sign)</td>
<td>7</td>
<td>The top bit of the result is set, so the result looks negative as a signed value.</td>
</tr>
<tr>
<td>TF (trap)</td>
<td>8</td>
<td>Single-step debugging is enabled.</td>
</tr>
<tr>
<td>IF (interrupt)</td>
<td>9</td>
<td>Maskable hardware interrupts are enabled; cleared by CLI, set by STI.</td>
</tr>
<tr>
<td>DF (direction)</td>
<td>10</td>
<td>String instructions auto-decrement (set by STD) instead of auto-increment (cleared by CLD).</td>
</tr>
<tr>
<td>OF (overflow)</td>
<td>11</td>
<td>A signed result is too large for its destination size.</td>
</tr>
</tbody>
</table>
<h2>Which instructions affect which flags</h2>
<p>MOV affects no flags at all. ADD, SUB and CMP affect OF, SF, ZF, AF, PF and CF. INC and DEC affect all of those except CF. Shifts and rotates affect CF and OF in ways that depend on the count, and the logic instructions AND, OR, XOR and TEST clear CF and OF and set SF, ZF and PF from the result. The practical rule is to place the jump immediately after the instruction whose flags it reads, and to check the table whenever another instruction sits in between.</p>
<p>For the jumps that read these flags, see the <a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP</a> post, and for the arithmetic that sets them, see <a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP</a>.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP in 8086 Assembly</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>8086 Interrupt Table: INT 10h, INT 16h and INT 21h Explained</title>
		<link>https://emu8086emulator.com/emu8086-interrupt-table-10h-16h-21h/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:24:45 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-interrupt-table-10h-16h-21h/</guid>

					<description><![CDATA[An interrupt is a detour with a return address. When a program executes INT n, the processor saves the flags, the code segment and the instruction pointer, looks up entry n in the interrupt vector table, and jumps to the handler it finds there. When the handler finishes with IRET, execution resumes exactly where it...]]></description>
										<content:encoded><![CDATA[<p>An interrupt is a detour with a return address. When a program executes INT n, the processor saves the flags, the code segment and the instruction pointer, looks up entry n in the interrupt vector table, and jumps to the handler it finds there. When the handler finishes with IRET, execution resumes exactly where it left off. INT 10h, INT 16h and INT 21h are the three software interrupts students meet first, because they cover the screen, the keyboard and DOS.</p>
<h2>The interrupt vector table</h2>
<p>The table lives at the very start of memory, from address 0000:0000 to 0000:03FFh. It has 256 entries, one for each interrupt number from 0 to 255, and each entry is four bytes: a 16-bit offset followed by a 16-bit segment, giving the full address of the handler. Entry n therefore sits at address n times 4. INT 21h uses entry 21h, which is at 0000:0084h; INT 10h uses entry 10h, at 0000:0040h; INT 16h uses entry 16h, at 0000:0058h. A program can read these entries, and advanced programs can replace them to install their own handlers, but ordinary student code simply calls the handlers that DOS and the BIOS already installed.</p>
<h2>INT 10h: video services</h2>
<table>
<thead>
<tr>
<th>AH</th>
<th>Function</th>
<th>Key registers</th>
</tr>
</thead>
<tbody>
<tr>
<td>00h</td>
<td>Set video mode</td>
<td>Mode number in AL; mode 03h is the standard 80 by 25 text mode and clears the screen.</td>
</tr>
<tr>
<td>02h</td>
<td>Set cursor position</td>
<td>Page in BH, row in DH, column in DL.</td>
</tr>
<tr>
<td>0Eh</td>
<td>Teletype output</td>
<td>Character in AL, page in BH; advances the cursor, honouring carriage return and line feed.</td>
</tr>
<tr>
<td>13h</td>
<td>Write a string</td>
<td>String in ES:BP, length in CX, position in DH/DL, attribute in BL.</td>
</tr>
</tbody>
</table>
<h2>INT 16h: keyboard services</h2>
<table>
<thead>
<tr>
<th>AH</th>
<th>Function</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>00h</td>
<td>Read a keystroke, waiting</td>
<td>ASCII code in AL, scan code in AH; waits until a key is pressed.</td>
</tr>
<tr>
<td>01h</td>
<td>Check for a keystroke</td>
<td>ZF set if no key is waiting; otherwise AL and AH hold the key without removing it from the buffer.</td>
</tr>
<tr>
<td>02h</td>
<td>Get shift flags</td>
<td>AL reports the state of Shift, Ctrl, Alt and the lock keys.</td>
</tr>
</tbody>
</table>
<p>The difference between INT 16h function 00h and function 01h is the difference between a program that waits and a program that polls. A game loop checks with function 01h and keeps animating when no key is waiting; a menu reads with function 00h and simply waits.</p>
<h2>INT 21h: DOS services</h2>
<p>INT 21h is covered in depth in its own post, but the summary belongs here: AH selects a DOS function, with 02h writing a character, 09h printing a &#8216;$&#8217;-terminated string, 01h reading a character with echo, and 4Ch exiting the program. The pattern, function number in AH and parameters in the other registers, is the same pattern INT 10h and INT 16h use, which is why learning one interrupt teaches the shape of all three.</p>
<h2>Worked example: clear the screen, print, wait for a key</h2>
<pre>ORG 100h

MOV AX, 0003h        ; INT 10h, AH=00h: video mode 03h, clears screen
INT 10h

LEA DX, message
MOV AH, 09h          ; INT 21h, AH=09h: print the string
INT 21h

MOV AH, 00h          ; INT 16h, AH=00h: wait for a keypress
INT 16h

MOV AX, 4C00h        ; INT 21h, AH=4Ch: exit
INT 21h

message DB 'Press any key to exit.', 0Dh, 0Ah, '$'
RET</pre>
<h2>Choosing between the three</h2>
<ul>
<li>Use INT 21h for ordinary console input and output and for files.</li>
<li>Use INT 10h when you need the screen itself: clearing it, moving the cursor, or writing at a position.</li>
<li>Use INT 16h when you need keyboard behaviour DOS does not offer, such as polling without blocking, or reading scan codes for keys that have no ASCII code.</li>
</ul>
<p>All three go through the same vector table, all three are selected by AH, and all three return through IRET to the instruction after the INT. Once that shape is clear, the rest is looking up the right function number.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-int-21h-deep-dive/">INT 21h in Depth</a></li>
<li><a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-addressing-modes-flags/">8086 Addressing Modes and Flags Explained</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>INT 21h in Depth: DOS Services Every 8086 Student Uses</title>
		<link>https://emu8086emulator.com/emu8086-int-21h-deep-dive/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:24:33 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-int-21h-deep-dive/</guid>

					<description><![CDATA[INT 21h is the doorway between an 8086 program and DOS. A program puts a function number in AH, puts any parameters in the other registers, executes INT 21h, and DOS does the work: printing, reading the keyboard, opening files, or ending the program. Almost every student program uses a handful of these functions, and...]]></description>
										<content:encoded><![CDATA[<p>INT 21h is the doorway between an 8086 program and DOS. A program puts a function number in AH, puts any parameters in the other registers, executes INT 21h, and DOS does the work: printing, reading the keyboard, opening files, or ending the program. Almost every student program uses a handful of these functions, and understanding the pattern matters more than memorising the whole list.</p>
<h2>How a DOS call works</h2>
<pre>MOV AH, 09h          ; select the function: print a string
LEA DX, message      ; parameter: address of the string
INT 21h              ; DOS runs the function</pre>
<p>Three conventions run through nearly all INT 21h functions. AH selects the function. Input parameters arrive in registers such as DX, BX, CX or AL, and the documentation for each function says exactly which. Results come back in registers, most often AX, and file functions signal an error by setting the carry flag, with an error code in AX. INT 21h itself does not print anything or read anything on its own; it dispatches to the function AH names.</p>
<h2>The functions students use first</h2>
<table>
<thead>
<tr>
<th>AH</th>
<th>Function</th>
<th>Parameters and result</th>
</tr>
</thead>
<tbody>
<tr>
<td>01h</td>
<td>Read a character with echo</td>
<td>Returns the character in AL; waits for a key.</td>
</tr>
<tr>
<td>02h</td>
<td>Write a character</td>
<td>Character in DL; prints it.</td>
</tr>
<tr>
<td>09h</td>
<td>Print a string</td>
<td>DS:DX points to the string, which must end with &#8216;$&#8217;.</td>
</tr>
<tr>
<td>0Ah</td>
<td>Buffered keyboard input</td>
<td>DS:DX points to a buffer whose first byte is its maximum length.</td>
</tr>
<tr>
<td>2Ah</td>
<td>Get the system date</td>
<td>Returns year in CX, month in DH, day in DL.</td>
</tr>
<tr>
<td>2Ch</td>
<td>Get the system time</td>
<td>Returns hours in CH, minutes in CL, seconds in DH.</td>
</tr>
<tr>
<td>4Ch</td>
<td>Exit to DOS</td>
<td>Exit code in AL; the standard way to end a program.</td>
</tr>
</tbody>
</table>
<h2>File functions: the same pattern, with error handling</h2>
<table>
<thead>
<tr>
<th>AH</th>
<th>Function</th>
<th>Key registers</th>
</tr>
</thead>
<tbody>
<tr>
<td>3Dh</td>
<td>Open a file</td>
<td>DS:DX points to the filename, AL is the access mode, handle returns in AX.</td>
</tr>
<tr>
<td>3Eh</td>
<td>Close a file</td>
<td>Handle in BX.</td>
</tr>
<tr>
<td>3Fh</td>
<td>Read from a file</td>
<td>Handle in BX, buffer in DS:DX, count in CX, bytes read return in AX.</td>
</tr>
<tr>
<td>40h</td>
<td>Write to a file</td>
<td>Handle in BX, buffer in DS:DX, count in CX, bytes written return in AX.</td>
</tr>
<tr>
<td>42h</td>
<td>Move the file pointer</td>
<td>Handle in BX, mode in AL, offset in CX:DX.</td>
</tr>
</tbody>
</table>
<p>For these functions, always check the carry flag after the call. If CF is set, AX holds an error code instead of a handle or a byte count, and using AX as if it were a valid handle is a classic bug.</p>
<h2>Worked example: print a string, read a key, exit cleanly</h2>
<pre>ORG 100h

LEA DX, message
MOV AH, 09h          ; print the '$'-terminated string
INT 21h

MOV AH, 01h          ; wait for one keypress, echo it
INT 21h

MOV AX, 4C00h        ; exit with code 0
INT 21h

message DB 'Press any key to continue...', 0Dh, 0Ah, '$'
RET</pre>
<p>In a .COM program, DS starts out pointing at the program segment, so LEA DX, message reaches the string without a separate segment setup step. The 0Dh, 0Ah pair before the &#8216;$&#8217; is the carriage return and line feed that move the cursor to the start of the next line.</p>
<h2>What INT 21h is not</h2>
<p>INT 21h is a DOS service, not a processor instruction. It does not exist on a bare 8086 chip, and modern operating systems do not run DOS programs natively. In Emu8086 it works because the emulator provides a DOS environment, which is exactly why student code written for the emulator cannot simply be copied onto a modern machine and expected to run. For screen and keyboard work that is not DOS-specific, see the <a href="https://emu8086emulator.com/emu8086-interrupt-table-10h-16h-21h/">interrupt table</a> post, which covers INT 10h and INT 16h alongside INT 21h.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-interrupt-table-10h-16h-21h/">8086 Interrupt Table: INT 10h, INT 16h and INT 21h</a></li>
<li><a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>JMP and LOOP in 8086 Assembly: Unconditional and Conditional Control Flow</title>
		<link>https://emu8086emulator.com/emu8086-jmp-loop-instructions/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:24:21 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-jmp-loop-instructions/</guid>

					<description><![CDATA[Every loop, every branch and every repeated action in an 8086 program is built from a small set of control-flow instructions. JMP goes somewhere unconditionally. The conditional jumps go somewhere only if the flags say so. LOOP combines a counter and a jump into one instruction. JMP: the unconditional jump JMP target JMP transfers control...]]></description>
										<content:encoded><![CDATA[<p>Every loop, every branch and every repeated action in an 8086 program is built from a small set of control-flow instructions. JMP goes somewhere unconditionally. The conditional jumps go somewhere only if the flags say so. LOOP combines a counter and a jump into one instruction.</p>
<h2>JMP: the unconditional jump</h2>
<pre>JMP target</pre>
<p>JMP transfers control to the label without looking at any flag. It is the instruction for skipping over code, for the end of an if/else chain, and for infinite loops that are exited some other way, such as a key press or a counted LOOP. A JMP to a nearby label is encoded as a short jump; the assembler handles the encoding, but the idea is the same: execution continues at the label, not at the next instruction.</p>
<h2>Conditional jumps: reading the flags</h2>
<p>Conditional jumps are almost always paired with CMP, or with an instruction that sets ZF such as TEST or SUB. The most used ones are:</p>
<table>
<thead>
<tr>
<th>Jump</th>
<th>Meaning</th>
<th>Reads</th>
</tr>
</thead>
<tbody>
<tr>
<td>JE / JZ</td>
<td>Jump if equal / zero</td>
<td>ZF = 1</td>
</tr>
<tr>
<td>JNE / JNZ</td>
<td>Jump if not equal / not zero</td>
<td>ZF = 0</td>
</tr>
<tr>
<td>JA / JB</td>
<td>Jump if above / below (unsigned)</td>
<td>CF and ZF</td>
</tr>
<tr>
<td>JAE / JBE</td>
<td>Jump if above or equal / below or equal (unsigned)</td>
<td>CF and ZF</td>
</tr>
<tr>
<td>JG / JL</td>
<td>Jump if greater / less (signed)</td>
<td>SF, OF and ZF</td>
</tr>
<tr>
<td>JGE / JLE</td>
<td>Jump if greater or equal / less or equal (signed)</td>
<td>SF, OF and ZF</td>
</tr>
<tr>
<td>JC / JNC</td>
<td>Jump if carry / no carry</td>
<td>CF</td>
</tr>
<tr>
<td>JS / JNS</td>
<td>Jump if sign / no sign</td>
<td>SF</td>
</tr>
</tbody>
</table>
<p><strong>Conditional jumps are short-range: the target must be within about 127 bytes of the jump.</strong> If a branch target is too far away, the assembler reports an out-of-range error. The standard fix is to invert the condition and jump over a JMP: instead of a long conditional jump, write the opposite condition jumping over a short distance to a nearby JMP that reaches the far target.</p>
<h2>LOOP: a counter and a jump in one instruction</h2>
<pre>MOV CX, 10
again:
; ... body ...
LOOP again</pre>
<p>LOOP subtracts one from CX and jumps to the label if CX is not zero. When CX reaches zero, execution falls through to the next instruction. LOOPE (also written LOOPZ) jumps only if CX is not zero and ZF is set; LOOPNE (LOOPNZ) jumps only if CX is not zero and ZF is clear. JCXZ jumps if CX is already zero, which is useful before entering a loop that must run zero times rather than 65,536 times.</p>
<h2>Worked example: add the numbers 1 to 10</h2>
<pre>ORG 100h

MOV AX, 0        ; running total
MOV CX, 10       ; loop counter
add_next:
ADD AX, CX       ; add the current counter value
LOOP add_next    ; CX = CX - 1, repeat while CX is not zero
; AX is now 55.
RET</pre>
<p>Trace it by hand once: the first pass adds 10, the next adds 9, and so on down to 1, for a total of 55. Notice that LOOP itself does not affect the flags, so the ADD flags from the last pass are still intact after the loop finishes, although this program does not use them.</p>
<h2>Common mistakes</h2>
<ul>
<li>Using a signed jump for unsigned data, or the reverse. See the <a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP</a> post for the difference.</li>
<li>Putting a MOV between CMP and its conditional jump and assuming the flags are lost. MOV preserves flags, so that particular worry is unfounded; an ADD or SUB in between is the real danger.</li>
<li>Forgetting that LOOP counts down. A loop written as if CX counted up will run a surprising number of times.</li>
<li>Letting a conditional jump target drift more than about 127 bytes away after edits, and getting a range error that seems to come from nowhere.</li>
</ul>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-addressing-modes-flags/">8086 Addressing Modes and Flags Explained</a></li>
</ul>
<p>New to assembly? Start with <a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a>, then return here.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>ADD and CMP in 8086 Assembly: Arithmetic, Comparison and Flags</title>
		<link>https://emu8086emulator.com/emu8086-add-cmp-instructions/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:24:09 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-add-cmp-instructions/</guid>

					<description><![CDATA[ADD and CMP are the pair that turns the 8086 from a copying machine into a machine that can make decisions. ADD changes a value and records what happened in the flags. CMP does the same subtraction as SUB, but throws the result away and keeps only the flags, so a conditional jump can act...]]></description>
										<content:encoded><![CDATA[<p>ADD and CMP are the pair that turns the 8086 from a copying machine into a machine that can make decisions. ADD changes a value and records what happened in the flags. CMP does the same subtraction as SUB, but throws the result away and keeps only the flags, so a conditional jump can act on the comparison.</p>
<h2>ADD: syntax and effect on flags</h2>
<pre>ADD destination, source   ; destination = destination + source</pre>
<p>ADD affects all six arithmetic flags: overflow (OF), sign (SF), zero (ZF), auxiliary carry (AF), parity (PF) and carry (CF). If the addition overflows the destination size, the extra bit lands in CF; if a signed result overflows, OF is set. A quick way to remember it: ADD tells the truth about the result in every flag at once.</p>
<h2>CMP: compare without storing</h2>
<pre>CMP AX, BX   ; computes AX - BX, keeps only the flags</pre>
<p>After CMP, ZF tells you whether the operands were equal, CF tells you about an unsigned borrow, and SF and OF together tell you about a signed comparison. That is why two families of conditional jumps exist: JA, JB, JAE and JBE read the result as unsigned, while JG, JL, JGE and JLE read it as signed. Using the wrong family is one of the most common bugs in student programs, because the same two numbers can be &#8220;greater&#8221; unsigned and &#8220;less&#8221; signed.</p>
<h2>INC and DEC: the exception to remember</h2>
<p>INC adds one and DEC subtracts one, and both affect OF, SF, ZF, AF and PF, but <strong>neither affects CF</strong>. That is deliberate: a loop counter incremented with INC does not destroy a carry flag that surrounding code is using. If you need CF updated, use ADD or SUB with 1 instead.</p>
<h2>Worked example: compare two numbers and print the larger</h2>
<p>This .COM example compares two values, prints a character for the larger one, and exits through DOS. It uses only instructions covered in this post and in the <a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV</a> post:</p>
<pre>ORG 100h

MOV AX, 25
MOV BX, 40
CMP AX, BX
JAE ax_is_bigger     ; unsigned: AX &gt;= BX
; BX is bigger here.
MOV DL, 'B'
JMP print_it
ax_is_bigger:
MOV DL, 'A'
print_it:
MOV AH, 02h          ; INT 21h, AH=02h: write character in DL
INT 21h
MOV AX, 4C00h        ; INT 21h, AH=4Ch: exit to DOS
INT 21h
RET</pre>
<p>Change the two starting values and watch the printed letter change. Then change JAE to JGE and try values that cross the signed boundary, such as comparing a value with its high bit set against a small positive value, to see the signed and unsigned families disagree.</p>
<h2>Quick reference: which instructions touch which flags</h2>
<table>
<thead>
<tr>
<th>Instruction</th>
<th>OF</th>
<th>SF</th>
<th>ZF</th>
<th>AF</th>
<th>PF</th>
<th>CF</th>
</tr>
</thead>
<tbody>
<tr>
<td>MOV</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
</tr>
<tr>
<td>ADD, SUB, CMP</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
</tr>
<tr>
<td>INC, DEC</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>no</td>
</tr>
</tbody>
</table>
<p>The rule of thumb: if an instruction computes a result, it usually reports on it; MOV is the notable exception, and INC and DEC are the partial exception.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-mov-instruction/">MOV in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-jmp-loop-instructions/">JMP and LOOP in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MOV in 8086 Assembly: Syntax, Forms and Examples</title>
		<link>https://emu8086emulator.com/emu8086-mov-instruction/</link>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 24 Oct 2026 10:23:28 +0000</pubDate>
				<category><![CDATA[Reference]]></category>
		<guid isPermaLink="false">https://emu8086emulator.com/emu8086-mov-instruction/</guid>

					<description><![CDATA[MOV is the instruction you will use more than any other in 8086 assembly. It copies data from a source to a destination: a register, a memory location, or a segment register. It does not do arithmetic, and it does not change any flags, which makes it safe to use between a comparison and a...]]></description>
										<content:encoded><![CDATA[<p>MOV is the instruction you will use more than any other in 8086 assembly. It copies data from a source to a destination: a register, a memory location, or a segment register. It does not do arithmetic, and it does not change any flags, which makes it safe to use between a comparison and a conditional jump.</p>
<h2>The basic syntax</h2>
<pre>MOV destination, source</pre>
<p>The destination and the source must be the same size: you cannot move a 16-bit register into an 8-bit register, or a byte into a word, without an explicit size step in between. The two operands also cannot both be memory locations. If you need to copy memory to memory, move the value through a register first.</p>
<h2>The forms you will actually use</h2>
<table>
<thead>
<tr>
<th>Form</th>
<th>Example</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Register to register</td>
<td><code>MOV BX, AX</code></td>
<td>Both operands the same size.</td>
</tr>
<tr>
<td>Immediate to register</td>
<td><code>MOV AX, 1234h</code></td>
<td>The value is written into the instruction itself.</td>
</tr>
<tr>
<td>Register to memory</td>
<td><code>MOV [SI], AL</code></td>
<td>Stores AL at the address in SI.</td>
</tr>
<tr>
<td>Memory to register</td>
<td><code>MOV AX, [1234h]</code></td>
<td>Loads a word from a fixed address.</td>
</tr>
<tr>
<td>Immediate to memory</td>
<td><code>MOV BYTE PTR [DI], 0</code></td>
<td>The size keyword is needed because the value alone does not say byte or word.</td>
</tr>
<tr>
<td>Segment register</td>
<td><code>MOV DS, AX</code></td>
<td>Segment registers are loaded through a general register, never directly from an immediate value.</td>
</tr>
</tbody>
</table>
<h2>Rules that catch beginners</h2>
<ul>
<li><strong>MOV never affects the flags.</strong> After <code>CMP AX, BX</code>, a MOV will not disturb the result, so you can set up a value and then jump on the comparison.</li>
<li><strong>You cannot move one segment register to another directly.</strong> <code>MOV DS, ES</code> is not allowed; go through AX.</li>
<li><strong>CS cannot be the destination.</strong> The code segment is changed by jumps, calls and returns, not by MOV.</li>
<li><strong>An immediate value cannot go straight into a segment register.</strong> <code>MOV DS, 1000h</code> is not allowed; load AX first, then <code>MOV DS, AX</code>.</li>
<li><strong>Byte and word registers are separate views.</strong> AX is made of AH (high byte) and AL (low byte). <code>MOV AL, 0FFh</code> leaves AH untouched.</li>
</ul>
<h2>Worked example: setting up a data segment</h2>
<p>The classic opening of an 8086 program loads DS so the program can reach its own data. In a .COM program DS already points at the program segment, but the pattern is the same in both program models:</p>
<pre>; Load a data segment address through AX.
MOV AX, @data
MOV DS, AX

; Copy a value through a register, not memory to memory.
MOV AX, [counter]
MOV [result], AX

; Clear a register with an immediate value.
MOV BX, 0
RET</pre>
<h2>Common mistakes</h2>
<p>The three most frequent MOV errors are a size mismatch (<code>MOV AX, BL</code>), a memory-to-memory move (<code>MOV [DI], [SI]</code>), and forgetting that MOV leaves the flags alone and then wondering why a jump after a MOV behaves as if the earlier comparison never happened. It behaves that way because the flags really were preserved, which is usually what you want.</p>
<h2>What to learn next</h2>
<p>Once MOV feels automatic, the next step is arithmetic that does change the flags, and the jumps that read them. The <a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP</a> post covers both, and the <a href="https://emu8086emulator.com/emu8086-addressing-modes-flags/">addressing modes and flags</a> post explains every way an operand can name a location.</p>
<h2>Further reading</h2>
<ul>
<li><a href="https://emu8086emulator.com/8086-instruction-set-opcode-reference/">8086 Instruction Set and Opcode Reference</a></li>
<li><a href="https://emu8086emulator.com/">Emu8086 Home</a></li>
<li><a href="https://emu8086emulator.com/emu8086-add-cmp-instructions/">ADD and CMP in 8086 Assembly</a></li>
<li><a href="https://emu8086emulator.com/emu8086-addressing-modes-flags/">8086 Addressing Modes and Flags Explained</a></li>
<li><a href="https://emu8086emulator.com/emu8086-hello-world-first-program/">Your First 8086 Program: Hello World</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
