<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=Z80%3AData_Manipulation_and_Basic_Math</id>
	<title>Z80:Data Manipulation and Basic Math - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=Z80%3AData_Manipulation_and_Basic_Math"/>
	<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;action=history"/>
	<updated>2026-05-13T12:06:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=72&amp;oldid=prev</id>
		<title>KermMartian: Adjusted lowercase z80</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=72&amp;oldid=prev"/>
		<updated>2016-02-03T20:58:09Z</updated>

		<summary type="html">&lt;p&gt;Adjusted lowercase z80&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:58, 3 February 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;= Introduction =&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you&amp;#039;re ever going to get anything do in assembly, you&amp;#039;ll probably find yourself having to  manipulate data and do basic math on your calculator. However, doing math in assembly is a lot harder than doing math on the home screen or in a TI-BASIC program. For the most part you&amp;#039;ll do math on the byte level. This leaves a lot to be desired, but for now let&amp;#039;s start at the most basic part of doing math in assembly.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you&amp;#039;re ever going to get anything do in assembly, you&amp;#039;ll probably find yourself having to  manipulate data and do basic math on your calculator. However, doing math in assembly is a lot harder than doing math on the home screen or in a TI-BASIC program. For the most part you&amp;#039;ll do math on the byte level. This leaves a lot to be desired, but for now let&amp;#039;s start at the most basic part of doing math in assembly.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l118&quot;&gt;Line 118:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 114:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s take the number 4. In binary, it is %00000100. If we shift it left, it will become %00001000. Hey, isn&amp;#039;t that the number 8? So, shifting an operator left allows you to multiply a number by 2. Well, that&amp;#039;s quite lame if all we can do is multiply a number by powers of 2! Or is it? Remember, the z80 processor (in fact, all modern computers) are binary based. And also, the shift operators are &amp;#039;&amp;#039;&amp;#039;extremely fast!&amp;#039;&amp;#039;&amp;#039; They can make the difference in crucial code that needs to go as fast as possible.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s take the number 4. In binary, it is %00000100. If we shift it left, it will become %00001000. Hey, isn&amp;#039;t that the number 8? So, shifting an operator left allows you to multiply a number by 2. Well, that&amp;#039;s quite lame if all we can do is multiply a number by powers of 2! Or is it? Remember, the z80 processor (in fact, all modern computers) are binary based. And also, the shift operators are &amp;#039;&amp;#039;&amp;#039;extremely fast!&amp;#039;&amp;#039;&amp;#039; They can make the difference in crucial code that needs to go as fast as possible.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The shift left operators are [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLA|SLA]] and [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLL|SLL]]. There is quite a difference between the two, such as [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLA|SLA]] will put the 7th bit into the carry, while [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLL|SLL]] will destroy it. Also, [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLA|SLL]] will put a 1 into the 0th bit, as opposed to a 0 from [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SLA|SLA]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The shift left operators are [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLA|SLA]] and [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLL|SLL]]. There is quite a difference between the two, such as [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLA|SLA]] will put the 7th bit into the carry, while [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLL|SLL]] will destroy it. Also, [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLA|SLL]] will put a 1 into the 0th bit, as opposed to a 0 from [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SLA|SLA]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Division =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Division =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l126&quot;&gt;Line 126:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 122:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Shift Operators ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Shift Operators ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you can shift an operator left, you can also shift it right. Note that there are two shift operators: [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SRA|SRA]] and [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SRL|SRL]]. They both shift to the right, but the difference is that [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SRA|SRA]] preserves the 7th bit, which holds the sign (1=negative, 0=positive). [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80&lt;/del&gt;:Opcodes:SRL|SRL]] will shift all 8 bits, so should be used if your number is to be unsigned.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you can shift an operator left, you can also shift it right. Note that there are two shift operators: [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SRA|SRA]] and [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SRL|SRL]]. They both shift to the right, but the difference is that [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SRA|SRA]] preserves the 7th bit, which holds the sign (1=negative, 0=positive). [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80&lt;/ins&gt;:Opcodes:SRL|SRL]] will shift all 8 bits, so should be used if your number is to be unsigned.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Other Division Methods ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Other Division Methods ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l164&quot;&gt;Line 164:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 160:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{lowercase}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{lowercase}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80 &lt;/del&gt;Assembly]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80 &lt;/ins&gt;Assembly]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80 &lt;/del&gt;Heaven]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Z80 &lt;/ins&gt;Heaven]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>KermMartian</name></author>
	</entry>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=37&amp;oldid=prev</id>
		<title>KermMartian at 16:17, 3 February 2016</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=37&amp;oldid=prev"/>
		<updated>2016-02-03T16:17:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:17, 3 February 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l118&quot;&gt;Line 118:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 118:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s take the number 4. In binary, it is %00000100. If we shift it left, it will become %00001000. Hey, isn&amp;#039;t that the number 8? So, shifting an operator left allows you to multiply a number by 2. Well, that&amp;#039;s quite lame if all we can do is multiply a number by powers of 2! Or is it? Remember, the z80 processor (in fact, all modern computers) are binary based. And also, the shift operators are &amp;#039;&amp;#039;&amp;#039;extremely fast!&amp;#039;&amp;#039;&amp;#039; They can make the difference in crucial code that needs to go as fast as possible.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let&amp;#039;s take the number 4. In binary, it is %00000100. If we shift it left, it will become %00001000. Hey, isn&amp;#039;t that the number 8? So, shifting an operator left allows you to multiply a number by 2. Well, that&amp;#039;s quite lame if all we can do is multiply a number by powers of 2! Or is it? Remember, the z80 processor (in fact, all modern computers) are binary based. And also, the shift operators are &amp;#039;&amp;#039;&amp;#039;extremely fast!&amp;#039;&amp;#039;&amp;#039; They can make the difference in crucial code that needs to go as fast as possible.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The shift left operators are [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLA |SLA]] and [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLL |SLL]]. There is quite a difference between the two, such as [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLA |SLA]] will put the 7th bit into the carry, while [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLL |SLL]] will destroy it. Also, [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLA |SLL]] will put a 1 into the 0th bit, as opposed to a 0 from [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SLA |SLA]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The shift left operators are [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLA|SLA]] and [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLL|SLL]]. There is quite a difference between the two, such as [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLA|SLA]] will put the 7th bit into the carry, while [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLL|SLL]] will destroy it. Also, [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLA|SLL]] will put a 1 into the 0th bit, as opposed to a 0 from [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SLA|SLA]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Division =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Division =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l126&quot;&gt;Line 126:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 126:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Shift Operators ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Shift Operators ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you can shift an operator left, you can also shift it right. Note that there are two shift operators: [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SRA |SRA]] and [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SRL |SRL]]. They both shift to the right, but the difference is that [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SRA |SRA]] preserves the 7th bit, which holds the sign (1=negative, 0=positive). [[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;instructions-set&lt;/del&gt;:SRL |SRL]] will shift all 8 bits, so should be used if your number is to be unsigned.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you can shift an operator left, you can also shift it right. Note that there are two shift operators: [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SRA|SRA]] and [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SRL|SRL]]. They both shift to the right, but the difference is that [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SRA|SRA]] preserves the 7th bit, which holds the sign (1=negative, 0=positive). [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;z80:Opcodes&lt;/ins&gt;:SRL|SRL]] will shift all 8 bits, so should be used if your number is to be unsigned.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Other Division Methods ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Other Division Methods ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l162&quot;&gt;Line 162:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 162:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Conclusion =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Conclusion =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{lowercase}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:z80 Assembly]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:z80 Heaven]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>KermMartian</name></author>
	</entry>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=32&amp;oldid=prev</id>
		<title>KermMartian: Created page with &quot;  = Introduction =  If you&#039;re ever going to get anything do in assembly, you&#039;ll probably find yourself having to  manipulate data and do basic math on your calculator. However...&quot;</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:Data_Manipulation_and_Basic_Math&amp;diff=32&amp;oldid=prev"/>
		<updated>2016-02-03T16:07:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;  = Introduction =  If you&amp;#039;re ever going to get anything do in assembly, you&amp;#039;ll probably find yourself having to  manipulate data and do basic math on your calculator. However...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;re ever going to get anything do in assembly, you&amp;#039;ll probably find yourself having to  manipulate data and do basic math on your calculator. However, doing math in assembly is a lot harder than doing math on the home screen or in a TI-BASIC program. For the most part you&amp;#039;ll do math on the byte level. This leaves a lot to be desired, but for now let&amp;#039;s start at the most basic part of doing math in assembly.&lt;br /&gt;
