<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEcBRXsyeyp7ImA9WhRUEk0.&quot;"><id>tag:blogger.com,1999:blog-6501711</id><updated>2012-01-21T22:14:14.593-05:00</updated><title>codebytez</title><subtitle type="html">code lessons</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://codebytez.blogspot.com/" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/mYxXC" /><feedburner:info uri="blogspot/myxxc" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;D0MESXw8eyp7ImA9WhdbGEw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-7646106841676245154</id><published>2011-10-16T21:36:00.000-04:00</published><updated>2011-10-16T21:36:48.273-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-16T21:36:48.273-04:00</app:edited><title>Prime algorithm in assembler</title><content type="html">One of the greatest strengths of assembly language is the extreme compactness of code. Digging though my old files I found this gem that prints all prime numbers under 2^32. The COM file size is 165 bytes. That's right! You could memorize the bytes if you wanted to and hand assemble it.&lt;br /&gt;
&lt;br /&gt;
The algorithm is not sieve (which would create 2^31 locations and strike off multiples of primes). Rather this is a space optimized algorithm that repeatedly divides each number n from 2 to sqrt(n) to determine if a number is prime. This algorithm uses no additional storage than the 165 bytes to hold the code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;.model tiny&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;.code&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;.386&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; org &amp;nbsp; &amp;nbsp; 100h&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;start:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;main &amp;nbsp; &amp;nbsp;proc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; eax,eax&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; al,3&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@m2:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call &amp;nbsp; &amp;nbsp;isprime&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jnc &amp;nbsp; &amp;nbsp; @@m1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call &amp;nbsp; &amp;nbsp;printdword&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call &amp;nbsp; &amp;nbsp;printcrlf&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@m1:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; eax&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jnz &amp;nbsp; &amp;nbsp; @@m2&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ax,4c00h&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; 21h&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;main &amp;nbsp; &amp;nbsp;endp&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;isprime proc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pushad&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; esi,eax &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; save number&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; ecx,ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ebx,ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; edx,ecx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; edx = 0&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call &amp;nbsp; &amp;nbsp;sqrt&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; cx,ax &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; save sqrt&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; bl,2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; ebx = 2 (divisor)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@i2:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; eax,esi &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; restore number&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cmp &amp;nbsp; &amp;nbsp; ecx,ebx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; is sqrt &amp;lt; divisor?&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jl &amp;nbsp; &amp;nbsp; &amp;nbsp;@@i4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; yes, no need to divide any more&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; div &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; or &amp;nbsp; &amp;nbsp; &amp;nbsp;edx,edx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jz &amp;nbsp; &amp;nbsp; &amp;nbsp;@@i1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; edx,edx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jnz &amp;nbsp; &amp;nbsp; @@i2&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@i4:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jmp &amp;nbsp; &amp;nbsp; @@i3&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@i1:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@i3:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; popad&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;isprime endp&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;sqrt &amp;nbsp; &amp;nbsp;proc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; push &amp;nbsp; &amp;nbsp;ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; push &amp;nbsp; &amp;nbsp;ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; ecx,ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ebx,ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@s2:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sub &amp;nbsp; &amp;nbsp; eax,ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jl &amp;nbsp; &amp;nbsp; &amp;nbsp;@@s1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; cx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jmp &amp;nbsp; &amp;nbsp; @@s2&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@s1:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ax,cx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pop &amp;nbsp; &amp;nbsp; ecx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pop &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;sqrt &amp;nbsp; &amp;nbsp;endp&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;printdword &amp;nbsp; &amp;nbsp; &amp;nbsp;proc&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pushad&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; ebx,ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; cx,bx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; bl,10&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@p1:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xor &amp;nbsp; &amp;nbsp; edx,edx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; div &amp;nbsp; &amp;nbsp; ebx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; push &amp;nbsp; &amp;nbsp;dx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; inc &amp;nbsp; &amp;nbsp; cx&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; or &amp;nbsp; &amp;nbsp; &amp;nbsp;eax,eax&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jnz &amp;nbsp; &amp;nbsp; @@p1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;@@p2:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pop &amp;nbsp; &amp;nbsp; ax&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; add &amp;nbsp; &amp;nbsp; al,'0'&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; dl,al&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ah,02&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; 21h&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; loop &amp;nbsp; &amp;nbsp;@@p2&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; popad&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;printdword &amp;nbsp; &amp;nbsp; &amp;nbsp;endp&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;printcrlf &amp;nbsp; &amp;nbsp; &amp;nbsp; proc&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pusha&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; dl,13&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ah,02&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; 21h&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; dl,10&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mov &amp;nbsp; &amp;nbsp; ah,2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; 21h&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; popa&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ret&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;printcrlf &amp;nbsp; &amp;nbsp; &amp;nbsp; endp&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #274e13; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end &amp;nbsp; &amp;nbsp; start&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-7646106841676245154?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pEPkJX3SFMqkZ6Lnw8gcxB_Bvdc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pEPkJX3SFMqkZ6Lnw8gcxB_Bvdc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pEPkJX3SFMqkZ6Lnw8gcxB_Bvdc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pEPkJX3SFMqkZ6Lnw8gcxB_Bvdc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/l061t5DP0ac" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/7646106841676245154/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=7646106841676245154" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7646106841676245154?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7646106841676245154?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/l061t5DP0ac/prime-algorithm-in-assembler.html" title="Prime algorithm in assembler" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/10/prime-algorithm-in-assembler.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMFR3szfip7ImA9WhdQFUg.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-6764910978726366899</id><published>2011-08-16T23:06:00.000-04:00</published><updated>2011-08-16T23:06:56.586-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-16T23:06:56.586-04:00</app:edited><title>Fix for NFS v4 inverse squashing</title><content type="html">Due to an &lt;a href="https://bugs.launchpad.net/ubuntu/+source/nfs-utils/+bug/662711"&gt;NFS Bug&lt;/a&gt;, when ZFS is shared over NFS4 on the client side all files will appear owned by nobody:nogroup. If idmapd is not set it will be&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; color: #333333; font-family: 'UbuntuBeta Mono', 'Ubuntu Mono', monospace; font-size: 12px; line-height: 18px;"&gt;4294967294:&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #333333; font-family: 'UbuntuBeta Mono', 'Ubuntu Mono', monospace; font-size: 12px; line-height: 18px;"&gt;&amp;nbsp;4294967294.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The client can still read and write and the files will appear normally on the server. Chown will fail, which means you cannot run VM images off this share.&lt;br /&gt;
&lt;br /&gt;
Mounting this with nfs option vers=3 in /etc/fstab is the only workaround until the bug is fixed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-6764910978726366899?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CqBj62cxBImyzytYtihheaFcF0E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CqBj62cxBImyzytYtihheaFcF0E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CqBj62cxBImyzytYtihheaFcF0E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CqBj62cxBImyzytYtihheaFcF0E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/qn70Okjdhco" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/6764910978726366899/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=6764910978726366899" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/6764910978726366899?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/6764910978726366899?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/qn70Okjdhco/fix-for-nfs-v4-inverse-squashing.html" title="Fix for NFS v4 inverse squashing" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/08/fix-for-nfs-v4-inverse-squashing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AFQX06eCp7ImA9WhdQFUk.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-6307085127318889045</id><published>2011-08-16T19:22:00.001-04:00</published><updated>2011-08-16T20:41:50.310-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-16T20:41:50.310-04:00</app:edited><title>Native (non-FUSE) ZFS on linux</title><content type="html">Thanks to Darik Horn, we can have native ZFS on linux. Instructions &lt;a href="http://zfsonlinux.org/faq.html"&gt;here&lt;/a&gt;. Works on natty, but may have issues on Lucid.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Preemptible kernels not supported. This should be OK for servers.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The ppa does not actually cover all dependencies. I had to figure out zlib1g-dev and uuid-dev&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;
sudo add-apt-repository ppa:dajhorn/zfs
sudo apt-get update
sudo apt-get install zlib1g-dev uuid-dev ubuntu-zfs 
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
If you get the following error, the build is unsuccessful:

&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;
Failed to load ZFS module stack.
Load the module manually by running 'insmod &lt;location&gt;/zfs.ko' as root.
&lt;/location&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
To determine missing dependencies:

