<?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>Ultraviolence: 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 = "CBW/CWDE: Convert Byte to Word/Convert Word to Doubleword (x86 Instruction Set Reference)";
//]]>
</script>
<h1>CBW/CWDE</h1>
<h2>Convert Byte to Word/Convert Word to Doubleword</h2>
<object>
<table class="box">
<tr>
<th>Opcode</th>
<th>Mnemonic</th>
<th>Description</th>
</tr>
<tr>
<td class="grid"><code>98</code></td>
<td class="grid"><code>CBW</code></td>
<td class="grid">AX = sign-extend of AL</td>
</tr>
<tr>
<td class="grid"><code>98</code></td>
<td class="grid"><code>CWDE</code></td>
<td class="grid">EAX = sign-extend of AX</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Description</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>Double the size of the source operand by means of sign extension. The CBW (convert byte to word) instruction copies the sign (bit 7) in the source operand into every bit in the AH register. The CWDE (convert word to doubleword) instruction copies the sign (bit 15) of the word in the AX register into the higher 16 bits of the EAX register.</p>
<p>The CBW and CWDE mnemonics reference the same opcode. The CBW instruction is intended for use when the operand-size attribute is 16 and the CWDE instruction for when the operandsize attribute is 32. Some assemblers may force the operand size to 16 when CBW is used and to 32 when CWDE is used. Others may treat these mnemonics as synonyms (CBW/CWDE) and use the current setting of the operand-size attribute to determine the size of values to be converted, regardless of the mnemonic used.</p>
<p>The CWDE instruction is different from the CWD (convert word to double) instruction. The CWD instruction uses the DX:AX register pair as a destination operand; whereas, the CWDE instruction uses the EAX register as a destination.</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>OperandSize <span class="operator">==</span> <span class="number">16</span><span class="operator">)</span> AX <span class="operator">=</span> SignExtend<span class="operator">(</span>AL<span class="operator">)</span><span class="operator">;</span> <span class="comment">//instruction == CBW</span>
<span class="keyword">else</span> EAX <span class="operator">=</span> SignExtend<span class="operator">(</span>AX<span class="operator">)</span><span class="operator">;</span> <span class="comment">//OperandSize == 32, instruction == CWDE</span>
</pre>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Flags affected</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>None.
</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>
