cpu-simulator/build/alu/full/index.html

67 lines
4.7 KiB
HTML
Executable File

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="../" />
<title>Build an ALU</title>
<script type="text/javascript" src="../js/page.js"></script>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>
<body>
<h1>Time to put it all together</h1>
<p>Now we've built the constituent parts, it's now time to put everything together into our ALU chip.</p>
<p>The ALU has two outputs: the 8-bit result of the operation that was performed, and a 4-bit <a href="https://en.wikipedia.org/wiki/FLAGS_register">"flags"</a> value which contains information about the calculation.</p>
<img src="../img/flags_diagram.png" alt="flags" />
<p>You should set the flags according to the following logic:</p>
<div style="width:100%;display: flex; justify-content: center;margin-top:-20px;">
<table>
<thead><tr><td>Flag</td><td>Logic</td></thead>
<tbody>
<tr><td><a href="https://en.wikipedia.org/wiki/Overflow_flag#:~:text=The%20overflow%20flag%20is,operands%20are%20the%20same).">Overflow</a></td><td>1 if the <b>addition</b> of two numbers with the same <a href="https://en.wikipedia.org/wiki/Sign_bit">sign bit</a> produces a result with a different sign, or if the <b>subtraction</b> of two numbers with different signs produces a result with the same sign as the number being subtracted.<br>0 otherwise.</td></tr>
<tr><td><a href="https://en.wikipedia.org/wiki/Carry_flag">Carry / Borrow</a></td><td>1 if an <b>addition</b> or <b>subtraction</b> operation results in a carry / borrow.<br>0 otherwise.</td></tr>
<tr><td><a href="https://en.wikipedia.org/wiki/Negative_flag">Negative flag</a></td><td>1 if the <b>sign bit</b> (most significant bit) of the result is 1.<br>0 otherwise.</td></tr>
<tr><td><a href="https://en.wikipedia.org/wiki/Zero_flag">Zero flag</a></td><td>1 if <b>every</b> bit of the result is 0. <br>0 otherwise.</td></tr>
</tbody>
</table>
</div>
<p>The ALU has three inputs: the first and second 8-bit operands, and a 4-bit "opcode" which selects the operation to be performed.<br> This processor's ALU will use the following opcodes:</p>
<div style="width:100%;display: flex; justify-content: center;margin-top:-20px;">
<!--<ol data-bin=1>
<li>add</li>
<li>subtract</li>
<li>add with carry</li>
<li>left shift</li>
<li>logical NAND</li>
<li data-before="1XX">logical XOR</li>
</ol>
-->
<table class="c1c">
<thead><tr><td>Opcode</td><td>Operation</td><td>Explaiation</td></tr></thead>
<tbody>
<tr><td>0000</td><td>add </td><td>Adds the second operand to the first, setting the carry in to 0.</td></tr>
<tr><td>0001</td><td>subtract (sub)</td><td>Subtracts the second operand from the first, setting the carry in to 0.</td></tr>
<tr><td>0010</td><td>add with carry<br>(adc)</td><td>Adds the second operand to the first, setting the carry in to the value of the carry flag.</td></tr>
<tr><td>0011</td><td>subtract with borrow<br>(subb)</td><td>Subtracts the second operand from the first, setting the carry in to the value of the carry flag.</td></tr>
<tr><td>0100</td><td>nand</td><td>Each bit of the output is the result of NANDing together the respective bits of each operand.</td></tr>
<tr><td>0101</td><td>xor</td><td>Each bit of the output is the result of XORing together the respective bits of each operand.</td></tr>
<tr><td>0110</td><td>shift left<br>(sll)</td><td>Each bit of operand 1 is shifted to the left by the number of places specified by operand 2.</td></tr>
<tr><td>0111</td><td>shift right<br>(srl)</td><td>Each bit of operand 1 is shifted to the right by the number of places specified by operand 2.</td></tr>
<tr><td>1XXX</td><td>move<br>(mov)</td><td>Operand 2 is passed straight through to the result. No operation is performed.</td></tr>
</tbody>
</table>
</div>
<p><i>This is the most complicated part of the process</i>, and it's OK if you don't quite understand everything yet. You can use the green links to get more information about certain words, and now might be a good time to ask your tutor for help if you are truly stuck.</p>
<h3><a href="/cpu/build/editor/?item=alu" data-newtab=1>Start building</a></h3>
<!--<ol>
<li><a href="1/" data-newtab=1>construct <b>2:1 mux</b></a></li>
<li><a href="2/" data-newtab=1>assemble <b>16:8 mux</b></a></li>
</ol>
-->
<p>
Once you are finished, you can <a href="/cpu/">return to the CPU</a>.
</p>
</body>
</html>