<?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>Schadenfreude &#187; code</title>
	<atom:link href="http://www.ralree.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ralree.com</link>
	<description>Malicious enjoyment derived from observing someone else's misfortune</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:49:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>LXPanel Plugins: Simplified</title>
		<link>http://www.ralree.com/2011/04/03/lxpanel-plugins-simplified/</link>
		<comments>http://www.ralree.com/2011/04/03/lxpanel-plugins-simplified/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 18:01:07 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lxde]]></category>
		<category><![CDATA[lxpanel]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[scons]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=23083</guid>
		<description><![CDATA[I started using LXDE last night, and I&#8217;m really liking it. It seems to take a whole ton less memory than Gnome did, and as a result my Intel Atom box runs a lot smoother because it doesn&#8217;t have to continuously swap. Anyway, I&#8217;ve been customizing some things, and I eventually found myself in plugin development land. LXPanel is the gnome-panel equivalent for LXDE. There doesn&#8217;t seem to be a Trash can plugin for it, and I think that&#8217;s just [...]]]></description>
			<content:encoded><![CDATA[<p>I started using LXDE last night, and I&#8217;m really liking it.  It seems to take a whole ton less memory than Gnome did, and as a result my Intel Atom box runs a lot smoother because it doesn&#8217;t have to continuously swap.  Anyway, I&#8217;ve been customizing some things, and I eventually found myself in plugin development land.  </p>
<p>LXPanel is the gnome-panel equivalent for LXDE.  There doesn&#8217;t seem to be a Trash can plugin for it, and I think that&#8217;s just sad.  So, I decided to learn how these plugins are coded and make one of my own.  I&#8217;m not sure if I&#8217;ll end up succeeding, but at least it will be a learning experience either way.</p>
<p>I found <a href="http://home.student.utwente.nl/j.vanderhoff/LXPanel_HowTo.html">this page</a>, which outlines a simple plugin that doesn&#8217;t do anything.  It seems to be a good starting point.  I followed the directions and ended up looking at an autoconf project that required a lot of work to get running in Ubuntu.  Even though I finally got it to compile, I decided it took way to long to do so.  I converted it to a scons project, and now it&#8217;s just one directory with a simple build script:</p>
<p><script src="http://gist.github.com/900615.js"></script></p>
<p>The shared object that&#8217;s output is exactly the same size as the one created by autoconf, so that&#8217;s good enough for me at the moment.  Time to keep hammering away.  The code for the example is available <a href="https://github.com/hank/life/tree/master/code/c/lxpanel_plugin">here</a> for reuse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2011/04/03/lxpanel-plugins-simplified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing WFM Oscilloscope files in C</title>
		<link>http://www.ralree.com/2011/02/22/parsing-wfm-oscilloscope-files-in-c/</link>
		<comments>http://www.ralree.com/2011/02/22/parsing-wfm-oscilloscope-files-in-c/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 22:33:37 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[instructables]]></category>
		<category><![CDATA[oscilloscope]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[wfm]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=23060</guid>
		<description><![CDATA[So, I got this Rigol Oscilloscope &#8211; I wrote a little instructable about it. One cool feature is the ability to save waveforms to a USB stick. There are many options for the file format, but the default is a WFM file. Now, a true minimalist could just use the CSV option, but the WFM is a binary format that contains a lot more information directly from the scope. I wrote a little C program hosted on github that allows [...]]]></description>
			<content:encoded><![CDATA[<p>So, I got this Rigol Oscilloscope &#8211; I wrote a little <a href="http://www.instructables.com/id/Hacking-the-Rigol-DS1052E-Oscilloscope-with-Linux/">instructable</a> about it.  One cool feature is the ability to save waveforms to a USB stick.  There are many options for the file format, but the default is a WFM file.  Now, a true minimalist could just use the CSV option, but the WFM is a binary format that contains a lot more information directly from the scope.  I wrote a little C program hosted on <a href="https://github.com/hank/life/tree/master/code/c/rigol_wfm_reader">github</a> that allows you to convert those pesky proprietary files into something useful &#8211; namely a gnuplot image!</p>
<p>This is super alpha, and I&#8217;ll happily take patches.  Cheers!</p>
<p><a href="https://github.com/hank/life/tree/master/code/c/rigol_wfm_reader"><img alt="" src="https://github.com/hank/life/raw/master/code/c/rigol_wfm_reader/test2.gif" title="GNUPlot WFM to GIF" class="alignnone" width="640" height="480" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2011/02/22/parsing-wfm-oscilloscope-files-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diving into OOC, a fun new programming language</title>
		<link>http://www.ralree.com/2009/11/12/diving-into-ooc-a-fun-new-programming-language/</link>
		<comments>http://www.ralree.com/2009/11/12/diving-into-ooc-a-fun-new-programming-language/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 14:41:42 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[ooc]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=22722</guid>
		<description><![CDATA[OOC is cool.  Yesterday I started writing some code in it after reading about it on the github blog.  Here is the first result: I&#8217;m extremely happy with how well this performs.  Using the latest ooc Java compiler from the github trunk to handle the each() functions, this compiles down to a bunch of C code, and then is automagically compiled behind the scenes into an ELF Binary!  This is totally awesome, and I have to commend nddrylliog and the [...]]]></description>
			<content:encoded><![CDATA[<p>OOC is cool.  Yesterday I started writing some code in it after reading about it on the github blog.  Here is the first result:</p>
<p><script src="http://gist.github.com/232942.js"></script></p>
<p>I&#8217;m extremely happy with how well this performs.  Using the latest ooc Java compiler from the github trunk to handle the each() functions, this compiles down to a bunch of C code, and then is automagically compiled behind the scenes into an ELF Binary!  This is totally awesome, and I have to commend nddrylliog and the other contributors for their work on this awesome project.  Now I should use it for something useful :D</p>
<p>A quick note about getting it running on Ubuntu:</p>
<pre><code>
sudo apt-get install sun-java6-jdk
git clone git://github.com/nddrylliog/ooc.git
cd ooc
JAVA_HOME=/usr/lib/jvm/java-6-sun/ make
</code></pre>
<p>At least, that&#8217;s how I did it.  Then I compile all my ooc with a Makefile like this:</p>
<pre><code>
INPUTS=$(wildcard *.ooc)
TARGETS=$(patsubst %.ooc, %, $(INPUTS))

all: $(TARGETS)

%: %.ooc
  java -jar ~/repos/ooc/bin/ooc.jar $@
</code></pre>
<p>That will compile all ooc files in the directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2009/11/12/diving-into-ooc-a-fun-new-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1,000,000th Fibonacci Number One-Liner in C</title>
		<link>http://www.ralree.com/2009/09/09/1000000th-fibonacci-number-one-liner-in-c/</link>
		<comments>http://www.ralree.com/2009/09/09/1000000th-fibonacci-number-one-liner-in-c/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 05:04:40 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[one-liner]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=22673</guid>
		<description><![CDATA[This is possibly the best one-liner I&#8217;ve ever written: gcc -x c -o /tmp/out - -lgmp]]></description>
			<content:encoded><![CDATA[<p>This is possibly the best one-liner I&#8217;ve ever written:</p>
<p><code>
<pre>
gcc -x c -o /tmp/out - -lgmp <<< '#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdint.h&gt;
#include &lt;gmp.h&gt;
void omg_i_love_leonardo_of_pisa(uint32_t num, mpz_t * result) { mpz_t retval, last, tmp; mpz_init(retval);
 mpz_init(last); mpz_init(tmp); uint32_t i = 1; if(num == 0) return; mpz_set_ui(retval, 1U);
mpz_set_ui(last, 0U); for(; i < num; i++) { mpz_set(tmp, retval); mpz_add(retval, retval, last);
mpz_set(last, tmp); } mpz_set(*result, retval); } int main() { uint32_t num; mpz_t fibo; mpz_init(fibo);
omg_i_love_leonardo_of_pisa(1000001, &#038;fibo); mpz_out_str(stdout, 10, fibo); printf("\n"); return 1; }
' &#038;&#038; time /tmp/out
</pre>
<p></code></p>
<p>It compiles a C program given from <code>STDIN</code>, puts it in <code>/tmp/out</code>, and runs it with time to find the time it takes to run.  It generates the 1,000,000th Fibonacci number.  <strong>Try it!</strong></p>
<h2>Update May 21, 2011</h2>
<p>I changed the algorithm to do a matrix multiplication trick.  The only problem is it goes over the number you ask for currently.  I'm going to fix this with memoization soon.</p>
<pre>
gcc -x c -o /tmp/out - -lgmp &lt;&lt;&lt; '#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdint.h&gt;
#include &lt;gmp.h&gt;
void print_state(mpz_t* fm2, mpz_t* fm1, mpz_t* f, uint32_t n){gmp_printf("fib(%d) = %Zd\n", n, f);}
#define NEXT_FIB() mpz_set(oldfm1, fm1);mpz_set(oldf, f);mpz_mul(f, f, f);mpz_mul(tmp, fm1, fm1);\
mpz_add(f, f, tmp);mpz_mul(fm1, oldf, fm1);mpz_mul(tmp, oldfm1, fm2);mpz_add(fm1, fm1, tmp); \
mpz_set(tmp, fm2);mpz_mul(fm2, oldfm1, oldfm1);mpz_mul(tmp, tmp, tmp);mpz_add(fm2, fm2, tmp);\
n += i;i *= 2;
int main(){mpz_t fm2, fm1, f;uint32_t n = 2;uint32_t i = 1;mpz_inits(fm2, fm1, f, NULL);mpz_set_si(fm2,
0);mpz_set_si(fm1, 1);mpz_set_si(f, 1);mpz_t oldf, oldfm1, tmp;mpz_inits(oldf, oldfm1, tmp, NULL);
uint32_t g = 1000000;while(n&lt;g){NEXT_FIB();}print_state(&#038;fm2, &#038;fm1, &#038;f, n);return 0;}' &#038;&#038; time /tmp/out
</pre>
<p>This outputs almost immediately on my Intel Atom:</p>
<pre>

fib(1048577) = 19202837189514814.................

real	0m0.840s
user	0m0.280s
sys	0m0.010s
</pre>
<p>The code is <a href="https://github.com/hank/life/blob/master/code/interview_practice/fibo_mat.c">here</a>.  Feel free to fork and improve!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2009/09/09/1000000th-fibonacci-number-one-liner-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ruby to generate RSS feeds for sites that don&#8217;t offer them</title>
		<link>http://www.ralree.com/2009/08/23/ruby-to-generate-rss-feeds-for-sites-that-dont-offer-them/</link>
		<comments>http://www.ralree.com/2009/08/23/ruby-to-generate-rss-feeds-for-sites-that-dont-offer-them/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 14:53:41 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubyrss]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=22648</guid>
		<description><![CDATA[There&#8217;s this site that has an equipment exchange I wanted to keep track of. Yet, it&#8217;s done with what seems to be a custom php file rather than vbulletin, so none of the usual RSS feeds from the site apply to it. So, I decided to make a scraper/feed-generator to get me the latest version every 5 minutes and generate a nice RSS feed, so I can view it in Google Reader. The volume of posting is low enough that [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s this site that has an equipment exchange I wanted to keep track of.  Yet, it&#8217;s done with what seems to be a custom php file rather than vbulletin, so none of the usual RSS feeds from the site apply to it.  So, I decided to make a scraper/feed-generator to get me the latest version every 5 minutes and generate a nice RSS feed, so I can view it in Google Reader.  The volume of posting is low enough that this won&#8217;t be annoying to see in my daily feeds.</p>
<p>I usually use Ruby for this because it offers Hpricot, a very nice and fast scraper and XPath interface. This time, I resolved to find something that does RSS generation better, and I stumbled upon <a href="http://rubyrss.com/">RubyRSS</a>, which <strong>happens to be in the core ruby distribution</strong>!<br />
<span id="more-22648"></span><br />
Here&#8217;s what I ended up with after about an hour:</p>
<p><script src="http://gist.github.com/173318.js"></script></p>
<p>Now this is impressive if you look at the fail of html <code>id</code> and <code>class</code> attributes coming out of the original page.  I had to base everything off of the links to the items that were not images, and then the structure <em>up the tree</em> from there (see the liberal use of <code>.parent</code>).  I&#8217;ve rediscovered that Hpricot is awesome (_why, come back to us!), and that it truly only takes 30 lines of code to generate a nice RSS feed in ruby.  The resultant RSS feed for MDShooters Classifieds site is <a href="http://www.ralree.com/mdshooters_classifieds.xml">here</a>.</p>
<p>And now, yet another RSS feed generator: <a href="http://ralree.com/md_super_ads.xml">MD Super Ads</a></p>
<p>Here&#8217;s the code:</p>
<p><script src="http://gist.github.com/173623.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2009/08/23/ruby-to-generate-rss-feeds-for-sites-that-dont-offer-them/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Greasemonkey Script to get Jabber Room for Google Group Chat</title>
		<link>http://www.ralree.com/2009/03/15/greasemonkey-script-to-get-jabber-room-for-google-group-chat/</link>
		<comments>http://www.ralree.com/2009/03/15/greasemonkey-script-to-get-jabber-room-for-google-group-chat/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 03:23:28 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[gchat]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google chat]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=22468</guid>
		<description><![CDATA[So, today I was invited to Google Group chat for the first time. This would be really cool on a terminal that&#8217;s not equipped with an IM client, since it&#8217;s all done through the web with flash and magic. But, since I don&#8217;t like having 2 IM clients running at the same time (Pidgin and the Flash one from Google), I decided I needed to rip out the Jabber Group Chat Room name from the invite page. I got some [...]]]></description>
			<content:encoded><![CDATA[<p>So, today I was invited to Google Group chat for the first time.  This would be really cool on a terminal that&#8217;s not equipped with an IM client, since it&#8217;s all done through the web with flash and magic.  But, since I don&#8217;t like having 2 IM clients running at the same time (Pidgin and the Flash one from Google), I decided I needed to rip out the Jabber Group Chat Room name from the invite page.  I got some tips from <a href="http://mkokotovich.blogspot.com/2007/12/google-talk-groupchat.html">this site</a>, and wrote a Greasemonkey script to do so.</p>
<p><a href="http://www.ralree.com/newblog/wp-content/uploads/2009/03/whoa.jpg"><img class="aligncenter size-full wp-image-22469" title="whoa" src="http://www.ralree.com/newblog/wp-content/uploads/2009/03/whoa.jpg" alt="whoa" width="531" height="271" /></a></p>
<p>All you have to do is copy the room name into the <strong>Join Chat</strong> window, and put in <strong>groupchat.google.com</strong> as the server.  I hope you find it useful.  If anyone knows how to make this a link that GNOME will throw at Pidgin, let me know.  That would be awesome.</p>
<h2><a href="http://github.com/hank/life/raw/6b085700963110559c3dca29a94a701a2f0ec2df/code/greasemonkey/google_talk_chat_channel.user.js">Get the Script</a></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2009/03/15/greasemonkey-script-to-get-jabber-room-for-google-group-chat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSA Made Easy</title>
		<link>http://www.ralree.com/2009/02/27/rsa-made-easy/</link>
		<comments>http://www.ralree.com/2009/02/27/rsa-made-easy/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 05:41:07 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.ralree.com/?p=22383</guid>
		<description><![CDATA[After obsessing over it today, I decided to write a quick primer on RSA Encryption you can do in your head. It&#8217;s pretty simple, and to the point. The numbers are very small. Try it out! I plan to write some code implementing the algorithm.  That should be fun.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-22385" title="Lock Icon" src="http://www.ralree.com/newblog/wp-content/uploads/2009/02/lock.png" alt="Lock Icon" width="128" height="128" />After obsessing over it today, I decided to write <a href="http://github.com/hank/life/blob/d104176046f46d96399c9980213b3a2e6b3cd17b/docs/RSA.Fun.rdoc">a quick primer</a> on RSA Encryption you can do in your head.  It&#8217;s pretty simple, and to the point.  The numbers are very small.  Try it out!</p>
<p>I plan to write some code implementing the algorithm.  That should be fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2009/02/27/rsa-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Fun with NASM</title>
		<link>http://www.ralree.com/2007/11/22/random-fun-with-nasm/</link>
		<comments>http://www.ralree.com/2007/11/22/random-fun-with-nasm/#comments</comments>
		<pubDate>Thu, 22 Nov 2007 03:45:00 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[nasm]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ralree.info/2007/11/22/random-fun-with-nasm</guid>
		<description><![CDATA[I was on IRC tonight and someone was having trouble with their NASM homework. I decided to help them by learning NASM and coding up their homework problem for fun. It was pretty cool. I was on IRC tonight and someone was having trouble with their NASM homework. I decided to help them by learning NASM and coding up their homework problem for fun. It was pretty cool. Here&#8217;s the resultant program: ; Goal: (a+b)*c+d*b ; PARI/GP says: ; ? [...]]]></description>
			<content:encoded><![CDATA[<p>I was on IRC tonight and someone was having trouble with their NASM homework.  I decided to help them by learning NASM and coding up their homework problem for fun.  It was pretty cool.</p>
<p>            <span id="more-5031"></span></p>
<p>I was on IRC tonight and someone was having trouble with their NASM homework.  I decided to help them by learning NASM and coding up their homework problem for fun.  It was pretty cool.  Here&#8217;s the resultant program:</p>
<pre><code>
; Goal: (a+b)*c+d*b
; PARI/GP says:
; ? (1.234+5.678)*9.012+3.456*5.678
; %1 = 81.91411200000000000000000000
;
;=== Output ===
;hank@rofl:/tmp$ nasm -felf floating_point_arith.asm &#038;&#038; \
; gcc floating_point_arith.o &#038;&#038; ./a.out
;Answer: 81.91411
;===
;QED

  extern printf

  section .data
  a: dq 1.234
  b: dq 5.678
  c: dq 9.012
  d: dq 3.456
  e: dq 7.890
  fmt: db "Answer: %.5f",10,0

  section .bss
  f: resq 1

  section .text

  global main
  main:
    fldz
    fld   qword [a]
    fadd  qword [b]
    fmul  qword [c]
    fstp  qword [f]

    fld   qword [d]
    fmul  qword [b]
    fadd  qword [f]
    fstp  qword [f]

    push  dword [f+4]
    push  dword [f]
    push  dword fmt
    call  printf
    add   esp, 12
    mov   eax, 0
    ret
</code></pre>
<p>Code is also available here:</p>
<pre><code>

http://modzer0.cs.uaf.edu/repos/hank/code/asm/floating_point_arith.asm

</code></pre>
<p>All this does is add some floats and call <code>printf</code>, but it was fun to monkey around low-level again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2007/11/22/random-fun-with-nasm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

