<?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>Eli Bendersky's website &#187; Assembly</title>
	<atom:link href="http://eli.thegreenplace.net/category/programming/assembly/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net</link>
	<description>Eli Bendersky's personal website</description>
	<lastBuildDate>Fri, 30 Jul 2010 12:30:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introducing Luz</title>
		<link>http://eli.thegreenplace.net/2010/05/05/introducing-luz/</link>
		<comments>http://eli.thegreenplace.net/2010/05/05/introducing-luz/#comments</comments>
		<pubDate>Wed, 05 May 2010 17:43:38 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Assembly]]></category>
		<category><![CDATA[EE / Embedded]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2164</guid>
		<description><![CDATA[OK, so the documentation still isn&#8217;t complete, but I can&#8217;t wait to introduce my newest concoction &#8211; Luz. Luz is a pure-Python implementation of a MIPS-like CPU (as a simulator, of course). This CPU is programmable in an assembly language, a complete assembler for which has been implemented, along with a linker that takes together [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/03/13/python-documentation-annoyance/' rel='bookmark' title='Permanent Link: Python documentation annoyance'>Python documentation annoyance</a> <small>Edit: I&#8217;ve actually started working on fixing this annoyance in...</small></li><li><a href='http://eli.thegreenplace.net/2005/02/20/mix-implementation-in-perl-completed/' rel='bookmark' title='Permanent Link: MIX implementation in Perl completed !'>MIX implementation in Perl completed !</a> <small>I&#8217;ve recently completed my Perl implementation of Knuth&#8217;s MIX/MIXAL (Perlmix)....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>OK, so the documentation still isn&#8217;t complete, but I can&#8217;t wait to introduce my newest concoction &#8211; <a href="http://code.google.com/p/luz-cpu/">Luz</a>. Luz is a pure-Python implementation of a MIPS-like CPU (as a simulator, of course). This CPU is programmable in an assembly language, a complete assembler for which has been implemented, along with a linker that takes together several object files and creates an executable image to run on the simulator. Oh, and did I mention that it also includes a rudimentary debugger and disassembler? All of this is Luz:</p>
<p><img src="http://eli.thegreenplace.net/wp-content/uploads/2010/05/luz_proj_toplevel.png" alt="" title="luz_proj_toplevel" width="437" height="952" class="aligncenter size-full wp-image-2165" /></p>
<p>To call Luz new is a bit of a stretch, because I started working on it more than two years ago. It has been a jagged road, with occasional spurts of productivity, but now Luz is finally in a presentable form.</p>
<p>I&#8217;ll paste from its &#8220;getting started guide&#8221;:</p>
<blockquote><p>
<strong>What is Luz useful for?</strong></p>
<p>I don&#8217;t know yet. It&#8217;s a self-educational project of mine, and I learned a lot by working on it. I suppose that Luz&#8217;s main value is as an educational tool. Its implementation focuses on simplicity and modularity, and is done in Python, which is a portable and very readable high-level language.</p>
<p>Luz can serve as a sample of implementing a complete assembler, a complete linker, a complete CPU simulator. Other such tools exist, but usually not in the clean and self-contained form offered by Luz. In any case, if you&#8217;ve found Luz iseful, I&#8217;d love to receive feedback.</p></blockquote>
<p>This summarizes it, really. Not much more to add, except that Luz is available from its <a href="http://code.google.com/p/luz-cpu/">Google Code project</a> in source-only form for now, so you&#8217;ll have to check it out from SVN or just look at the sources in the online browser. Checking the source out is recommended because it allows one to view the documentation in nice HTML format. A few example programs in Luz assembly are available. Luz requires Python 2.6 or higher and the PLY module installed. I tested it on Windows XP and Ubuntu.</p>
<p>I&#8217;ve written <a href="http://eli.thegreenplace.net/2005/02/20/mix-implementation-in-perl-completed/">an assembler and a CPU simulator before</a>, but that was for a very weird architecture (Knuth&#8217;s MIX from TAOCP). Luz is a much more useful beast &#8211; the CPU is not far from real modern CPUs (the embedded kind, mostly), the assembly language is familiar and best of all, Luz also includes a linker, which will make it much easier to compile C for it in the future.</p>
<p>I&#8217;ll write more about Luz in sometime later, when I find the time to work on its documentation.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2164&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2009/03/13/python-documentation-annoyance/' rel='bookmark' title='Permanent Link: Python documentation annoyance'>Python documentation annoyance</a> <small>Edit: I&#8217;ve actually started working on fixing this annoyance in...</small></li><li><a href='http://eli.thegreenplace.net/2005/02/20/mix-implementation-in-perl-completed/' rel='bookmark' title='Permanent Link: MIX implementation in Perl completed !'>MIX implementation in Perl completed !</a> <small>I&#8217;ve recently completed my Perl implementation of Knuth&#8217;s MIX/MIXAL (Perlmix)....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2010/05/05/introducing-luz/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating a tiny &#8216;Hello World&#8217; executable in assembly</title>
		<link>http://eli.thegreenplace.net/2009/12/21/creating-a-tiny-hello-world-executable-in-assembly/</link>
		<comments>http://eli.thegreenplace.net/2009/12/21/creating-a-tiny-hello-world-executable-in-assembly/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 04:53:53 +0000</pubDate>
		<dc:creator>eliben</dc:creator>
				<category><![CDATA[Assembly]]></category>

		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=2026</guid>
		<description><![CDATA[By writing x86 assembly code and assembling it into a .COM file you can get very small executables. The .COM format, originated with 16-bit MS-DOS, is literally nothing except binary code. There&#8217;s no relocation information and no import tables, it is loaded by the OS at address 0&#215;100 and starts executing from there. This executable [...]


Related posts:<ol><li><a href='http://eli.thegreenplace.net/2005/09/04/cool-hack-creating-custom-subroutines-on-the-fly-in-perl/' rel='bookmark' title='Permanent Link: Cool hack: creating custom subroutines on-the-fly in Perl'>Cool hack: creating custom subroutines on-the-fly in Perl</a> <small>In an effort to adapt my Perl data-decoding program to...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>By writing x86 assembly code and assembling it into a <tt class="docutils literal"><span class="pre">.COM</span></tt> file you can get very small executables. The <tt class="docutils literal"><span class="pre">.COM</span></tt> format, originated with 16-bit MS-DOS, is literally nothing except binary code. There&#8217;s no relocation information and no import tables, it is loaded by the OS at address 0&#215;100 and starts executing from there. This executable format is still supported by modern Windows OSes, that run it inside a <a class="reference external" href="http://en.wikipedia.org/wiki/Virtual_DOS_machine">DOS emulator</a>.</p>
<p>Here&#8217;s a basic &#8216;Hello, World!&#8217;:</p>
<div class="highlight">
<pre>org 100h
mov dx,msg
mov ah,9
int 21h
mov ah,4Ch
int 21h
msg db &#39;Hello, World!&#39;,0Dh,0Ah,&#39;$&#39;
</pre>
</div>
<p>The most interesting part of the code is the <tt class="docutils literal"><span class="pre">int</span> <span class="pre">21h</span></tt> operations. These are software interrupts to call MS-DOS services. The code placed in the <tt class="docutils literal"><span class="pre">AH</span></tt> register prior to calling <tt class="docutils literal"><span class="pre">int</span> <span class="pre">21h</span></tt> specifies the <a class="reference external" href="http://en.wikipedia.org/wiki/Int_21">service to call into</a>.</p>
<p>The first service is 9, which asks DOS to print the string pointed by <tt class="docutils literal"><span class="pre">DX</span></tt> into standard output, until a dollar ($) sign is encountered. This is what does the printing in this program. The second service is 4C, which asks DOS to terminate the program.</p>
<p>Assembling this code into a .COM file is easy with <a class="reference external" href="http://www.nasm.us/">Nasm</a>:</p>
<div class="highlight">
<pre>nasm -f bin helloworld.asm -o helloworld.com
</pre>
</div>
<p>This results in a 27-byte .COM file that executes and prints &#8216;Hello, World!&#8217;.</p>
<img src="http://eli.thegreenplace.net/?ak_action=api_record_view&id=2026&type=feed" alt="" />

<p>Related posts:<ol><li><a href='http://eli.thegreenplace.net/2005/09/04/cool-hack-creating-custom-subroutines-on-the-fly-in-perl/' rel='bookmark' title='Permanent Link: Cool hack: creating custom subroutines on-the-fly in Perl'>Cool hack: creating custom subroutines on-the-fly in Perl</a> <small>In an effort to adapt my Perl data-decoding program to...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://eli.thegreenplace.net/2009/12/21/creating-a-tiny-hello-world-executable-in-assembly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