&lt;br /&gt;
= Data Manipulation =&lt;br /&gt;
&lt;br /&gt;
Data manipulation is the process of changing data to fit the needs of the programmer. There are a few elementary ways of changing data, and also advanced ways to manipulate data. For now, we&amp;#039;ll focus on manipulating on the byte level and higher.&lt;br /&gt;
&lt;br /&gt;
= Increasing =&lt;br /&gt;
One way to add is to just increase a number by one.  The instruction to do this is &amp;quot;inc.&amp;quot;  It stands for increase and this is it&amp;#039;s syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Inc A&lt;br /&gt;
    Inc HL&lt;br /&gt;
    Inc (HL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Inc will add 1 to a register, register pair, or (HL).  So if A=9 then after this instruction, A=10.&lt;br /&gt;
&lt;br /&gt;
= Adding =&lt;br /&gt;
Increasing a number wont get you very far if you want to do some serious adding.  So the next instruction is &amp;quot;add.&amp;quot;  It&amp;#039;s syntax is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Add  A, $06&lt;br /&gt;
    Add  A, B&lt;br /&gt;
    Add  A,(HL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What this does is adds either a register, a constant, or what HL is pointing to, to A and in the end, the final answer is in A.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Add HL, DE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This adds BC or DE to HL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Ld B, 0&lt;br /&gt;
    Ld C, A&lt;br /&gt;
    Add HL, BC&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This adds A to HL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Add A, E&lt;br /&gt;
    Ld E, A&lt;br /&gt;
    Adc A, D&lt;br /&gt;
    Sub E&lt;br /&gt;
    Ld D, A&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a better version of the previous code.  It can add A to HL, BC, or DE, it doesn&amp;#039;t require that you destroy the data in BC or DE, and it takes 2 clock cycles less.  The only disadvantage is that it takes up 1 more byte.&lt;br /&gt;
&lt;br /&gt;
= Decreasing =&lt;br /&gt;
just like increasing, decreasing only subtracts 1.  It works just like Inc too. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    Dec A&lt;br /&gt;
    Dec HL&lt;br /&gt;
    Dec (HL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Dec subtracts 1 from registers, register pairs, and (HL).  So if A=10, then after this instruction, A=9.&lt;br /&gt;
&lt;br /&gt;
= Subtracting =&lt;br /&gt;
The instruction is called sub, but it works differently.  It only takes one input because it always subtracts from the accumulator.&lt;br /&gt;
&lt;br /&gt;
    Sub B&lt;br /&gt;
    Sub (HL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first code subtracts B from A.  The second code subtracts the value pointed to by HL from A.&lt;br /&gt;
*It is also worth noting that adding the negation of a number to another number is the equivalent of subtraction. Say, for instance that you wish to subtract 7 from 12.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    ld a,12&lt;br /&gt;
    ld b,-7&lt;br /&gt;
    add a,b    ;result, 5, is in a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Multiplication =&lt;br /&gt;
&lt;br /&gt;
This is where actually coding gets sketchy. Multiplication really depends on the goals you want to achieve. Here are a few general ways to multiply 8 bit and 16 bit registers.&lt;br /&gt;
&lt;br /&gt;
== Repeated adding ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to multiply. It works all the time (mostly because it&amp;#039;s the definition of multiplication).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    LD A, 6			;multiply 6*6&lt;br /&gt;
     LD B,6&lt;br /&gt;
    Multiply:&lt;br /&gt;
     ADD A,6&lt;br /&gt;
     DJNZ Multiply&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Extremely simple, and for the most part a rather small size. However, what it lacks in complexity it more than makes up in its slowness. There are special ways you can get around it. One is if you know what one of the numbers you are multiplying by is going to be (like 8*X, or 4*X) you can write a custom routine that will be faster, and many times even smaller.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    ;multiply by 4&lt;br /&gt;
     ADD A,A			;A+A=2A&lt;br /&gt;
     ADD A,A			;&amp;#039;2A&amp;#039;+&amp;#039;2A&amp;#039;=&amp;#039;4A&amp;#039;&lt;br /&gt;
    &lt;br /&gt;
    ;multiply by 6&lt;br /&gt;
     ADD A,A&lt;br /&gt;
     LD B,A&lt;br /&gt;
     ADD A,A&lt;br /&gt;
     ADD A,B&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Shift Operators ==&lt;br /&gt;
&lt;br /&gt;
An equally simple way to multiply is to shift the bits of a register. How does this work?&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s take the number 4. In binary, it is %00000100. If we shift it left, it will become %00001000. Hey, isn&amp;#039;t that the number 8? So, shifting an operator left allows you to multiply a number by 2. Well, that&amp;#039;s quite lame if all we can do is multiply a number by powers of 2! Or is it? Remember, the z80 processor (in fact, all modern computers) are binary based. And also, the shift operators are &amp;#039;&amp;#039;&amp;#039;extremely fast!&amp;#039;&amp;#039;&amp;#039; They can make the difference in crucial code that needs to go as fast as possible.&lt;br /&gt;
&lt;br /&gt;
The shift left operators are [[instructions-set:SLA |SLA]] and [[instructions-set:SLL |SLL]]. There is quite a difference between the two, such as [[instructions-set:SLA |SLA]] will put the 7th bit into the carry, while [[instructions-set:SLL |SLL]] will destroy it. Also, [[instructions-set:SLA |SLL]] will put a 1 into the 0th bit, as opposed to a 0 from [[instructions-set:SLA |SLA]].&lt;br /&gt;
&lt;br /&gt;
= Division =&lt;br /&gt;
&lt;br /&gt;
Division is a bit trickier. Again, it all depends on what you want to get done. Also, remember that there are no decimals in registers, so your division will either be rounded off or you can create code that will give you a remainder. Here are a few examples of code that will divide a register by a number.&lt;br /&gt;
&lt;br /&gt;
== Shift Operators ==&lt;br /&gt;
&lt;br /&gt;
If you can shift an operator left, you can also shift it right. Note that there are two shift operators: [[instructions-set:SRA |SRA]] and [[instructions-set:SRL |SRL]]. They both shift to the right, but the difference is that [[instructions-set:SRA |SRA]] preserves the 7th bit, which holds the sign (1=negative, 0=positive). [[instructions-set:SRL |SRL]] will shift all 8 bits, so should be used if your number is to be unsigned.&lt;br /&gt;
&lt;br /&gt;
== Other Division Methods ==&lt;br /&gt;
&lt;br /&gt;
Here is a routine that will give you an idea on dividing registers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    ;===================================&lt;br /&gt;
    ; Divide&lt;br /&gt;
    ;===================================&lt;br /&gt;
    ;&lt;br /&gt;
    ;Inputs:&lt;br /&gt;
    ;	A=divisor&lt;br /&gt;
    ;	C=dividend&lt;br /&gt;
    ;&lt;br /&gt;
    ;Outputs:&lt;br /&gt;
    ;	B=A/C&lt;br /&gt;
    ;	A=A%C	(the remainder)&lt;br /&gt;
    ;&lt;br /&gt;
    &lt;br /&gt;
    Divide:&lt;br /&gt;
     Ld B,0&lt;br /&gt;
    DivLoop:&lt;br /&gt;
     sub A,C&lt;br /&gt;
     jr c,DivEnd&lt;br /&gt;
     inc B&lt;br /&gt;
     jr DivLoop&lt;br /&gt;
    &lt;br /&gt;
    DivEnd:&lt;br /&gt;
     add a,c&lt;br /&gt;
     ret&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Review =&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;/div&gt;</summary>
		<author><name>KermMartian</name></author>
	</entry>
</feed>