&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;
cd /var/lib/dkms/zfs/*/build
./configure. # Error message will tell you what dependencies are missing
&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;make&lt;/tt&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;tt&gt;make install&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
Repeat or other directories under dkms if they had errors. If you get any error regarding unknown symbol or module format, you have booted the wrong kernel.&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-6307085127318889045?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LVPH8RPWwrahoaPgpvrDRxEpjJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LVPH8RPWwrahoaPgpvrDRxEpjJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LVPH8RPWwrahoaPgpvrDRxEpjJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LVPH8RPWwrahoaPgpvrDRxEpjJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/JEyxaFhbNLM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/6307085127318889045/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=6307085127318889045" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/6307085127318889045?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/6307085127318889045?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/JEyxaFhbNLM/native-non-fuse-zfs-on-linux.html" title="Native (non-FUSE) ZFS on linux" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/08/native-non-fuse-zfs-on-linux.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUABQ34-eip7ImA9WhdSGEw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-2618598619755250856</id><published>2011-07-27T20:39:00.004-04:00</published><updated>2011-07-27T20:42:32.052-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-27T20:42:32.052-04:00</app:edited><title>Migrating running VMs using virsh</title><content type="html">Prerequisites:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;All VM images are mounted on a shared location, &amp;nbsp;for example: /vmimages. If any images are qcow2 images with a backing file, those files also need to be present on shared locations.&lt;/li&gt;
&lt;li&gt;kvm-pxe needs to be installed. If not, the migration occurs, but the VM is suspended at the destination.&lt;/li&gt;
&lt;li&gt;Optional: If you want to be able to do this from scripts, setup ssh keys so you don't need to enter passwords&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
Migrate with the following command as root on the source host:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;
virsh migrate --live vmname qemu+ssh://destination.host/system
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
or if you are not on source, you can first connect to the source host&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;
virsh --connect qemu://source.host/system migrate --live vmname \
      qemu+ssh://destination.host/system
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-2618598619755250856?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w0M-qknIhaxkGXzc9ej56uPwrj8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w0M-qknIhaxkGXzc9ej56uPwrj8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w0M-qknIhaxkGXzc9ej56uPwrj8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w0M-qknIhaxkGXzc9ej56uPwrj8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/0I9e_Fb1gy8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/2618598619755250856/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=2618598619755250856" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/2618598619755250856?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/2618598619755250856?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/0I9e_Fb1gy8/migrating-running-vms-using-virsh.html" title="Migrating running VMs using virsh" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/07/migrating-running-vms-using-virsh.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQGR3g4fip7ImA9WhZaGEo.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-8347158440757045602</id><published>2011-07-03T11:52:00.001-04:00</published><updated>2011-07-05T08:52:06.636-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-05T08:52:06.636-04:00</app:edited><title>Read only root on VMs</title><content type="html">Follow the instructions from here:&amp;nbsp;https://help.ubuntu.com/community/aufsRootFileSystemOnUsbFlash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
disable app-armor on dhclient (otherwise networking will fail)&lt;/div&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', 'Lucida Grande', Helvetica, Arial, Verdana, sans-serif; font-size: 14px;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style="background-color: #f0eee6; border-bottom-color: rgb(193, 180, 150); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(193, 180, 150); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(193, 180, 150); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(193, 180, 150); border-top-style: dashed; border-top-width: 1px; font-family: courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 4pt; padding-left: 4pt; padding-right: 4pt; padding-top: 4pt; white-space: pre-wrap; word-wrap: break-word;"&gt;sudo aa-complain /etc/apparmor.d/sbin.dhclient&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
edit /etc/grub.d/00_header to not show menu on unclean close:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;/div&gt;
&lt;pre style="background-color: #f0eee6; border-bottom-color: rgb(193, 180, 150); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(193, 180, 150); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(193, 180, 150); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(193, 180, 150); border-top-style: dashed; border-top-width: 1px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 4pt; padding-left: 4pt; padding-right: 4pt; padding-top: 4pt; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: courier, monospace; white-space: pre-wrap;"&gt;
# if [ "\${recordfail}" = 1 ]
# then
set timeout=-1
#else
set timeout=${2}
#fi

&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
Optionally, you can choose to not unmount NFS paritions, etc in /etc/rc0.d/S35networking and S40unmountfs&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-8347158440757045602?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5_Wlx1NtPCiwCUICUUtDxWVV9xQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5_Wlx1NtPCiwCUICUUtDxWVV9xQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5_Wlx1NtPCiwCUICUUtDxWVV9xQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5_Wlx1NtPCiwCUICUUtDxWVV9xQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/1ZO5kT-AFik" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/8347158440757045602/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=8347158440757045602" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/8347158440757045602?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/8347158440757045602?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/1ZO5kT-AFik/read-only-root-on-vms.html" title="Read only root on VMs" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/07/read-only-root-on-vms.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MGQXg6fCp7ImA9WhdQEUw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-7475696345903034742</id><published>2011-06-30T20:24:00.010-04:00</published><updated>2011-08-11T22:17:00.614-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-11T22:17:00.614-04:00</app:edited><title>Exporting ZFS filesystem over NFS</title><content type="html">First you need to install nfs-kernel-server. You also need a later kernel: 2.6.35 or better&lt;br /&gt;
&lt;br /&gt;
Install zfs native (or zfs-fuse):&lt;br /&gt;
&lt;tt&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;sudo add-apt-repository ppa:dajhorn/zfs
sudo apt-get update
sudo apt-get install ubuntu-zfs 
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
By default NFS sharing is off. To export a zfs filesystem, say zfs/home:&lt;br /&gt;
&lt;br /&gt;
&lt;tt&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;#Setup shared FS
zfs create -o compression=on -o atime=off -o sharesmb=on zfs/home

#export RO
zfs set sharenfs=ro zfs/home

#stop exporting. Also for next command to take effect
zfs set sharenfs=off zfs/home  

# export RW, fsid needs to be unique per filesystem
zfs set \
 sharenfs=10.1.1.0/24:rw,fsid=100,no_subtree_check,async,no_root_squash zfs/home

# add this to /etc/rc.local
zfs share -a

#To mount from OSX use the following command. -P option is for secure (&amp;lt;1024) ports
mount_nfs -P 10.1.1.1:/zfs/home/${USER} /mnt/home
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
Later invocations override earlier, so to export RW to only one host and RO to others:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;tt&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;zfs set sharenfs=off zfs/backup
zfs set sharenfs=10.0.0.0/8:ro,no_subtree_check,async,no_root_squash zfs/backup
zfs set sharenfs=10.1.1.1:rw,no_subtree_check,async,no_root_squash zfs/backup
&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
The host writing the backup is 10.1.1.1 and will get read/write access. The rest will get read only access.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;strong&gt;Note: &lt;/strong&gt;Setting the mountpoint property of a ZFS dataset to anything other than the default &lt;tt&gt;pool/dataset&lt;/tt&gt; will cause it to be exported with &lt;tt&gt;all_squash&lt;/tt&gt;. Do not change the mountpoint if you want to NFS share a dataset&lt;/em&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are getting a lot of stale NFS handles, the IO requests are timing out before they can be serviced due to heavy IO load. Mount your NFS shares using these options (example fstab entry):
&lt;p&gt;
&lt;pre&gt;&lt;tt&gt;
server:/zfs/dataset    /mnt       nfs     defaults,timeo=20,retrans=5,rsize=8192,wsize=8192,intr    0       0

&lt;/tt&gt;&lt;/pre&gt;
&lt;br/&gt;
The timeo to 2 seconds from default of 0.7 seconds is the most important attribute.
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-7475696345903034742?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PhPedoYxqZPb9krNDow-eOg5QpY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PhPedoYxqZPb9krNDow-eOg5QpY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PhPedoYxqZPb9krNDow-eOg5QpY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PhPedoYxqZPb9krNDow-eOg5QpY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/VZoedUB14rk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/7475696345903034742/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=7475696345903034742" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7475696345903034742?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7475696345903034742?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/VZoedUB14rk/exporting-zfs-filesystem-over-nfs.html" title="Exporting ZFS filesystem over NFS" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/06/exporting-zfs-filesystem-over-nfs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04CRHsyeSp7ImA9WhdSEkQ.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-2649737751340492916</id><published>2011-06-03T22:57:00.003-04:00</published><updated>2011-07-21T21:59:25.591-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-21T21:59:25.591-04:00</app:edited><title>Minimal graphical Ubuntu install</title><content type="html">&lt;tt&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;pre&gt;&lt;tt&gt;#!/bin/sh
# Minimal Ubuntu Graphical install
sudo apt-get install gnome-panel gdm gnome-terminal network-manager-gnome \
network-manager gnome-power-manager chromium-browser \
ubuntu-artwork libaudiofile0 flashplugin-installer
&lt;/tt&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-2649737751340492916?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rI1AQSsmXl9g4P7Ezzpg44NUdDY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rI1AQSsmXl9g4P7Ezzpg44NUdDY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rI1AQSsmXl9g4P7Ezzpg44NUdDY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rI1AQSsmXl9g4P7Ezzpg44NUdDY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/IZqSe--vSTs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/2649737751340492916/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=2649737751340492916" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/2649737751340492916?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/2649737751340492916?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/IZqSe--vSTs/minimal-graphical-ubuntu-install.html" title="Minimal graphical Ubuntu install" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/06/minimal-graphical-ubuntu-install.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQCSXw_fCp7ImA9WhZWF04.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-7088724706834845595</id><published>2011-05-18T11:52:00.002-04:00</published><updated>2011-05-18T11:59:28.244-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-18T11:59:28.244-04:00</app:edited><title>Time machine on a network drive</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
A very good explanation of &lt;a href="http://safalra.com/other/time-machine-network-drive/"&gt;how to use a network drive for time machine&lt;/a&gt;. However, there is no need to reboot your OS X once you change the setting. I also make a shell script to create a time machine compatible network drive using all the above steps automatically. Enjoy!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;tt&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/sh
# Create a time machine compatible network drive 
# (c) codebytez.blogspot.com
NETLOC=$1
if [ -z "$1" ]
then
        echo Usage: $0 /Volumes/network_volume \[size\]
        exit 1
fi

if [ -z "$2" ]
then
        SIZE=100g
else
        SIZE=$2
fi

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
MAC=`ifconfig en0 | grep ether | perl -lne 'print @f if (@f = /[0-9a-f]{2}/g)'`
HOST=`echo $HOSTNAME | perl -F'\.' -lane 'print $F[0]'`
VOL=${HOST}_${MAC}.sparsebundle
hdiutil create -size $SIZE -fs HFS+J -volname "Time Machine" $VOL
rsync -aE $VOL $NETLOC
rm -rf $VOL
echo Created $NETLOC/$VOL
echo Select as backup disk in Time Machine Preferences
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-7088724706834845595?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rMFKkxQlp-_f87-Xtsx6Yimv1nE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rMFKkxQlp-_f87-Xtsx6Yimv1nE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rMFKkxQlp-_f87-Xtsx6Yimv1nE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rMFKkxQlp-_f87-Xtsx6Yimv1nE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/2Ak1eGAUTik" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/7088724706834845595/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=7088724706834845595" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7088724706834845595?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/7088724706834845595?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/2Ak1eGAUTik/time-machine-on-network-drive.html" title="Time machine on a network drive" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2011/05/time-machine-on-network-drive.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEIFSX88eyp7ImA9WBRXGEw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-112325875291397496</id><published>2005-08-22T20:35:00.000-04:00</published><updated>2005-08-23T11:55:18.173-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-08-23T11:55:18.173-04:00</app:edited><title>Gates' Law</title><content type="html">&lt;span style="font-style: italic;"&gt;"The speed of processors doubles every 18 months" -- Moore's law&lt;/span&gt;&lt;p&gt;
&lt;span style="font-style: italic;"&gt;"The speed of software halves every 18 months" -- Gates' law &lt;/span&gt;
&lt;p&gt;
I'm uncertain if Gates' Law was meant as a joke, but I did notice that Lotus 123 ran at about the same speed on an old 80286 as excel runs on your modern PC.
&lt;p&gt;
Some of it is certainly because newer hardware makes more things possible, such as the graphical interface and tooltips. Newer software does try to be sexier by doing flashy things such as the talking paperclip. This causes a tendency for the software to bloat to the point of saturation, i.e. until it performs at barely acceptable speeds.
&lt;p&gt;
But application programming seems to get worse with faster processors. Even with more memory, faster disks and multiple CPUs, your average web application runs slower. Is it possible that the faster hardware has made us worse programmers?
&lt;p&gt;
In the old days, to set a register to the value 1, even an average assembly programmer would do something like this:&lt;pre&gt;&lt;tt&gt;
xor ax,ax
inc ax&lt;/tt&gt;&lt;/pre&gt;
rather than:&lt;tt&gt;&lt;pre&gt;
mov ax,1&lt;/pre&gt;&lt;/tt&gt;
The reason was simple. The programmer knew the latter alternative required access to memory, which is generally ten times slower than accessing registers. Modern programming languages hide details like this from the programmer, so he does not know the real cost of bad programming.
&lt;p&gt;
With garbage collection now part of many languages, we see many applications having to deal with memory problems. Why? Because the average programmer does not know the cost of object creation since he does not have to deal with cleanup.
&lt;p&gt;
For example in C++ you would do this:
&lt;pre&gt;&lt;tt&gt;
// case 1: allocate on stack
int a = 1;
// other code
DirEnt de;
&lt;/tt&gt;&lt;/pre&gt;&lt;pre&gt;&lt;tt&gt;
// case 2: allocate on heap
int *a = new int;
// other code
DirEnt *de = new DirEnt;
&lt;/tt&gt;&lt;/pre&gt;
In the first case, the variable is allocated on the stack and disappears when execution moves outside the scope. The compiler calculates the required space at compile time and generates a simple instruction such as:
&lt;pre&gt;&lt;tt&gt;
sub bp, 2+248        ; int is 2 bytes, dirent is 248 bytes
&lt;/tt&gt;&lt;/pre&gt;
In the second case, the variable is allocated on the heap, which is a comparatively slow operation. First, a check is made for sufficient free memory. The heap is then searched for contiguous free memory of the desired size and then initialized. The region is marked "in-use" and a pointer to the memory is returned. If there is no contiguous memory, the system may choose to compact/defragment memory.
&lt;p&gt;
Two characteristics of the heap vs stack in the above example are that the memory allocation routine would need to be called twice, since the compiler has no way of knowing if the allocations can be combined given there is other code between the two allocations. Also while each thread has its own stack, multiple threads compete for the same heap allocator (except a small portion of thread local heap, which is not really a factor in large memory footprints).
&lt;p&gt;
In languages such as Java you cannot really allocate anything except primitives on the stack even if you don't intend to use them beyond the immediate scope. This represents a big load on the memory management system. Objects that properly belong on the stack now crowd the heap, putting a strain on the entire system.
&lt;p&gt;
"But how slow can memory allocation be? Isn't memory accessible in nanoseconds?"
&lt;p&gt;
In most operating systems, for practically all applications, the memory allocated is virtual memory from the theoretical address space rather than actual physical memory. This implies that you need huge amounts of memory to never have a page fault. Page faults generally work at the speed of storage, which is measured in milliseconds unless you have a solid state disk.
&lt;p&gt;
With fragmented memory and a large memory footprint, we end up dealing with multiple page faults, causing the system to thrash. This is especially apparent in multi-threaded programming where the locality of reference principle does not save you from multiple simultaneous page faults.
&lt;p&gt;
Unfortunately, even a programmer who is aware of these issues is helpless if the language itself is restrictive. What java could have done is allocate objects on the stack if they are not passed to other methods.
&lt;pre&gt;&lt;tt&gt;
// new translates to alloc on stack
DirEnt e = new DirEnt(".");
e.list();
&lt;/tt&gt;&lt;/pre&gt;&lt;pre&gt;&lt;tt&gt;
// passed to other class, alloc on heap
DirEnt e = new DirEnt("..");
stack.add(e);
&lt;/tt&gt;&lt;/pre&gt;
Theoretically, the java compiler could follow the object in the call tree and see if anyone retains a reference to it, but that would render the compiler prohibitively slow and perhaps incorrect if reflection is used.
&lt;p&gt;
It is therefore up to the programmer to not trust the much touted features of any language (or any technology) without sufficient experience. Failing which, your programs end up testifying for Gates' Law.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-112325875291397496?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MIPKF07CByEhJMOd8_qUGzGyrDY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MIPKF07CByEhJMOd8_qUGzGyrDY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MIPKF07CByEhJMOd8_qUGzGyrDY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MIPKF07CByEhJMOd8_qUGzGyrDY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/R449YcPGBmg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/112325875291397496/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=112325875291397496" title="24 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112325875291397496?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112325875291397496?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/R449YcPGBmg/gates-law.html" title="Gates' Law" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>24</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/08/gates-law.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8FQXg-fip7ImA9WBRQFU8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-112351773925933420</id><published>2005-08-08T06:10:00.000-04:00</published><updated>2005-08-08T15:03:30.656-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-08-08T15:03:30.656-04:00</app:edited><title>The problem with DTDs and schemas</title><content type="html">Many would agree with me that XML is too bulky for its intended purposes. But would you say the same about HTML? probably not.
&lt;p&gt;
And why should that be? Isnt XML a glorified, genericized HTML? Despite what the historians say about both being children of SGML, the fact of the matter is that XML only came into being after the spectacular success of HTML and if you remember the original marketing hype, it was all about how web documents would be XML in the future and how they would be rendered or used differently by other consumers.
&lt;p&gt;
One of the important factors for the failure of XML is the reliance on DTDs and schemas. HTML succeeded simply because there was no predefined format for any given web page. Browsers ignored what they did not understand, and did the best with what they could. HTML was a &lt;i&gt;language&lt;/i&gt; that browsers and servers spoke. There was a syntax, but no schema. The schema came later, long after HTML was refined through multi-year, multi-user testing.
&lt;p&gt;
Your typical enterprise application does not have that luxury.
&lt;p&gt;
Consider this snippet of XML:
&lt;p&gt;
&lt;pre&gt;&lt;code&gt;
&amp;lt;orders&gt;
&amp;lt;date&gt;Dec-24&amp;lt;/date&gt;
 &amp;lt;order&gt;
  &amp;lt;customer&gt;Joe Schlubbs&amp;lt;/customer&gt;
  &amp;lt;customer-address&gt;10 drowning st&amp;lt;/customer-address&gt;
  &amp;lt;customer-city&gt;London&amp;lt;/customer-city&gt;
  &amp;lt;order-line&gt;
     &amp;lt;quantity&gt;100&amp;lt;/quantity&gt;
     &amp;lt;item-number&gt;J-350&amp;lt;/item-number&gt;
     &amp;lt;item-name&gt;extra large onions&amp;lt;/item-name&gt;
     &amp;lt;price-per-item&gt;12.35&amp;lt;/price-per-item&gt;
     &amp;lt;!-- other fields --&gt;
  &amp;lt;/order-line&gt;
 &amp;lt;/order&gt;
 &amp;lt;order&gt;
   &amp;lt;customer&gt;Joe Schlubbs&amp;lt;/customer&gt;
   &amp;lt;customer-address&gt;10 drowning st&amp;lt;/customer-address&gt;
   &amp;lt;customer-city&gt;London&amp;lt;/customer-city&gt;
   &amp;lt;order-line&gt;
      &amp;lt;quantity&gt;100&amp;lt;/quantity&gt;
      &amp;lt;item-number&gt;J-007&amp;lt;/item-number&gt;
      &amp;lt;item-name&gt;extra large bullets&amp;lt;/item-name&gt;
      &amp;lt;price-per-item&gt;1.99&amp;lt;/price-per-item&gt;
   &amp;lt;/order-line&gt;
  &amp;lt;/order&gt;
&amp;lt;/orders&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Lets assume we are writing an application that needs a list of all customers who spent more than a thousand bucks in the last month so we could mail them some coupons.
&lt;p&gt;
An SQL programmer would simply do a &lt;tt&gt;SELECT customer, sum(price*qty)  group by customer having sum(price*qty) &gt; 1000&lt;/tt&gt;. The typical XML programmer on the other hand, has to get all orders for the last month and skim through large amounts of text to produce the necessary results.  Depending on the number of tags, close to 90 percent of the input will be useless to the application.
&lt;p&gt;
Could the server simply omit the unnecessary data? Probably not, because the tags are not optional. Thats because when they designed the XML, they could not forsee that business would be so good that they would send out coupons.
&lt;p&gt;
It is simply impossible to forsee all possible future needs, so to really future-proof your schema, you would need to make nearly every tag optional. This pretty much void the purpose of a schema.
&lt;p&gt;
A schema where every tag is optional could still useful, to describe what tags go where and what they mean -- sort of like HTML.
&lt;p&gt;
Or you could just deal with the bulk.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-112351773925933420?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QqxWUBPDgvXH5qVf0v7YZHqlXfE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QqxWUBPDgvXH5qVf0v7YZHqlXfE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QqxWUBPDgvXH5qVf0v7YZHqlXfE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QqxWUBPDgvXH5qVf0v7YZHqlXfE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/m35VYPry6AM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/112351773925933420/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=112351773925933420" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112351773925933420?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112351773925933420?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/m35VYPry6AM/problem-with-dtds-and-schemas.html" title="The problem with DTDs and schemas" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/08/problem-with-dtds-and-schemas.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MMRXs6eCp7ImA9WBRQEUQ.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-112317210249354256</id><published>2005-08-04T20:00:00.000-04:00</published><updated>2005-08-04T19:51:24.510-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-08-04T19:51:24.510-04:00</app:edited><title>Semaphores in assembler and java</title><content type="html">How do you implement a semaphore in assembler taking into account the fact that you may have multiple CPUs with each CPU possibly executing multiple threads of code at any time?

We use the &lt;code&gt;xchg&lt;/code&gt; instruction, which performs atomic exchange of its arguments.

&lt;pre&gt;&lt;code&gt;
;acquire semaphore
    xor     ax, ax      ; set AX to zero
L1:
    xchg    ax, sema    ; atomic test and set. sema = 0, ax = sema
    or      ax, ax      ; is the value we obtained from sema 0?
    jz      L1          ; yes, wait for someone to release semaphore
    dec     ax          ; no, we got the semaphore.
    xchg    ax, sema    ; decrease by one and store

;process stuff

; release semaphore
    xchg    ax, sema    ; sema value may have been changed by other threads
    inc     ax          ; bump to notify we have released it
    xchg    ax, sema    ; atomic store
&lt;/code&gt;&lt;/pre&gt;

This is why there is an atomic exchange instruction in many processors. An atomic test and set instruction is indispensable for a variety of systems programming, semaphores being one of them. On systems with multiple processors, you probably want to lock the bus before executing the &lt;code&gt;xchg&lt;/code&gt;. The code becomes:
&lt;pre&gt;&lt;code&gt;
    lock xchg  ax, sema
&lt;/code&gt;&lt;/pre&gt;
In case you have forgotten, the &lt;code&gt;lock&lt;/code&gt; instruction locks the memory bus for the duration of the next instruction, which ensures that another processor does not read or write to sema when we are writing to it.

The sequence of instructions
&lt;pre&gt;&lt;code&gt;
L1:
    xchg    ax, sema
    or      ax, ax
    jz      L1
&lt;/code&gt;&lt;/pre&gt;
form an anti-pattern called "busy-waiting" and burns up CPU resources when waiting to acquire the semaphore. In real life systems programming, it is often replaced by a spin lock, (which is a "design pattern")

A spin lock busy waits for a few instruction cycles and then goes to sleep. The idea behind this is that context switches are expensive, and for many operations, semaphores are held briefly enough that the majority of the time, the waiting thread acquires the semaphore without the added cost of a context switch.

&lt;pre&gt;&lt;code&gt;
;acquire semaphore
L0:
    mov     cx, 0800h    ; spin the test loop so many times ...
    xor     ax, ax       ; ... choose 1/2 cost of context switch and tweak
L1:
    xchg    ax, sema
    or      ax, ax
    jnz     L2           ; got the semaphore, go to update
    loop    L1           ; repeat till cx is zero
    call    monitor_wait ; context switch
    jmp     L0           ; need to retest after notify
L2:
    dec     ax
    xchg    ax, sema

&lt;/code&gt;&lt;/pre&gt;
As you can see this implementation is very efficient and wastes very few cycles. A semaphore variable needs to be initialized with the number of simultaneous threads that can access it. For a mutex (equivalent to java's synchronized) we set the value to 1.

The Linux kernel approaches the problem in a similar manner (albeit in C).

The java equivalent looks like this:
&lt;pre&gt;&lt;code&gt;
synchronized(lock) // sema is an invisible variable inside object lock
{                  // sema acquired if you get here
    // process
}                  // release sema
&lt;/code&gt;&lt;/pre&gt;
Given that mutexes are nothing but special case of semaphores which have been in use in systems programming since antiquity and the relative simplicity of the machine code to implement them, its surprising that the &lt;code&gt;monitorenter&lt;/code&gt; and &lt;code&gt;monitorexit&lt;/code&gt; instructions were prohibitively expensive in early JVM implementations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-112317210249354256?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w_9QrKyeh9GrVscvByV_drl_asI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w_9QrKyeh9GrVscvByV_drl_asI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w_9QrKyeh9GrVscvByV_drl_asI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w_9QrKyeh9GrVscvByV_drl_asI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/JF4fheqBqNI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/112317210249354256/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=112317210249354256" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112317210249354256?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112317210249354256?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/JF4fheqBqNI/semaphores-in-assembler-and-java.html" title="Semaphores in assembler and java" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/08/semaphores-in-assembler-and-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkQGRn08eCp7ImA9WBRQEU8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-112311656940763041</id><published>2005-08-03T20:01:00.000-04:00</published><updated>2005-08-04T00:05:27.370-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-08-04T00:05:27.370-04:00</app:edited><title>SEXML</title><content type="html">XML has the unfortunate side effect of being bulky. While bulk is good for the large intestine, its pretty much useless in computing.

Which is why I devised SEXML. That's Simple Elemental XML.

This is how it was derived:

First, we get rid of attributes. What good are attributes for? They can easily be replaced by elements:
&lt;pre&gt;
&amp;lt;order qty="12" price="13.5" brokerage="15%"&gt;
&amp;lt;order-type&gt;buy&amp;lt;/order-type&gt;
&amp;lt;effective-time&gt;market-close&amp;lt;/effective-time&gt;
&amp;lt;/order&gt;
&lt;/pre&gt;
can be rewritten as:
&lt;pre&gt;
&amp;lt;order&gt;
&amp;lt;qty&gt;12&amp;lt;/qty&gt;
&amp;lt;price&gt;13.5&amp;lt;/price&gt;
&amp;lt;brokerage&gt;15%&amp;lt;/brokerage&gt;
&amp;lt;order-type&gt;buy&amp;lt;/order-type&gt;
&amp;lt;effective-time&gt;market-close&amp;lt;/effective-time&gt;
&amp;lt;/order&gt;
&lt;/pre&gt;
Next, we get rid of the irritating double tags. We accomplish this by turning &amp;lt;qty&gt;12&amp;lt;/qty&gt; into qty&amp;lt;12&gt;. The XML above becomes:
&lt;pre&gt;
order&amp;lt;
qty&amp;lt;12&gt;
price&amp;lt;13.5&gt;
brokerage&amp;lt;15%&gt;
order-type&amp;lt;buy&gt;
effective-time&amp;lt;market-close&gt;
&gt;
&lt;/pre&gt;
To avoid confusion between XML and SEXML, and to enable embedding one in the other, lets replace &amp;lt;&gt; with something else, say {} and while we are at it, put them on just one line:
&lt;pre&gt;
order{qty{12}price{13.5}brokerage{15%}order-type{buy}effective-time{market-close}}
&lt;/pre&gt;Perhaps we should separate the items with a comma, in case there are empty elements:

&lt;pre&gt;order{qty{12},price{13.5},brokerage{15%},order-type{buy},effective-time{market-close}}
&lt;/pre&gt;
There we go. If we had used parantheses, it would look too much like lisp and scare people off.
Of course, you would put everything on one line only for use in URLs and the like.
&lt;p&gt;
The above has the same informational content of the XML above, but is much more compact and simpler to parse.
&lt;/p&gt;&lt;p&gt;
"But wait!" I hear screams. "What about schemas? What about the XML header? Character encoding? Entities?"
&lt;/p&gt;&lt;p&gt;
Nothing prevents you from using a schema. After all, it only describes structure and type information, not whether you use braces or angle brackets. Your schema just wont mention any attributes. As an exercise, try writing a schema for the above in SEXML.
&lt;/p&gt;&lt;p&gt;
As for the header, I dont see why you cant SEXML it up.
&lt;/p&gt;&lt;pre&gt;
sexml {
 version{1.0}, encoding{utf-8},
 order{
     qty{12},price{13.5},brokerage{15%},order-type{buy},effective-time{market-close}
 }
}
&lt;/pre&gt;
Entities such as &amp;amp;lt; can live as is.
&lt;p&gt;
I believe CDATA is quite unnecessary for SEXML and in fact, seems to be rarely used in XML. If you believe otherwise, please enlighten me.
&lt;/p&gt;&lt;p&gt;
/*&lt;br&gt;
Since the original reason the comment in xml became the unweildy &amp;lt;!-- --&gt; to maintain compatibility with HTML, we can break it here to use C++ style comments.
(Do you really need 4 chars to start a comment?)&lt;br&gt;
*/

