<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style/style.css" />
<title>Shroud: x86 Instruction Set Reference</title>
<link rel="icon" type="image/ico" href="../icon/siyobik.ico" />
<meta name="keywords" content="assembly,asm,programming,optimization,optimisation,c,c++,x86,pastebin,opcode,opcodes,dictionary,intel,amd,download,downloads,tutorial" />
<meta name="description" content="x86 assembly tutorials, x86 opcode reference, programming, pastebin with syntax highlighting" />
<meta name="robots" content="index, follow" />
</head>
<body>
<div class="main_container"><h1>x86 Instruction Set Reference</h1>
<script type="text/javascript">
//<![CDATA[
document.title = "AAS: ASCII Adjust AL After Subtraction (x86 Instruction Set Reference)";
//]]>
</script>
<h1>AAS</h1>
<h2>ASCII Adjust AL After Subtraction</h2>
<object>
<table class="box">
<tr>
<th>Opcode</th>
<th>Mnemonic</th>
<th>Description</th>
</tr>
<tr>
<td class="grid"><code>3F</code></td>
<td class="grid"><code>AAS</code></td>
<td class="grid">ASCII adjust AL after subtraction</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Description</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>Adjusts the result of the subtraction of two unpacked BCD values to create a unpacked BCD result. The AL register is the implied source and destination operand for this instruction. The AAS instruction is only useful when it follows a SUB instruction that subtracts (binary subtraction) one unpacked BCD value from another and stores a byte result in the AL register. The AAA instruction then adjusts the contents of the AL register to contain the correct 1-digit unpacked BCD result.</p>
<p>If the subtraction produced a decimal carry, the AH register decrements by 1, and the CF and AF flags are set. If no decimal carry occurred, the CF and AF flags are cleared, and the AH register is unchanged. In either case, the AL register is left with its top nibble set to 0.</p>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Operation</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<pre><span class="keyword">if</span><span class="operator">(</span><span class="operator">(</span>AL <span class="operator">&amp;</span> <span class="number">0xF</span><span class="operator">)</span> <span class="operator">&gt;</span> <span class="number">9</span> <span class="operator">||</span> AF <span class="operator">==</span> <span class="number">1</span><span class="operator">)</span> {
	AL <span class="operator">=</span> AL <span class="operator">-</span> <span class="number">6</span><span class="operator">;</span>
	AH <span class="operator">=</span> AH <span class="operator">-</span> <span class="number">1</span><span class="operator">;</span>
	AF <span class="operator">=</span> <span class="number">1</span><span class="operator">;</span>
	CF <span class="operator">=</span> <span class="number">1</span><span class="operator">;</span>
}
<span class="keyword">else</span> {
	CF <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span>
	AF <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span>
}
AL <span class="operator">=</span> AL <span class="operator">&amp;</span> <span class="number">0xF</span><span class="operator">;</span>
</pre>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Flags affected</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>The AF and CF flags are set to 1 if there is a decimal borrow; otherwise, they are set to 0. The OF, SF, ZF, and PF flags are undefined.
</p>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Exceptions</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
None.
</td>
</tr>
</table>
</object>
</div>
</body>
</html>