&lt;/p&gt;&lt;p&gt;
Lets see what it looks like with parantheses:
&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;pre&gt;sexml (
 version(1.0), encoding(utf-8),
 order (
     qty(12),price(13.5),brokerage(15%),order-type(buy),effective-time(market-close)
 )
)

&lt;/pre&gt; Guess the Lisp folks were right. Everything is a list of lists.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-112311656940763041?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WJFfuGdJQ9WaR4RYZN49h6VXKco/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WJFfuGdJQ9WaR4RYZN49h6VXKco/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WJFfuGdJQ9WaR4RYZN49h6VXKco/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WJFfuGdJQ9WaR4RYZN49h6VXKco/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/cyJN2Pf7Gbc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/112311656940763041/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=112311656940763041" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112311656940763041?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/112311656940763041?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/cyJN2Pf7Gbc/sexml.html" title="SEXML" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>5</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/08/sexml.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcBQHw4eyp7ImA9WBZaE0Q.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110724089308115630</id><published>2005-02-01T01:09:00.000-05:00</published><updated>2005-02-25T23:44:11.233-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-02-25T23:44:11.233-05:00</app:edited><title>Assembling a home theatre PC</title><content type="html">I've wanted to build an AMD-64 for some time and I finally got started with the following parts. All items were located on &lt;a href='http://www.pricewatch.com'&gt;Pricewatch&lt;/a&gt;. For some items, I did not automatically choose the cheapest vendor if the vendor had less than best ratings.
&lt;p/&gt;
The general plan is to have a media box such as &lt;a href='http://angerman.net/articles/jukebox/'&gt;this&lt;/a&gt;.
&lt;p/&gt;
&lt;table border=1 align='right'&gt;
&lt;tr&gt;&lt;th&gt;Item&lt;/th&gt;&lt;th align='right'&gt;Price (w/. shipping)&lt;/th&gt;&lt;th&gt;Qty&lt;/th&gt;&lt;th&gt;Amount&lt;/th&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;AMD Athlon 64 939 3500+&lt;/td&gt; &lt;td&gt;$262.70&lt;/td&gt;&lt;td align='right'&gt;1&lt;/td&gt;&lt;td&gt;$262.70&lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Asus A8N SLI skt939&lt;/td&gt;&lt;td&gt;$194.00&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;  $194.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Ahanix D4 &lt;/td&gt;&lt;td&gt;$229.58&lt;/td&gt;&lt;td&gt;  1&lt;/td&gt;&lt;td&gt;  $229.58 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Zalman CNPS7000B-CU Cooler &lt;/td&gt;&lt;td&gt;$52.00&lt;/td&gt;&lt;td&gt;  1&lt;/td&gt;&lt;td&gt;  $52.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Samsung PC3200 512MB&lt;/td&gt;&lt;td&gt; $82.00 &lt;/td&gt;&lt;td&gt; 2&lt;/td&gt;&lt;td&gt;  $164.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;HITACHI 250GB SATA&lt;/td&gt;&lt;td&gt; $120.00 &lt;/td&gt;&lt;td&gt; 2&lt;/td&gt;&lt;td&gt;  $240.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Hauppage WinPVR-250 &lt;/td&gt;&lt;td&gt;$128.00 &lt;/td&gt;&lt;td&gt; 1&lt;/td&gt;&lt;td&gt;  $128.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;PCI express eVGA 6600 256MB &lt;/td&gt;&lt;td&gt;$129.00 &lt;/td&gt;&lt;td&gt; 1&lt;/td&gt;&lt;td&gt;  $129.00 &lt;/td&gt;&lt;/tr&gt;
&lt;tr align='right'&gt;&lt;td&gt;Arctic Silver 5&lt;/td&gt;&lt;td&gt;$6.00&lt;/td&gt;&lt;td&gt;  1&lt;/td&gt;&lt;td&gt;  $6.00 &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;
In addition, I bought some &lt;a href='http://www.bevmo.com/productinfo.asp?area=home&amp;seref=froogle&amp;pf_id=00000012007'&gt;Everclear 95% grain alcohol&lt;/a&gt; from a liquor store for cleaning the computer parts. (Never use anything other than pure grain alcohol!)
&lt;p&gt;
In general, stores where shipping is free tend to ship via &lt;a href='http://www.usps.com'&gt;snail mail&lt;/a&gt;, so when looking at the price, factor that in.
&lt;p&gt;
Most items were packed perfectly. I was impressed with the packing of the hard drives and the Ahanix case. Other items were packaged adequately. The only exception was the Zalman cooler, which had some copper cooling blades bent because they did not seal the box. Copper is a soft metal and bends easily. the fan also looked very slightly scuffed. I straightened out the fins of the Zalman carefully. Then I verified that the fan ran silently and decided not to ask for an exchange.
&lt;p&gt;
&lt;h4&gt;First impressions:&lt;/h4&gt;
The &lt;a href='http://www.ahanix.com/ahanix_product.asp?pid=9'&gt;Ahanix D4&lt;/a&gt; case looks like a stereo component device. The front metal face is about a quarter inch thick and feels luxurious. A hinged door that covers the 5.25 inch bays is held together by magnets and impresses quality. The entire case is aluminum and is very well constructed. The included power supply is silent and the case is designed to be kept cool. I wont review the case fully here since its been reviewed elsewhere, but suffice to say this is the best case you can get that holds a full ATX board and worth every penny. The D5 is cooler looking, but does not seem to have front USB/firewire ports and has an infra-red remote control sensor that is plugged to the USB port. I was not sure how it would work with &lt;a href='http://www.lirc.org'&gt;lirc&lt;/a&gt;, so I did not buy it. The only negetive about this box is that smudges can be easily seen when you touch it.
&lt;p&gt;
The &lt;a href='http://www.amd.com/us-en/Processors/ProductInformation/0,,30_118_9485_9487,00.html'&gt;AMD Athlon 64 CPU&lt;/a&gt; looked like it had some extremely thin layer of gunk on it (returned item?) but I washed it with alcohol and it evaporated.
&lt;p&gt;
The &lt;a href='http://www.zalmanusa.com/usa/product/view.asp?idx=145&amp;code=005009'&gt;Zalman CNPS7700-Cu cooler&lt;/a&gt; is a thing of beauty. It looks like a copper flower. The fan is large and silent. It comes with a fan control device, some thermal grease and various brackets. I cleaned its bottom with alcohol too.
&lt;p&gt;
The &lt;a href='http://usa.asus.com/products/mb/socket939/a8nsli-d/overview.htm'&gt;Asus A8N SLI deluxe&lt;/a&gt; motherboard truly deserves the &lt;em&gt;Deluxe&lt;/em&gt; tag. It comes with every imaginable cable and fixture including a SATA fixture that allows you to plug in SATA drives at the back. The chipset fan is reasonably silent. The optical SPDIF out makes this board attractive to Home Theater projects. The 8 SATA RAID interfaces don't hurt either. The most important feature however, is Nvidia chipset, which has good Linux support from the vendor. 
&lt;p&gt;
The &lt;a href='http://www.arcticsilver.com/as5.htm'&gt;Arctic silver 5&lt;/a&gt; compound comes in a tiny syringe with a rubber dome top. 
&lt;p&gt;
The &lt;a href='http://www.hitachigst.com/portal/site/hgst/?epi_menuItemID=268b770f407cc00ae4c0c516bac4f0a0&amp;epi_menuID=8d237906f078b6fd25ad4e8060e4f0a0&amp;epi_baseMenuID=22f0deefa8f3967dafa0466460e4f0a0'&gt;Hitachi SATA hard drives&lt;/a&gt; run great, but are not as silent as their IBM counterparts (before IBM sold their hard drive division to Hitachi). It could be because I have 2 SATA drives in raid config (more on that later) and they make the seek sound simultaneously. I need to investigate into silencing the drives a bit more.
&lt;p/&gt;
The &lt;a href='http://evga.com/products/moreinfo.asp?pn=256-P2-N369-TX'&gt;eVGA GeForce 6600 with 256MB&lt;/a&gt; seems to be the fastest card at the price. This card comes with a shrouded fan. If you are a serious gamer (I'm not), its a good idea to go with the &lt;a href='http://www.nvidia.com/page/geforce_6800.html'&gt;6800 GT&lt;/a&gt; and get the &lt;a href='http://www.arctic-cooling.com/vga1.php'&gt;Arctic cooler&lt;/a&gt; for it.
&lt;p/&gt;
The RAM looked like ... RAM. The DIMMS had Copper heat spreaders on them and the word RAMSES printed. I complained to the vendor that he had sent me Ramses brand when I had requested Micron. He told me that the heat spreader was Ramses and the RAM was actually Samsung, which was allegedly better than Micron. I decided to keep the RAM if it ran stable. Fortunately, it did.
&lt;p/&gt;
I had an &lt;a href='http://www.plextor.com/english/products/712A.htm'&gt;old Plextor 712A  DVD Writer&lt;/a&gt;, which I plugged into the system.
&lt;p/&gt;
&lt;h4&gt;Hardware installation:&lt;/h4&gt;
First, I removed the motherboard backplate provided by Ahanix. The items simply did not match my motherboard. I replaced it with one included by ASUS. The motherboard comes with a bracket and baseplate for the stock CPU cooler which I removed and then attached the baseplate that came with the Zalman cooler (using the nipples provided). I placed the motherboard on a flat surface and lifted the ZIF socket's lever and then aligned the CPU's golden triangle with the triangular mark on the ZIF socket. It fell into place easily. Placing the CPU on the ZIF socket and pushing the lever back to horizontal position is about the easiest thing to do. 
&lt;p/&gt;
Next, I took the Arctic silver 5 syringe and punctured the top with a pin and then squeezed about 1 and a half rice grain lengths on the CPU. I then gently lowered the Zalman cooler and aligned the screw holes with the nipples. Once the cooler sits on the CPU, a suction prevents you from easily picking up the cooler. but you can turn it slightly. I then screwed in the cooler tight alternating each screw.
&lt;p/&gt;
I then lifted the motherboard with the CPU and cooler into the case and screwed it to the base. (Some folks prefer to attach the board first and then install the CPU and heatsink, but given that Arctic silver is slightly capacitative, I needed to be absolutely sure that not a single particle would fall onto the motherboard.)
&lt;p/&gt;
Next, I installed the Samsung 512MBx2 PC3200 RAM which had copper heat spreaders on them into the appropriate banks (A1 and B1) to make best use of DDR feature.
&lt;p/&gt;
Next, I installed the Hitachi SATA hard drives. You only get access to one side of the bay, so I screwed them in.
&lt;p/&gt;
Next, I installed the PCI-Express eVGA card into the blue PCIe slot (as recommended if using a single slot)
&lt;p/&gt;
Last, I connected all the case connections such as the power and hard drive LEDs
&lt;p/&gt;
Linux Installation: Most folks would do well to just install the &lt;a href='http://www.mysettopbox.tv/knoppmyth.html'&gt;KnoppMyth distribution&lt;/a&gt;, but I'm a &lt;a href='http://www.gentoo.org/'&gt;gentoo&lt;/a&gt; fanatic, so I downloaded the AMD64 ISO and installed gentoo and installed from stage3. &lt;a href='http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?full=1'&gt;Standard procedure&lt;/a&gt; with some hints for &lt;a href='http://www.gentoo.org/doc/en/gentoo-x86-tipsntricks.xml'&gt;raid&lt;/a&gt;. 
&lt;p/&gt;
The only things I need to tell you are: For the sound card, I chose snd-intel8x0 (alsa driver) and for the net I chose forcedeth. Although I got nvidia's &lt;a href='http://www.nvidia.com/object/linux_nforce_amd64_1.0-0292.html'&gt;nvsound and nvnet&lt;/a&gt; to work after applying &lt;a href='http://www.nvnews.net/vbulletin/showthread.php?p=510644#post510644'&gt;patches&lt;/a&gt;, I saw no advantage over standard kernel provided drivers. For the video, I emerge nvidia-kernel and added nvidia to modules.autoload. I managed to setup SPDIF using instructions &lt;a href='http://www.wlug.org.nz/NForce2Notes'&gt;here&lt;/a&gt;. 
I see that my SPDIF is properly setup:
&lt;pre&gt;
# cat /proc/asound/pcm
00-00: Intel ICH : NVidia CK804 : playback 1 : capture 1
00-01: Intel ICH - MIC ADC : NVidia CK804 - MIC ADC : capture 1
00-02: Intel ICH - IEC958 : NVidia CK804 - IEC958 : playback 1
&lt;/pre&gt;
So I should be able to play it like this:
&lt;pre&gt;
# mplayer -ao alsa:device=hw=0.2 mozart.mp3
&lt;/pre&gt;
But either my receiver has no support for it or I need to do something &lt;a href='http://opensrc.org/alsa/index.php?page=intel8x0'&gt;like this&lt;/a&gt; or &lt;a href='http://www.alsa-project.org/alsa-doc/doc-php/template.php?company=Intel&amp;card=.&amp;chip=440MX%2C+i810%2C+i810%2C+i810E%2C+i820%2C+i820&amp;module=intel8x0'&gt;this&lt;/a&gt;. So I went back to analog sound output.
&lt;p/&gt;
The video was tricky. I finally managed to get the right xorg.conf file but I had two serious problems. The first, the cursor was a transparent square area with a cluster of black dots and second, the icons and text would disappear if the mouse went over them (or sometimes just by themselves). Fortunately, I found a &lt;a href='https://bugs.freedesktop.org/show_bug.cgi?id=2322'&gt;patch&lt;/a&gt; on the internet for xorg and recompiled with it. All I did was emerge it, when it said 'Source unpacked' I pressed control+Z, applied the patch and resumed the job. I really should do something &lt;a href='http://www.sable.mcgill.ca/~clump/Gentoo%20Install.html'&gt;like this (go to bottom)&lt;/a&gt;, but I'm guessing that they will have the bugfix in the next version anyway.
&lt;p/&gt;
Its important to autoload the nvidia module or you get a "failure to load nvidia" error when you start X.
&lt;p/&gt;
I struggled to setup the RAID, until I realized that the onboard RAID controllers are nothing more than a place in the BIOS to store your settings. Linux still sees the physical hard drives. Grub probes the BIOS, so it sees the real drives. You cannot install GRUB with fakeraid. The best option was to use mdadm and Linux software raid, which is just as fast if not faster. The utility &lt;a href='http://www.linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html'&gt;mdadm&lt;/a&gt; was part of the installation cd, so I used it to setup the raid. The trick of course, is to set your boot partition as RAID-1, so that grub will load off it. Install grub in both partitions as shown &lt;a href='http://www.linuxsa.org.au/mailing-list/2003-07/1270.html'&gt;here&lt;/a&gt;. I could probably have used the hardware using instructions &lt;a href='http://forums.gentoo.org/viewtopic.php?t=69554'&gt;here&lt;/a&gt;.
&lt;p/&gt;
I got the Vacuum Fluorescent Display (part of the D4 case) working using &lt;a href='http://venky.ws/forums/viewtopic.php?t=14'&gt;these instructions&lt;/a&gt;. The VFD displays y with umlaut when the it tries to display a filled square for which I found a patch &lt;a href='http://angerman.net/articles/jukebox/'&gt;here&lt;/a&gt;
&lt;p/&gt;
Wealth of info &lt;a href='http://www.nforcershq.com/forum/viewtopic.php?t=45973'&gt;here&lt;/a&gt;

&lt;h4&gt;Noise&lt;/h4&gt;
In general, I can constantly hear the constant whoosh of the fans at the back (I've disconnected one). The motherboard chip fan was the noisiest and I noticed that it was running at 8000+ RPM. I fixed the fan speed regulator that came with the CPU cooler and attached it to the motherboard chip fan and turned it fully down. The fan now runs at 4000+ RPM, but has almost negligible sound. The hard disks are silent unless there is activity, which I figure is the sound echoing off the case. The activity is occaisional even when compiling the kernel due to the 8MB caches.
&lt;p&gt;
&lt;h4&gt;Infrared&lt;/h4&gt;
I purchased the parts off &lt;a href='http://www.radioshack.com'&gt;Radio Shack&lt;/a&gt; and soldered my own infra red receiver. I attached the IR sensor off a long wire, so I could squeeze it into the space provided by the D4 case (just above the HDD light left of the VFD).
&lt;h4&gt;Heat&lt;/h4&gt;
In general, the CPU runs at 35C with the case open and 43C with the case closed at idle. On heavy load, it goes upto 55C. The motherboard temp and the case ambient temperature is generally about 5C and 15C below the CPU temperature.
&lt;p&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
All in all, I'm happy with the power and performance of this machine. I aim to install the arctic cooler for my VGA card and I also need to figure out how to reduce the noise of the fans and the hard disks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110724089308115630?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZPr_1msF_pmXvzjokJKvr9Gd0Rg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZPr_1msF_pmXvzjokJKvr9Gd0Rg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZPr_1msF_pmXvzjokJKvr9Gd0Rg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZPr_1msF_pmXvzjokJKvr9Gd0Rg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/vv7KM6XHFD8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110724089308115630/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110724089308115630" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110724089308115630?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110724089308115630?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/vv7KM6XHFD8/assembling-home-theatre-pc.html" title="Assembling a home theatre PC" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/02/assembling-home-theatre-pc.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QHQHYyeCp7ImA9WBZVFk8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110662533188837751</id><published>2005-01-24T22:52:00.000-05:00</published><updated>2005-01-24T22:55:31.890-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-01-24T22:55:31.890-05:00</app:edited><title>Historical: Typewriter</title><content type="html">When I was a kid, I wrote this assembly program that would play with the VGA fonts (I wrote a whole bunch of programs that messed with the VGA fonts) One particular program that comes to mind is one that shifts the lines on the VGA font one scan line upward, making it look like it was typed on a typewriter with an errant key.
&lt;pre&gt;&lt;tt&gt;

SCANLINES	equ	16
SHIFT		equ	 2

.model small
.code
	org	100h
main	proc
	mov	ax,1130h	; read char vector
	mov	bh,06		; 8*16 vga/mcga
	int	10h

	mov	ah,0		; read char
	int	16h
	cbw
	push	ax
	
		
	mov	cl,4		; map of offending char
	shl	ax,cl
	add	bp,ax
	add	bp,SHIFT	
	
	mov	cx,SCANLINES-SHIFT	; save char bitmap
	push	ds
	push	es		
	pop	ds
	pop	es
	mov	si,bp		; ds:si-&gt;original map
	lea	di,charmap	; es:di-&gt;our buf
	cld
	rep	movsb	
			
	mov	ax,1100h	; set char
	mov	cx,1
	pop	dx
	mov	bh,10h		; 8*16 vga/mcga
	lea	bp,charmap
	int	10h

	mov	ax,4c00h
	int	21h
main	endp

charmap	db SCANLINES dup(0)	; init to 0 as last lines must be blank
	end	main
&lt;/tt&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110662533188837751?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d959Yu4CXPjMRjkSmoUl_lfeEmE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d959Yu4CXPjMRjkSmoUl_lfeEmE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d959Yu4CXPjMRjkSmoUl_lfeEmE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d959Yu4CXPjMRjkSmoUl_lfeEmE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/oVrw5HhrKm0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110662533188837751/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110662533188837751" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110662533188837751?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110662533188837751?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/oVrw5HhrKm0/historical-typewriter.html" title="Historical: Typewriter" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/01/historical-typewriter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8ARH4yfip7ImA9WBZVFk8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110662284509503651</id><published>2005-01-24T21:51:00.000-05:00</published><updated>2005-01-24T22:14:05.096-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-01-24T22:14:05.096-05:00</app:edited><title>History: Executing a program in DOS</title><content type="html">A common trick in the old days was to execute an application from within another. Here is some code example of how that was normally done:
&lt;pre&gt;&lt;tt&gt;
.model tiny
.code

ExecBlk	Struc
	Psp	dw	?
	Cmdline	dw	?
	CmdSeg	dw	?
	FCB1	dw	?
	FCB1seg	dw	?
	FCB2	dw	?
	FCB2seg	dw	?
ExecBlk	ends

	org	100h

main	proc
	lea	bx,pspblk
	mov	sp,bx
	call	resize	

	mov	execb.psp,0		; copy our environment
	mov	execb.cmdline,80h	; pass command line as is
	mov	execb.FCB1,5ch
	mov	execb.FCB2,6ch
	mov	execb.cmdseg,cs
	mov	execb.FCB1seg,cs
	mov	execb.FCB2seg,cs
	lea	dx,execf
	push	ds
	pop	es
	lea	bx,execb
	mov	ax,4b00h
	int	21h
merr:
	mov	ax,4c00h
	int	21h
main	endp

resize	proc
	add	bx,15
	mov	cl,4
	shr	bx,cl
	mov	ax,cs
	add	bx,ax
	mov	ah,4ah
	int	21h
	jc	merr
	ret
resize	endp


execf	db	"PAT.COM",0		; ASCIIZ pathname of file to be execd
execb	ExecBlk	&lt;&gt;
_stack	dw	1000h dup(?)

pspblk	label	byte

	end	main
&lt;/tt&gt;&lt;/pre&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110662284509503651?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ybjkZlCglLABz4JnDxs7rTzgvH4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ybjkZlCglLABz4JnDxs7rTzgvH4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ybjkZlCglLABz4JnDxs7rTzgvH4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ybjkZlCglLABz4JnDxs7rTzgvH4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/kJYv0q3NAIo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110662284509503651/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110662284509503651" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110662284509503651?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110662284509503651?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/kJYv0q3NAIo/history-executing-program-in-dos.html" title="History: Executing a program in DOS" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2005/01/history-executing-program-in-dos.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYBRnk5eyp7ImA9WBZVFk8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110452369373977690</id><published>2004-12-31T14:51:00.000-05:00</published><updated>2005-01-24T22:35:57.723-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-01-24T22:35:57.723-05:00</app:edited><title>Is BASIC good for anything?</title><content type="html">Has BASIC become the red haired stepchild that nobody wants?
&lt;p&gt;
Some folks look down upon BASIC programmers; in fact they even avoid thier company. I'm not trying to say that all programmers are equal in the eyes of the CPU or anything, but remember that Bill Gates is basically a BASIC programmer and that BASIC was once the language of choice for many music related application in the 80's. BASIC's &lt;tt&gt;PLAY&lt;/tt&gt; keyword makes it simple to program musical notes and I'm sure the language has a couple of other redeeming features as well (I just can't remember what they are at the moment). 
&lt;p&gt;
BASIC's lack of the need for formal structure such as class declarations or include statements plus its interpreted nature makes it a popular language to learn programming   even in places like India where everyone is allegedly born partially a programmer.
&lt;p&gt;
Speaking of India, here is a song written entirely in BASIC.
&lt;tt&gt;&lt;pre&gt;
10 '+------------------------------------------------------------------------+
20 '|                      The Indian National Anthem                        |
90 '+------------------------------------------------------------------------+
110  PLAY "L8C#D#FFFFFFL4FL8FFD#FL4F#"  '| Jana gana mana adhinayaka jaya hai|
120  PLAY "L4FL8FFL4D#L8D#D#CD#L2C#"    '| Bharatha bhagya vidhatha          |
130  PLAY "L4D#G#L8G#L4G#L5G#"          '| Punjaba Sinda                     |
140  PLAY "L8G#L4G#L8G#G#G#L8A#L4G#"    '| Gujaratha maratha                 |
150  PLAY "L4F#L8F#F#L4FL8FFD#F#L1F"    '| Dravida uthkala vanga             |
160  PLAY "L4FL8FFl4Fl8fd#g#g#l4g#f#f#" '| Vindhya Himachala Yamuna Ganga    |
170  PLAY "L4fl8ffd#d#d#l8cl4d#l1c#"    '| Uthkala jaladi taranga            |
180  PLAY "L8ffffl4fl4fl8d#fl1f#"       '| Tava shubha name jage             |
190  PLAY "L8ff#g#g#l4g#l8f#fd#l8f#l1f" '| Tava shubha ashisa mage           |
200  PLAY "l4ffl8d#d#d#d#cd#l1c#"       '| Gahe Tava jaya gatha              |
210  PLAY "l8g#g#g#g#l4g#l8g#g#"        '| Jana gana mangala                 |
220  PLAY "l4g#l8g#g#g#l8a#l4g#"        '| Dayaka jaya hai                   |
230  PLAY "l4f#l8f#f#l4fl8ffl8d#f#l1f"  '| Bharatha bhagya vidhata           |
240  PLAY "o5l8ccl1c#l8co4a#l1o5c"      '| Jaya hai jaya hai                 |
250  PLAY "l8o4g#g#o5l1o4a#"            '| Jaya hai                          |
260  PLAY "l8c#d#fff#f#d#fl1f#"         '| Jaya jaya jaya jaya hai           |
270  END                                '+-----------------------------------+

&lt;/pre&gt;&lt;/tt&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110452369373977690?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4wCJS93rASfzmXjhJ9vOR-UccjQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4wCJS93rASfzmXjhJ9vOR-UccjQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4wCJS93rASfzmXjhJ9vOR-UccjQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4wCJS93rASfzmXjhJ9vOR-UccjQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/7zCxrn2Z7aM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110452369373977690/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110452369373977690" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110452369373977690?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110452369373977690?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/7zCxrn2Z7aM/is-basic-good-for-anything.html" title="Is BASIC good for anything?" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/12/is-basic-good-for-anything.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04AR3Y8eyp7ImA9WBZXFU8.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110452194687335679</id><published>2004-12-31T14:24:00.000-05:00</published><updated>2004-12-31T14:39:06.873-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2004-12-31T14:39:06.873-05:00</app:edited><title>Choosing the best suited language</title><content type="html">But its got to be done in Jaavaa! (or .NET or VB or whatever)
&lt;p&gt;
No, Dr. Dre, you need to choose what's the most suitable language to solve the problem. Believe it or not, the complexity of the application changes dramatically with a language that thinks differently from the problem class at hand.
&lt;p&gt;
For example, consider a simple app that converts strips non-ASCII characters by converting them to their ASCII counterparts.
&lt;p&gt;
Lets say your manager loves BASIC and writes it as below
&lt;pre&gt;&lt;tt&gt;
OPEN "unstripped" FOR INPUT AS #1
OPEN "stripped" FOR OUTPUT AS #2
WHILE NOT EOF(1)
     a$ = INPUT$(1, 1)
     n = ASC(a$)
     IF n &gt; 127 THEN
           PRINT #2, CHR$(ASC(a$) - 128);
     ELSE
           PRINT #2, a$;
     END IF
WEND
CLOSE
END
&lt;/tt&gt;&lt;/pre&gt;
That is quite reasonable, isn't it? You could probably write something equivalent in C, Java or related languages.
&lt;br&gt;
Yes, but look how much simpler it would be if Perl was chosen as the language of choice.
&lt;pre&gt;&lt;tt&gt;
perl -pe 'y/\x80-\xff/\x00-\x7f/'
&lt;/tt&gt;&lt;/pre&gt;
Its a one liner you type on the command line. For text processing, Perl tends to beat any other language.
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110452194687335679?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BqocsbNa15mKmQlHK5EH7szu-w0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BqocsbNa15mKmQlHK5EH7szu-w0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BqocsbNa15mKmQlHK5EH7szu-w0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BqocsbNa15mKmQlHK5EH7szu-w0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/DM1jVBD0DI4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110452194687335679/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110452194687335679" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110452194687335679?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110452194687335679?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/DM1jVBD0DI4/choosing-best-suited-language.html" title="Choosing the best suited language" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/12/choosing-best-suited-language.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQFR3k9fip7ImA9WBZUFE0.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-110244832470738249</id><published>2004-12-07T13:56:00.000-05:00</published><updated>2005-02-02T23:51:56.766-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-02-02T23:51:56.766-05:00</app:edited><title>Writing good hashcodes and equals</title><content type="html">How would one write a good hashcode?
Here is one I've seen in real life:
&lt;pre&gt;&lt;span style="font-family:courier new;"&gt;
class Thing
{
    List itemlist;

    public int hashCode()
    {
        return toString().hashCode();
    }

    public boolean equals(Object o)
    {
        return o.toString().equals(toString());
    }

    public String toString()
    {
        return "Items = " + itemlist.toString() ;
    }
}
&lt;/span&gt;&lt;/pre&gt;

For reasons of brevity, I've drastically reduced the size of the original toString() function, but suffice to say, it printed the all elements of the entire complex Object with appropriate keywords. And the member &lt;span style="font-family:courier new;"&gt;itemlist&lt;/span&gt; was one that could grow indefinitely long.

It was obvious that the dude who wrote it does not know what a hashcode is at all. A hashcode serves as a value for quick comparison between Objects. It is essentially used to quickly locate which bucket the item is stored in HashMaps and other data structures that provide near constant access time.

If the hashCode computation takes &lt;span style="font-style: italic;"&gt;longer &lt;/span&gt;than the equals comparison, then you need to brush up on your fundamentals.

What could be done differently?

A simple way to define a good hashCode is given below:

&lt;span style="font-family:courier new;"&gt;&lt;pre&gt;
class A
{
    Integer a, b;
    String c;
    Set d;

    public int hashCode()
    {
        // Sum of (prime number * hashcode) for selected members
        return 7 * a.hashCode() + 11 * b.hashCode();
    }

    public boolean equals(Object o)
    {
        if(o == null || !getClass().equals(o.getClass()) || o.hashCode() != hashCode())
            return false;
        A other = (A)o;
        return other.a == a &amp;amp;&amp;amp; other.b == b
            &amp;amp;&amp;amp; c.equals(other.c) &amp;amp;&amp;amp; d.equals(other.d);
    }
}
&lt;/pre&gt;&lt;/span&gt;

As you can see, while equal Objects imply equal hashCodes, the converse is not necessarily true.

Most of the time, the check for class and hashCode will eliminate most matches. Among the few that do match, you just need to compare the itemlists without converting them to String first. This has the added benefit that the comparison can terminate early for example if the lengths are different. 

If you do not have any other members or you believe that they do not sufficiently provide a proper distribution of the hashcodes, you can define the functions as below:

&lt;span style="font-family:courier new;"&gt;&lt;pre&gt;
class Thing
{
  private List itemlist;

    public int hashCode()
    {
        if( itemlist != null &amp;&amp;amp; itemlist.size() &gt; 0 )
            return itemlist.size() * 7 + itemlist.get(0).hashCode();
        else
            return 0;
    }

    public boolean equals(Object o)
    {
        if (o == null || !getClass().equals(o.getClass()) || o.hashCode() != hashCode())
            return false;
        Thing thing = (Thing)o;
        return thing.itemlist == null &amp;&amp;amp; itemlist == null ||
            thing.itemlist.equals(itemlist);
    }

    public String toString()
    {
        return "Items = " + itemlist.toString() ;
    }
}
&lt;/pre&gt;&lt;/span&gt;

Of course, you have to ask yourself what business you have in returning toString() of classes that can be very large. If unavoidable, you should at least cache the results of toString() and hashCode() and update them on changes. This may need synchronization, so generally keeping hashcodes and toString functions simple is the better choice.

&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-110244832470738249?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/h8lYOC3Bss5DsEzagps0CXXDOEU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h8lYOC3Bss5DsEzagps0CXXDOEU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/h8lYOC3Bss5DsEzagps0CXXDOEU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h8lYOC3Bss5DsEzagps0CXXDOEU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/qWGepH7-e2Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/110244832470738249/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=110244832470738249" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110244832470738249?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/110244832470738249?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/qWGepH7-e2Y/writing-good-hashcodes-and-equals.html" title="Writing good hashcodes and equals" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/12/writing-good-hashcodes-and-equals.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYBQXoyeCp7ImA9WR9VE0w.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-109543279986917077</id><published>2004-09-16T22:07:00.000-04:00</published><updated>2004-09-27T16:32:30.490-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2004-09-27T16:32:30.490-04:00</app:edited><title>Does Java pass Objects by reference?</title><content type="html">You often hear that Java passes primitives by value and Objects by reference. Unfortunately, this is misleading.

A reference has a specific meaning in programming terminology. A reference is the variable itself. Its not a pointer, its not a copy, its the actual variable. This means that if a variable is passed by reference to a function and the function assigns another value to it, the changes are visible outside the function.

C++ implements references faithful to the original meaning while Java does not.

&lt;tt&gt;&lt;pre&gt;
#include &amp;lt;iostream.h&amp;gt;

class Ref
{
        public:
        int one(int&amp; it) { it = 1; } // Reassign variable
        void two(int&amp; it) { it++; }  // Change variable
};

int main()
{
        Ref ref;

        int item = 0;
        ref.one(item);
        cout &lt;&lt; "Item is " &lt;&lt; item &lt;&lt; endl;
        ref.two(item);
        cout &lt;&lt; "Item is " &lt;&lt; item &lt;&lt; endl;

        int* i = new int(0);
        ref.one(*i);
        cout &lt;&lt; "I is " &lt;&lt; *i &lt;&lt; endl;
}
&lt;/pre&gt;&lt;/tt&gt;

Prints:
&lt;tt&gt;&lt;pre&gt;
Item is 1
Item is 2
I is 1
&lt;/pre&gt;&lt;/tt&gt;

Java on the other hand, passes a &lt;em&gt;copy&lt;/em&gt; of the reference. This means that any changes to the variable are preserved, but you cannot reassign the variable to point to something else within the traditional meaning of "reference."

&lt;tt&gt;&lt;pre&gt;
import java.util.Date;

public class Ref
{
        public void one(Date item) { item = new Date(); }

        public void two(Date item) { item.setTime(365*24*60*60*1000L); }

        public static void main(String[] args)
        {
                Date item = new Date();
                item.setTime(0);
                Ref ref = new Ref();
                ref.one(item); // Change not reflected here
                System.out.println("Item is "+item);
                ref.two(item); // Change is reflected here
                System.out.println("Item is "+item);
        }
}
&lt;/pre&gt;&lt;/tt&gt;

Prints:
&lt;tt&gt;&lt;pre&gt;
Item is Wed Dec 31 19:00:00 EST 1969
Item is Thu Dec 31 19:00:00 EST 1970
&lt;/pre&gt;&lt;/tt&gt;

The net effect of this is that a Java function can change the Object passed to it, but any reassignment to something else is lost. Many argue that this is indeed safer and C++ funtionality can be achieved by having the function return the new value and let the caller assign it to the actual variable. It also protects the programmer from having to overload the = operator when calling outside code to ensure that the reference is not reassigned.

&lt;A href="http://burks.brighton.ac.uk/burks/language/cpp/cppfaq/references.html"&gt;Click here for good reference on References&lt;/A&gt;

&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-109543279986917077?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/n5QuR4CuNWjkC1nP6xQl1ndqDkM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n5QuR4CuNWjkC1nP6xQl1ndqDkM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/n5QuR4CuNWjkC1nP6xQl1ndqDkM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n5QuR4CuNWjkC1nP6xQl1ndqDkM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/BhL1KxHgpS4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/109543279986917077/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=109543279986917077" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109543279986917077?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109543279986917077?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/BhL1KxHgpS4/does-java-pass-objects-by-reference.html" title="Does Java pass Objects by reference?" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/09/does-java-pass-objects-by-reference.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cHQHkzeyp7ImA9WBRQE0o.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-109131560968312091</id><published>2004-07-31T18:39:00.000-04:00</published><updated>2005-08-06T20:37:11.783-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2005-08-06T20:37:11.783-04:00</app:edited><title>Tricks with Comments</title><content type="html">&lt;span style="font-weight: bold;"&gt;Trick one: The code switch&lt;/span&gt;

Sometimes it is essential to switch between two blocks of code. On systems that support C style comments, you could use the following construct:

&lt;tt&gt;&lt;pre&gt;
//* Two slashes for version A, one slash for version B

int main() // version A
{
   printf("Version A\n");
}

/*/

int main() // version B
{
   printf("Version B\n");
}

//*/
&lt;/pre&gt;&lt;/tt&gt;

Works on C/C++/Java/C#.

For SQL:

&lt;tt&gt;&lt;pre&gt;
--/*
SELECT * FROM A
/*/
SELECT * FROM B
--*/
&lt;/pre&gt;&lt;/tt&gt;

Remove the &lt;tt&gt;--&lt;/tt&gt; on the first line to switch to the second block.
Now, if anyone knows how to do it in other languages...
&lt;p&gt;
&lt;span style="font-weight: bold;"&gt;Trick two: Nested comments&lt;/span&gt;
Some compilers support nested comments (actually, only Borland!). This piece of code helps you detect if the compiler supports nested comments:

&lt;tt&gt;&lt;pre&gt;
#define NESTED /* /* /*/ 0 */*/*/1

main()
{
   puts(NESTED ? "Supported" : "Unsupported");
}
&lt;/pre&gt;&lt;/tt&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-109131560968312091?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/e8IUUHw6x9YYzI-ejHFJnqf1814/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e8IUUHw6x9YYzI-ejHFJnqf1814/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/e8IUUHw6x9YYzI-ejHFJnqf1814/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e8IUUHw6x9YYzI-ejHFJnqf1814/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/8sL6BjpThj0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/109131560968312091/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=109131560968312091" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109131560968312091?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109131560968312091?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/8sL6BjpThj0/tricks-with-comments.html" title="Tricks with Comments" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/07/tricks-with-comments.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04AQH08fip7ImA9WBZXFUw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-109115869271621315</id><published>2004-07-29T21:21:00.000-04:00</published><updated>2004-12-31T11:52:21.376-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2004-12-31T11:52:21.376-05:00</app:edited><title>Bad algorithms and caching</title><content type="html">The fibonacci function is traditionally defined recursively:
&lt;p/&gt;
 fib(n) = fib(n-1) + fib(n-2); fib(1) = fib(0) = 1
&lt;p/&gt;
This would typically be implemented in the venerable C language as:
&lt;pre&gt;
unsigned long long fib(int n)
{
        return n == 0 || n == 1 ? 1 : fib(n-1) + fib(n-2);
}
&lt;/pre&gt;
The problem with this implementation is that the performance is atrocious.
&lt;tt&gt;&lt;pre&gt;
$ time ./fib -r 40
165580141
 
real    0m18.263s
user    0m18.262s
sys     0m0.002s
&lt;/pre&gt;&lt;/tt&gt;
The reason is that each higher number needs geometrically increasing number of recursive invocations:
&lt;pre&gt; 
 fib(0) = 1 call
 fib(1) = 1 call
 fib(2) = 3 calls
 fib(3) = 5 calls
 fib(4) = 9 calls
 fib(5) = 15 calls
 fib(6) = 25 calls
 fib(7) = 41 calls
 fib(8) = 67 calls
 fib(9) = 109 calls
 fib(10)=177 calls
 ....
 fib(40) = 331160281 calls
&lt;/pre&gt;
Curiously, the number of calls for fib(n) can be defined as:
&lt;pre&gt;
 fib_calls(n) = 1 + fib_calls(n-1) + fib_calls(n-2); fib_calls(1) = fib_calls(0) = 1 
 
&lt;/pre&gt;
The performance problem is addressed by rewriting the function to work iteratively:
&lt;tt&gt;&lt;pre&gt;
unsigned long long iterative_fib(int n)
{
        register unsigned long long n1 = 0, n2 = 1, tmp;
 
        int i = 0;
        for(i = 0 ; i &amp;lt; n; i++)
        {
                tmp = n2;
                n2 = n2 + n1;
                n1 = tmp;
        }
        return n2;
}
&lt;/pre&gt;&lt;/tt&gt;
This gives a remarkable boost in performance:
&lt;tt&gt;&lt;pre&gt;
$ time ./fib -i 40
165580141
 
real    0m0.003s
user    0m0.001s
sys     0m0.002s
&lt;/pre&gt;&lt;/tt&gt;
Another way to get around the performance problem is to use caching with the recursive algorithm:
 &lt;tt&gt;&lt;pre&gt;
static unsigned long long cache[100];
 
unsigned long long cached_fib(int n)
{
        if(cache[n])
                return cache[n];

        return n == 0 || n == 1 ? 1 : (cache[n] = cached_fib(n-1)+cached_fib(n-2));
}
&lt;/pre&gt;&lt;/tt&gt;
Performance is similar to that of the iterative version:
&lt;tt&gt;&lt;pre&gt;
$ time ./fib -c 40
165580141
 
real    0m0.003s
user    0m0.000s
sys     0m0.003s
&lt;/pre&gt;&lt;/tt&gt;
However, in a program that calls the fibonacci function numerous times, the cached recursive version would work on an average, faster than the iterative verion. The flip side is that caching uses up memory. After a certain threshold, the system starts swapping to disk and performance degrades rapidly. So you really want to select good algorithms wherever possible and save caching for operations that simply have to be cached such as those involving disk or network IO.
&lt;p/&gt; 
&lt;a href="http://www.codebytez.com/src/c/fib.c"&gt;Click here to download the complete source&lt;/a&gt;
 
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-109115869271621315?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WeGkkBJVCyz4ZrUAGpqqgykq5yM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WeGkkBJVCyz4ZrUAGpqqgykq5yM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WeGkkBJVCyz4ZrUAGpqqgykq5yM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WeGkkBJVCyz4ZrUAGpqqgykq5yM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/_fTprKo4nVk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codebytez.blogspot.com/feeds/109115869271621315/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6501711&amp;postID=109115869271621315" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109115869271621315?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/109115869271621315?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/_fTprKo4nVk/bad-algorithms-and-caching.html" title="Bad algorithms and caching" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://codebytez.blogspot.com/2004/07/bad-algorithms-and-caching.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEARHs_eCp7ImA9WBZXFUw.&quot;"><id>tag:blogger.com,1999:blog-6501711.post-107725383880955142</id><published>2004-02-19T23:59:00.000-05:00</published><updated>2004-12-31T12:04:05.540-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2004-12-31T12:04:05.540-05:00</app:edited><title>Simplicity, the first principle</title><content type="html">Simple programs evolve, complex programs die. 99 percent of features are under utilized in any program. Simplicity and elegance is way more successful than feature load. So is adherence to existing standards.

&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6501711-107725383880955142?l=codebytez.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VNo2E3fan3EBScVGsLv5n9ChVZo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VNo2E3fan3EBScVGsLv5n9ChVZo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VNo2E3fan3EBScVGsLv5n9ChVZo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VNo2E3fan3EBScVGsLv5n9ChVZo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/mYxXC/~4/GsJdsGVgXf8" height="1" width="1"/&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/107725383880955142?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6501711/posts/default/107725383880955142?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/mYxXC/~3/GsJdsGVgXf8/simplicity-first-principle.html" title="Simplicity, the first principle" /><author><name>cadaver</name><uri>http://www.blogger.com/profile/00205606370921389742</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="24" height="32" src="http://1.bp.blogspot.com/_bCZAN396MeU/TTJDM2iV2mI/AAAAAAAAAJw/OyeBSBCzxZA/S220/Cadaver.jpg" /></author><feedburner:origLink>http://codebytez.blogspot.com/2004/02/simplicity-first-principle.html</feedburner:origLink></entry></feed>

