<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-19163975</id><updated>2012-02-12T19:36:35.723-08:00</updated><category term='technology'/><category term='hacking'/><category term='hiking'/><category term='india'/><category term='R'/><category term='life'/><title type='text'>Vikram and Neha</title><subtitle type='html'>Articles for technology enthusiasts</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.eggwall.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default?start-index=101&amp;max-results=100'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>217</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-19163975.post-7328790962873837476</id><published>2012-01-24T19:19:00.000-08:00</published><updated>2012-01-24T19:19:11.694-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Project Euler in R: Problem 25</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Solutions in R to&amp;nbsp;&lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt;&amp;nbsp;problems are generally hard to find, so I've&amp;nbsp;recently started posting R solutions&amp;nbsp;on this site.&amp;nbsp;&amp;nbsp;Here are the previous problems: &lt;a href="http://www.eggwall.com/2012/01/project-euler-in-r-problem-22.html"&gt;problem 22&lt;/a&gt;,&amp;nbsp;&lt;a href="http://www.eggwall.com/2012/01/project-euler-in-r-problem-23.html"&gt;problem 23&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://www.eggwall.com/2012/01/project-euler-in-r-problem-24.html"&gt;problem 24&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now let's look at &lt;a href="http://projecteuler.net/problem=25"&gt;Problem 25&lt;/a&gt; from Project Euler. &amp;nbsp;Here is the problem statement:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;The Fibonacci sequence is defined by the recurrence relation:&amp;nbsp;Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.&lt;br /&gt;Hence the first 12 terms will be:&lt;br /&gt;F1 = 1&lt;br /&gt;F2 = 1&lt;br /&gt;...&lt;br /&gt;F11 = 89&lt;br /&gt;F12 = 144&lt;br /&gt;The 12th term, F12, is the first term to contain three digits.&amp;nbsp;What is the first term in the Fibonacci sequence to contain 1000 digits?&lt;/blockquote&gt;This is an easy problem to solve for a small number of digits. It gets interesting once we increase the required number of digits to 1000. The R &lt;i&gt;integer&lt;/i&gt;&amp;nbsp;type can hold 10 digits at most, and the type &lt;i&gt;double&lt;/i&gt; can hold 309 digits. &amp;nbsp;There is no Big Integer class in R that can hold larger numbers, so to compute the 1000 digit Fibonacci number we will have to be creative.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Computing Fibonacci numbers iteratively&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is a basic iterative Fibonacci function, that works for Fibonacci numbers with 309 or fewer digits.&lt;br /&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;fib &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;  a = &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;br /&gt;  b = &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;:n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    tmp = b&lt;br /&gt;    b = a&lt;br /&gt;    a = a + tmp&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;a&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;The version that works with larger numbers is similar, with the following changes&lt;br /&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;ul&gt;&lt;li&gt;Integer vectors are used to store each Fibonacci number.&lt;/li&gt;&lt;li&gt;Each element of the vector is at most nine digits long. &amp;nbsp;&lt;/li&gt;&lt;li&gt;Once all the nine digits are used, a new element is added to the vector and the Fibonacci number computation is carried over to the new element.&lt;/li&gt;&lt;li&gt;The variable &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;numberDigits&lt;/span&gt; counts the number of digits in the latest Fibonacci number. &amp;nbsp;When&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;numberDigits&lt;/span&gt;&amp;nbsp;exceeds &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;999&lt;/span&gt;, the function exits, returning the Fibonacci number index.&lt;/li&gt;&lt;/ul&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;fib.bigint &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/packages/cran/LIM"&gt;lim&lt;/a&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;  a = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  b = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  n = &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;           &lt;span style="color: #666666; font-style: italic;"&gt;# Fibonacci number index&lt;/span&gt;&lt;br /&gt;  integerSize &amp;lt;- &lt;span style="color: #cc66cc;"&gt;1000000000&lt;/span&gt;  &lt;span style="color: #666666; font-style: italic;"&gt;## How big is each integer&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    n = n + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;     &lt;span style="color: #666666; font-style: italic;"&gt;# Compute next Fibonacci number&lt;/span&gt;&lt;br /&gt;    tmp = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/rep"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;rep&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/length"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;a&lt;span style="color: #009900;"&gt;)&lt;/span&gt;-&lt;a href="http://inside-r.org/r-doc/base/length"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;b&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; b&lt;span style="color: #009900;"&gt;)&lt;/span&gt;  &lt;span style="color: #666666; font-style: italic;"&gt;# Pad beginning with zero&lt;/span&gt;&lt;br /&gt;    b = a&lt;br /&gt;&amp;nbsp;&lt;br /&gt;    &lt;span style="color: #666666; font-style: italic;"&gt;# Add a and tmp&lt;/span&gt;&lt;br /&gt;    carry = &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;a href="http://inside-r.org/r-doc/base/length"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;a&lt;span style="color: #009900;"&gt;)&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;      sum.i = tmp&lt;span style="color: #009900;"&gt;[&lt;/span&gt;i&lt;span style="color: #009900;"&gt;]&lt;/span&gt; + a&lt;span style="color: #009900;"&gt;[&lt;/span&gt;i&lt;span style="color: #009900;"&gt;]&lt;/span&gt; + carry&lt;br /&gt;      a&lt;span style="color: #009900;"&gt;[&lt;/span&gt;i&lt;span style="color: #009900;"&gt;]&lt;/span&gt; = sum.i %% integerSize&lt;br /&gt;      carry = &lt;a href="http://inside-r.org/r-doc/base/floor"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;floor&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;sum.i / integerSize&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;carry &amp;gt; &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;a &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;carry&lt;span style="color: #339933;"&gt;,&lt;/span&gt; a&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;    numberDigits &amp;lt;- &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/length"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;length&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;a&lt;span style="color: #009900;"&gt;)&lt;/span&gt; - &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; * &lt;span style="color: #cc66cc;"&gt;9&lt;/span&gt; + countDigits&lt;span style="color: #009900;"&gt;(&lt;/span&gt;a&lt;span style="color: #009900;"&gt;[&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;]&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;numberDigits &amp;gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/packages/cran/LIM"&gt;lim&lt;/a&gt; - &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt; &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;countDigits &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;  count &amp;lt;- &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;9&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;n/&lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &amp;gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;      count &amp;lt;- count + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;br /&gt;      n = n / &lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #009900;"&gt;}&lt;/span&gt; &lt;span style="color: black; font-weight: bold;"&gt;else&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;count&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;On my Intel Core 2 Duo 1.6Ghz laptop running Linux, this function less than 4 seconds to find the Fibonacci number with 1000 digits.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The analytical solution&lt;/span&gt;&lt;br /&gt;Fibonacci numbers have a closed form solution, which leads to a simpler &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding"&gt;approximation by rounding&lt;/a&gt;&amp;nbsp;(from Wikipedia), &lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;i&gt;F&lt;/i&gt;&lt;sub style="line-height: 1em;"&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;= the closest integer to&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(golden ratio)^n / sqrt(5)&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;We need the first Fibonacci number with 1000 digits. &amp;nbsp;This number will be greater than or equal to &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;10^999.&lt;/span&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;i&gt;F&lt;/i&gt;&lt;sub style="line-height: 1em;"&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;= the closest integer to&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(golden ratio)^n / sqrt(5) &amp;gt;= 10^999&lt;/span&gt;&lt;/blockquote&gt;We can drop the closest integer function because if&amp;nbsp;&lt;i&gt;F&lt;/i&gt;&lt;sub style="line-height: 1em;"&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sub&gt;&amp;nbsp;rounds off to the floor of the ratio, the resulting Fibonacci number will have less than the required digits. &amp;nbsp;So we need smallest n satisfying&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(golden ratio)^n / sqrt(5) &amp;gt;= 10^999&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Or, n &amp;gt;= (999 log(10) + log(sqrt(5)))/log(golden ratio)&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Or, n &amp;gt;= 4781.86&lt;/span&gt;&lt;/blockquote&gt;So we need the 4782nd Fibonacci number to get the required 1000 digits.&lt;br /&gt;&lt;br /&gt;This problem was particularly interesting to R users because it runs into an R-specific limitation. Many other languages don't have this problem and can just use a simple Fibonacci generator to get the answer. For example, in Scheme (or other Lisp variants), a naive Fibonacci implementation produces all the digits.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Aside&lt;/u&gt;: Having started writing about R, I have found an excellent online resource,&amp;nbsp;&lt;a href="http://www.r-bloggers.com/"&gt;R-bloggers&lt;/a&gt;&amp;nbsp;-&amp;nbsp;&amp;nbsp;an aggregator of content from various blogs about R. You can search for&amp;nbsp;&lt;a href="http://www.r-bloggers.com/?s=euler"&gt;other R Project Euler solutions&lt;/a&gt;&amp;nbsp;here. &amp;nbsp;Be sure to check out the top articles box on&amp;nbsp;&lt;a href="http://www.r-bloggers.com/"&gt;R-bloggers&lt;/a&gt;&amp;nbsp;landing page if you're looking for new and interesting applications of R.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7328790962873837476?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7328790962873837476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-25.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7328790962873837476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7328790962873837476'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-25.html' title='Project Euler in R: Problem 25'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2561957859589510645</id><published>2012-01-19T19:52:00.000-08:00</published><updated>2012-01-19T20:21:32.944-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Project Euler in R: Problem 24</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I had previously posted solutions in R to&amp;nbsp;Project Euler&amp;nbsp;&lt;a href="http://www.eggwall.com/2012/01/project-euler-in-r-problem-23.html"&gt;problem 23&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://www.eggwall.com/2012/01/project-euler-in-r-problem-22.html"&gt;problem 22&lt;/a&gt;. &amp;nbsp;This is the next &lt;a href="http://projecteuler.net/problem=24"&gt;problem&lt;/a&gt; from&amp;nbsp;&lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt;. The statement of problem 24 is as follows.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;blockquote class="tr_bq"&gt;A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:&amp;nbsp;012 &amp;nbsp; 021 &amp;nbsp; 102 &amp;nbsp; 120 &amp;nbsp; 201 &amp;nbsp; 210&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?&lt;/blockquote&gt;&lt;/blockquote&gt;This is a very interesting problem and it can be solved analytically.&amp;nbsp;The key insight is that &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;n&lt;/span&gt; distinct digits can be arranged in &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;n!&lt;/span&gt; permutations.&lt;br /&gt;&lt;br /&gt;Here's the logic you could use. If the permutations of the numbers 0 through 9 are arranged in lexicographic order,&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;The first 9! permutations, #1 to #362,880 are numbers starting with 0, in order from 0123456789 to 0987654321&lt;/li&gt;&lt;li&gt;The next 9! permutations, #362,881 to #725,760, are numbers from 1023456789 to 1987654320&lt;/li&gt;&lt;li&gt;The next 9! permutations, #725,761 to #1,088,640 &amp;nbsp;are numbers from 2013456789 to 2987654310. &amp;nbsp;The millionth permutation is contained in this set. &amp;nbsp;Thus we know that the millionth number must start with a 2. &amp;nbsp;In fact, it is the&amp;nbsp;274,240th = (1000000 - 725760) number contained in this set.&lt;/li&gt;&lt;li&gt;Our problem has now reduced to finding the&amp;nbsp;274,240th&amp;nbsp;lexicographic permutation of the numbers 0, 1, 3, 4, 5, 6, 7, 8 and 9 - the nine digits excluding 2. &amp;nbsp;We can repeat the above process to get each successive digit.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Essentially we're writing one million as the following sum&lt;/div&gt;&lt;blockquote class="tr_bq"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;1000000 = (a1 x 9!) + (a2 x 8!) + ... + (a10 x 1)&lt;/span&gt;&lt;/blockquote&gt;&lt;div&gt;As shown above, the index &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;a1&lt;/span&gt; is 2. &amp;nbsp;That is, only two times 9! numbers fit perfectly within 1,000,000. &amp;nbsp;So the first digit of the millionth number is the third digit in 01&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;span style="background-color: white;"&gt;2&lt;/span&gt;&lt;/span&gt;3456789. &amp;nbsp;The index &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;a2&lt;/span&gt; is 6, so the second digit of the millionth number is the seventh digit of the remaining numbers 013456&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;span style="background-color: white;"&gt;7&lt;/span&gt;&lt;/span&gt;89, which is 7. &amp;nbsp;The remaining digits can be found similarly. While finding the digits you have to be careful to ignore the digits that have been previously used. This is a permutation, so each digit appears exactly once.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The process is tedious, so here is some R code that will make it easier. &amp;nbsp;This generalizes the solution to find the nth permutation of the numbers 0 to 9.&lt;/div&gt;&lt;div&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;findperm &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #666666; font-style: italic;"&gt;# Find the indices a1 - a10&lt;/span&gt;&lt;br /&gt;  indices = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;9&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    index = &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/factorial"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;factorial&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &amp;lt; n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;      n = n - &lt;a href="http://inside-r.org/r-doc/base/factorial"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;factorial&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;      index = index + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;    indices = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;indices&lt;span style="color: #339933;"&gt;,&lt;/span&gt; index&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: #666666; font-style: italic;"&gt;# Use the indices to find the nth permutation&lt;/span&gt;&lt;br /&gt;  input = &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;9&lt;/span&gt;                         &lt;span style="color: #666666; font-style: italic;"&gt;# The list of numbers to permute&lt;/span&gt;&lt;br /&gt;  output = &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;j &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    output&lt;span style="color: #009900;"&gt;[&lt;/span&gt;j&lt;span style="color: #009900;"&gt;]&lt;/span&gt; = input&lt;span style="color: #009900;"&gt;[&lt;/span&gt;indices&lt;span style="color: #009900;"&gt;[&lt;/span&gt;j&lt;span style="color: #009900;"&gt;]&lt;/span&gt; + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;]&lt;/span&gt; &lt;span style="color: #666666; font-style: italic;"&gt;# Move digit to output&lt;/span&gt;&lt;br /&gt;    input = input&lt;span style="color: #009900;"&gt;[&lt;/span&gt;-&lt;span style="color: #009900;"&gt;(&lt;/span&gt;indices&lt;span style="color: #009900;"&gt;[&lt;/span&gt;j&lt;span style="color: #009900;"&gt;]&lt;/span&gt; + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;]&lt;/span&gt;  &lt;span style="color: #666666; font-style: italic;"&gt;# Remove the assigned digits from input&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;output&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;That was straight-forward and a fun illustration of R's capabilities.&lt;br /&gt;&lt;br /&gt;But you can do better. The strength of R lies in the wealth of user defined libraries and functions that can ease the implementation of tricky computation. &amp;nbsp;For a simpler solution, try the&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace; white-space: pre;"&gt;lexicographicPermutation&lt;/span&gt;&amp;nbsp;function in the library &lt;a href="http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/R.basic/html/lexicographicPermutation.html"&gt;R.basic&lt;/a&gt;. Here is the entire solution.&lt;/div&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;&lt;a href="http://inside-r.org/r-doc/base/library"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;library&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;R.basic&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;lexicographicPermutation&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;3&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;4&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;5&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;6&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;7&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;8&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;9&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;999999&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;The first solution illustrates that even tricky computation can be coded easily in R and the code is pretty readable. &amp;nbsp;The second solution suggests that before writing your own code, it is a good idea to look for existing libraries that can help. Statistical computations can get complex and tricky. You can write your own k-means clustering algorithm but it is&amp;nbsp;difficult&amp;nbsp;getting all the edge cases correct. Rather than writing your own routine, look around and see if it has been written already. An expert does a better job writing such routines. And you can leverage their code and their expertise.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2561957859589510645?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2561957859589510645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-24.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2561957859589510645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2561957859589510645'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-24.html' title='Project Euler in R: Problem 24'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2593045460326823804</id><published>2012-01-15T15:56:00.000-08:00</published><updated>2012-01-19T20:21:32.952-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Project Euler in R: Problem 23</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was just looking through the programming language statistics on Project Euler. It shows that only 7% of the problems have been solved in R, whereas 8% have been solved on any kind of spreadsheet. &amp;nbsp;This is outrageous!&lt;br /&gt;&lt;br /&gt;Let's look at the solution of problem 23 in R. Here is the statement of Project Euler's problem 23:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.&lt;br /&gt;A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.&lt;br /&gt;As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.&lt;br /&gt;Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.&lt;/blockquote&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Find proper divisors&lt;/span&gt;&lt;br /&gt;First we write a function to find the proper divisors (that is divisors less than the number itself) of a number n.&lt;/div&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;divisor &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    divs &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;    i = &lt;span style="color: #cc66cc;"&gt;2&lt;/span&gt;&lt;br /&gt;    &lt;a href="http://inside-r.org/packages/cran/LIM"&gt;lim&lt;/a&gt; = &lt;a href="http://inside-r.org/r-doc/base/floor"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;floor&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/sqrt"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;sqrt&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &amp;lt;= &lt;a href="http://inside-r.org/packages/cran/LIM"&gt;lim&lt;/a&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n %% i == &lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;          divs &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;divs&lt;span style="color: #339933;"&gt;,&lt;/span&gt; i&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n/i != i&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt; divs &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;divs&lt;span style="color: #339933;"&gt;,&lt;/span&gt; n/i&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;        i = i + &lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;divs&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Check if number is abundant&lt;/span&gt;&lt;br /&gt;Next we create a simple function which checks whether a number n is abundant.&lt;/div&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;abundant &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/function"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;function&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/sum"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;sum&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;divisor&lt;span style="color: #009900;"&gt;(&lt;/span&gt;n&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &amp;gt; n&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: black; font-weight: bold;"&gt;TRUE&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: black; font-weight: bold;"&gt;else&lt;/span&gt; &lt;a href="http://inside-r.org/r-doc/base/return"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: black; font-weight: bold;"&gt;FALSE&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The solution&lt;/span&gt;&lt;br /&gt;With the above two functions we have the tools we need to solve the main problem: finding the sum of all positive integers which can not be written as the sum of two abundant numbers.&lt;br /&gt;&lt;br /&gt;All the numbers greater than 28,123 can be written as sum of two abundant numbers, so we only need to check numbers smaller than 28,123 for this property. &amp;nbsp;The vector&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace; white-space: pre;"&gt;abunlist&lt;/span&gt;&amp;nbsp;in the code below holds all abundant numbers starting from 12 to 28,123. &amp;nbsp;With every new abundant number than we find, we create all possible two abundant number sums and store them in the vector&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace; white-space: pre;"&gt;sumno&lt;/span&gt;. &amp;nbsp;The answer we're looking for is the sum of all numbers 1 to 28,123 except the ones in the vector&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace; white-space: pre;"&gt;sumno&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="overflow: auto;"&gt;&lt;div class="geshifilter"&gt;&lt;pre class="r geshifilter-R" style="font-family: monospace;"&gt;abunlist &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;12&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;            &lt;span style="color: #666666; font-style: italic;"&gt;# The smallest abundant number = 12&lt;/span&gt;&lt;br /&gt;sumno &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;24&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;               &lt;span style="color: #666666; font-style: italic;"&gt;# The smallest abundant number sum = 12 + 12 = 24&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: black; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;i &lt;span style="color: black; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;13&lt;/span&gt;:&lt;span style="color: #cc66cc;"&gt;28123&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: black; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;(&lt;/span&gt;abundant&lt;span style="color: #009900;"&gt;(&lt;/span&gt;i&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &lt;span style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;    abunlist &amp;lt;- &lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;abunlist&lt;span style="color: #339933;"&gt;,&lt;/span&gt; i&lt;span style="color: #009900;"&gt;)&lt;/span&gt;                   &lt;span style="color: #666666; font-style: italic;"&gt;# Latest abundant number = i&lt;/span&gt;&lt;br /&gt;    tmp &amp;lt;- abunlist&lt;span style="color: #009900;"&gt;[&lt;/span&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;abunlist + i&lt;span style="color: #009900;"&gt;)&lt;/span&gt; &amp;lt;= &lt;span style="color: #cc66cc;"&gt;28123&lt;/span&gt;&lt;span style="color: #009900;"&gt;]&lt;/span&gt; + i   &lt;span style="color: #666666; font-style: italic;"&gt;# New abundant sums &amp;lt;= 28123 using i&lt;/span&gt;&lt;br /&gt;    sumno &amp;lt;-&lt;a href="http://inside-r.org/r-doc/base/unique"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;unique&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://inside-r.org/r-doc/base/c"&gt;&lt;span style="color: #003399; font-weight: bold;"&gt;c&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;(&lt;/span&gt;sumno&lt;span style="color: #339933;"&gt;,&lt;/span&gt; tmp&lt;span style="color: #009900;"&gt;)&lt;/span&gt;&lt;span style="color: #009900;"&gt;)&lt;/span&gt;                &lt;span style="color: #666666; font-style: italic;"&gt;# Add to existing list&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #009900;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;This is certainly not the most efficient solution, but runs in approximately 25 seconds - well within the stated 1 minute goal.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Note: The code for this post was formatted in&amp;nbsp;&lt;a href="http://www.inside-r.org/pretty-r" title="Created by Pretty R at inside-R.org"&gt;Pretty R at inside-R.org&lt;/a&gt;.&lt;/i&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2593045460326823804?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2593045460326823804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-23.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2593045460326823804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2593045460326823804'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-23.html' title='Project Euler in R: Problem 23'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7816178942417091163</id><published>2012-01-11T20:31:00.000-08:00</published><updated>2012-01-11T21:45:54.126-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Generate UML Diagrams From Java Source</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was navigating through a large Java project today, and I needed some source tools to help me visualize the massive class hierarchy. Looking on Google didn't produce anything obvious: people pointed to eUML2, which was difficult to install, and some tools didn't generate UML from existing code.&lt;br /&gt;&lt;br /&gt;After a while of searching, I remembered the &lt;a href="http://www.doxygen.org/"&gt;Doxygen&lt;/a&gt; utility which writes documentation from source code. It works on C,C++, and Java, among many other languages. While its diagrams might not be perfect, they were very helpful for C++ projects in the past.&lt;br /&gt;&lt;br /&gt;So I decided to give it a shot. It worked out beautifully.&lt;br /&gt;&lt;br /&gt;Here are the steps involved in generating UML diagrams.&lt;br /&gt;First, you install doxygen (to parse the files) and graphviz (to write out PNG of graphs)&lt;br /&gt;&lt;pre&gt;$ &lt;span style="color: #274e13;"&gt;sudo apt-get install doxygen graphviz&lt;/span&gt;&lt;/pre&gt;Then, run doxygen to generate a config file.&lt;br /&gt;&lt;pre&gt;$ &lt;span style="color: #274e13;"&gt;cd &amp;lt;path-to-source&amp;gt;&lt;/span&gt;&lt;br /&gt;$ &lt;span style="color: #274e13;"&gt;doxygen -g&lt;/span&gt;&lt;/pre&gt;Now you have a config file called Doxyfile. Edit this to allow recursive searching, to look for java source, to generate call graphs and to generate pictures, and to generate UML style diagrams. Here are all the changes I made to this file.&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #27134e;"&gt;FILE_PATTERNS     = *.java&lt;br /&gt;RECURSIVE       = YES&lt;br /&gt;HAVE_DOT        = YES&lt;br /&gt;CALL_GRAPH       = YES&lt;br /&gt;CALLER_GRAPH      = YES&lt;br /&gt;DOT_GRAPH_MAX_NODES  = 500&lt;br /&gt;UML_LOOK            = YES&lt;/span&gt;&lt;/pre&gt;Now, generate documentation with this command:&lt;br /&gt;&lt;pre&gt;$ &lt;span style="color: #274e13;"&gt;doxygen Doxyfile&lt;/span&gt;&lt;/pre&gt;To test this out for a blog post, I downloaded the source code to &lt;a href="http://azureus.sourceforge.net/"&gt;Azureus&lt;/a&gt;, a large Java-based project. Here is a graph from one of the files. The top right shows a close-up view of a tiny section of the picture. Even in this simple example, you can see how a zoomed-out view allows you to understand the complex structure.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-z_wzlWupzgs/Tw5hYmCo__I/AAAAAAAAAZw/vyAB37ASEDg/s1600/blogpost.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-z_wzlWupzgs/Tw5hYmCo__I/AAAAAAAAAZw/vyAB37ASEDg/s1600/blogpost.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Doxygen reads code written in C, C++, Java, and many other languages. So if you are in need of UML style diagrams to better understand a class hierarchy, give it a try. It is freely available, easy to install, and easy to use. In addition to class graphs, it can also make call graphs and caller graphs.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7816178942417091163?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7816178942417091163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/generate-uml-diagrams-from-java-source.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7816178942417091163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7816178942417091163'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/generate-uml-diagrams-from-java-source.html' title='Generate UML Diagrams From Java Source'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-z_wzlWupzgs/Tw5hYmCo__I/AAAAAAAAAZw/vyAB37ASEDg/s72-c/blogpost.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-27971455845824222</id><published>2012-01-09T00:00:00.000-08:00</published><updated>2012-01-09T00:00:10.178-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Entertainment comes from many activities</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I came across an interesting post by &lt;a href="http://rogerebert.suntimes.com/apps/pbcs.dll/article?AID=/20111228/COMMENTARY/111229973"&gt;Roger Ebert about why movie revenue is dropping&lt;/a&gt;. He raises important points about high ticket prices and the poor&amp;nbsp;theater&amp;nbsp;experience. &amp;nbsp;I agree with most of the post. Many years ago, I had written about the &lt;a href="http://www.eggwall.com/2008/07/movies-at-home-premium-experience.html"&gt;abysmal theater experience&lt;/a&gt;&amp;nbsp;and it is nice to see that my concern is shared.&lt;br /&gt;&lt;br /&gt;Movies are losing revenue because they are chasing ghosts. The days of mass theater watching is history. Even in India, people are comfortable renting or buying DVDs and watching the movie at home. The theater experience deserves much blame. Theaters function in a world of limited supply. Their glory days were when few movies were released and there was little alternate entertainment. Both assumptions are false today. Thanks to streaming video and increased access to foreign movies, I can watch Korean movies from 2011 if Hollywood produced poor movies. And I don't need to watch movies. I can play video games, watch &lt;a href="http://www.youtube.com/watch?v=Vw4KVoEVcr0"&gt;short videos online&lt;/a&gt;, or spend my evening looking at &lt;a href="http://icanhascheezburger.com/"&gt;cute kittens online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Our definition of entertainment is changing. Movies are just a way of spending time having fun. We have many more ways of having fun. Traditional media likes their definition of "entertainment", which is "consuming content". This is a very narrow definition. It has never held true. Children's idea of enjoyment ranges from drawing to making a mess out of newspaper. Adults are similar.&lt;br /&gt;&lt;br /&gt;Computers on the Internet are the ultimate tool. I write articles (like this one) and it entertains me. Others use Facebook or Google Plus to keep in touch with their friends and family. Still others contribute to Wikipedia or online forums. Each of these activities provides enjoyment for the person. Each of these are entertainment.&lt;br /&gt;&lt;br /&gt;Some of the terminology from the movie industry indicates this bias. "&lt;a href="http://www.eonline.com/"&gt;Entertainment Online&lt;/a&gt;" and "&lt;a href="http://www.ew.com/ew/"&gt;Entertainment Weekly&lt;/a&gt;" are focused entirely on the movie and television industry. &lt;a href="http://entertainment.msn.com/"&gt;Entertainment on MSN&lt;/a&gt; is all about movie stars.&lt;br /&gt;&lt;br /&gt;Even in the absence of online streaming videos and DVDs, the number of people watching movies would drop. There is a lot more stuff you can do on a computer. And sitting in an uncomfortable chair for ninety minutes staring at a screen is not always entertainment.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-r2b4Yz4HsnA/Twjo8ki_TQI/AAAAAAAAAZo/Umo4VLvm7OA/s1600/fun.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-r2b4Yz4HsnA/Twjo8ki_TQI/AAAAAAAAAZo/Umo4VLvm7OA/s1600/fun.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-27971455845824222?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/27971455845824222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/entertainment-comes-from-many.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/27971455845824222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/27971455845824222'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/entertainment-comes-from-many.html' title='Entertainment comes from many activities'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-r2b4Yz4HsnA/Twjo8ki_TQI/AAAAAAAAAZo/Umo4VLvm7OA/s72-c/fun.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-1073001695461634400</id><published>2012-01-08T00:00:00.000-08:00</published><updated>2012-01-08T00:00:05.732-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Learning Languages as a puzzle game</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I am interested in languages. I tried learning some Japanese when I was young. I gave up rather quickly. It might have been due to the lack of good books, or the lack of teachers. It might have been the lack of native Japanese speakers with whom I could practice my skills. My experience with Japanese instilled a love for learning new languages, and understanding a culture from their perspective, through their language.&lt;br /&gt;&lt;br /&gt;A few months ago I started learning Mandarin Chinese. We found ourselves in Beijing, and we came across some great Chinese books lesson books for English speakers. These were useful in teaching characters and sentence construction in a very academic setting. Learning a language in this way is difficult. For one: your&amp;nbsp;pronunciation&amp;nbsp;is all wrong. For another, it is difficult to apply such academic learning to everyday speech.&lt;br /&gt;&lt;br /&gt;Next, I tried using audio lessons only. These were a bit more helpful. They had correct pronunciation and useful everyday phrases. I did find that the lessons were geared more towards scoring women rather than real everyday phrases. Early lessons started with, "Where do you want to go to drink?", "Would you like to come to my place?" Useful stuff I'm sure, but not for a boring family man like me. A person like me needs directions to the hospital and the rest room. Further, the audio lessons made it difficult to distinguish between close syllables like 'ga' and 'ka'. You could easily mispronounce words and not realize it. Finally, you have no idea of written Chinese. This is a real limitation. Chinese is written in a strange and confusing way. Starting out with characters is much better than trying to learn them later. Building an initial comfort level helps if you travel.&lt;br /&gt;&lt;br /&gt;Finally, we settled on Rosetta Stone (RS for short). RS teaches language in an interesting way. You don't see any of your native language written down. Concepts are introduced entirely through pictures, and you see Chinese to go along with the concepts. It is a strange feeling. You see a big ball and a small ball, and there are strange words. With time, you form the connection between the word and the concept. All without relying on the equivalent word in your native language. I was skeptical of this idea when a friend explained it to me. And RS costs an arm and a leg, which made me even more skeptical.&lt;br /&gt;&lt;br /&gt;Luckily for me, I seem to learn Chinese with RS. I use RS as a puzzle game rather than language learning. It is fun to try to understand the game and get better. Now I'm on the final unit in Level One, I am surprised at how much Chinese I can understand. We have a few Chinese friends and I can understand bits of their conversation with their children. It is a great feeling.&lt;br /&gt;&lt;br /&gt;Chinese is a devilishly hard language to learn. Right at the beginning, you start out learning&amp;nbsp;pictographs&amp;nbsp;(characters), tones in pronunciation, vocabulary, and grammar. If RS works for Chinese, I suspect it will work for Japanese too. Once I go through RS Mandarin lessons, I might just look at the RS Japanese lessons.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-wWk0n9Hu-OA/TwjV1qUA5WI/AAAAAAAAAZg/CrjRpN56rz0/s1600/rosettaStone.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-wWk0n9Hu-OA/TwjV1qUA5WI/AAAAAAAAAZg/CrjRpN56rz0/s1600/rosettaStone.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;Fun fact for the day: The original&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Rosetta_Stone"&gt;rosetta stone&lt;/a&gt;&amp;nbsp;was a stone which had three languages inscribed on it. The three languages had the same message. The discovery of this stone led to a breakthrough in deciphering Ancient Egyptian. It is ironic that the Rosetta Stone software teaches you a language by only showing you the language you wish to learn. Rosetta Stone never shows you a rosetta stone.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-1073001695461634400?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/1073001695461634400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/learning-languages-as-puzzle-game.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1073001695461634400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1073001695461634400'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/learning-languages-as-puzzle-game.html' title='Learning Languages as a puzzle game'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-wWk0n9Hu-OA/TwjV1qUA5WI/AAAAAAAAAZg/CrjRpN56rz0/s72-c/rosettaStone.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-1016391388696698160</id><published>2012-01-07T15:55:00.000-08:00</published><updated>2012-01-19T20:21:32.939-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Project Euler in R:  Problem 22</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I solve &lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt; problems for recreation. I am using the &lt;a href="http://www.r-project.org/"&gt;Statistical Language R&lt;/a&gt; to solve these. R is free for use and download, so I would recommend downloading it if you are interested in Statistical computation. &lt;br /&gt;This is &lt;a href="http://projecteuler.net/problem=22"&gt;problem 22&lt;/a&gt; from &lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt;:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. &lt;br /&gt;For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 x 53 = 49714.&lt;br /&gt;What is the total of all the name scores in the file?&lt;/blockquote&gt;While this is an easy problem, its solution involves some nice R concepts. Let's go through solving this in R.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Reading free form text using scan()&lt;/span&gt;&lt;br /&gt;The first order of business is to read the text file. The file names.txt  is a single line of text, separated by commas:  &lt;br /&gt;&lt;pre&gt;"MARY","PATRICIA","LINDA","BARBARA", ...&lt;/pre&gt;The scan function reads free form text and stores each element in a vector.  We specify that the input is character data separated by commas. That should do the trick, right?&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt; &amp;lt;- &lt;span style="color: #2040a0;"&gt;scan&lt;/span&gt;(&lt;span style="color: green;"&gt;"names.txt"&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;what&lt;/span&gt;= &lt;span style="color: green;"&gt;""&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sep&lt;/span&gt;=&lt;span style="color: green;"&gt;","&lt;/span&gt;,)&lt;br /&gt;&lt;/pre&gt;Unfortunately, this does not work. After many minutes of scratching your head you'll find that one of the names in the file is 'NA'.  This confuses the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;scan&lt;/span&gt; function since it is interpreted as the constant NA, or "Not Available" in R.  This can be fixed by setting an na.strings argument in the scan function.  &lt;br /&gt;&lt;pre&gt;&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt; &amp;lt;- &lt;span style="color: #2040a0;"&gt;scan&lt;/span&gt;(&lt;span style="color: green;"&gt;"names.txt"&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;what&lt;/span&gt;= &lt;span style="color: green;"&gt;""&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sep&lt;/span&gt;=&lt;span style="color: green;"&gt;","&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;na&lt;/span&gt;&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;strings&lt;/span&gt;=&lt;span style="color: green;"&gt;""&lt;/span&gt;)&lt;br /&gt;  &lt;/pre&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Dictionaries / hashtables in R&lt;/span&gt;&lt;br /&gt;Getting the alphabetical value of each character is easiest if it is stored in a hashtable somewhere. In R, named vectors can be used as hashtables.  The traditional definition would go as follows:&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt; = &lt;span style="color: #2040a0;"&gt;c&lt;/span&gt;(&lt;span style="color: green;"&gt;"A"&lt;/span&gt; = &lt;span style="color: red;"&gt;1&lt;/span&gt;, &lt;span style="color: green;"&gt;"B"&lt;/span&gt; = &lt;span style="color: red;"&gt;2&lt;/span&gt;, &lt;span style="color: red;"&gt;...&lt;/span&gt;)  &lt;br /&gt;While you can sit and write the entire dictionary by hand, you should avoid such repeated work. Here's a niftier definition using the names() function:  &lt;br /&gt;&lt;pre&gt;&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt; = &lt;span style="color: red;"&gt;1&lt;/span&gt;:&lt;span style="color: red;"&gt;26&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;names&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt;) = &lt;span style="color: #2040a0;"&gt;unlist&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;strsplit&lt;/span&gt;(&lt;span style="color: green;"&gt;"ABCDEFGHIJKLMNOPQRSTUVWXYZ"&lt;/span&gt;, &lt;span style="color: green;"&gt;""&lt;/span&gt;))&lt;/pre&gt;This should be a trivial method to write in a C-style language where you can turn a character into an integer. R, however, has no internal ASCII table that I could find. If there is a simpler solution, please let me know.  &lt;br /&gt;  &lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Name scoring function&lt;/span&gt;&lt;br /&gt;The scoring function gets the name as an input, pulls the score for each letter in the name and then adds up the letter scores.&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #2040a0;"&gt;score&lt;/span&gt; &amp;lt;- &lt;strong&gt;function&lt;/strong&gt; (&lt;span style="color: #2040a0;"&gt;name&lt;/span&gt;) {&lt;br /&gt;    &lt;strong&gt;return&lt;/strong&gt; (&lt;span style="color: #2040a0;"&gt;sum&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt;[&lt;span style="color: #2040a0;"&gt;unlist&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;strsplit&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;name&lt;/span&gt;, &lt;span style="color: green;"&gt;""&lt;/span&gt;))]))&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Calculating weighted scores&lt;/span&gt;&lt;br /&gt;The vector of name scores is obtained by applying the score function defined above to each name in nlist.  We use the sapply function, which gives a simplified vector output by default.  The vector of weights is a sequence of numbers from 1 to the length of nlist.  Multiply the two vectors to get the vector of weighted scores.&lt;br /&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="color: #2040a0;"&gt;weighted.score&lt;/span&gt; = (&lt;span style="color: red;"&gt;1&lt;/span&gt;:&lt;span style="color: #2040a0;"&gt;length&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt;))*(&lt;span style="color: #2040a0;"&gt;sapply&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;score&lt;/span&gt;)) &lt;br /&gt;  &lt;/pre&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The full solution&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt; &amp;lt;- &lt;span style="color: #2040a0;"&gt;scan&lt;/span&gt;(&lt;span style="color: green;"&gt;"names.txt"&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;what&lt;/span&gt;= &lt;span style="color: green;"&gt;""&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sep&lt;/span&gt;=&lt;span style="color: green;"&gt;","&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;na&lt;/span&gt;&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;strings&lt;/span&gt;=&lt;span style="color: green;"&gt;""&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt; = &lt;span style="color: red;"&gt;1&lt;/span&gt;:&lt;span style="color: red;"&gt;26&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;names&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt;) = &lt;span style="color: #2040a0;"&gt;unlist&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;strsplit&lt;/span&gt;(&lt;span style="color: green;"&gt;"ABCDEFGHIJKLMNOPQRSTUVWXYZ"&lt;/span&gt;, &lt;span style="color: green;"&gt;""&lt;/span&gt;))&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;score&lt;/span&gt; &amp;lt;- &lt;strong&gt;function&lt;/strong&gt; (&lt;span style="color: #2040a0;"&gt;name&lt;/span&gt;) {&lt;br /&gt;    &lt;strong&gt;return&lt;/strong&gt; (&lt;span style="color: #2040a0;"&gt;sum&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;dict&lt;/span&gt;[&lt;span style="color: #2040a0;"&gt;unlist&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;strsplit&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;name&lt;/span&gt;, &lt;span style="color: green;"&gt;""&lt;/span&gt;))]))&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt; &amp;lt;- &lt;span style="color: #2040a0;"&gt;sort&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt;)&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #2040a0;"&gt;weighted.score&lt;/span&gt; = (&lt;span style="color: red;"&gt;1&lt;/span&gt;:&lt;span style="color: #2040a0;"&gt;length&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt;))*(&lt;span style="color: #2040a0;"&gt;sapply&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;nlist&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;score&lt;/span&gt;)) &lt;br /&gt;&lt;span style="color: #2040a0;"&gt;sum&lt;/span&gt;(&lt;span class="Apple-style-span" style="color: #2040a0;"&gt;weighted.score&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;This was an interesting problem to solve in R. It demonstrates the flexibility of R in reading and processing free form text. Trying to do a similar task in SAS would be hard.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-1016391388696698160?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/1016391388696698160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-22.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1016391388696698160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1016391388696698160'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/project-euler-in-r-problem-22.html' title='Project Euler in R:  Problem 22'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-9166222608566470736</id><published>2012-01-06T00:00:00.000-08:00</published><updated>2012-01-06T00:00:09.403-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: Foundation Trilogy by Asimov</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to start reading some good science fiction? Pick up the &lt;a href="http://en.wikipedia.org/wiki/Foundation_series"&gt;Foundation series&lt;/a&gt; by Isaac Asimov.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Isaac_Asimov"&gt;Asimov&lt;/a&gt; was a prolific writer. The foundation series comprises many books. The first three are called "Foundation", "Foundation and Empire" and "Second Foundation".&lt;br /&gt;&lt;br /&gt;The books have an interesting premise: the behavior of individual humans is unpredictable, but the behavior of a large number of people can be collectively predicted. This is similar to the behavior of molecules of a gas, or movements of electrons. It is an interesting idea, and Asimov takes this concept and writes a kind of history for the Galactic Empire. In the introduction, Asimov says that he wanted to write a science fiction book, modeled on &lt;a href="http://en.wikipedia.org/wiki/The_History_of_the_Decline_and_Fall_of_the_Roman_Empire"&gt;Gibbon's History of the Roman Empire&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The first three books are very interesting, though I did find my interest flagging in the third book. As expected, the first is the strongest. It talks of how the first Foundation was established, and how they made it through their turbulent years. The second book talks of how the Foundation faced very determined opposition, and how it escaped through it. The third talks of the second Foundation, whether it was indeed established, and what happened to it.&lt;br /&gt;&lt;br /&gt;I don't read too much science fiction, and I am impatient when reading fiction. The foundation series were a great introduction to the genre. They are old now, but they are short and punchy. After reading the first book you'll have a pretty good idea whether you like the genre.&lt;br /&gt;&lt;br /&gt;Science fiction is a popular genre among computer engineers and programmers. Imagining the future gives the author a lot of room to imagine a better future. The first Foundation books were published in 1952. Fifty years in the future, I was wondering how much of the world has changed. Looking back at old science fiction gives you an idea of what the older generations were hoping for.&lt;br /&gt;&lt;br /&gt;The first three books are a great trilogy to start reading science fiction.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-i4qSIcP5hwM/TwRzl0v1lWI/AAAAAAAAAZY/LJhTzXzpwPg/s1600/asimovfoundation.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="228" src="http://3.bp.blogspot.com/-i4qSIcP5hwM/TwRzl0v1lWI/AAAAAAAAAZY/LJhTzXzpwPg/s320/asimovfoundation.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-9166222608566470736?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/9166222608566470736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/book-review-foundation-trilogy-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9166222608566470736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9166222608566470736'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/book-review-foundation-trilogy-by.html' title='Book Review: Foundation Trilogy by Asimov'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-i4qSIcP5hwM/TwRzl0v1lWI/AAAAAAAAAZY/LJhTzXzpwPg/s72-c/asimovfoundation.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2760193278175754217</id><published>2012-01-05T00:00:00.000-08:00</published><updated>2012-01-05T00:00:06.655-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Book Review: The Elements of Computing Systems</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to really, truly understand how computers work? Read "&lt;a href="http://www1.idc.ac.il/tecs/"&gt;The Elements of Computing Systems&lt;/a&gt;", by Noam Nisan and Shimon Schocken.&lt;br /&gt;&lt;br /&gt;I studied Computer Science through graduate school. I love the field, and I own the texts that make this field fun. So I was surprised when this book came from nowhere. It promised to teach Computer Science completely through building an entire computer from the most basic pieces. After reading through it, and doing most of the exercises, I am convinced. This is &lt;b&gt;the&lt;/b&gt;&amp;nbsp;way to teach Computer Science. This way doesn't come easy, a high school student could go through it, but he would need a lot of exposure to Computing concepts in advance: flip-flops, how a VHDL-like language works, and programming. An undergraduate student could start on this book in this third year. It forms the textbook for a course at MIT. Lucky students.&lt;br /&gt;&lt;br /&gt;The most important concept in Computer Science is abstraction: how a layer of abstraction can hide the underlying complexity. This is a difficult concept to grasp in practice, though you see it everywhere. A CPU is an abstraction layer: you program it in Assembly, and assume that it is a magical box that "understands" assembly. The CPU itself is built using transistors and logic gates. Computer Science is built on many abstractions: a memory, a processing unit, a lower-level language, a compiler, an operating system.&lt;br /&gt;&lt;br /&gt;The Elements of Computing Systems is written in a very interesting way. It starts out with logic gates and a flip-flop as the basic unit. Using these, you create all the complexity of an adder, a register, a simple arithmetic unit. Using your creation, you create a full CPU. Using your CPU, you use an assembly language to program it. For your assembly language, you write a compiler, and then an operating system. This shows you the entire stack for a make-believe computer. The computer made is a simpler version of your laptop or desktop. Knowing one allows you to understand the more complex version.&lt;br /&gt;&lt;br /&gt;This method of learning by doing is very powerful. This is the only way this understanding sticks in the minds of students. I've seen many of these topics covered in separate Computer Science coursework. But a single book tying the topics together has more impact.&lt;br /&gt;&lt;br /&gt;This book isn't for everyone. You will need some experience with a C or Java like programming language, and perseverance. A smart high school student could tackle this with some help from his parents. I cannot think of a better way to learn computing.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-gI_qQdgTj5Q/TvkhAIomoWI/AAAAAAAAAVg/jjIa2xURDv8/s1600/cover.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-gI_qQdgTj5Q/TvkhAIomoWI/AAAAAAAAAVg/jjIa2xURDv8/s320/cover.jpg" width="284" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2760193278175754217?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2760193278175754217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/book-review-elements-of-computing.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2760193278175754217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2760193278175754217'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/book-review-elements-of-computing.html' title='Book Review: The Elements of Computing Systems'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-gI_qQdgTj5Q/TvkhAIomoWI/AAAAAAAAAVg/jjIa2xURDv8/s72-c/cover.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3790127097353948639</id><published>2012-01-04T00:00:00.000-08:00</published><updated>2012-01-04T00:00:09.346-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: Three Cups of Deceit</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to know the true story behind &lt;a href="http://en.wikipedia.org/wiki/Greg_Mortenson"&gt;Greg Mortenson&lt;/a&gt;? Read Jon Krakauer's short book, "Three Cups of Deceit", to find how Greg was able to fool millions of people.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Greg_Mortenson"&gt;Greg Mortenson&lt;/a&gt; is a person who runs the Central Asia Institute (CAI), where they collect charity money to construct schools in Afghanistan and Pakistan. His book, "&lt;a href="http://en.wikipedia.org/wiki/Three_Cups_of_Tea"&gt;Three Cups of Tea&lt;/a&gt;", has sold many copies, and is popular in the West. Greg claims that he stumbled into the town of Korphe, and was so moved by the poverty that he made a solemn vow to return and construct a school there. In his books, he recounts this journey, and the difficulty in building a school in such a remote place. He claims to have been apprehended by Taliban, and describes how he was released on the promise of building a school. His story is a miraculous tale of transforming hotbeds of fundamentalist religion by building schools.&lt;br /&gt;&lt;br /&gt;It would be fantastic, if it were true. Jon Krakauer shows how much of Greg's story is a fabrication. Jon supports his claims with real proof. The most damning evidence is Greg's photograph alongside people whom Greg claimed were Taliban. In reality, they were his bodyguards through dangerous territory. Greg is shown holding an AK-47, and happily posing for the photograph with his tormentors. Jon also shows how other claims of success are completely hollow. Not only is the CAI building far fewer schools than it claims, but also the schools are mere buildings. There are no students because there are no teachers.&lt;br /&gt;&lt;br /&gt;Jon Krakauer writes beautifully. From his book about Everest, "&lt;a href="http://en.wikipedia.org/wiki/Into_Thin_Air"&gt;Into Thin Air&lt;/a&gt;", to the insightful account of Mormons, "&lt;a href="http://en.wikipedia.org/wiki/Under_the_Banner_of_Heaven"&gt;Under the Banner of Heaven&lt;/a&gt;". Get this book now. It is a quick and captivating read.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We're done with the review. But there is a lingering feeling in my mind that something has been left unsaid.&lt;br /&gt;&lt;br /&gt;A passage in Jon's book made me think deeply. On Page 68, Jon says how Greg was able to fool his audience.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;It soothed the national conscience. Greg may have used smoke and mirrors to generate the hope he offered, but the illusion made people feel good about themselves, so nobody was in a hurry to look behind the curtain. Although it doesn't excuse his dishonesty, Mortenson was merely selling what the public was eager to buy.&lt;/blockquote&gt;This brilliant passage made me think of more than just Greg Morentson's fraud. People have an inherent need to believe in a feel-good story. We want to believe happy stories from hopeless areas because we are so eager for hope. This is as true in yogi-infested India as it is in the West. Many babas and yogis originate in rural India. We are eager for stories that show India in a good light. We want to believe the lies that India has a stronger spiritual connection with God than the rest of the world. We want to believe that India has all the mystic and spiritual men, the land that gave birth to five religions. In the absence of good news about the economy, or education, or political progress, we'll believe in far-fetched stories about how God favors Indians.&amp;nbsp;In our eagerness to believe such stories, we are fooled by crooks posing as saints.&lt;br /&gt;&lt;br /&gt;I am glad that Jon wrote a book exposing Greg Mortenson. But the real people I applaud are his audience. People realized that they were fooled, and they admitted this. Jon himself was a supporter of Greg's work, and had donated more than $77,000 of his own money to support the effort. It takes a lot of courage to investigate someone's fraud. But it takes a log more courage to admit that you have been fooled. I applaud the people for realizing their deceit, and having the strength to end the charade.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-48XY1zDcK7I/Tv8rj6t6g8I/AAAAAAAAAYs/xNHOvNMVp30/s1600/threecups.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-48XY1zDcK7I/Tv8rj6t6g8I/AAAAAAAAAYs/xNHOvNMVp30/s1600/threecups.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3790127097353948639?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3790127097353948639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/book-review-three-cups-of-deceit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3790127097353948639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3790127097353948639'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/book-review-three-cups-of-deceit.html' title='Book Review: Three Cups of Deceit'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-48XY1zDcK7I/Tv8rj6t6g8I/AAAAAAAAAYs/xNHOvNMVp30/s72-c/threecups.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5690009962676709318</id><published>2012-01-03T00:00:00.001-08:00</published><updated>2012-01-03T00:00:04.572-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Indie Gaming</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was going to bemoan the loss of innovative ideas in gaming. I had seen too many first person shooters, too many car racing games, and the same old Japanese Role Playing Games.&lt;br /&gt;&lt;br /&gt;And then I met Indie Gaming, and I was blown away.&lt;br /&gt;&lt;br /&gt;If you're new to the concept, as I was, Indie Gaming are games made by independent studios. Sometimes, these are very small teams of developers producing a single game. The large game studios want to chase millions of installs and the big blockbuster game. They do not deviate much from formulaic games, massive story-lines, insanely detailed graphics and big budgets. Independent games are made by smaller teams, so they have a limited story, small budgets. This limits what they can do: they cannot put millions of dollars into graphics. And as a result, they need something to attract audience away from well established games. They need to be innovative.&lt;br /&gt;&lt;br /&gt;My introduction to Indie gaming was through the &lt;a href="http://www.humblebundle.com/"&gt;Humble Indie Bundle&lt;/a&gt;. The concept of an Indie bundle is as innovative as the games. Independent developers cannot get their games stocked in Walmart, and they don't have the traffic that can sustain Internet-only sales. As a result, they suffer from poor visibility and&amp;nbsp;lackluster&amp;nbsp;sales. So some independent game developers tried to offer a bundle of independent games at a price that the customer sets. Everyone chooses their own price. If you pay more than the mean donation amount, you also get some freebie games. The games are available for Windows, Mac, and Linux. The games have no Digital Rights Management, so you can confidently run the game on your computers in the future. They have no copy protection, so you can install the games on all your home computers. The &lt;a href="http://en.wikipedia.org/wiki/Humble_Indie_Bundle"&gt;independent games bundle&lt;/a&gt; concept has taken off. The sales are bigger and more prominent each year. The Humble Indie Bundle was the first bundle, and now there are many different types of bundles offered on the Internet.&lt;br /&gt;&lt;br /&gt;This year, I purchased the Humble Indie Bundle #4, and it included the Indie Bundle #3, since my donation amount was larger than the average. I paid $10. &amp;nbsp;I get eleven games with no DRM, and they all work on Linux: it is a bargain.&lt;br /&gt;&lt;br /&gt;The games are refreshingly innovative. &lt;a href="http://pc.ign.com/articles/114/1142949p1.html"&gt;Night Sky&lt;/a&gt; is a 2D physics platformer, where you have to roll a ball around to progress through levels. &lt;a href="http://en.wikipedia.org/wiki/Hammerfight"&gt;Hammerfight&lt;/a&gt; is a game in which you battle with a floating hammer. Hammerfight uses only a mouse, and no buttons. &lt;a href="http://en.wikipedia.org/wiki/Bit.Trip_Runner"&gt;Bit Trip Runner&lt;/a&gt; is a rhythm-based platformer, where your character has to jump and navigate through a level and your moves have to be synchronized to the background music.&lt;br /&gt;&lt;br /&gt;Independent gaming are bringing fun back into gaming with their innovative games.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-H1A38J4IC0Q/TwH4Gf4I8kI/AAAAAAAAAZE/bk4VadSlaTE/s1600/humble.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-H1A38J4IC0Q/TwH4Gf4I8kI/AAAAAAAAAZE/bk4VadSlaTE/s1600/humble.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5690009962676709318?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5690009962676709318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/indie-gaming.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5690009962676709318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5690009962676709318'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/indie-gaming.html' title='Indie Gaming'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-H1A38J4IC0Q/TwH4Gf4I8kI/AAAAAAAAAZE/bk4VadSlaTE/s72-c/humble.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7709957940400911754</id><published>2012-01-02T00:00:00.000-08:00</published><updated>2012-01-02T16:48:38.926-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: Binary, by Michael Crichton</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to read good fiction? Read "Binary", by Michael Crichton, one of his best works that you've never heard of. Yes, that &lt;a href="http://en.wikipedia.org/wiki/Jurassic_Park_(novel)"&gt;Michael Crichton&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The first book I read by Michael Crichton was an unknown book called "Binary" that none of my friends had heard about. I was in high school, and my father's friend had dropped this short book at our place. The author was John Lange, whom nobody had heard of. Inside, the book mentioned that the author was now revealed to be the great Michael Crichton, but I hadn't heard of Crichton either, so I wasn't expecting much.&lt;br /&gt;&lt;br /&gt;The book starts with a gripping description of a heist. It grabs you, and pulls you in. The book is a thriller, of a plot involving dangerous weapons, and one man's race to stop it all. It is a short book, written very well.&lt;br /&gt;&lt;br /&gt;I had harbored fond memories of this book. I had recommended it to many friends, knowing full well how difficult it was to obtain a copy. Recently, I received a copy of this book, and I sat down to read it. A short evening passed, and I was done. Despite having read it over a decade ago, I remembered most of the plot and many of the scenes. It was a thrilling book made punchier by the fact that I knew the story. I marveled at the plot and the excellent writing.&lt;br /&gt;&lt;br /&gt;A fantastic novel, a thrilling plot. The ending isn't blockbuster by today's standards, and that is part of the lure. No superfluous nonsense, and no extra pages.&amp;nbsp;A snappy story beautifully told.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ETzKvMsCowM/Tvqg42adP-I/AAAAAAAAAXY/OhwqIagguKY/s1600/binary.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-ETzKvMsCowM/Tvqg42adP-I/AAAAAAAAAXY/OhwqIagguKY/s320/binary.jpg" width="198" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7709957940400911754?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7709957940400911754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/book-review-binary-by-michael-crichton.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7709957940400911754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7709957940400911754'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/book-review-binary-by-michael-crichton.html' title='Book Review: Binary, by Michael Crichton'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-ETzKvMsCowM/Tvqg42adP-I/AAAAAAAAAXY/OhwqIagguKY/s72-c/binary.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5601398768651772126</id><published>2012-01-01T00:00:00.000-08:00</published><updated>2012-01-01T00:00:05.099-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Book Review: The Argumentative Indian</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Suffering from insomnia? Read "The Argumentative Indian", by Amartya Sen.&lt;br /&gt;&lt;br /&gt;"The Argumentative Indian" is supposed to be observations about Indian culture and society. It might be that, but the language was so convoluted that any beauty or meaning was lost in the maze of words. Here is a sample passage, after which I decided to drop the book.&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;Yet, as is discussed in Essays 7, 8 and 15, general statements about India and Indians can be found throughout history, from the ancient days of Alexander the Great, of Megasthenes (author of the Indika, in the third century BCE), and of Apollonius of Tyana (an India-expert in the first century CE) to the 'medieval' days of Arab and Iranian visitors (who, like Alberuni, wrote so much about the land and the people of India), all the way to the Enlightenment and post-Enlightenment Europe (with heroic generalizations about India presented by Herder, Schelling, Schlegel and Schopenhauer, among many others).&lt;/blockquote&gt;Say what? If you were counting, that contained &lt;b&gt;one&lt;/b&gt;&amp;nbsp;sentence.&lt;br /&gt;&lt;br /&gt;I'm sure the book contains some useful insight but the unconnected ideas and the lack of flow made the book unreadable. I would recommend V.S. Naipaul instead. Not only does he have insight into Indian culture and society, but the language is beautifully readable.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-1HK5JBz4xpo/TvkraoAtJdI/AAAAAAAAAV4/FduLt736l-Q/s1600/103008762.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-1HK5JBz4xpo/TvkraoAtJdI/AAAAAAAAAV4/FduLt736l-Q/s320/103008762.jpg" width="213" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5601398768651772126?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5601398768651772126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2012/01/book-review-argumentative-indian.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5601398768651772126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5601398768651772126'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2012/01/book-review-argumentative-indian.html' title='Book Review: The Argumentative Indian'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-1HK5JBz4xpo/TvkraoAtJdI/AAAAAAAAAV4/FduLt736l-Q/s72-c/103008762.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8113326604303274106</id><published>2011-12-31T00:00:00.000-08:00</published><updated>2011-12-31T00:00:08.369-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: "Secrets" by Daniel Ellsberg</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Do you always do the "right" thing, or do you take the path of least resistance? "Secrets", by Daniel Ellsberg reveals the life of a person who did the right thing.&lt;br /&gt;&lt;br /&gt;Daniel Ellsberg is the person who leaked The Pentagon Papers, a secret study about the lessons learned during the Vietnam war. Leaking the study required a lot of personal courage. He was tried for acts of treason, though he was later acquitted. I find the lives of people like Daniel fascinating. They knew the path of least resistance, and yet they actively worked against it because of their conviction about the "right" thing to do. I wonder if I will have the strength that people like Daniel did.&lt;br /&gt;&lt;br /&gt;Secrets starts of with the Gulf of Tonkin incident, and Daniel talks about his observations when he was posted in Vietnam. This section of the book was very riveting: Daniel has incisive observations about the war that he saw. Later, Daniel was a scholar for the RAND corporation, studying the Vietnam war. The Pentagon Papers are the result of this study. Daniel talks about his experience with the secrecy in RAND and the Department of&amp;nbsp;Defense.&lt;br /&gt;&lt;br /&gt;I found Daniel's observation about the effect of access to secret clearance beautifully insightful. He warned Kissinger what the access to secret information will do. (Page 237 in the paperback version). I'll paraphrase Daniel's commentary:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;At first, you'll feel&amp;nbsp;exhilarated&amp;nbsp;by the volume and extent of information. Then, you'll feel like a fool for having analyzed these topics without even knowing that these secret documents existed. Then, you'll be aware of others who don't have this information, and you'll think that these people are fools. Finally, you'll become incapable of learning from people, because most people don't have access to these secret documents. No matter how great their experience compared to yours, you'll be incapable of learning from them.&amp;nbsp;&lt;/blockquote&gt;This passage should be read in the original. It is a beautifully crisp understanding of the impact of secret clearances, and power in general.&lt;br /&gt;&lt;br /&gt;Daniel talks about his thought-process, and why he decided to release the confidential study. He talks about the impact of the study, and the impact to his freedom. It makes a very interesting read.&lt;br /&gt;&lt;br /&gt;It reads like a war thriller, but it carries deep lessons about how difficult it is to do the right thing.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--VgPpNwPU1A/TvklNkxNCII/AAAAAAAAAVs/m83HppfP3co/s1600/secrets.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/--VgPpNwPU1A/TvklNkxNCII/AAAAAAAAAVs/m83HppfP3co/s320/secrets.jpg" width="219" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-8113326604303274106?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8113326604303274106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-secrets-by-daniel-ellsberg.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8113326604303274106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8113326604303274106'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-secrets-by-daniel-ellsberg.html' title='Book Review: &quot;Secrets&quot; by Daniel Ellsberg'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/--VgPpNwPU1A/TvklNkxNCII/AAAAAAAAAVs/m83HppfP3co/s72-c/secrets.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8938652090317849274</id><published>2011-12-30T00:00:00.001-08:00</published><updated>2011-12-30T00:00:04.779-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Book Review: Autobiography of a Yogi</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Why not read some third-grade fiction this weekend? Pick up a copy of "&lt;a href="http://en.wikipedia.org/wiki/Autobiography_of_a_Yogi"&gt;Autobiography of a Yoga&lt;/a&gt;" by&amp;nbsp;Paramhansa Yogananda.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The book is about a "yogi", a person who has attained enlightenment of some sort. However, the book reads like a supernatural fairy tale.&amp;nbsp;The very first chapter started off with this hoot of a passage.&lt;/div&gt;&lt;blockquote class="tr_bq"&gt;The helpless humiliations of infancy are not banished from my mind. I was resentfully conscious of not being able to walk or express myself freely.... &amp;nbsp;Psychological ferment and my unresponsive body brought me to many obstinate crying-spells.&lt;/blockquote&gt;&lt;div&gt;The author claims that he was fully conscious of his infancy, and that he cried because he couldn't express himself. This is pretty damn hard to believe. Of course, the author is gone now, and no supporting evidence can be obtained. From what we know about brain development, it is difficult to believe that any child could have such capability. A few sentences before that, he claims that in his previous birth he was a Himalayan yogi. You would think such a highly perceptive creature would wait for the infancy days to get over before trying to talk.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A few pages later, &amp;nbsp;we get another passage tailor-made for the gullible audience:&lt;/div&gt;&lt;blockquote class="tr_bq"&gt;An immense flash of light at once manifested to my inward gaze. Diving shapes of saints, sitting in meditating posture in mountain caves, formed like miniature cinema pictures on the large screen of radiance within my forehead.&lt;br /&gt;"Who are you", I spoke aloud&lt;br /&gt;"We are the Himalayan yogis." The celestial response is difficult to describe; my heart was thrilled.&lt;br /&gt;"Ah, I long to go to the Himalayas and become like you!" The vision vanished, but silvery beams expanded in ever-widening circles to infinity.&lt;br /&gt;"What is this wondrous glow"&lt;br /&gt;"I am Iswara, I am Light." The voice was as murmuring clouds.&lt;br /&gt;"I want to be one with Thee!"&lt;/blockquote&gt;&lt;div&gt;It is as poorly written as it is imagined. In the first chapter, he had recognized himself as a Himalayan yogi from a previous birth, and now that he sees a few people more, he needs them to positively identify themselves.&amp;nbsp;The book is filled with&amp;nbsp;extravagant&amp;nbsp;recounting of supernatural events. Looks like the author lived in a charmed world, only dimly aware of laws of Physics. The miracles themselves are difficult to take seriously.&amp;nbsp;Extraordinary claims require extraordinary proof, none of which is provided by the book. And they aren't even written in a funny or engaging manner. They're stated with a nonchalance that suggests that this is commonplace. Even if this were a work of fiction I'd pass it by.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The lesson from the book is that you are a yogi if unnatural stuff happens to you. If it doesn't, tough luck. Maybe next birth pal.&amp;nbsp;Wait this life out.&amp;nbsp;Even as a spiritual text the book is abysmal. It has no lesson about how to live a good life, or how to achieve peace. A much more concise and beautiful lesson is the one-liner from Mae West, "You only live once, but if you do it right, once is enough."&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;I am amused by "Autobiography of a Yogi". It comes highly recommended from seemingly sane people. People swear by it, and say that it changed their life. You have to be very desperate for meaning if this book gives you any. It is like finding deep meaning in "Baa Baa Black Sheep".&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Due to the poorly imagined plot, and the haphazard story-line, I didn't read too far. If someone could point out passages that they thought were spiritually enlightening, I'd be happy to revise my opinion.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-kYIwk0of2HE/Tv1CyBI8QdI/AAAAAAAAAYg/mQGYXUyqwmo/s1600/Autobiography+of+a+Yogi.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-kYIwk0of2HE/Tv1CyBI8QdI/AAAAAAAAAYg/mQGYXUyqwmo/s320/Autobiography+of+a+Yogi.jpg" width="210" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(In case you are offended by this: Calm down. If this guy is half as divine as he claims, he won't mind it.)&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-8938652090317849274?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8938652090317849274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-autobiography-of-yogi.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8938652090317849274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8938652090317849274'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-autobiography-of-yogi.html' title='Book Review: Autobiography of a Yogi'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-kYIwk0of2HE/Tv1CyBI8QdI/AAAAAAAAAYg/mQGYXUyqwmo/s72-c/Autobiography+of+a+Yogi.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-755226056705458037</id><published>2011-12-29T00:00:00.000-08:00</published><updated>2011-12-29T00:00:08.837-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: The Golden Gate by Vikram Seth</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to read a moving novel in sonnets? Grab a copy of &lt;a href="http://en.wikipedia.org/wiki/The_Golden_Gate_(Vikram_Seth_novel)"&gt;"The Golden Gate", by Vikram Seth&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I am prejudiced against "popular" Indian authors. Past experiences have made me critical towards them, especially if their fiction is popular in the West. I don't know what I was thinking when I picked up "The Golden Gate" by Vikram Seth. I had heard of Vikram Seth, but I had not read anything by him.&lt;br /&gt;&lt;br /&gt;The Golden Gate is a story about a few friends, and a few years of their life. The book is written entirely in verse, which took me by surprise. It has been a few years since I read verse. I need not have worried, the Golden Gate is a great way to start reading verse again. It is easy to read, and many passages in it are moving, and thought provoking. The book starts out with a person who should be happy at his success, but he feels lonely. It follows his journey, and tells you about his friends, and their lives. Written during the turbulent period of the Vietnam era, it raises interesting questions about life, ambition, following one's dreams, and what it takes to be happy and at peace.&lt;br /&gt;&lt;br /&gt;The locations are all from the San Francisco Bay Area: San Francisco, San Jose, Marin county, and introduce the reader to the joy of living in this wonderful part of the world. It makes the reader appreciate the world we live in, and our friends.&lt;br /&gt;&lt;br /&gt;I started out skeptical, and ended up enjoying the book immensely. I was sad when it ended, Vikram had done such a fine job of introducing the characters that they felt like friends.&lt;br /&gt;&lt;br /&gt;Get the book, and enter the charming world of Vikram Seth's verse.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-whrsLFCd-J0/Tvi1aWjl3PI/AAAAAAAAAVU/eNYjESyNHyo/s1600/200px-TheGoldenGate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-whrsLFCd-J0/Tvi1aWjl3PI/AAAAAAAAAVU/eNYjESyNHyo/s1600/200px-TheGoldenGate.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Image courtesy &lt;a href="http://en.wikipedia.org/wiki/The_Golden_Gate_(Vikram_Seth_novel)"&gt;Wikipedia&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-755226056705458037?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/755226056705458037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-golden-gate-by-vikram-seth.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/755226056705458037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/755226056705458037'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-golden-gate-by-vikram-seth.html' title='Book Review: The Golden Gate by Vikram Seth'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-whrsLFCd-J0/Tvi1aWjl3PI/AAAAAAAAAVU/eNYjESyNHyo/s72-c/200px-TheGoldenGate.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-4496313605514123689</id><published>2011-12-28T00:00:00.000-08:00</published><updated>2011-12-28T00:00:09.298-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: Spice Route</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Want to know why bay leaves were once more expensive than saffron? Read &lt;a href="http://books.google.com/books/about/The_Spice_Route.html?id=yUYdAQAAMAAJ"&gt;"The Spice Route", by John Keay&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The book is a history of the Spice Route, and the general quest of Europeans to find exotic aromas and flavors. It goes through time, showing how the trade route was a long chain of sea and overland routes through the Middle Ages. Various spices were harvested in South East Asia: India, Indonesia, and other countries. These were traded by Arabian traders, who brought them to the Middle East. Here, they were traded to others who took them to the Mediterranean.&lt;br /&gt;&lt;br /&gt;The history of this route is fascinating: spices were a big motivation for the European powers to expand East and West. Many campaigns were waged: trying all the routes, trying all ways to gain more access. The merchants from Holland successfully bypassed the Mediterranean, and the Spanish and&amp;nbsp;Portuguese&amp;nbsp;managed to go in different directions: the Spanish went towards the New World, while the Portuguese went East towards Goa and Japan. It is difficult to transport a person to that time, where travel was wretched and dangerous, but John does a fine job in giving the reader a flavor of that world.&lt;br /&gt;&lt;br /&gt;The spice route led to a colonization of the world, as the European powers carved up the commercial world among themselves. It is instructive to read this history, and learn about how a new improvement fundamentally changes the field.&lt;br /&gt;&lt;br /&gt;This book will shed a light into the colonial era, and will take the reader back through time. It made me look at my spice cabinet very differently, and treat my bay leaves with a lot more respect.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-1F_eQQuVVjQ/Tvix56i9ArI/AAAAAAAAAVI/sznnRCSmob0/s1600/spiceroute.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-1F_eQQuVVjQ/Tvix56i9ArI/AAAAAAAAAVI/sznnRCSmob0/s1600/spiceroute.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-4496313605514123689?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/4496313605514123689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-spice-route.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4496313605514123689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4496313605514123689'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-spice-route.html' title='Book Review: Spice Route'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-1F_eQQuVVjQ/Tvix56i9ArI/AAAAAAAAAVI/sznnRCSmob0/s72-c/spiceroute.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7424588296058887544</id><published>2011-12-27T00:00:00.000-08:00</published><updated>2011-12-27T00:00:08.754-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: H20 A Biography</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Looking for some good science writing about a common topic? Pick up Philip Ball's, "H20, A Biography".&lt;br /&gt;&lt;br /&gt;Philip writes about water from a few different angles. It talks about how water originated in the Universe. The book talks about the origin of the Universe (Big Bang, not 6000 years), and how planets were formed. Then it goes into how Earth might have got its water. We take water for granted, but many planets have little or no water at all. If we believe that intelligent life requires water, we need to understand how water could have come around in the first place. It is a very strange set of circumstances that caused Earth to get water and retain it. Many planets might have had water, but they lost it over time. Astronomers and&amp;nbsp;Physicists&amp;nbsp;have looked at Venus and Mars and tried to reason about how Earth might have had water. The Science behind this is quite beautiful and involved, and it helps that Philip explains it so well.&lt;br /&gt;&lt;br /&gt;Next, Philip explains how humans discovered water. This is the most interesting part of the book, the history of Science. Ancients thought that water was an element, and they did not know that ice, water and steam are the same compound. This led to a long set of mistakes and it shaped the thinking of early chemists, leading them astray. I found this section remarkable. How does one realize what water contains? Philip lists all the major Physics and Chemistry milestones that allowed humans to recognize that water is a compound of hydrogen and oxygen. The book also talks of how humans realized that ice, water and steam are the same compound. The mis-steps are very instructive. They lead to a better understanding of how science proceeds and how mistakes are corrected. Early chemists thought that when something is burned, it gives up phlogiston (rather than taking up oxygen). This was an easy mistake, given the instruments of the time. Early chemistry made quick advances when people showed that burning was a process of oxidation, combining chemically with oxygen. (Similar mistakes were made in early experiments with electricity. Electricity was through to flow from the positive lead to the negative lead, when the actual flow is in the opposite direction. Thus, electrons now have a negative charge by convention.)&lt;br /&gt;&lt;br /&gt;In the third section, the book talks about the behavior of water in cells, and the anomalous behavior of water under various circumstances: low temperature, high pressure, low pressure, presence of solid bodies. I didn't know much of it, though I confess that I wasn't able to retain much of this information. It was just too dense for me in parts, and I had to skim through.&amp;nbsp;The book ends with drinking water, and explains why the lack of drinking water is one of the biggest problems facing humanity.&lt;br /&gt;&lt;br /&gt;The book is a beautiful history of early chemistry and various aspects of water. It does get technical at times explaining in quite some detail how certain things work. It is best to skim such sections and return to them later. A majority of the book is an easy and insightful read.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ExIcaG9jSrk/Tvii7UwWLZI/AAAAAAAAAU8/I1_edkczGu8/s1600/h2o.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-ExIcaG9jSrk/Tvii7UwWLZI/AAAAAAAAAU8/I1_edkczGu8/s1600/h2o.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7424588296058887544?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7424588296058887544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-h20-biography.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7424588296058887544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7424588296058887544'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-h20-biography.html' title='Book Review: H20 A Biography'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-ExIcaG9jSrk/Tvii7UwWLZI/AAAAAAAAAU8/I1_edkczGu8/s72-c/h2o.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-347142469445554242</id><published>2011-12-26T08:05:00.000-08:00</published><updated>2011-12-29T21:20:58.046-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: Seeing Voices</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Oliver Sacks is a neurologist of some renown. He has written some fascinating books on the working of the mind: the most famous are "The Man Who Mistook His Wife for a Hat", and "Musicophilia". "Seeing Voices" is a short book about the deaf.&lt;br /&gt;&lt;br /&gt;When I first picked up the book, I wondered if brain development for deaf people is very different from that of hearing people. Oliver's book lists the various ways in which language development suffers if a deaf person isn't allowed to sign naturally, or if he doesn't have access to other people who sign. I didn't know much about sign language before reading the book. Sign language isn't a simple translation of English or Hindi into gestures. Rather, it has its own idioms, its own grammar. So sign has a notion of poetry and of puns.&lt;br /&gt;&lt;br /&gt;Oliver lists various cases of deaf people whose parents did not sign. When these children grew up and finally encountered signing, a world of language opened up to them. This process is beautifully described, and provides valuable insights into the working of the language part of the brain. For example, without language, there was no way to describe time: today versus tomorrow blend in if there is no way to describe them.&lt;br /&gt;&lt;br /&gt;There are also examples of a few hearing individuals whose language development has been artificially suppressed. These examples showed how both hearing and non-hearing individuals pick up language in similar manner.&lt;br /&gt;&lt;br /&gt;"Seeing Voices" is a great book to read if you have a small child in the house. Children learn sign language faster than spoken language. Spoken language requires a complicated co-ordination of the vocal chords, and these develop rather late in children. Sign language requires arm motion which children acquire rather early. Based on this, many hearing parents teach their children sign language. From an early age, the child learns how to express himself: pain, hunger, boredom, and a need for mommy, daddy, or sibling. This allows for a limited communication between parent and child, removing frustrations on both ends.&lt;br /&gt;&lt;br /&gt;After reading this book, I could think of many friends who would love to read this. You don't need to be interested in neuroscience, language development, child development, or the world of the deaf to love this book. This short book makes you aware of language, and gives you much to consider about.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-kZdJ-dmMQ4g/TviTSlql_vI/AAAAAAAAAUs/61mjWXitJ4A/s1600/6_seeing_low_res.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-kZdJ-dmMQ4g/TviTSlql_vI/AAAAAAAAAUs/61mjWXitJ4A/s320/6_seeing_low_res.jpg" width="208" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-347142469445554242?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/347142469445554242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-seeing-voices.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/347142469445554242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/347142469445554242'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-seeing-voices.html' title='Book Review: Seeing Voices'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-kZdJ-dmMQ4g/TviTSlql_vI/AAAAAAAAAUs/61mjWXitJ4A/s72-c/6_seeing_low_res.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2934401171731512871</id><published>2011-12-25T18:21:00.000-08:00</published><updated>2011-12-25T18:21:27.298-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Book Review: The Man Who Knew Infinity</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;a href="http://en.wikipedia.org/wiki/Srinivasa_Ramanujan"&gt;Srinivas Ramanujan&lt;/a&gt; was a brilliant Indian mathematician who made seminal contributions to Number Theory and the theory of continued fractions. Robert Kanigel's book, "The Man Who Knew Infinity" is a biography of Ramanujan.&lt;br /&gt;&lt;br /&gt;The book talks about Ramanujan's life in quite some detail. Robert has provided a lot of color by traveling to the places involved, and deeply researching Ramanujan's life. The book has photographs of the places and maps of areas, making it easy to identify with the story. The biography is well balanced and impartial. If this was all the book contained, it would already be a worthy read.&lt;br /&gt;&lt;br /&gt;What I found most interesting was the associated commentary on Indian society, values and the education system. Ramanujan was ignored by the Indian education system, largely because he refused to conform to its requirements. Ramanujan showed an early brilliance in Mathematics. But the system didn't care for exceptional performance in one field. Due to the inflexibility of the system, the talent of a brilliant mathematician was wasted. Having suffered through the Indian education system, I found the passages revealing. Even back in Ramanujan's day, the system was inflexible and idiotic. Many people recognized the inflexibility of the system, its arbitrary outcome, and the ill effect on genuine talent.&lt;br /&gt;&lt;br /&gt;How much part did Indian society and customs play in Ramanujan's downfall? Ramanujan refused to alter his diet in cold, cloudy England. As a result, he got very little vitamin D, and suffered poor health. This is a problem that persists to this day: Indians who firmly adhere to a restricted diet suffer from problems in countries where an Indian diet is unsuitable. Ramanujan's wife was poorly treated by his mother, and this poor treatment led to misunderstanding and stress in Ramanujan's life. Would the outcome have been different if the Indian arranged marriage was not as&amp;nbsp;stifling?&lt;br /&gt;&lt;br /&gt;Ramanujan's life is full of questions. It makes me sad at the outcome. But more importantly, it makes me wonder.&lt;br /&gt;&lt;br /&gt;Would a Ramanujan be possible today? Could a lower middle class boy with no talent for anything other than Mathematics be recognized as a genius? Could he even reach a point where he could seek collaboration or patronage from Western mathematicians?&lt;br /&gt;&lt;br /&gt;It is a very sad tale, though one I think every Indian student should know. Indian students yearn for exposure to foreign&amp;nbsp;education and worldwide recognition. This is one example of a person who got both, and yet he had a sad and lonely life. The outcome could have been so much different. Ramanujan was as good as &lt;a href="http://en.wikipedia.org/wiki/Euler"&gt;Euler&lt;/a&gt; or a &lt;a href="http://en.wikipedia.org/wiki/Gauss"&gt;Gauss&lt;/a&gt;, according to people who worked with him. And yet his talent was squandered away. An early death, a lonely life full of struggle. And Ramanujan was lucky. Today, he probably would have no hope of success.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-y1uTYoSKR2Q/TvfXoTjVoYI/AAAAAAAAANY/6g2ATEhtw8Q/s1600/200px-Ramanujan.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-y1uTYoSKR2Q/TvfXoTjVoYI/AAAAAAAAANY/6g2ATEhtw8Q/s1600/200px-Ramanujan.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Image courtesy &lt;a href="http://en.wikipedia.org/wiki/Srinivasa_Ramanujan"&gt;Wikipedia&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2934401171731512871?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2934401171731512871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-man-who-knew-infinity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2934401171731512871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2934401171731512871'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-man-who-knew-infinity.html' title='Book Review: The Man Who Knew Infinity'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-y1uTYoSKR2Q/TvfXoTjVoYI/AAAAAAAAANY/6g2ATEhtw8Q/s72-c/200px-Ramanujan.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-4040947261202329612</id><published>2011-12-19T00:00:00.000-08:00</published><updated>2011-12-19T00:00:04.931-08:00</updated><title type='text'>Book Review: The Male Brain &amp; The Female Brain</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div&gt;Rather than waste your time with pop-culture books about men and women, how about read books with real science and insight this holiday season?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;This is a review of two delightful books called "The Female Brain" and "The Male Brain" written by&amp;nbsp;&lt;a href="http://drlouann.ning.com/"&gt;Louann Brizendine&lt;/a&gt;. Dr. Brizendine is a professor at UC San Francisco. Both books talk about the peculiarities of each brain from a scientific viewpoint. The books are scientifically accurate, and are accessible to a layperson with no background in neurology.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;The books contain a lot of insight about the behavior of both men and women. For example, The Female Brain talks about how women's brain is highly geared towards social connections. It provides many examples to demonstrate this, and talks about the development of a female brain from a newborn to adult and to a mature brain. Along the way, you see the various changes in the brain. A lot of behavior changes accompany the development of the brain. This book made me understand the motivation behind the baffling behavior of friends and relatives.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The Female Brain was the earlier book. Recently, Dr. Brizendine wrote The Male Brain. The second book is as interesting and as revealing as the first. It talks of the development of the male brain through the years. There are many ways in which the adult male brain is different from the teenage male brain. Reading about the male brain allowed me to better understand how I will change as I grow older. It also allowed me to understand male toddlers behavior.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Both books are a quick read, they make cutting-edge scientific research accessible to everyone. This is scientific writing at its best.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-0-P2qjYHVn4/Tuzh2o57XRI/AAAAAAAAABc/I3g0-8ukJpk/s1600/brains.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-0-P2qjYHVn4/Tuzh2o57XRI/AAAAAAAAABc/I3g0-8ukJpk/s1600/brains.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-4040947261202329612?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/4040947261202329612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/12/book-review-male-brain-female-brain.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4040947261202329612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4040947261202329612'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/12/book-review-male-brain-female-brain.html' title='Book Review: The Male Brain &amp; The Female Brain'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-0-P2qjYHVn4/Tuzh2o57XRI/AAAAAAAAABc/I3g0-8ukJpk/s72-c/brains.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-6704844965943724320</id><published>2011-10-12T09:02:00.000-07:00</published><updated>2011-10-13T22:29:51.483-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Book Review: Kashmir, The Wounded Valley</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Many years ago, Neha and I were walking around Santa Rosa in Northern California. We came across a used bookstore where the owner was listening to some good blues, and improvising with a harmonica. It was a perfect setting. We entered the store and found some very interesting books. Some of these books have been impossible to find elsewhere.&lt;br /&gt;&lt;br /&gt;Today's review is about one book from that store. The book is &lt;a href="http://openlibrary.org/books/OL1253432M/Kashmir_the_wounded_valley"&gt;"Kashmir, The Wounded Valley", by Ajit Bhattacharjea&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The book is a condensed history of the Kashmir valley. It starts around 700AD, when authoritative written record begins, and continues on till 1992. It is an insightful read. Written in an easy style, Ajit takes the reader through time in Kashmir's history. Entirely factual, and entirely gripping, the book has the pull of a crime thriller rather than the yawn of history books. It is even more chilling when you realize that all the events occurred. And when you turn to the evening news, you realize that we are still living with the repercussions.&lt;br /&gt;&lt;br /&gt;Two things struck me when reading the book.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;The valley has had mismanagement and &lt;b&gt;cruel monarchs&lt;/b&gt;. Few rulers have cared for the well-being of their people. Dynasties follow a predictable pattern. The first monarch in a dynasty is an aggressive conqueror, or a cunning statesman. The second is a benevolent and able leader. Successive leaders are selfish, greedy, and insensitive to the needs of the people. Few monarchs have focused on improving education or living conditions. As a result, the people have suffered greatly and their lot has worsened over the years. Even before the British Raj, the condition of the people was miserable.&lt;/li&gt;&lt;li&gt;The people are surprisingly &lt;b&gt;resilient&lt;/b&gt;, and a little gullible. Kashmiris have a liberal outlook towards life. Most Kashmiris converted from Hinduism and Buddhism to Islam willingly. The benevolent influence of liberal sufis struck a chord among the liberal Kashmiris. Culture played a bigger role than religion in their life. All through the turmoil of Mughal India, Kashmir had peaceful co-existence among Hindus and Muslims. The gullibility of the people leads to their willingness to be ruled and oppressed. And it shows in the lack of popular uprising to demand better rights and better living conditions. They supported outsiders to overthrow the existing monarch, only to find the new boss was same as the old boss. Even when democracy was at hand, they did not demand their rights aggressively. As a result, leaders turned into tyrants, ignoring the needs of the people and holding Kashmir back from fully awakening.&lt;/li&gt;&lt;/ol&gt;The book also explains how Kashmir became a contentious issue between India and Pakistan, and the mistakes that led us there. The book is impartial: it points out mistakes on all sides. The ruler of Kashmir, Hari Singh, refused to make a concrete decision on joining either side. He had hopes of staying independent despite the impossibility of such an arrangement for Kashmir. Rulers of India and Pakistan refused to give the Kashmir issue the importance it deserved. And as we have seen countless times before, administrative incompetence and widespread corruption made a bad situation worse. Heavy-handed actions by the central government, corruption by well-known people, and a lack of respect for the people's needs alienated an entire state. The people started out amicable to India, eager to strengthen ties with the land of Nehru and Gandhi. Over years, all good will was squandered, culminating in the excesses of the armed forces. Warm friends turned into bitter enemies.&lt;br /&gt;&lt;br /&gt;A small bruise festered into an open sore, leading to much pain and hardship for both countries for over fifty years. Over time, that pain has spread through both countries. It has led to war and terrorism.&lt;br /&gt;&lt;br /&gt;This book should be a required reading for every Indian and Pakistani student. It has valuable lessons for future statesmen. Due to mortal follies, a place with heavenly beauty has been turned into a dark hell. Having deteriorated so far, it is debatable if the situation will ever improve. If&amp;nbsp;a workable remedy exists,&amp;nbsp;knowing how we got into this mess is the first step towards it.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-gLVJdCvSN4Y/TpW00GnF5-I/AAAAAAAAAAg/r6Z0fNDx7Q0/s1600/kashmir.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-gLVJdCvSN4Y/TpW00GnF5-I/AAAAAAAAAAg/r6Z0fNDx7Q0/s1600/kashmir.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-6704844965943724320?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/6704844965943724320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/book-review-kashmir-wounded-valley.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6704844965943724320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6704844965943724320'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/book-review-kashmir-wounded-valley.html' title='Book Review: Kashmir, The Wounded Valley'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-gLVJdCvSN4Y/TpW00GnF5-I/AAAAAAAAAAg/r6Z0fNDx7Q0/s72-c/kashmir.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3978723635118917182</id><published>2011-10-10T22:37:00.000-07:00</published><updated>2011-10-11T06:13:06.810-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>The State of Free Software Today: What We Need to Do</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;a href="http://stallman.org/archives/2011-jul-oct.html#06_October_2011_(Steve_Jobs)"&gt;Richard Stallman (popularly called RMS) wrote an eulogy to Steve Jobs&lt;/a&gt; recently. It was widely reported due to its angry tone. In summary, RMS was happy that Steve Jobs is dead because Jobs personifies the "walled garden" approach to computing. In the Free Software camp, nothing is more abhorrent than the walled garden approach. Free software is all about giving people a lot of freedom: including the full source code of the software, and the freedom to modify it and copy it. The walled garden approach is all about tight control: not just of the source code but also the development and the overall experience.&lt;br /&gt;&lt;br /&gt;It is easy for me to pick sides: I have been a free software enthusiast since 1995, when my friend and I chanced upon something called Linux. I spent many hours playing with Linux, and have used it as my primary system for well over a decade. In addition to Linux, I spend all my time in free application software: Firefox, Chrome, Blender, GIMP, R, Eclipse, Emacs, Arduino, ... The list goes on.&lt;br /&gt;&lt;br /&gt;I abhor the walled garden approach. It is damaging to my livelihood as a software engineer if I cannot learn from a system or modify it. I enjoy programming and have tinkered with most systems I own. My tinkering was lousy and inconsequential, but I enjoyed it. And I learned a lot by poking inside them.&lt;br /&gt;&lt;br /&gt;It is easy to identify with RMS' criticism of Steve Jobs. It is easy to rally people when you demonize someone.&amp;nbsp;But free software doesn't need this kind of rallying.&lt;br /&gt;&lt;br /&gt;I think&amp;nbsp;&lt;b&gt;RMS is&amp;nbsp;wrong&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Lure of Free Software&lt;/span&gt;&lt;br /&gt;Free software is compelling. Many programs like Blender, Eclipse, Emacs are the best in their class. They are exceptional tools. I write better in Emacs than any other editor. Emacs is an extension of my mind: it is a supremely capable editor. My other editor, vim, is equally good. It is beautiful to watch an expert use emacs or vi: the software makes them insanely productive. Free software has done exceptionally well in technical areas like Statistics (R), 3D modelling (Blender), web serving (Apache), microcontroller hackery (Arduino), development tools (Eclipse, GCC, emacs/vi, ..) In these areas, non-free tools are at a significant disadvantage. Who would bother using some souped-up microcontroller tool when Arduino works so beautifully? Who would bother with a strange new Statistical language, now that you can download, install and use R right away? And if you have a newbie question with R, the wizard&amp;nbsp;&lt;a href="https://groups.google.com/group/r-help-archive/browse_thread/thread/fb967bc018cb0f2c/22de5b6ba2f92d0b?pli=1"&gt;Peter Dalgaard himself replies to questions&lt;/a&gt;! That is how awesome the community is. The software is great, the community is knowledgeable and helpful, and you can read the source code to learn more. It doesn't get better than that.&lt;br /&gt;&lt;br /&gt;With software like that, you don't need to yell about the virtues of free software and the evils of the walled garden. The software stands on its own merit. And it continues to attract people like me who care about the freedom.&lt;br /&gt;&lt;br /&gt;The free software world has produced some exceptional non-technical software: Firefox and Chrome as browsers, VLC as a media player. But in the non-technical area, free software has lagged behind. Ubuntu is making a gorgeous operating system that my mother can use. But companies like Canonical are the exception rather than the norm.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Lure of the Walled Garden&lt;/span&gt;&lt;br /&gt;In recent past, Apple has gained a large following. Their products like the iPhone and the iPad are phenomenally popular. People are buying these products because of the superior user interface, and the ease of use. The &lt;a href="http://www.eggwall.com/2011/07/age-of-technology-age-of-interface.html"&gt;user interface really is the killer feature&lt;/a&gt;. Free software advocates might dislike the walled garden approach, but we cannot deny that Apple devotes extraordinary resources to getting an excellent user interface. The first bite of the Apple is bewitchingly delicious. The interface sells.&lt;br /&gt;&lt;br /&gt;For a long time, the free software world has been blind to the needs of the "common" user. We have aimed at the technical audience, and have ignored the needs of the vast majority of computer users: our parents, our grandparents, our friends. We justified this stance because there were limited developers, and we needed to get our own house in order. We needed development tools, drivers for technical products, technical software. Developers were more interested in scratching their own itches, writing programs that satisfied their needs. Nobody can be blamed for the situation we are in. Every free software developer has been working hard, quite often without pay. Asking a Statistics programmer to write a cute game would be a disaster.&lt;br /&gt;&lt;br /&gt;In the meanwhile, a walled garden has appeared with exceptional usability, even if it has a limited set of features.&lt;br /&gt;&lt;br /&gt;It is a testimony to good usability that people are willing to enter the walled garden. Many people don't care about the freedom. People who do care continue to enter the walled garden despite their loss of freedom. It is a question of convenience, and people choose their battles carefully.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The way forward&lt;/span&gt;&lt;br /&gt;We have many glimmers of hope. Look at Firefox or Chrome. Both are free software, and both wrested browser market share from Internet Explorer (IE). IE was never an explicit walled garden, but it did curtail freedoms: it ran on specific platforms, it fragmented the web with its own extensions. For a long time, the lack of a good browser was the chief hurdle for free software users. We couldn't use IE, and nothing else was good enough. Navigator was barely&amp;nbsp;usable.&lt;br /&gt;&lt;br /&gt;Then came Firefox: it was a compelling browser. Firefox was fast, it ran on every system, it was more secure. Most importantly, it was beautiful. Compared to Netscape Navigator and IE: man, was it gorgeous! Put the navigation buttons and URL bar along the menu bar, and you had one pretty interface. Chrome went one step ahead: it is an exceptional browser. It is fast, it is pretty, it is secure. Oh, and the source is available. People who don't care about freedom of software use it because it is good. And people who care about freedom can download its source code.&lt;br /&gt;&lt;br /&gt;Something similar is happening with Android now. Android's source code is available. But that's not why millions flock to buy the Nexus-S or the Droid. They want the system because it is excellent. With Gingerbread, the Android system looks beautiful. With the next release, I'm sure it will look even better. Now that it is comparable on features, it is polishing its usability.&lt;br /&gt;&lt;br /&gt;That is the way forward: to &lt;b&gt;make exceptional software&lt;/b&gt;. Make the best damn system in the world. Make it gorgeous, fast, cheap, reliable, rugged, stable. And then release the source code. Find opportunities like the Mozilla Foundation did with Firefox. Like&amp;nbsp;Canonical did with Ubuntu.&amp;nbsp;Or like Google did with Chrome, Chrome OS and Android.&lt;br /&gt;&lt;br /&gt;Users are being charmed by the the usability of the software that Steve Jobs provided. Provide the same usability with the freedom. The walled garden will disappear by itself.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-CB1bfz5A-5s/TpO_k-91BPI/AAAAAAAAAAY/MPD3BUM4bhw/s1600/Adam-and-Eve-apple.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-CB1bfz5A-5s/TpO_k-91BPI/AAAAAAAAAAY/MPD3BUM4bhw/s1600/Adam-and-Eve-apple.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3978723635118917182?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3978723635118917182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/state-of-free-software-today-what-we.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3978723635118917182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3978723635118917182'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/state-of-free-software-today-what-we.html' title='The State of Free Software Today: What We Need to Do'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-CB1bfz5A-5s/TpO_k-91BPI/AAAAAAAAAAY/MPD3BUM4bhw/s72-c/Adam-and-Eve-apple.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-4320221611329549876</id><published>2011-10-09T16:28:00.000-07:00</published><updated>2011-10-09T16:29:00.913-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Indian Universities are no longer world class</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;A recent survey carried out by the &lt;a href="http://www.timeshighereducation.co.uk/world-university-rankings/2011-2012/top-400.html"&gt;Times Higher Education magazine ranked all the universities in the world&lt;/a&gt;. Sadly, Indian universities don't figure too highly. The best Indian university in that list is IIT Bombay. Its ranking is 301-350: no specific rank is given. One thing is for sure, IIT Bombay is worse than many small universities few people have heard about, like places in Turkey and Brazil.&lt;br /&gt;&lt;br /&gt;Many years ago, &lt;a href="http://www.eggwall.com/2005/11/lets-all-go-to-iit.html"&gt;I had written about how the IITs are not world class&lt;/a&gt;. When you venture out of India, you realize how bad they are. That article got a lot of pageviews, and lots of comments. Many IIT students wrote to say how deluded I was, in their own special way. Eat humble pie, my friends.&lt;br /&gt;&lt;br /&gt;The Times Higher Education survey is quite comprehensive. You can look at the &lt;a href="http://www.timeshighereducation.co.uk/world-university-rankings/2011-2012/analysis-rankings-methodology.html"&gt;methodology details here&lt;/a&gt;. In short, they asked industry and education leaders for their views of universities. Universities were graded along a variety of factors: the number of citations for their papers, the amount of research funding, the impact of its research on industry, the teaching environment. The study looks solid: all income has been adjusted for purchasing power parity, so poor countries are not penalized for their lower cost of living. Also, there is a normalization across disciplines, so sciences where overall publication frequency is lower are not penalized for having lesser research output. The weight for research output is 30%, which is perhaps too low. They have an&lt;a href="http://www.timeshighereducation.co.uk/world-university-rankings/2011-2012/iphone.html"&gt; iPhone application which allows you to change the weights&lt;/a&gt; and see the impact on the ranking.&lt;br /&gt;&lt;br /&gt;I don't have access to their raw data, but from reading about the study, their method looks sound. Ranking an institution is a difficult task, and this study is probably the most precise answer we have right now. A better study could look at the impact of graduates from the universities, or the difference between the capability of students with and without the education: thereby measuring the impact of the institution itself. Alas, such controlled studies are difficult to come by.&lt;br /&gt;&lt;br /&gt;So where does this leave us? This leaves us in the sorry state of admitting that Indian educational institutions are really not that good. The Chinese are far ahead of us. The prestigious Tsinghua University in China is at position 71, ranking near well known universities Rice and Vanderbilt, both in the US. Among Asian countries, Japan, Hong Kong, and Singapore all fare very well. In fact, the &lt;a href="http://www.timeshighereducation.co.uk/world-university-rankings/2011-2012/asia.html"&gt;top Asian universities are dominated by Japan, Hong Kong, China, Singapore, and Korea&lt;/a&gt;,&amp;nbsp;and now the reasons are somewhat clearer.&amp;nbsp;. These countries have made investments in education, and the results speak for themselves. &lt;a href="http://www.rediff.com/money/2007/feb/05edu.htm"&gt;Even between Brazil, Russia, and China, India spends the least amount of money on education, per student&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Admitting that our educational institutions have fallen behind is the first step. Only after we admit the problem can we find ways to rectify the situation.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-N_euakTOUBg/TpIdyIpvUMI/AAAAAAAAAAM/jP9a9TJDKt4/s1600/iit2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-N_euakTOUBg/TpIdyIpvUMI/AAAAAAAAAAM/jP9a9TJDKt4/s1600/iit2.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-4320221611329549876?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/4320221611329549876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/indian-universities-are-no-longer-world.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4320221611329549876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4320221611329549876'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/indian-universities-are-no-longer-world.html' title='Indian Universities are no longer world class'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/14128872612935211717</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-N_euakTOUBg/TpIdyIpvUMI/AAAAAAAAAAM/jP9a9TJDKt4/s72-c/iit2.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5756260876902997156</id><published>2011-10-08T13:00:00.000-07:00</published><updated>2011-10-08T14:28:41.095-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Learning a new software: Blender</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://en.wikipedia.org/wiki/Blender_(software)"&gt;Blender is a 3D design software&lt;/a&gt;. It is a complete tool, allowing you to create entire worlds in 3D, modelling, meshing, applying texture, and animating the world.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Here is an example of what Blender can do. This movie was created completely in Blender.&lt;/div&gt;&lt;iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/eRsGyueVLvQ" width="560"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Isn't that impressive? What is more impressive is that &lt;a href="http://www.blender.org/download/get-blender/"&gt;Blender is available for free, you can download it&lt;/a&gt;&amp;nbsp;and install it right now&amp;nbsp;(Windows/Mac/Linux). And if you want to make your own movie based on the characters behind Sintel, you can &lt;a href="http://www.sintel.org/download"&gt;download all the art and characters at the Sintel website&lt;/a&gt;. This level of sharing is refreshing: it allows new graphics designers to learn a complex tool, and be able to look behind the scenes of a very complex project.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Blender has a beautiful UI, though it looks very complicated initially. When you load it up the first time, the number of buttons and controls is overwhelming. This is what the default Blender 2.5 UI looks like. There is a small cube placed at the center of the viewport, and many properties and control widgets are open. Once you learn a few Blender principles, you find that the UI is clearly arranged, and every control is in the perfect place. As with any good tool, the tool itself vanishes pretty quickly. Within hours of learning Blender, you focus on the 3D modeling activity rather than the Blender tool.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-BIYflltyf8Q/TpCNlvx7ORI/AAAAAAAAATY/NzPJMtQ-rII/s1600/blender.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-BIYflltyf8Q/TpCNlvx7ORI/AAAAAAAAATY/NzPJMtQ-rII/s640/blender.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Learning Blender&lt;/span&gt;&lt;br /&gt;I tried learning how to use Blender using a book. It is hard to explain the various UI elements using written words. It is even harder to describe the 3D world you are creating using just words. The best book I have found till now is called &lt;a href="http://www.amazon.com/Blender-Dummies-Jason-van-Gumster/dp/0470584467/ref=dp_ob_title_bk/189-1885358-1820430"&gt;Blender for Dummies&lt;/a&gt;. It requires no previous knowledge, and is an excellent resource to begin modelling simple meshes in Blender. It covers Blender 2.5.&lt;br /&gt;&lt;br /&gt;In case you want to start while your book is on its way, here are a list of online resources. I list Blender 2.5 resources only. The Blender interface changed a lot between 2.4 and 2.5. If you are starting out, it is best to start with 2.5 directly.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://cgcookie.com/blender/get-started-with-blender/"&gt;Getting Started with Blender&lt;/a&gt;: This is a set of seven video tutorials. They are short and cover the very basics of using Blender. You can watch all seven within an hour and you will have a great idea of the Blender UI and basic features.&lt;/li&gt;&lt;li&gt;&lt;a href="http://gryllus.net/Blender/3D.html"&gt;Neal Hirsig's blender learning course&lt;/a&gt;: More than a collection of isolated tutorials, Neal has created a comprehensive learning course. You can download all videos to your machine and follow along with Neal as he patiently explains every feature of Blender. Neal's explanatory style is impeccable: it is a pleasure to follow along and learn. You can &lt;a href="http://sagefans.net/"&gt;downloads all these videos from sagefans.net&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://blenderlinks.com/"&gt;A collection of tutorials at Blenderlinks&lt;/a&gt;: Finally, when you have mastered the UI, you can focus on a specific topic by looking through the links at Blenderlinks. The videos are created by many contributors, so the videos differ in sound quality and expository style. But if you want to learn a single topic, the videos at cgcookie linked from Blenderlinks often provide the perfect recipe.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Blender is a powerful software, and it compares well against software which costs thousands of dollars. With a little bit of effort, you can learn how to create an entire 3D world inside your computer. It is scriptable in Python, which allows you to use Blender 3D models from an automated system. Give Blender a try, and see what you think!&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5756260876902997156?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5756260876902997156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/learning-new-software-blender.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5756260876902997156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5756260876902997156'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/learning-new-software-blender.html' title='Learning a new software: Blender'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/eRsGyueVLvQ/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-246927524195192521</id><published>2011-10-07T15:02:00.000-07:00</published><updated>2011-10-07T20:38:17.543-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: A Contract With God</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I came across a copy of Will Eisner's, "&lt;a href="http://en.wikipedia.org/wiki/A_Contract_with_God"&gt;A Contract With God&lt;/a&gt;" Trilogy at my library. This includes three books, "A Contract With God", "A Life Force", and "Dropsie Avenue". I had heard vaguely of this book, so I picked it up. I was expecting a good graphic novel.&lt;br /&gt;&lt;br /&gt;I wasn't expecting a book of this lyrical depth and insight into human behavior.&lt;br /&gt;&lt;br /&gt;These graphic novels are about life in a poor New York neighborhood starting near the Depression and going to more recent times.&amp;nbsp; It describes the life of poor migrants to America; their dreams, their lives, and how they escape the squalor of their world.&lt;br /&gt;&lt;br /&gt;I am struck by the depth and force of some of the stories. A few stories in the first book were very hard-hitting and thought provoking. I stopped reading after a few stories because there was so much to mull about. It is a rare book which has this level of insight coupled with such beautiful art.&lt;br /&gt;&lt;br /&gt;These books are not for children, though they may be okay for teenagers. They have plentiful  sex and nudity, putting the "graphic" back in "graphic novel". Use your own discretion if you have children or teenagers around or are squeamish about sex.&lt;br /&gt;&lt;br /&gt;The book can be ordered from online stores. &lt;a href="http://www.amazon.com/gp/product/0393061051/ref=ox_sc_act_title_1?ie=UTF8&amp;amp;m=ATVPDKIKX0DER"&gt;Amazon has a hardbound copy&lt;/a&gt; for $20 which is a steal.&lt;br /&gt;&lt;br /&gt;When Boston Brahmins were hoping that American classical would improve upon European Continental music,&amp;nbsp;Jazz took the world by surprise. In much the same way, Will Eisner's graphic novel is the epitome of American graphic art. Completely out of the blue, it defined the graphic novel genre and gave readers and future novelists something original and beautiful.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1RlRpVR6tSU/To9voONLE3I/AAAAAAAAATA/ajTJZlwRMkc/s1600/contractGod.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-1RlRpVR6tSU/To9voONLE3I/AAAAAAAAATA/ajTJZlwRMkc/s400/contractGod.png" width="258" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-246927524195192521?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/246927524195192521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/book-review-contract-with-god.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/246927524195192521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/246927524195192521'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/book-review-contract-with-god.html' title='Book Review: A Contract With God'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-1RlRpVR6tSU/To9voONLE3I/AAAAAAAAATA/ajTJZlwRMkc/s72-c/contractGod.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7200339984418447689</id><published>2011-10-06T07:44:00.000-07:00</published><updated>2011-10-07T13:12:24.156-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Google Plus versus online news sites (like Reddit)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Google Plus is a new social networking site. If you haven't heard about it, it is similar to other social networking sites like Orkut or Facebook.&lt;br /&gt;&lt;br /&gt;There has been a lot of discussion about how &lt;a href="http://www.huffingtonpost.com/2011/07/15/google-plus-vs-facebook-_n_899922.html#s300815&amp;amp;title=Hangouts_Video_Chat"&gt;Google Plus resembles Facebook&lt;/a&gt;. Indeed, you can search the Internet for the two names and there are countless comparisons. I think this misses a broader point.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Once I started using Google Plus, I haven't checked Reddit.&lt;/blockquote&gt;&lt;br /&gt;In case you don't know, &lt;a href="http://reddit.com/"&gt;reddit&lt;/a&gt; is a popular news website. Reddit started out as a small startup with mostly programming topics. The stories were interesting and it had an impressive signal to noise ratio due to the self-selected audience. For a while, reddit was even better than &lt;a href="http://slashdot.org/"&gt;Slashdot&lt;/a&gt;, another popular geek news website.&lt;br /&gt;&lt;br /&gt;Over time, reddit descended into cheeky cuteness, pictures, and pointless articles. At some point, I stopped reading the reddit main page, and started reading the &lt;a href="http://reddit.com/r/programming"&gt;programming subreddit&lt;/a&gt;. Even that is becoming irrelevant. At around this time, Google Plus came in.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Social Networking connects me to virtual cows&lt;/span&gt;&lt;br /&gt;I'm very skeptical about social networking. Very, very skeptical. Social networking puts me in touch with a wide number of acquaintances, where the level of interaction is shallow at best. I dislike shallow interactions, and so I avoid checking social networking sites. I check these sites roughly once every quarter. The quality of posts is between pointless and annoying. Things really went down the toilet when Facebook allowed games to post updates. Suddenly, you could see how some long-forgotten acquaintance of yours had just obtained a virtual cow in some online farm simulation. Do you want to make a farm next to his? No thanks. If I had hours to waste and wanted to simulate reality, &lt;a href="http://www.youtube.com/watch?v=zOSj7QcMqTM"&gt;I would duel in the sky&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So the previous social networking stuff was a total chore. I would check it infrequently, and post self-promotional content: links to my articles when I was happy with one.&lt;br /&gt;&lt;br /&gt;It took a &lt;b&gt;lot&lt;/b&gt; of prodding from my friends to try out Google Plus. You know who you are: thanks!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Google Plus connects me to Peter Norvig&lt;/span&gt;&lt;br /&gt;When Google Plus came in, it allowed me to subscribe to people who weren't friends: Tim O'Reilly, or Peter Norvig. These people have insightful articles to post or reshare. They are interesting to me, and are relevant to my area of work. Suddenly, Google Plus had much higher value content than Reddit. It was the Reddit front page, all over again. Except this time, it wasn't fluffykitten13, but Peter Norvig himself. Woohoo! The articles were interesting, topical, timely.&lt;br /&gt;&lt;br /&gt;I doubt Google Plus would descend into the cutesy pointlessness of Reddit anytime soon. I doubt Peter Norvig would switch completely to posting lolcats. Actually, knowing Peter, he probably would post lolcats to prove someone wrong.&lt;br /&gt;&lt;br /&gt;And that's the beauty of Google Plus, the articles are linked to the poster's reputation. I wouldn't post lolcat pictures: partly because I have better things to do, and partly because my friends would think me crazy if I did. People are free to engage in their interest of choice: it is like giving everyone their own reddit-like site. Unlike blogs, the content is usually smaller. You can subscribe to many people, and find related content very easily. Like blogs, it is personally generated content. The content is frequently updated, topical, personal, and recent. The site layout is great and no page is missing.&lt;br /&gt;&lt;br /&gt;Google Plus isn't perfect.  I still read Slashdot due to reasonable editorial filter and good comment moderation. Google Plus comments on highly visible posts are quite useless and spammy. But overall, Google Plus has given me a high signal news source. &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-He7g1Gj-LNo/To0kRuqyKtI/AAAAAAAAASY/KSXZ_RaZjmY/s1600/noise.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-He7g1Gj-LNo/To0kRuqyKtI/AAAAAAAAASY/KSXZ_RaZjmY/s1600/noise.gif" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7200339984418447689?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7200339984418447689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/google-plus-versus-online-news-sites.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7200339984418447689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7200339984418447689'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/google-plus-versus-online-news-sites.html' title='Google Plus versus online news sites (like Reddit)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-He7g1Gj-LNo/To0kRuqyKtI/AAAAAAAAASY/KSXZ_RaZjmY/s72-c/noise.gif' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-6811007364482736121</id><published>2011-10-05T16:39:00.000-07:00</published><updated>2011-10-05T16:39:44.154-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>The complicated Indian negotiation ritual: why decisions take much longer</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In traditional Indian conversation, you are never supposed to express willingness or displeasure in a straightforward manner. So when you are having lunch with extended family, you are &lt;a href="http://www.eggwall.com/2007/07/i-dislike-your-cooking.html"&gt;not supposed to clearly express that the daal was excellent and you would like some more&lt;/a&gt;. A similar dance is played out when arriving at agreement of any sort. The standard Indian conversation hovers on generalities with no preference clearly outlined. Most conversations are elaborate dances: both sides express a little more of their preference without clearly saying what they would like. Here is an example of a couple called Harry and Sally at a restaurant:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: What would you like to eat?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Anything is good.&lt;br /&gt;(At this point, you would think that they're in agreement. Well, you are wrong. Listen to the remaining conversation.)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: Would fish curry be good?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Yeah, that's ok. Does this restaurant make good lamb curry, I wonder?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: I guess, I haven't tried it. But I hear everything here is good. Would you like lamb?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Lamb is good too, I haven't had it for a while now.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: Would you like to try their lamb curry?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: That sounds good. What else is on their menu?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: They have a lot of things. Their vegetable selection is also great. The pav bhaji looks enticing.&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Yeah, pav bhaji sounds interesting. What other vegetables do they have?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: Their cauliflower curry gets good reviews. I tried it once. It is much like the fish curry, but the fish curry is clearly better. Weren't you craving fish yesterday?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Yeah, but I wonder if their preparation of fish is good. You can get that if it is their best dish.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: No, fish isn't their best dish, they make everything well. The cauliflower is also cooked perfectly.&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: I see. Both sound great. You know, just the other day I was telling my mom that it is difficult to make good okra, unless it is fresh. Did you know that?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harr&lt;/span&gt;y: No, I didn't know that. But that makes sense. Okra goes limp when it is old.&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: I wonder how this restaurant makes okra.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: I wonder too, I haven't tried it. Would you like to try it?&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Oh no, I didn't mean to imply that. Fish curry sounds great.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #990000;"&gt;Harry&lt;/span&gt;: But now I'm interested in the okra, let's order some this time.&lt;br /&gt;&lt;span style="color: #38761d;"&gt;Sally&lt;/span&gt;: Ok.&lt;br /&gt;&lt;br /&gt;All along, Sally didn't make her preference known, and neither did Harry. This elaborate ritual is even worse as the number of people increases. Going for lunch with one person is hard, lunch in a group of ten means that deciding the order can take a long time. I hope you had a snack before starting.&lt;br /&gt;&lt;br /&gt;There's no guarantee that this ritual produces the correct outcome. Among young people and close friends, this ritual has given way to specifying direct preference. And I feel a sense of relief when I can clearly list my preferences without having the song and dance. In cases when the song and dance is involved, the outcome is usually unfortunate. And when you cannot express your preference, you certainly cannot express your displeasure at the outcome.&lt;br /&gt;&lt;br /&gt;As the number of people increases, the outcome becomes more and more incorrect. Perhaps this is good, because it gives plentiful fodder for the gossip mill later on. "Jason was telling me that dining with Sally was such a chore, and how she was completely insensitive to Mark's needs."&lt;br /&gt;&lt;br /&gt;This ritual is carried out not just for meals, but for many other decisions: what people want to do, where they want to go, whom they want to marry...&lt;br /&gt;&lt;br /&gt;You notice some things only when you stop doing them. The complicated Indian negotiation ritual is one of these. Among friends and close family, I love the ability to say clearly what I want. Decisions happen quicker, and we can discuss things of consequence in the time saved.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ibnoT7DIIkY/Tozoz46E4wI/AAAAAAAAASQ/1ThAU3_aleo/s1600/decisions.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://2.bp.blogspot.com/-ibnoT7DIIkY/Tozoz46E4wI/AAAAAAAAASQ/1ThAU3_aleo/s320/decisions.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&amp;nbsp;(Fun fact: If Neo and Morpheus were Indian, the red pill, blue pill decision would have lasted the entire movie.)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-6811007364482736121?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/6811007364482736121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/complicated-indian-negotiation-ritual.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6811007364482736121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6811007364482736121'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/complicated-indian-negotiation-ritual.html' title='The complicated Indian negotiation ritual: why decisions take much longer'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-ibnoT7DIIkY/Tozoz46E4wI/AAAAAAAAASQ/1ThAU3_aleo/s72-c/decisions.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2775081297321439965</id><published>2011-10-01T19:58:00.000-07:00</published><updated>2011-10-05T16:55:22.498-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>What to do when friends are expecting: A guide for friends of new parents</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Your friends are having babies, and you haven't got any yourself. There are lots of guides for new parents, but few guides explaining what the friends of new parents can do. This guide will help you learn about the process, and help you deal with the change.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Fundamentals&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Your friends still love you the same. You would take care of a throbbing headache rather than being with friends. Having a child is similar. They need to take care of the child before being with you.&lt;/li&gt;&lt;li&gt;Your friends' priorities will change. It might have been you, now it will be the baby. Don't be hurt by this. You will feel the same when you have children.&lt;/li&gt;&lt;li&gt;Your friends will have zero time initially. Bringing up a baby takes a lot of time and effort from both parents.&lt;/li&gt;&lt;li&gt;Your friends still need social contact. They enjoy social visits, but the flavor changes considerably. Mothers might have less time to meet, but they continue enjoying telephone conversations and short visits.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;During Pregnancy&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Mom will be tired constantly. Pregnant mothers go through many physical  changes. They  feel tired constantly from carrying the extra weight. Be mindful of this. Moms also have to use the restroom very frequently.  Don't engage your friend for any long activity. Even long conversations are enough to tire mothers. If the mother looks or sounds uncomfortable, be prepared to give her some time off. If you are on a telephone, ask her if she needs to hang up.&lt;/li&gt;&lt;li&gt;Moms go through psychological changes. Many women go through mood swings. All this means that women's behavior changes considerably. Their behavior towards you will change too. Don't take it personally.&lt;/li&gt;&lt;li&gt;Less time. Your friends don't have a child yet. But preparing for a child is also time consuming. There are things to buy, doctors to visit, and a house to prepare. Limit your demands on their time.&lt;/li&gt;&lt;li&gt;Less patience. During pregnancy, your friends are going through a lot of mental and physical strain. Their levels of patience are very low. Pranks and tomfoolery are a terrible idea.&lt;/li&gt;&lt;li&gt;Positive conversations. Pregnancy is a scary time for parents already. Do your part by keeping all conversations positive. If you have heard of a scary pregnancy or delivery: keep the story to yourself! If there is a cautionary tale, give the moral precisely while keep gory details to yourself. Try to make all emotional stories positive. Negative emotional stories trouble the mother and make her very nervous. Dads can handle emotional stories better during this time. If you need to tell an un-nerving story, tell it to the dad, out of earshot of the mom.&lt;/li&gt;&lt;li&gt;Steer clear of stomach size conversations. Moms are worried about their health, their appearance, their progress. Our friends suggest the phrase, "You are carrying very well" rather than the variants that raise questions about the size or the rate of development of the baby. Definitely stay away from comments like "Are you sure you're not carrying twins?", or "Are you sure you're in your seventh month, you look small".&amp;nbsp; There's nothing to be gained from comparing the size of one mother's  belly with other mothers. If you are concerned about the baby's development, tell the father the specific concern and your suggestions. Let the dad discuss it with the OB or the mom.&lt;/li&gt;&lt;li&gt;You might want to ask the parents before gifting them anything for the baby. Or give them something that can be returned or exchanged. New parents get too many gifts. Make your gift  an asset, not a burden.&lt;/li&gt;&lt;li&gt;How &lt;span style="color: blue;"&gt;you can help&lt;/span&gt;: try to visit your friends at their place. Call before starting to confirm it is a good time and don't be upset by a last-minute change of plans. Carry some home-prepared meal that the mother enjoys. Be prepared to leave quickly.&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-size: large;"&gt;During Labor&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;The steps in labor are: contractions or water breaking (either can happen first), active labor (pushing) and delivery.&lt;/li&gt;&lt;li&gt;Labor takes time. Mothers may spend twelve to fourteen hours in labor, but it could easily be twice as much. First-time mothers usually take more time during delivery.&lt;/li&gt;&lt;li&gt;Active labor itself can take a few hours and is the most strenuous activity the mother will ever do in her life. Active labor is like doing twice your capacity of push-ups every five minutes.&lt;/li&gt;&lt;li&gt;Labor takes effort. A lot of effort. Don't expect parents to do anything during this time, even take your phone calls. In addition, don't expect them to do anything for at least four days after (for the father) and two weeks after (for the mother) as the fatigue of delivery takes time to wear off.&lt;/li&gt;&lt;li&gt;If the child was delivered through a C-section, double all recovery times. C-sections take a long time to heal, and the dad is fatigued from his supporting role during this time. &lt;/li&gt;&lt;li&gt;The only priority is the child. Parents are completely focused on delivering the baby. They have no time, let alone patience, for anything else. This is no time for telephone conversations, or status updates. Be patient. You'll know when labor is done.&lt;/li&gt;&lt;li&gt;How &lt;span style="color: blue;"&gt;you can help&lt;/span&gt;: spread the word, and ask others to hold off their calls to the parents. &lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;After Delivery&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Most hospitals keep mom and baby in a different room for a day or two. This is a critical time for mom to recover and learn about baby care from the nurses. Visiting mom and dad in the hospital room is usually a bad idea. There is no space in the hospital room, and mom and dad are constantly busy. In addition, the mom is weak and worn.&lt;/li&gt;&lt;li&gt;Mom has never been this tired. Labor drains the mother completely. Let her rest! You can speak with her later.&lt;/li&gt;&lt;li&gt;There's a lot to do. Post delivery, the child and mother have to be taken care of. There's food, bowel movements, health checks, doctor visits, ...&lt;/li&gt;&lt;li&gt;Limit infections. Just after delivery, both mom and baby are susceptible to infections. They will limit the number of people they meet. Give them a few weeks before visiting. if you have had a contagious disease like the flu, wait for many weeks of good health before visiting them. Be honest if you have any illness that can be spread.&lt;/li&gt;&lt;li&gt;Zero time. Mom and dad are focused on the child. They sleep when the child sleeps, and when the child is awake, they are completely busy with the child. If you do want to visit, be ready to help with the house during the visit. Your friend might ask you to help with the laundry or with the cooking or cleaning.&lt;/li&gt;&lt;li&gt;Prepare to hang up the phone anytime. When baby needs parents, they need to go right away. While talking with a new parent, I was once in the middle of a sentence, and my friend blurted, "Baby crying, got to go" and hung up. At the moment I thought it strange. Later I realized that it was an excellent idea rather than squirming on the phone.&lt;/li&gt;&lt;li&gt;Zero patience. New parents have absolutely no patience. Be as frank and honest about things. Luckily both mom and dad are happy with brutal honesty at this time. (Just not about mom's appearance.)&lt;/li&gt;&lt;li&gt;How &lt;span style="color: blue;"&gt;you can help&lt;/span&gt;: congratulate the parents on email, and plan social visits at their convenience, not yours. If you stay close, consider helping them with laundry, grocery shopping, dishes, cleaning and cooking.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Hopefully these steps have enlightened you on the new world of your friends. Your friends might seem self-centered, and eager for your help. But this is the time they need to focus on themselves, and they need your support.&lt;br /&gt;&lt;br /&gt;Rest assured that they will allow &lt;b&gt;you&lt;/b&gt; to prioritize correctly, and provide the same care for you when you have children.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-LffRJScoZg0/TofNdE2c1dI/AAAAAAAAASM/svMkwCMZXSY/s1600/baby.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-LffRJScoZg0/TofNdE2c1dI/AAAAAAAAASM/svMkwCMZXSY/s320/baby.jpg" width="277" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2775081297321439965?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2775081297321439965/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/10/what-to-do-when-friends-are-expecting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2775081297321439965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2775081297321439965'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/10/what-to-do-when-friends-are-expecting.html' title='What to do when friends are expecting: A guide for friends of new parents'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-LffRJScoZg0/TofNdE2c1dI/AAAAAAAAASM/svMkwCMZXSY/s72-c/baby.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3745504713109083628</id><published>2011-09-16T20:04:00.000-07:00</published><updated>2011-09-17T12:18:09.752-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Linux udev: two-factor USB token turned into a car ignition key</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We use two-factor authentication at work. The one-time token generator looks a lot like an automobile key. It is easy to modify Linux to make a silly car noise when the token generator is plugged in. It turns your lame one-time token into a cool ignition key for your laptop.&lt;br /&gt;&lt;br /&gt;Here is a video that shows what it looks like:&lt;br /&gt;&lt;iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/_Ce5KlHT82g?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;&lt;br /&gt;To do this for your device, create a shell script to make the sound of a car. I have created an audio file called car.mp3 containing the car sound. The shell script plays this file with  mplayer. Record the sound of your car, or grab a file from the internet.&lt;br /&gt;&lt;pre&gt;$ &lt;b&gt;cat /root/car.sh&lt;/b&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;# Play a silly car starting sound&lt;br /&gt;mplayer /root/car.mp3 &amp;amp;&lt;br /&gt;&lt;/pre&gt;Now you need obtain the vendor ID. Disconnect your token generator and run this command:&lt;br /&gt;&lt;pre&gt;$ &lt;b&gt;udevadm monitor&lt;/b&gt;&lt;br /&gt;&lt;/pre&gt;Now insert your device. You will see an output like this:&lt;br /&gt;&lt;pre&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1 (usb)&lt;br /&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0 (usb)&lt;br /&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/0003:&lt;span style="color: red;"&gt;1050&lt;/span&gt;:0010.0015 (hid)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1 (usb)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0 (usb)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/0003:&lt;span style="color: red;"&gt;1050&lt;/span&gt;:0010.0015 (hid)&lt;br /&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/input/input33 (input)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/0003:&lt;span style="color: red;"&gt;1050&lt;/span&gt;:0010.0015/hidraw/hidraw0 (hidraw)&lt;br /&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/input/input33/event13 (input)&lt;br /&gt;KERNEL[] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/0003:&lt;span style="color: red;"&gt;1050&lt;/span&gt;:0010.0015/hidraw/hidraw0 (hidraw)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/input/input33 (input)&lt;br /&gt;UDEV  [] add  /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/input/input33/event13 (input)&lt;br /&gt;&lt;/pre&gt;The part after the 0003: is your vendor ID. Of course, it will be different for you. Now create a udev rule to specify the action. This is what my rule looks like:&lt;br /&gt;&lt;pre&gt;$ &lt;b&gt;cat /etc/udev/rules.d/90-token.rules&lt;/b&gt;&lt;br /&gt;# Make a silly sound like the starting of a car&lt;br /&gt;SUBSYSTEM=="usb", ATTR{idVendor}=="1050", MODE="0664", GROUP="plugdev", RUN+="/root/car.sh"&lt;br /&gt;&lt;/pre&gt;That's it, you don't need to restart anything. If you have done it correctly, then the car sound will play every time you insert your key.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3745504713109083628?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3745504713109083628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/linux-udev-two-factor-usb-token-turned.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3745504713109083628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3745504713109083628'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/linux-udev-two-factor-usb-token-turned.html' title='Linux udev: two-factor USB token turned into a car ignition key'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/_Ce5KlHT82g/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-1439191692120633235</id><published>2011-09-13T02:00:00.000-07:00</published><updated>2011-09-13T07:02:45.600-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: Calling Assembly from Android (Part 8)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part eight in a series on learning ARM assembly on Android. This part covers calling Assembly code from Android applications.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Native Development Kit&lt;/span&gt;&lt;br /&gt;You've written some assembly code, made it run real fast, and now you want to include it in an Android application. What's the advantage of running little assembly programs that can't use the full feature set available to Android? You need  the Android Native Development Kit.&lt;br /&gt;&lt;br /&gt;Download the &lt;a href="http://developer.android.com/sdk/ndk/index.html"&gt;Native Development Kit from the Android development page&lt;/a&gt;. Follow the instructions on that page to install it. Installation is little more than unzipping the file in the correct directory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Sample Application&lt;/span&gt;&lt;br /&gt;My sample application has three parts. The first is the most familiar part: this is the assembly source. This is in an assembly source file called jni/multiple.s. This code computes 10y for a given value y.&lt;br /&gt;&lt;pre&gt;	@ &lt;span style="color: #2040a0;"&gt;This file is jni/multiple.s&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;&lt;/span&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;	&lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;:&lt;br /&gt;	@ &lt;span style="color: #2040a0;"&gt;Multiply by 10. Input value and return value in r0&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;,&lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;,&lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;add&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;,&lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;,&lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;br /&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;size&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;-&lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;The assembly code is called from a C stub. The C stub must have a very fixed name: Java_name_of_package_Class_function. This looks downright ugly but is required for Java to look up the correct function. I create a C stub to hold the strange name, and to accept the weird JNI arguments. You don't need to have a C stub, but it makes life easy.&lt;br /&gt;&lt;br /&gt;The type jint is a java int that you can treat as a 32 bit int value. Other types are jboolean, jbyte, jchar, jshort, jlong, jfloat, jdouble, and jobject. Notice the signature of the JNI function: it accepts the environment, which is a JNIEnv pointer, and an arbitrary object. Finally, we have the input value, which is an integer. In its implementation, we call our ARM assembly function on the input. The return value is a jint, which indicates that we are returning an integer.&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #444444;"&gt;/* This file is jni/hello-jni.c */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;#include &lt;span style="color: green;"&gt;&amp;lt;jni.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #444444;"&gt;/* This stub calls the function. It helps to have a stub like this to&lt;br /&gt; * save yourself the hassle of defining the function call in&lt;br /&gt; * Assembly. */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #2040a0;"&gt;jint&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;Java_com_eggwall_android_assembly_AssemblyActivity_factorialJNI&lt;/span&gt;(&lt;br /&gt;	&lt;span style="color: #2040a0;"&gt;JNIEnv&lt;/span&gt;* &lt;span style="color: #2040a0;"&gt;env&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;jobject&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;object&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;jint&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;input&lt;/span&gt;) &lt;b&gt;{&lt;/b&gt;&lt;br /&gt;	&lt;span style="color: #444444;"&gt;/* Try calling some local code */&lt;/span&gt;&lt;br /&gt;	&lt;b&gt;return&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;armFunction&lt;/span&gt;(&lt;span style="color: #2040a0;"&gt;input&lt;/span&gt;);&lt;br /&gt;&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;&lt;/pre&gt;Finally, there is a file that defines the sources in a Makefile. This is the jni/Android.mk file. It puts together the stub and the assembly code into a library called "hello-jni".&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #444444;"&gt;# This file is jni/Android.mk&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;LOCAL_PATH := $(call my-dir)&lt;br /&gt;&lt;b&gt;include &lt;/b&gt;$(CLEAR_VARS)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #444444;"&gt;# I want ARM, not thumb.&lt;/span&gt;&lt;br /&gt;LOCAL_ARM_MODE := arm&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #444444;"&gt;# Name of the local module&lt;/span&gt;&lt;br /&gt;LOCAL_MODULE    := hello-jni&lt;br /&gt;&lt;span style="color: #444444;"&gt;# The files that make up the source code&lt;/span&gt;&lt;br /&gt;LOCAL_SRC_FILES := hello-jni.c multiple.s&lt;br /&gt;&lt;br /&gt;&lt;b&gt;include &lt;/b&gt;$(BUILD_SHARED_LIBRARY)&lt;/pre&gt;&lt;br /&gt;The stub and the assembly input are compiled by calling the following command from the root directory of your project. This is the directory that contains jni/, src/, res/, ..etc. I am assuming the ndk is installed in /usr/local/android-sdk-linux_x86/android-ndk-r6b.&lt;br /&gt;&lt;pre&gt;$ &lt;b&gt;ls&lt;/b&gt;&lt;br /&gt;AndroidManifest.xml  assets/  bin/  build.properties  build.xml  default.properties&lt;br /&gt;gen/  jni/  libs/  local.properties  obj/  proguard.cfg  res/  src/&lt;br /&gt;$ &lt;b&gt;/usr/local/android-sdk-linux_x86/android-ndk-r6b/ndk-build&lt;/b&gt;&lt;br /&gt;Compile arm    : hello-jni &amp;lt;= multiple.s&lt;br /&gt;SharedLibrary  : libhello-jni.so&lt;br /&gt;Install        : libhello-jni.so =&amp;gt; libs/armeabi/libhello-jni.so&lt;/pre&gt;&lt;br /&gt;Finally, there is a Java source code to create the Activity in Android. This code creates an Android application. It extends Activity, and overrides the onCreate method. In this, it creates a TextView, which is a label, and then sets the contents of the label to the return value of the function. It defines a function called factorialJNI which accepts an integer input and returns an integer. It is marked as native, indicating that its implementation is not in Java.&lt;br /&gt;&lt;br /&gt;Finally, a static initialisation loads the jni library that was defined in the XML file.&lt;br /&gt;&lt;pre&gt;&lt;b&gt;package com.eggwall.android.assembly;&lt;/b&gt; &lt;br /&gt; &lt;br /&gt;&lt;b&gt;import android.app.Activity;&lt;/b&gt; &lt;br /&gt;&lt;b&gt;import android.widget.TextView;&lt;/b&gt; &lt;br /&gt;&lt;b&gt;import android.os.Bundle;&lt;/b&gt; &lt;br /&gt; &lt;br /&gt;&lt;b&gt;public&lt;/b&gt; &lt;b&gt;class&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;AssemblyActivity&lt;/span&gt; &lt;b&gt;extends&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;Activity&lt;/span&gt; &lt;b&gt;{&lt;/b&gt; &lt;br /&gt;	@&lt;span style="color: #2040a0;"&gt;Override&lt;/span&gt; &lt;br /&gt;	&lt;b&gt;public&lt;/b&gt; &lt;b&gt;void&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;onCreate&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: #2040a0;"&gt;Bundle&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;savedInstanceState&lt;/span&gt;&lt;b&gt;)&lt;/b&gt; &lt;b&gt;{&lt;/b&gt; &lt;br /&gt;		&lt;b&gt;super&lt;/b&gt;.&lt;span style="color: #2040a0;"&gt;onCreate&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: #2040a0;"&gt;savedInstanceState&lt;/span&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;		&lt;span style="color: #444444;"&gt;// Create a new Textview&lt;/span&gt; &lt;br /&gt;		&lt;span style="color: #2040a0;"&gt;TextView&lt;/span&gt;  &lt;span style="color: #2040a0;"&gt;tv&lt;/span&gt; = &lt;b&gt;new&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;TextView&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;b&gt;this&lt;/b&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;		&lt;span style="color: #444444;"&gt;// Print the multiple of 13 through assembly.&lt;/span&gt; &lt;br /&gt;		&lt;span style="color: #2040a0;"&gt;tv&lt;/span&gt;.&lt;span style="color: #2040a0;"&gt;setText&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: green;"&gt;"The multiple was: "&lt;/span&gt; + &lt;span style="color: #2040a0;"&gt;factorialJNI&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: red;"&gt;13&lt;/span&gt;&lt;b&gt;)&lt;/b&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;		&lt;span style="color: #2040a0;"&gt;setContentView&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: #2040a0;"&gt;tv&lt;/span&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;	&lt;b&gt;}&lt;/b&gt; &lt;br /&gt;	&lt;span style="color: #444444;"&gt;&lt;i&gt;/**&lt;br /&gt;	 * Multiply the number by 10.&lt;br /&gt;	 * @param input, the number to be multiplied&lt;br /&gt;	 * @return the multiple of the number&lt;br /&gt;	 */&lt;/i&gt;&lt;/span&gt; &lt;br /&gt;	&lt;b&gt;public&lt;/b&gt; &lt;b&gt;native&lt;/b&gt; &lt;b&gt;int&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;factorialJNI&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;b&gt;int&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;input&lt;/span&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;	&lt;span style="color: #444444;"&gt;/* This is used to load the 'hello-jni' library on application&lt;br /&gt;	 * startup. The library has already been unpacked into&lt;br /&gt;	 * /data/data/com.eggwall.android.AssemblyActivity/lib/libhello-jni.so at&lt;br /&gt;	 * installation time by the package manager.&lt;br /&gt;	 */&lt;/span&gt; &lt;br /&gt;	&lt;b&gt;static&lt;/b&gt; &lt;b&gt;{&lt;/b&gt; &lt;br /&gt;		&lt;span style="color: #2040a0;"&gt;System&lt;/span&gt;.&lt;span style="color: #2040a0;"&gt;loadLibrary&lt;/span&gt;&lt;b&gt;(&lt;/b&gt;&lt;span style="color: green;"&gt;"hello-jni"&lt;/span&gt;&lt;b&gt;)&lt;/b&gt;; &lt;br /&gt;	&lt;b&gt;}&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;&lt;b&gt;}&lt;/b&gt; &lt;br /&gt;&lt;/pre&gt;That is a lot of code to run a single assembly function! But now that you've seen the overall structure, you can begin modifying it to run your own assembly code. This is not a good way to experiment with assembly programming, though. Assembly programs can be hard to debug and it helps to have good tools during development. I would recommend developing using emacs, gcc, gdb, and other GNU tools, just as before. When the code is working correctly, hook it into Android Java source. The Android NDK has some useful debugging facilities, but I would consider them options of last resort.&lt;br /&gt;You can download the &lt;a href="http://vikram.eggwall.com/static/assembly-jni.tar.gz"&gt;entire ARM Android assembly example as an Eclipse project here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Speed versus Complexity&lt;/span&gt;&lt;br /&gt;Just because you are calling assembly code does not automatically make your program faster. The Dalvik virtual machine runs most code fairly fast, and the effort to develop assembly code is not worth the minor improvement in code execution speed. Here are some reasons why you might want to use native code. &lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Legacy code. You have a lot of existing code that you want to plug into Android.&lt;/li&gt;&lt;li&gt;Optimised code. You have CPU-intensive code that has been carefully optimised.&lt;/li&gt;&lt;/ol&gt;Assembly code takes a longer to develop, more effort to maintain, and is difficult to port. There are few people who can read assembly code, so your code will be out of reach of many programmers.&lt;br /&gt;&lt;br /&gt;A careful consideration of implementation speed and code complexity will lead you to the correct balance.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;/ol&gt;&lt;span style="font-size: large;"&gt;Things to try out&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Create a new function called factorial(int a) and its corresponding stub. Call it from Java.&lt;/li&gt;&lt;li&gt;Create a new source file called factorial.s, and put the function in there. Modify jni/Android.mk to run it correctly.&lt;/li&gt;&lt;li&gt;Try adding an input area, where a number is entered. Pass this number to the assembly source code, and print out its factorial. &lt;/li&gt;&lt;/ol&gt;My example builds upon the hello-jni example that ships with the NDK. You can read &lt;a href="http://developer.android.com/sdk/ndk/overview.html#samples"&gt;the other NDK samples for inspiration&lt;/a&gt;. You can learn more by reading the &lt;a href="http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html"&gt;JNI reference&lt;/a&gt;. It covers the data types, and the various functions available from native code.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-1439191692120633235?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/1439191692120633235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1439191692120633235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1439191692120633235'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html' title='Android ARM Assembly: Calling Assembly from Android (Part 8)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s72-c/android.png' height='72' width='72'/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3111073994605008746</id><published>2011-09-12T02:00:00.000-07:00</published><updated>2011-09-13T06:25:46.265-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: Conditional execution (Part 7)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part seven in a series on learning ARM assembly on Android. This part covers conditional execution.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Compare and Jump&lt;/span&gt;&lt;br /&gt;The previous lessons touched on a variety of microprocessor instructions. Let's move to conditional execution. These are the basis of all the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;if, while, for&lt;/span&gt; loops in programming languages.&lt;br /&gt;&lt;br /&gt;Conditions are implemented in microprocessors using the Status Register CPSR. The various bits on the status register are set using instructions. Then, you can jump to a different position in the code if the specific bit is set or unset. While this scheme looks primitive, it forms the basis of all conditional execution in every language on computers. Let's see the status register again.&lt;br /&gt;&lt;br /&gt;The conditions in the status register are:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Negative: the result was negative (bit 31 of the result was set)&lt;/li&gt;&lt;li&gt;Zero: the result was zero (all bits of the result were unset)&lt;/li&gt;&lt;li&gt;Carry:  integer addition, subtraction or shifts produce a carry or borrow (result bits could be anything)&lt;/li&gt;&lt;li&gt;oVerflow: there was carry or borrow during signed addition or subtraction (result bits could be anything)&lt;/li&gt;&lt;/ol&gt;The status register has other bits relating to the different processor modes, but we can ignore them for now. The bits in the CPSR are set on four instructions: CMP, CMN, TEQ, TST. Let's see these instructions.&lt;br /&gt;&lt;br /&gt;CMP &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This performs &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; - &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;, throws away the result and updates the status register. So doing a CMP R2, R2 would produce a zero output, and the Zero condition would be set. It is important to note that the result is never stored anywhere. From your perspective, you are asking the processor what the result would be like.&lt;br /&gt;&lt;br /&gt;This is a full list of the comparison instructions.&lt;br /&gt;&lt;br /&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Instruction&lt;/th&gt;&lt;th&gt;Rough Intention&lt;/th&gt;&lt;th&gt;The condition flags are set based on this value&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CMP &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;td&gt;(Addition)&lt;/td&gt;&lt;td&gt;&lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; - &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CMN &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;td&gt;(Negation)&lt;/td&gt;&lt;td&gt;&lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; + &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;TST &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;td&gt;(Test)&lt;/td&gt;&lt;td&gt;&lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; &amp;amp; &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;TEQ &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;td&gt;(Test Equivalence)&lt;/td&gt;&lt;td&gt;&lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; ^ &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Once the condition is set, you can use that condition to jump to a specific label. The easiest jump instruction doesn't care for flags. We saw it in &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;part 5&lt;/a&gt;, where it was used to return execution back from our function.&lt;br /&gt;&lt;pre&gt;        &lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;/pre&gt;This instruction branched execution to the address contained in the Link Register. This could be done with any register, though you better be sure that the register contains a valid address. It also needs to be a 32-bit aligned address. All ARM instructions are 32-bit (word) aligned. This isn't Intel, every instruction is exactly 32 bits long. BX is a Branch, while BL is a Branch and Link.&lt;br /&gt;&lt;br /&gt;Branch just jumps to the address specified in the register.&lt;br /&gt;&lt;br /&gt;Branch and Link stores the address of the existing Program Counter in the Link Register, in case you want to jump back. This is something you do all the time, so there is one instruction to handle it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;ARM and Thumb Instructions&lt;/span&gt;&lt;br /&gt;Most new ARM processors support two different instruction sets: ARM and Thumb. Thumb instructions are a subset of ARM instructions and are 16 bits each. Going back and forth between ARM and Thumb is possible, though it should be done correctly. The branch instructions ending in "X" do this. A "BX" instruction allows you to switch between ARM and Thumb while the "B" instruction doesn't. In general, you should use "BX" and "BLX" when you are unsure of the resulting code. If you are certain, you can use "B" for branch, and "BL" for branch and link.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Condition Codes &lt;/span&gt;&lt;br /&gt;How about adding the actual condition? The condition goes as a suffix to the instruction. Say you only want to check if the Zero condition was true. Then, the condition is called EQual, with mnemonic EQ. So this operation only branches when the zero condition is set:&lt;br /&gt;BLEQ lr&lt;br /&gt;&lt;br /&gt;The full list of conditions is:&lt;br /&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Suffix&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;th&gt;Condition tested&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;EQ&lt;/td&gt;&lt;td&gt;Equal&lt;/td&gt;&lt;td&gt;Z == 1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;NE&lt;/td&gt;&lt;td&gt;Not Equal&lt;/td&gt;&lt;td&gt;Z == 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CS or HS&lt;/td&gt;&lt;td&gt;Unsigned Higher or Same (Carry Set)&lt;/td&gt;&lt;td&gt;C == 1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CC or LO&lt;/td&gt;&lt;td&gt;Unsigned Lower (Carry Clear)&lt;/td&gt;&lt;td&gt;C == 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MI&lt;/td&gt;&lt;td&gt;MInus&lt;/td&gt;&lt;td&gt;N == 1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PL&lt;/td&gt;&lt;td&gt;PLus or Zero&lt;/td&gt;&lt;td&gt;N == 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;VS&lt;/td&gt;&lt;td&gt;Overflow (V Set)&lt;/td&gt;&lt;td&gt;V == 1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;VC&lt;/td&gt;&lt;td&gt;No Overflow (V Clear)&lt;/td&gt;&lt;td&gt;V == 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;HI&lt;/td&gt;&lt;td&gt;Unsigned Higher&lt;/td&gt;&lt;td&gt;C == 1 and Z == 0&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LS&lt;/td&gt;&lt;td&gt;Unsigned Lower or Same&lt;/td&gt;&lt;td&gt;C == 0 or Z == 1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;GE&lt;/td&gt;&lt;td&gt;Signed Greater Than or Equal&lt;/td&gt;&lt;td&gt;N == V&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LT&lt;/td&gt;&lt;td&gt;Signed Lesser Than &lt;/td&gt;&lt;td&gt;N != V&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;GT&lt;/td&gt;&lt;td&gt;Signed Greater Than &lt;/td&gt;&lt;td&gt;Z == 0 and N == V&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LE&lt;/td&gt;&lt;td&gt;Signed Less Than or Equal To&lt;/td&gt;&lt;td&gt;Z==1 or N != V&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;AL&lt;/td&gt;&lt;td&gt;Always&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;So you could have an instruction BXNE r3, which will branch to r3, only if the previous comparison did not set the Zero condition code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Conditional Execution&lt;/span&gt;&lt;br /&gt;Let's look at a single if-then loop to see how to run a simple conditional in Assembly. &lt;br /&gt;&lt;pre&gt; 1         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;section&lt;/span&gt;        &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;data&lt;/span&gt;&lt;br /&gt; 2         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt; &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt; 3 &lt;span style="color: #2040a0;"&gt;higher&lt;/span&gt;:&lt;br /&gt; 4         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;asciz&lt;/span&gt; &lt;span style="color: green;"&gt;"Yes, r2 is higher than or equal to r1\n"&lt;/span&gt;&lt;br /&gt; 5 &lt;span style="color: #2040a0;"&gt;lower&lt;/span&gt;:&lt;br /&gt; 6         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;asciz&lt;/span&gt; &lt;span style="color: green;"&gt;"No, r2 is lower than r1\n"&lt;/span&gt;&lt;br /&gt; 7 &lt;br /&gt; 8         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt; 9         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;  &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;10         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;br /&gt;11         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;   &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt;12 &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;:&lt;br /&gt;13         &lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;14 &lt;br /&gt;15         @ &lt;span style="color: #2040a0;"&gt;Load&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;some&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;values&lt;/span&gt;&lt;br /&gt;16         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;, #&lt;span style="color: red;"&gt;32&lt;/span&gt;&lt;br /&gt;17         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r2&lt;/span&gt;, #&lt;span style="color: red;"&gt;33&lt;/span&gt;&lt;br /&gt;18 &lt;br /&gt;19         @ &lt;span style="color: #2040a0;"&gt;Check&lt;/span&gt; if &lt;span style="color: #2040a0;"&gt;r2&lt;/span&gt; is &lt;span style="color: #2040a0;"&gt;lower&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;than&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;&lt;br /&gt;20         &lt;span style="color: #2040a0;"&gt;cmp&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r2&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;&lt;br /&gt;21 &lt;br /&gt;22         @ If &lt;span style="color: #2040a0;"&gt;it&lt;/span&gt; is &lt;span style="color: #2040a0;"&gt;greater&lt;/span&gt; or &lt;span style="color: #2040a0;"&gt;equal&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;jump&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;ahead&lt;/span&gt;&lt;br /&gt;23         &lt;span style="color: #2040a0;"&gt;bge&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;greaterOrEqual&lt;/span&gt;&lt;br /&gt;24 &lt;br /&gt;25         @ &lt;span style="color: #2040a0;"&gt;Otherwise&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;it&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;was&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;lower&lt;/span&gt;&lt;br /&gt;26         &lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, =&lt;span style="color: #2040a0;"&gt;lower&lt;/span&gt;&lt;br /&gt;27         @ &lt;span style="color: #2040a0;"&gt;Now&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;skip&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;past&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;to&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;the&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;common&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;point&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;again&lt;/span&gt;&lt;br /&gt;28         &lt;span style="color: #2040a0;"&gt;b&lt;/span&gt;       &lt;span style="color: #2040a0;"&gt;common&lt;/span&gt;&lt;br /&gt;29 &lt;br /&gt;30 &lt;span style="color: #2040a0;"&gt;greaterOrEqual&lt;/span&gt;:&lt;br /&gt;31         &lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, =&lt;span style="color: #2040a0;"&gt;higher&lt;/span&gt;&lt;br /&gt;32 &lt;br /&gt;33 &lt;span style="color: #2040a0;"&gt;common&lt;/span&gt;:&lt;br /&gt;34         @ &lt;span style="color: #2040a0;"&gt;Print&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;the&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;message&lt;/span&gt;&lt;br /&gt;35         &lt;span style="color: #2040a0;"&gt;bl&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;puts&lt;/span&gt;&lt;br /&gt;36 &lt;br /&gt;37         @ Return &lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;38         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, #&lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;39         &lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;40         &lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This program loads values in r2 and r3 and then compares the two. If (r2-r1) is greater than or equal to 0, then we skip to the greaterOrEqual label. Since there are only one kind of instructions (ARM instructions), we don't bother with the "X" variant of the branch. At the greaterOrEqual label, we move the string corresponding to the higher message. Otherwise, we move the string corresponding to the lower message into r0. Either case, we want to get to the common code, which prints the message, and returns 0. If we didn't return to the common case, it would continue running instructions linearly, and load r0 with the higher message. Then, we return 0, like every well behaved main() function should.&lt;br /&gt;&lt;br /&gt;The Program Counter holds the address that will be executed next. Since it is also r15, you can directly modify it. This is a terrible idea in most cases, so you should have a good reason to do this. In theory, you could implement logic by conditionally moving values into the Program Counter. For example, you could add 8 to the current value in the PC to skip an instruction. In practice, you will not do this because it is prone to errors. Such logic fails when the program is modified, and the address of instructions changes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Every Instruction is Conditional&lt;/span&gt;&lt;br /&gt;Now that you know what conditional execution looks like, you are ready for a real twist. In ARM architectures, every instruction is conditional. So the ADD, SUB, LDR, STR instructions can all have these condition codes appended to them. We could write instructions containing very few BX or BLX calls.&lt;br /&gt;&lt;br /&gt;In practice, however, you should use conditional operations only for a single instruction or two. If you find that a lot of operations act on the same condition, you should branch and skip all these operations. This is much more efficient, since ARM processors fetch more than one instruction and act upon parts of it in parallel. If you can start to execute the next few instructions, your code is considerably faster. So as a rule, use conditional operations only for two instructions or fewer. If you have a longer list of conditional operations that depend on the same condition, pull them out in a separate routine.&lt;br /&gt;&lt;br /&gt;In addition to every instruction being conditional, every instruction can set the CPSR flags. For this, you need to append the "S" flag (for Status) to every instruction. Here is what a MOV instruction really looks like:&lt;br /&gt;MOV{&lt;span style="color: blue;"&gt;condition_code&lt;/span&gt;}{S} &lt;span style="color: #741b47;"&gt;Rd&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;br /&gt;This allows you to set the status flag without performing a CMP, saving another instruction. The status flag can be set on most operations you have seen till now. So you can automatically set the condition codes when performing arithmetic operations.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Exercises&lt;/span&gt;&lt;br /&gt;Try your hand at these to see if you understand branches.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;What does the MOVGE r0, r2 instruction do?&lt;/li&gt;&lt;li&gt;Rewrite the program to use just one branch rather than two.&lt;/li&gt;&lt;li&gt;Rewrite the program using conditional move to avoid a branch. In this case, a conditional move is perhaps cleaner since the condition only changes one instruction.&lt;/li&gt;&lt;li&gt;Write a function isZero(n) to accept an unsigned number n and to return 1 if n is equal to 0 and n otherwise.&lt;/li&gt;&lt;li&gt;Improve on isZero() to write almostFactorial(n) which returns n*(n-1) if n is not zero, and 1 otherwise.&lt;/li&gt;&lt;li&gt;Try your hand at turning almostFactorial(n) to factorial(n) which returns n! for small values of n. As n gets large, you run out of bits, so you will need to test your function with small inputs.&lt;/li&gt;&lt;li&gt;Write a simple while { .. } loop in C and let GCC compile it to assembly. See if you can make sense of the code. GCC can compile code with optimisations turned on with the "-O2" flag. Try to read the assembly output with and without optimisations. See if you can figure out the optimisation logic.&lt;/li&gt;&lt;/ol&gt;This marks the end of all the functional pieces of ARM architecture. You should be able to read the disassembly of nearly any ARM program now. Isn't that impressive? Look up unknown instructions in the reference manual. As always, the &lt;a href="http://vikram.eggwall.com/static/ARM-ARM.pdf"&gt;ARM Reference Manual&lt;/a&gt; has more information on all condition codes, conditional execution and instructions that accept conditions and can set the flags.&lt;br /&gt;&lt;br /&gt;The final piece will be to integrate this with Android. We will see how to call assembly code from Android to be able to run fast processing directly in assembly.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3111073994605008746?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3111073994605008746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3111073994605008746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3111073994605008746'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html' title='Android ARM Assembly: Conditional execution (Part 7)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s72-c/android.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2163777734987224783</id><published>2011-09-11T15:11:00.000-07:00</published><updated>2011-09-11T19:37:16.301-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Book Review: The Big Necessity by Rose George</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Would you be worried if a Boeing 747 worth of people died? What if it were all children. How about 10 Boeing 747s of children dying, everyday?&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Diarrhea"&gt;Diarrhea&lt;/a&gt; causes 1.5 million deaths in children every year. That's roughly ten 747s worth every single day. And diarrhea is simple to cure. Good sanitation removes the occurrence of the disease. The reason why so many children still die of diarrhea is because of poor sanitation. Most deaths are in third-world countries, and the West is largely unaware of the problem because it is embarrassing to talk about poop.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://rosegeorge.com/site/books/the-big-necessity"&gt;Rose George's book, "The Big Necessity"&lt;/a&gt; talks about various aspects of poop in her book: from the science of waste water treatment, to the design of eco-friendly toilets and the problems of third-world sanitation. It is a delightful read which brings our awareness to many poop-related issues.&lt;br /&gt;&lt;br /&gt;We don't really talk about poop, even though many of our swear-words include fecal matter. And that's largely the problem. We can solve problems of nutrition because we can casually talk about African children only eating 400 calories a day. What we cannot do is talk about the fecal matter that is contaminating their food. So we can talk about to 400 calories they are eating, but not about the crap they are eating with it.&lt;br /&gt;&lt;br /&gt;Sanitation brings immense benefits. Children living in areas with good sanitation fall ill less, and are more likely to go to school. Girls' education is directly related to good sanitation. Yet, we're too civilised to talk about improving sanitation.&lt;br /&gt;&lt;br /&gt;The book is an insightful read. I would highly recommend it to anyone who has witnessed poverty and wondered what can be done to improve health of the poor. It talks about open defecation in India, the general lack of sanitation in India, and glimmers of hope from rural China. Each chapter deals with a single aspect of sanitation. You will learn about how waste water is treated in the West, and why it is a poor design. You will learn about the difficulties in marketing toilets to the poor. It should be an easy sell, but there are reasons why it is hard, and the book talks about creative solutions. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-E_aQQ1tIZgA/TmuOeACn8xI/AAAAAAAAASE/X1Cs88Na0fI/s1600/necessity_large.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-E_aQQ1tIZgA/TmuOeACn8xI/AAAAAAAAASE/X1Cs88Na0fI/s320/necessity_large.gif" width="187" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2163777734987224783?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2163777734987224783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/book-review-big-necessity-by-rose.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2163777734987224783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2163777734987224783'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/book-review-big-necessity-by-rose.html' title='Book Review: The Big Necessity by Rose George'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-E_aQQ1tIZgA/TmuOeACn8xI/AAAAAAAAASE/X1Cs88Na0fI/s72-c/necessity_large.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2115694351270171706</id><published>2011-09-10T08:03:00.000-07:00</published><updated>2011-09-13T06:26:03.237-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: Arithmetic and Logical Operations (Part 6)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part six in a series on learning ARM assembly on Android. This part covers arithmetic and logic expressions.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;We covered a lot of data moving in the previous articles. Let's see what processing we can do.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Arithmetic&lt;/span&gt;&lt;br /&gt;The ARM processors are packed with the usual arithmetic operators. If you have experience with some other processor, you might find the possible operations somewhat limited. This follows the Reduced Instruction Set principles: there are a few basic primitives and you are required to produce everything using these. So you lack complex instructions, but make up for it with faster code. More importantly, you make up for it with code that runs quiet, cool, and uses minimal battery life.&lt;br /&gt;&lt;br /&gt;All arithmetic instructions look identical. Remember the MOV instructions?&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;An immediate value. Ex. &lt;pre&gt;&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;,&lt;span style="color: #2040a0;"&gt; &lt;/span&gt;#&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;A register. Ex: &lt;pre&gt;&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;&lt;span style="color: red;"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;A register with an offset. Ex: &lt;pre&gt;&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, &lt;/span&gt;#&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;A register with a shift. Ex: &lt;pre&gt;&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, lsr &lt;/span&gt;#&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;A register with a register specifying the shift. Ex: &lt;pre&gt;&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, lsr r2&lt;/span&gt;&lt;span style="color: red;"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;The first part is called the destination register, since that's where the value is placed. The second part is called the shifter_operand, as a short-hand for one of many possibilities. In other words, MOV instructions have this structure:&lt;br /&gt;MOV &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;. This causes: Rd = shifter_operand&lt;br /&gt;&lt;br /&gt;Arithmetic instructions follow the same structure. Instead of having one register, they have two registers. This is the general structure of arithmetic instructions:&lt;br /&gt;OPERATION &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;, &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;, &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;OPERATION can be one of:&lt;br /&gt;&lt;table border="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;ADD &lt;/td&gt;&lt;td&gt;(Addition)&lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; + &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SUB: &lt;/td&gt;&lt;td&gt;(Subtraction) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; - &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RSB: &lt;/td&gt;&lt;td&gt;(Reverse Subtraction) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt; - &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ADC: &lt;/td&gt;&lt;td&gt;(Add with Carry) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; + &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt; + Carry&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SBC: &lt;/td&gt;&lt;td&gt;(Subtract with Carry) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; - &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt; - Carry&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RSC: &lt;/td&gt;&lt;td&gt;(Reverse Subtract with Carry) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt; - &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; - Carry&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;AND: &lt;/td&gt;&lt;td&gt;(Logical And) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; &amp;amp; &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;BIC: &lt;/td&gt;&lt;td&gt;(Logical Bit Clear)&lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; &amp;amp; ! &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ORR: &lt;/td&gt;&lt;td&gt;(Logical Or) &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; | &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;EOR: &lt;/td&gt;&lt;td&gt;(Logical Exclusive Or)&lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; = &lt;span style="color: #741b47;"&gt;Rn&lt;/span&gt; ^ &lt;span style="color: #274e13;"&gt;shifter_operand&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;The instructions are regular and follow the same pattern. The only unexplained thing is the Carry.&lt;br /&gt;&lt;br /&gt;Carry is a bit in the status register CPSR that is set when an addition overflows past 32 bits. This could happen when adding 1 to 0xff ff ff ff. The resulting number is 1 &amp;lt;&amp;lt; 32, which cannot be represented in 32 bits. It needs 33 bits. In such a case, the carry bit will be set. Addition with carry allows you to automatically add the carry bit.&lt;br /&gt;&lt;br /&gt;The carry bit is also set when subtraction produces underflow: If you subtract INT_MAX from 0, the resulting number cannot be expressed in 2's complement because it needs to borrow a bit. In such a case, the carry is set again.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Multiply&lt;/span&gt;&lt;br /&gt;Multiplications only take a register argument. They don't take a shifter_operand.&lt;br /&gt;&lt;br /&gt;&lt;table border="1" cellpadding="2" cellspacing="0"&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;MLA 	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;, Rn		&lt;/td&gt;&lt;td&gt;Multiply with Accummulate &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; =  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt; + Rn	&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;MUL	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;		&lt;/td&gt;&lt;td&gt;Multiply &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt; =  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;		&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SMLAL	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32, &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;td&gt;Signed Multiply with Accummulate Long&lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32 +=  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SMULL	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32, &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;td&gt;Signed Multiply Long &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32 =  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;UMLAL	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32, &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;td&gt;Unsigned Multiply with Accummulate Long &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32 +=  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;UMULL	&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32, &lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt;,  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;td&gt;Unsigned Multiply Long &lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;64,&lt;span style="color: blue;"&gt;Rd&lt;/span&gt;32 =  &lt;span style="color: #741b47;"&gt;Rm&lt;/span&gt; *  &lt;span style="color: #741b47;"&gt;Rs&lt;/span&gt;	&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;MLA and MUL are easy to understand. The difference between Signed and Unsigned instructions is that signed instructions use bit 31 as a sign bit, and &lt;a href="http://en.wikipedia.org/wiki/Two%27s_complement"&gt;2's complement arithmetic&lt;/a&gt;. If you know you have unsigned numbers, using the unsigned variants allows you to express higher numbers.&lt;br /&gt;&lt;br /&gt;The Long version of the instructions stores the lower 32 bits of the result in Rd32 and the higher bits in Rd64. MLA and MUL store only the lower 32 bits of the result, so if you multiply two very large numbers, you will get incorrect results.&lt;br /&gt;&lt;br /&gt;A multiply is slower than using the barrel shifter. If you need to multiply by 4, you are much better off supplying "lsl #2".&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Links&lt;/span&gt;&lt;br /&gt;Arithmetic and logical instructions are very easy in ARM processors. I have covered the instructions available in v5 of ARM processors. These instructions are guaranteed to be available nearly everywhere. v6 adds a few instructions, but the regular structure means that once you understand the v5 set, you can immediately learn the v6 additions.&lt;br /&gt;&lt;br /&gt;You can try the following to test your knowledge till now:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Write a function to input an integer y and return y * (y-1). Check by calling it inside main() and using the &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;program from Part 5&lt;/a&gt; to print the value.&lt;/li&gt;&lt;li&gt;Test out the behaviour of BIC using a program and different inputs. Why is it called Bit Clear?&lt;/li&gt;&lt;/ol&gt;As before, the &lt;a href="http://vikram.eggwall.com/static/ARM-ARM.pdf"&gt;ARM Reference Manual&lt;/a&gt; has more information on all operations.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s1600/android.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2115694351270171706?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2115694351270171706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2115694351270171706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2115694351270171706'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html' title='Android ARM Assembly: Arithmetic and Logical Operations (Part 6)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-XObWfE7l-lw/TmmjThC5gGI/AAAAAAAAASA/oJAY1ngsdpc/s72-c/android.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2793428900736304582</id><published>2011-09-09T04:00:00.000-07:00</published><updated>2011-09-19T09:54:53.730-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: Stack and Functions (Part 5)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part five in a series on learning ARM assembly on Android. This part covers  the stack and function calling.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Stack&lt;/span&gt;&lt;br /&gt;The stack is a linear data structure in memory that holds function-specific information. When a function call is made, the stack is grown, and we place local variables on the stack. When a function  returns, we shrink the stack, and the local variables are lost.  The stack is a temporary structure. For permanent non-constant variables, we need to allocate space on the heap. The heap is an operating system (OS) concept that we'll cover later. It is an OS concept because the processor is unaware of its presence. It is a programming paradigm rather than a facility provided by the silicon on the chip. The stack, on the other hand, is a processor-level concept. Life is a lot simpler if the processor  supports stack primitives.&lt;br /&gt;&lt;br /&gt;The stack grows up: to allocate space on the stack, you subtract multiples of 4 from the Stack Pointer. If you need 5 variables, you need to subtract 20 from the Stack Pointer. (In many documents, the memory is laid out from highest address to the lowest address. In such documents, the stack is said to grow downwards. Unfortunately, this is a standard convention even though humans think of stacks growing upward, so I explain everything with the stack growing upward.)&lt;br /&gt;&lt;br /&gt;If you write memory as a linear list of addresses, you can see why this makes sense. Here is the memory laid out from top to bottom as a linear list going from the lowest address to the highest address. All addresses and data are in hexadecimal.&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Data&lt;/th&gt;&lt;th&gt;Location&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ab&lt;/td&gt;&lt;td&gt;0000&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;cd&lt;/td&gt;&lt;td&gt;0004&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;de&lt;/td&gt;&lt;td&gt;0008&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f0&lt;/td&gt;&lt;td&gt;0080&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f0&lt;/td&gt;&lt;td&gt;0084 &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f2&lt;/td&gt;&lt;td&gt;0088&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f3&lt;/td&gt;&lt;td&gt;008c &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f4&lt;/td&gt;&lt;td&gt;0090 &amp;lt;- SP &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ff&lt;/td&gt;&lt;td&gt;ffff&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;The Stack Pointer is pointing at location 90, which means that it contains the value 0x90. The value at the top of the stack is f4, and this is the contents of memory location 0x90.&lt;br /&gt;&lt;br /&gt;If we want to allocate two variables, we need to subtract 4 * 2 = 8 from the stack pointer. Say we store values 99 and AA at these locations, then the stack looks like this:&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Data&lt;/th&gt;&lt;th&gt;Location&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ab&lt;/td&gt;&lt;td&gt;0000&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;cd&lt;/td&gt;&lt;td&gt;0004&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;de&lt;/td&gt;&lt;td&gt;0008&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f0&lt;/td&gt;&lt;td&gt;0080&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f0&lt;/td&gt;&lt;td&gt;0084 &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;99&lt;/td&gt;&lt;td&gt;0088 &amp;lt;- SP &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;AA&lt;/td&gt;&lt;td&gt;008c &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;f4&lt;/td&gt;&lt;td&gt;0090&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ff&lt;/td&gt;&lt;td&gt;ffff&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;We ended up clobbering the existing values at those locations. To deallocate space from the stack, you add to the SP. Every allocation on the stack should be matched by a de-allocation. Otherwise you get out of sync, and read the wrong value. Functions start out by storing all the local registers on the stack. Then, on top of the stack, they allocate function-specific data.&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Data&lt;/th&gt;&lt;th&gt;Location&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ab&lt;/td&gt;&lt;td&gt;0000&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;cd&lt;/td&gt;&lt;td&gt;0004&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;de&lt;/td&gt;&lt;td&gt;0008&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;current function's stack&lt;/td&gt;&lt;td&gt;0080 &amp;lt;- SP&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SP&lt;/td&gt;&lt;td&gt;0084 &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;LR&lt;/td&gt;&lt;td&gt;0088 &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;PC&lt;/td&gt;&lt;td&gt;008c &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;previous function's stack&lt;/td&gt;&lt;td&gt;0090&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;xx&lt;/td&gt;&lt;td&gt;...&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ff&lt;/td&gt;&lt;td&gt;ffff&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As a result, the new function has space to grow, and when it returns, the previous variable values are moved from the stack to the registers. From the perspective of the calling function, nothing has changed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Writing Functions&lt;/span&gt; &lt;br /&gt;Let's look at a program to see how variables are stored on the stack. I'll use a long program, because we need a main function and another function that we can change to our liking. The main() function has a fixed signature, so we need something different.&lt;br /&gt;&lt;pre&gt; 1         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt; 2         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;  &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt; 3         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;&lt;br /&gt; 4         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;   &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt; 5 &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;:&lt;br /&gt; 6         &lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt; 7         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;br /&gt; 8         &lt;span style="color: #2040a0;"&gt;add&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 9         &lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;10         &lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;br /&gt;11         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;size&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;-&lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;&lt;br /&gt;12 &lt;br /&gt;13         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;section&lt;/span&gt;        &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;rodata&lt;/span&gt;&lt;br /&gt;14         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;  &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;15 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;LC0&lt;/span&gt;:&lt;br /&gt;16         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;ascii&lt;/span&gt;  &lt;span style="color: green;"&gt;"The number is %d\012\000"&lt;/span&gt;&lt;br /&gt;17 &lt;br /&gt;18         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt;19         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;  &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;20         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;br /&gt;21         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;   &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt;22 &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;:&lt;br /&gt;23         &lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;24 &lt;br /&gt;25         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, #&lt;span style="color: red;"&gt;32&lt;/span&gt;&lt;br /&gt;26         &lt;span style="color: #2040a0;"&gt;bl&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;&lt;br /&gt;27 &lt;br /&gt;28         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;&lt;br /&gt;29         &lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L3&lt;/span&gt;&lt;br /&gt;30         &lt;span style="color: #2040a0;"&gt;bl&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;printf&lt;/span&gt;&lt;br /&gt;31 &lt;br /&gt;32         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, #&lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;33         &lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;34         &lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;br /&gt;35 &lt;br /&gt;36         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;  &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;37 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L3&lt;/span&gt;:&lt;br /&gt;38         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;word&lt;/span&gt;   &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;LC0&lt;/span&gt;&lt;br /&gt;39         &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;size&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;-&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;/pre&gt;The program is long, but you should be able to understand most of it by now.&lt;br /&gt;This is the function we made:&lt;br /&gt;&lt;pre&gt; 5 &lt;span style="color: #2040a0;"&gt;multiplyByTen&lt;/span&gt;:&lt;br /&gt; 6         &lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt; 7         &lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;br /&gt; 8         &lt;span style="color: #2040a0;"&gt;add&lt;/span&gt;     &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;asl&lt;/span&gt; #&lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 9         &lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;10         &lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;      &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;/pre&gt;This function returns the input multiplied by 10 through its creative uses of shifts. Multiplying y by 10 is the same as (y &amp;lt;&amp;lt; 3 + y &amp;lt;&amp;lt; 1) = (8y + 2y). The function is made to illustrate how function calling works. The first four inputs to a function are kept in r0-r3. Here we have just one input, so it is in r0. Line 7 moves 8*r0 to r3, and line 8 adds 2*r0 to this, and stores it back in r0. The return value of the function is kept in r0. However, we also have line 6 and line 9. What are they doing?&lt;br /&gt;&lt;pre&gt; 6         &lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;/pre&gt;This is a multi-register move operation. This moves the registers FP,IP,LR into the area specified by the register SP. Since SP is the stack pointer, this is the same as pushing registers FP,IP,LR to the top of the stack in a single operation. FP is another name for r11. Once this is done, the stack pointer is updated since it has an exclamation mark. The order of specifying the registers doesn't matter. ARM processors have a bitmask to specify which registers are written, and they are always written in the same order, irrespective of the order you specify them in. GCC might complain if you specify them in the wrong order, though. STM is the base operation, there are variants depending on how you want the stack to grow. STM is STore Multiple, and it comes in variants like IA: Increment After, IB: Increment Before, DA: Decrement After, DB: Decrement Before. These describe when the stack pointer is updated (before writing to memory, or after), and whether it is incremented or decremented. These operations also have handy mnemonics describing their use for operating with stacks. Linux uses a Full Descending type of a stack. Full because the stack pointer points to the last used location, and Descending because the stack grows downward, when memory listed from highest address to lowest address. If you use the FD versions of these operations, your code will interoperate well with other libraries.&lt;br /&gt;&lt;pre&gt; 9         &lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;   &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;/pre&gt;This is another multi-register move that undoes the action on line 6. This reads back the values that were written earlier, popping them from the  stack. The combined effect of lines 6 and 9 is to store the important register values on the stack and then restore them. This allows the function to modify them in the main body. As with STMFD, the values are specified in a bitmask, so they are always read in the same order.&lt;br /&gt;&lt;br /&gt;The function semantics require that r0-r3 are the only registers that can be clobbered during a function call. If you need more than four registers in a function, you need to include them in the STMFD and LDMFD lines to ensure they are restored before exit. If you need a lot of local variables in a function, you need to keep the rest in memory using load and store commands. You can safely keep variables past the stack, in locations like SP-4, SP-8. When your function returns, the stack pointer is restored and the next function can reuse this storage. You can either grow the stack by subtracting multiples of 4 from it, or you can refer to offsets from the stack.  The &lt;a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf"&gt;ARM Procedure call Standard&lt;/a&gt; mentions that r4-r8, r10, r11, and the SP need to be preserved in a subroutine. So if you are modifying these registers, ensure that you store them at the start and load them back before the end of your routine.&lt;br /&gt;&lt;br /&gt;If you need to pass more than four input values to a function, you need to store them on the stack. The function needs to read the exact number of values from the stack. Finally, if you need to return more than one value, you need to modify values in the stack, or return them in r0-r3, and hope your code is never called by anyone else's code.  &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Exercises&lt;/span&gt;&lt;br /&gt;Try experimenting with the following:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Break the function at various points with GDB and examine the memory starting at the Stack Pointer. Does the stack pointer point to the last variable on the stack, or &lt;b&gt;past&lt;/b&gt; the last variable on the stack?&lt;/li&gt;&lt;li&gt; Try removing the STMFD and LDMFD in the multiplyByTen function. Does the function still work?&lt;/li&gt;&lt;li&gt;Change multiplyByTen to return the value of SP. Print it using '%p' in the printf. Does it match what GDB says?&lt;/li&gt;&lt;li&gt;Change the multiplyByTen to modify IP, LR and FP in the function and assert that they are indeed restored. Verify the modification and the restoring through GDB.&lt;/li&gt;&lt;li&gt;Rewrite the function to use LDR and STR rather than multi-register moves. You will need to modify the stack pointer with each load and store.&lt;/li&gt;&lt;/ol&gt;The &lt;a href="http://vikram.eggwall.com/static/ARM-ARM.pdf"&gt;ARM Reference Manual&lt;/a&gt; has more information on mutiple loads and stores, including information about the IA,IB,DA,DB, and FD versions, and what they mean.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s200/android.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2793428900736304582?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2793428900736304582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2793428900736304582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2793428900736304582'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html' title='Android ARM Assembly: Stack and Functions (Part 5)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s72-c/android.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5376632858802953786</id><published>2011-09-08T08:11:00.000-07:00</published><updated>2011-09-13T06:26:19.967-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: GCC and GDB (Part 4)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part four of a multi-part series. This part covers the Gnu C Compiler and the Gnu Debugger. Both are essential development tools.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;In case you already know how to use Gnu tools in the Intel world, they work in the same way for ARM machines.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;GCC&lt;/span&gt;&lt;br /&gt;GCC is the default compiler on Linux systems. It is a versatile compiler. We need very few options for our ARM assembly development.&lt;br /&gt;&lt;pre&gt;$ gcc -S source.c&lt;/pre&gt;This is perhaps the most useful way in which we can use gcc. It creates an assembly source.s file which corresponds to the C source code. This is great for learning how gcc translates specific C constructs to assembly.&lt;br /&gt;&lt;pre&gt;$ gcc -o hello source.c&lt;/pre&gt;Compile C file source.c into an executable called hello.&lt;br /&gt;&lt;pre&gt;$ gcc -o hello source.s&lt;/pre&gt;Compile assembly file source.s into an executable called hello. This is probably what you will be using all along.&lt;br /&gt;The full &lt;a href="http://gcc.gnu.org/onlinedocs/"&gt;GCC manual can be downloaded online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;GAS&lt;/span&gt;&lt;br /&gt;Gas is the GNU assembler, and is the default assembler on Linux systems. My tutorials don't call gas directly. If you invoke gas yourself, you get an object file that you need to link against glibc using the linker. Invoking gcc on assembly source code calls gas and the linker, so I prefer to do that.&lt;br /&gt;&lt;br /&gt;Knowledge of the assembler helps when you want to use specific assembler directives. The &lt;a href="http://sourceware.org/binutils/docs/as/"&gt;gas manual is available online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;GDB&lt;/span&gt;&lt;br /&gt;While programming assembly, you often need something to show you what the state of the machine is. You need to see every register and every memory location. This is where GDB comes in. It is free, it is easy to use. Here is a gentle introduction to gdb to cover most assembly needs.&lt;br /&gt;&lt;pre&gt;$ gdb hello&lt;/pre&gt;Start gdb with the executable called hello. It prints a helpful message, and drops you to the (gdb) prompt. This prompt is where you type all commands.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;disassemble main&lt;/b&gt;&lt;br /&gt;Dump of assembler code for function main:&lt;br /&gt;   0x000083d0 &amp;lt;+0&amp;gt;:	push	{r11, lr}&lt;br /&gt;   0x000083d4 &amp;lt;+4&amp;gt;:	add	r11, sp, #4&lt;br /&gt;   0x000083d8 &amp;lt;+8&amp;gt;:	sub	sp, sp, #8&lt;br /&gt;   0x000083dc &amp;lt;+12&amp;gt;:	str	r0, [r11, #-8]&lt;br /&gt;   0x000083e0 &amp;lt;+16&amp;gt;:	str	r1, [r11, #-12]&lt;br /&gt;   0x000083e4 &amp;lt;+20&amp;gt;:	ldr	r0, [pc, #20]	; 0x8400 &lt;main+48&gt;&lt;br /&gt;   0x000083e8 &amp;lt;+24&amp;gt;:	bl	0x82e8 &lt;puts&gt;&lt;br /&gt;   0x000083ec &amp;lt;+28&amp;gt;:	mov	r3, #0&lt;br /&gt;   0x000083f0 &amp;lt;+32&amp;gt;:	mov	r0, r3&lt;br /&gt;   0x000083f4 &amp;lt;+36&amp;gt;:	sub	sp, r11, #4&lt;br /&gt;   0x000083f8 &amp;lt;+40&amp;gt;:	pop	{r11, lr}&lt;br /&gt;   0x000083fc &amp;lt;+44&amp;gt;:	bx	lr&lt;br /&gt;   0x00008400 &amp;lt;+48&amp;gt;:	andeq	r8, r0, r8, lsl #9&lt;br /&gt;End of assembler dump.&lt;/puts&gt;&lt;/main+48&gt;&lt;/pre&gt;Look at the assembly source of any function. In this case, we looked through the assembly output of main, the entry point to our hello word function. There are some familiar instructions here already. Disassembly can be done for any executable. You don't need the source code for the program.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;break *0x000083e4&lt;/b&gt;&lt;br /&gt;Breakpoint 1 at 0x83e4&lt;/pre&gt;This sets a breakpoint at the specified memory address. When you run the program, the execution will break at that location, and you will be dropped back on the gdb shell to inspect the state.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;run&lt;/b&gt;&lt;br /&gt;Starting program: /home/user/ARM/hello &lt;br /&gt;&lt;br /&gt;Breakpoint 1, 0x000083e4 in main ()&lt;br /&gt;&lt;/pre&gt;Alright, we started the program and it broke exactly where we asked it to. This is a great time to examine the registers and the memory.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;info registers&lt;/b&gt;&lt;br /&gt;r0             0x1	1&lt;br /&gt;r1             0xbed9a924	3201935652&lt;br /&gt;r2             0xbed9a92c	3201935660&lt;br /&gt;r3             0x83d0	33744&lt;br /&gt;r4             0x0	0&lt;br /&gt;r5             0x0	0&lt;br /&gt;r6             0x0	0&lt;br /&gt;r7             0x0	0&lt;br /&gt;r8             0x0	0&lt;br /&gt;r9             0x0	0&lt;br /&gt;r10            0x40025000	1073893376&lt;br /&gt;r11            0xbed9a7d4	0xbed9a7d4&lt;br /&gt;r12            0xbed9a840	3201935424&lt;br /&gt;sp             0xbed9a7c8	0xbed9a7c8&lt;br /&gt;lr             0x4003b508	1073984776&lt;br /&gt;pc             0x83e4	0x83e4 &lt;main+20&gt;&lt;br /&gt;cpsr           0x60000010	1610612752&lt;br /&gt;&lt;/main+20&gt;&lt;/pre&gt;This command shows you the register state. As you can see, there are the standard registers r0-r12, and SP, LR, and PC. You can also see the status register CPSR printed in full. The function calling convention on ARM is that the first four arguments to a function are stored in r0-r3. Let's verify that this is the case.&lt;br /&gt;The function we are looking at is main(int argc, char* argv[]). It has two arguments argc and argv, which should be in r0 and r1 respectively. r0 should contain argc, or the number of commandline arguments given. We invoked the program with no arguments, so the commandline arguments consist of only the program name. argc should be 1, which is what r0 contains&lt;br /&gt;argv is trickier. It is a pointer to pointers containing strings. This is partly confirmed by r2, which is a large hex number: 0xbed9a924. It could be a memory location. Let's find out.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;x/w 0xbed9a924&lt;/b&gt;&lt;br /&gt;0xbed9a924:	0xbed9aa0d&lt;br /&gt;&lt;/pre&gt;The "x/w" stands for eXamine memory/ parse as Word. Memory locations could contain anything, so we want to parse it as a 32 bit word to start out. The contents look a lot like the address itself. Let's see what the next few contents hold.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;x/12w 0xbed9a924&lt;/b&gt;&lt;br /&gt;0xbed9a924:	0xbed9aa0d	0x00000000	0xbed9aa22	0xbed9aa32&lt;br /&gt;0xbed9a934:	0xbed9aa3d	0xbed9aa47	0xbed9af37	0xbed9af43&lt;br /&gt;0xbed9a944:	0xbed9af80	0xbed9af8f	0xbed9afa2	0xbed9afab&lt;br /&gt;&lt;/pre&gt;x/12w stand for eXamine memory/show me 12 Words. As you can see, all the contents of memory look like they are addresses. Let's see what is at the first address: at 0xbed9aa0d&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;x/w 0xbed9aa0d&lt;/b&gt;&lt;br /&gt;0xbed9aa0d:	0x6d6f682f&lt;br /&gt;&lt;/pre&gt;Hmm, that doesn't look like an address. This should be a string, and rather than converting the 0x6d 0x6f 0x68 ... to ascii myself, I'll let gdb help me out.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;x/s 0xbed9aa0d&lt;/b&gt;&lt;br /&gt;0xbed9aa0d:	 "/home/user/ARM/hello"&lt;br /&gt;&lt;/pre&gt;We are asking gdb to "eXamine memory / as String". gdb knows that C strings are null terminated, so it helpfully walks over the successive memory locations, interpreting each byte as ASCII, till it comes to a null terminator. So we have verified that argv[1] is a pointer to a string, containing the program name. Let's see what the next few memory addresses hold.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;x/10s 0xbed9aa0d&lt;/b&gt;&lt;br /&gt;0xbed9aa0d:	 "/home/user/ARM/hello"&lt;br /&gt;0xbed9aa22:	 "SHELL=/bin/bash"&lt;br /&gt;0xbed9aa32:	 "TERM=xterm"&lt;br /&gt;0xbed9aa3d:	 "USER=user"&lt;br /&gt;0xbed9aa47:	 "LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:...&lt;br /&gt;0xbed9ab0f:	 ":*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tl...&lt;br /&gt;0xbed9abd7:	 "eb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=0"...&lt;br /&gt;0xbed9ac9f:	 ":*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.ti...&lt;br /&gt;0xbed9ad67:	 "v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=0...&lt;br /&gt;0xbed9ae2f:	 "yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv...&lt;br /&gt;&lt;/pre&gt;We "eXamine 10 memory locations as String", and we find that we have run past the end of argv. We are seeing the environment variables that are specified by the Bash shell, including the name of the shell, the username, and the colors for the different file types. I forgot, where were we?&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;where&lt;/b&gt;&lt;br /&gt;#0  0x000083e4 in main ()&lt;br /&gt;&lt;/pre&gt;We can find out our state in the execution by asking 'where'. Though we could just as easily have looked up the Program Counter register for this simple program.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;disassemble main&lt;/b&gt;&lt;br /&gt;Dump of assembler code for function main:&lt;br /&gt;   0x000083d0 &amp;lt;+0&amp;gt;:	push	{r11, lr}&lt;br /&gt;   0x000083d4 &amp;lt;+4&amp;gt;:	add	r11, sp, #4&lt;br /&gt;   0x000083d8 &amp;lt;+8&amp;gt;:	sub	sp, sp, #8&lt;br /&gt;   0x000083dc &amp;lt;+12&amp;gt;:	str	r0, [r11, #-8]&lt;br /&gt;   0x000083e0 &amp;lt;+16&amp;gt;:	str	r1, [r11, #-12]&lt;br /&gt;=&amp;gt; 0x000083e4 &amp;lt;+20&amp;gt;:	ldr	r0, [pc, #20]	; 0x8400 &lt;main+48&gt;&lt;br /&gt;   0x000083e8 &amp;lt;+24&amp;gt;:	bl	0x82e8 &lt;puts&gt;&lt;br /&gt;   0x000083ec &amp;lt;+28&amp;gt;:	mov	r3, #0&lt;br /&gt;   0x000083f0 &amp;lt;+32&amp;gt;:	mov	r0, r3&lt;br /&gt;   0x000083f4 &amp;lt;+36&amp;gt;:	sub	sp, r11, #4&lt;br /&gt;   0x000083f8 &amp;lt;+40&amp;gt;:	pop	{r11, lr}&lt;br /&gt;   0x000083fc &amp;lt;+44&amp;gt;:	bx	lr&lt;br /&gt;   0x00008400 &amp;lt;+48&amp;gt;:	andeq	r8, r0, r8, lsl #9&lt;br /&gt;End of assembler dump.&lt;br /&gt;&lt;/puts&gt;&lt;/main+48&gt;&lt;/pre&gt;gdb shows a helpful arrow showing where we are. We can set another breakpoint if we like. After a long debugging session, you might forget which breakpoints you have set.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;info breakpoints &lt;/b&gt;&lt;br /&gt;Num     Type           Disp Enb Address    What&lt;br /&gt;1       breakpoint     keep y   0x000083e4 &lt;main+20&gt;&lt;br /&gt;	breakpoint already hit 1 time&lt;br /&gt;        info registers&lt;br /&gt;3       breakpoint     keep y   0x000083f0 &lt;main+32&gt;&lt;br /&gt;        info registers&lt;br /&gt;&lt;/main+32&gt;&lt;/main+20&gt;&lt;/pre&gt;You can see all breakpoints with 'info breakpoints' and you can delete breakpoints with 'delete x', where x is the number of the breakpoint. When deleting breakpoints, gdb doesn't produce any output if it is successful.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;delete 3&lt;/b&gt;&lt;br /&gt;&lt;/pre&gt;A very helpful technique when debugging for loops is to run some commands automatically when a breakpoint is hit. This is done with the 'commands' directive as folows.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;break *0x000083ec&lt;/b&gt;&lt;br /&gt;Breakpoint 4 at 0x83ec&lt;br /&gt;(gdb) &lt;b&gt;commands 4&lt;/b&gt;&lt;br /&gt;Type commands for breakpoint(s) 4, one per line.&lt;br /&gt;End with a line saying just "end".&lt;br /&gt;&amp;gt;&lt;b&gt;info registers&lt;/b&gt;&lt;br /&gt;&amp;gt;&lt;b&gt;end&lt;/b&gt;&lt;br /&gt;(gdb) &lt;br /&gt;&lt;/pre&gt;Now, when the breakpoint is hit, gdb will automatically run the 'info registers' command. Let's continue running this program so it can hit the next breakpoint.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;continue&lt;/b&gt;&lt;br /&gt;Continuing.&lt;br /&gt;Hello World&lt;br /&gt;&lt;br /&gt;Breakpoint 4, 0x000083ec in main ()&lt;br /&gt;r0             0xc	12&lt;br /&gt;r1             0x0	0&lt;br /&gt;r2             0x40153228	1075130920&lt;br /&gt;r3             0x83d0	33744&lt;br /&gt;r4             0x0	0&lt;br /&gt;r5             0x0	0&lt;br /&gt;r6             0x0	0&lt;br /&gt;r7             0x0	0&lt;br /&gt;r8             0x0	0&lt;br /&gt;r9             0x0	0&lt;br /&gt;r10            0x40025000	1073893376&lt;br /&gt;r11            0xbed9a7d4	0xbed9a7d4&lt;br /&gt;r12            0x0	0&lt;br /&gt;sp             0xbed9a7c8	0xbed9a7c8&lt;br /&gt;lr             0x83ec	33772&lt;br /&gt;pc             0x83ec	0x83ec &lt;main+28&gt;&lt;br /&gt;cpsr           0x60000010	1610612752&lt;br /&gt;&lt;/main+28&gt;&lt;/pre&gt;gdb ran past the puts(), and printed "Hello World" on the screen. It hit the breakpoint, and automatically showed us the registers. Great. Let's finish up by continuing.&lt;br /&gt;&lt;pre&gt;(gdb) &lt;b&gt;continue &lt;/b&gt;&lt;br /&gt;Continuing.&lt;br /&gt;[Inferior 1 (process 17307) exited normally]&lt;br /&gt;(gdb) &lt;b&gt;info registers &lt;/b&gt;&lt;br /&gt;The program has no registers now.&lt;br /&gt;&lt;/pre&gt;The program is done. We can't examine registers or memory because it isn't running anymore.&lt;br /&gt;The full &lt;a href="http://www.gnu.org/s/gdb/documentation/"&gt;GDB documentation is available online&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Links&lt;/span&gt;&lt;br /&gt;Now that you know how to examine registers and memory, you can write ARM programs and verify that they do the right thing. You can break at various locations and verify that your load store and move instructions are working as expected.&lt;br /&gt;&lt;br /&gt;The Gnu tools are ubiquitous and mature. Once you learn how to use gdb and gcc on ARM, you can easily use the same tricks on another platform like Intel. Here are all the manual links again:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://gcc.gnu.org/onlinedocs/"&gt;GCC manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sourceware.org/binutils/docs/as/"&gt;Gas (Gnu Assembler) manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.gnu.org/s/gdb/documentation/"&gt;GDB manual&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-4jJ4KIRC2WM/TmjbwdgQgQI/AAAAAAAAAR8/vSa1ljN7qQU/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-4jJ4KIRC2WM/TmjbwdgQgQI/AAAAAAAAAR8/vSa1ljN7qQU/s1600/android.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5376632858802953786?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5376632858802953786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5376632858802953786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5376632858802953786'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html' title='Android ARM Assembly: GCC and GDB (Part 4)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-4jJ4KIRC2WM/TmjbwdgQgQI/AAAAAAAAAR8/vSa1ljN7qQU/s72-c/android.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3516767273920495553</id><published>2011-09-07T20:31:00.000-07:00</published><updated>2011-09-13T06:26:27.114-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: Registers, Memory and Addressing Modes (Part 3)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part three of a series on learning ARM assembly on Android. This part covers registers, memory and addressing modes.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Registers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;On ARM processors you have 16 registers. Actually, that is not entirely true. ARM processors have 32 registers, each 32 bits wide. ARM processors have different programming modes to distinguish user-level and system-level access. Only some registers are visible in each mode. In the user-level mode you can access 16 registers. This is the mode you will use most frequently, so you can ignore the entire mode stuff for now. By the time you need to write Linux device drivers, you will be well past this introduction.&lt;br /&gt;&lt;br /&gt;The registers are called r0-r15, and the last four are special.&lt;br /&gt;&lt;b&gt;r12: IP&lt;/b&gt;, or Intra-Procedure call stack register. This register is used by the linker as a scratch register between procedure calls. A procedure must not modify its value on return. This register isn't used by Linux gcc or glibc, but another system might.&lt;br /&gt;&lt;b&gt;r13: SP,&lt;/b&gt; or Stack Pointer. This register points to the top of the stack. The stack is area of memory used for local function-specific storage. This storage is reclaimed when the function returns. To allocate space on the stack, we subtract from the stack register. To allocate one 32-bit value, we subtract 4 from the stack pointer.&lt;br /&gt;&lt;b&gt;r14: LR&lt;/b&gt;, or Link Register. This register holds the return value of a subroutine. When a subroutine is called, the LR is filled with the program counter.&lt;br /&gt;&lt;b&gt;r15: PC&lt;/b&gt;, or Program Counter. This register holds the address of memory that is currently being executed.&lt;br /&gt;There is one more register, the &lt;b&gt;Current Program Status Register (CPSR)&lt;/b&gt; that contains values indicating some flags like Negative, Zero, Carry, etc. We'll visit it later, you can't read and write it like a normal register anyway.&lt;br /&gt;&lt;br /&gt;In assembly language, these are all the variables you have access to. If you need to perform any computation, they need to operate upon these registers. Since there are a small number of registers, you need to be judicious in their use. A lot of optimisation boils down to being miserly with register allocation.&lt;br /&gt;&lt;br /&gt;Here are all the data move instructions:&lt;br /&gt;&lt;pre&gt;	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;&lt;/pre&gt;This moves the value from r1 to r0. This achieves r0 = r1&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, lsl &lt;/span&gt;#&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;/pre&gt;Logical Shift Left (lsl) variable r1 by 2 bits, and then move to r0. This achieves r0 = r1 &amp;lt;&amp;lt; 2. There is a limitation on how much rotation is allowed: rotation is specified using five bits, so any value of rotation between 0-31 is allowed. The effect of a single left-shift is multiplication by 2. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, lsr &lt;/span&gt;#&lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;/pre&gt;Logical Shift Right (lsr) variable r1 by 3, and then move to r0. This achieves r0 = (int) (r1 &amp;gt;&amp;gt; 3) The effect of a single left-shift is (the integer part of) division by 2. &lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r1, lsl r2&lt;/span&gt;&lt;/pre&gt;Logical Shift Left (lsl) variable r1 by the amount given in r2, and then move to r0. The value in register r2 should be between 0 and 31. This achieves r0 = (int) (r1 &amp;lt;&amp;lt; r2)&lt;br /&gt;LSL and LSR are not the only shifts. There are also Arithmetic Shifts: ASL and ASR that maintain signed-ness. ASR is different from LSR for negative numbers. Negative numbers have leading bits set 1, and ASR right shifting propagates the 1 bits. In case you don't remember how negative numbers are represented, you might want to read a &lt;a href="http://en.wikipedia.org/wiki/One%27s_complement"&gt;One's Complement&lt;/a&gt; review.  ASL is the same as LSL because the sign extension doesn't happen when shifting left. Finally there is ROtate Right, or ROR. Rotation preserves all information, the bits are cycled like the barrel of a six-shooter. You can rotate by five bits, which means from 0-31 positions. There is no rotate left, since to rotate left by 3 bits, you can rotate right by 32-3 = 29 bits. Every shift can take either a five bit value or a register that contains a value between 0 and 31.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;,#&lt;span style="color: red;"&gt;10&lt;/span&gt;&lt;/pre&gt;Move the literal value 10 r0. This achieves r0 = 10. This is an example of &lt;b&gt;Immediate&lt;/b&gt; addressing, the literal value of the constant is given in the instruction. There is a limit to what can be listed in immediate values. Any number that can be expressed in 8 bits constant, plus 5 bits in rotation is allowed. Anything other that that must be declared as a constant, and loaded from memory. Examples of valid values are 0x10, 0x100 (both using the constant alone), and 0x40000 (using rotate to left)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Loading from and Storing to Memory&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The memory on the ARM architecture is laid out as a flat array. No more segment register nonsense of the Intel world. Addressing modes are equally straight forward and easy to remember.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;.L3&lt;/span&gt;&lt;/pre&gt;Move the contents of address label .L3 to r0. This achieves r0 = *(.L3) &lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1]&lt;/span&gt;&lt;/pre&gt;Move the contents of data pointed to by r1 to r0. This achieves r0 = *(r1). This addressing mode is using a register for a base address.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1&lt;/span&gt;, #&lt;span style="color: red;"&gt;4&lt;/span&gt;]&lt;/pre&gt;Move the contents of data pointed to by (r1 + 4) to r0. This achieves r0 = *(r1 + 1) since 32 bits are moved at a time. Byte alignment might enforce this, so you might not be able to do "ldr r0, [r1, #1]". This addressing mode is using an immediate offset value.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, r2]&lt;/span&gt;&lt;/pre&gt;Move the contents of data pointed to by (r1 + r2) to r0. This achieves r0 = *(r1 + (r2/4)). This addressing mode is using a register as an offset, in addition to a register as a bass address.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, -r2]&lt;/span&gt;&lt;/pre&gt;It is possible to specify the offsets as negative.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, r2, lsl #&lt;/span&gt;&lt;span style="color: red;"&gt;4&lt;/span&gt;]&lt;/pre&gt;Move the contents of data pointed to by (r1 + (r2 logical shift left by four bits)) to r0. This achieves r0 = *(r1 + ((r2 &amp;lt;&amp;lt; 4)/4)). This addressing mode is using a register for base address, and a shifted register for offset.&lt;br /&gt;You get the picture. The load instructions take the same barrel shift arguments as the move instructions, so LSL, LSR, ASL, ASR, and ROR are all valid.The interesting stuff happens when you have the ability to use a register as a pointer while modifying the pointer and the destination. There are two ways of doing this, post-index addressing, and pre-index addressing. These correspond roughly to the postincrement (a++) and preincrement (++a) operators in C. Here is a post-increment operator&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1], &lt;/span&gt;#&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;/pre&gt;Move the contents of data pointed to by r1 to r0, and stores the value r1+4 in r1. This achieves r0 = *(r1), r1 = r1 + 1.  As before, variants where registers are used as offsets and shifted registers as offsets are valid.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1], r2&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1], r2, asl &lt;/span&gt;#&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;In pre-indexed addressing, we modify the base address register before loading the address from the memory to the register. This is indicated by an exclamation mark at the end of the address, indicating that it is written first.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, &lt;/span&gt;#&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;]&lt;/span&gt;&lt;span style="color: red;"&gt;!&lt;/span&gt;&lt;/pre&gt;Increase the content of r1 by 4, and then move the contents of data pointed to by (r1) to r0. This achieves r1 = r1 + 4, r0 = *(r1)&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, r2]&lt;/span&gt;&lt;span style="color: red;"&gt;!&lt;/span&gt;&lt;/pre&gt;Increase the content of r1 by the contents of r2, and then move the contents of data pointed to by (r1) to r0. This achieves r1 = r1 + r2, r0 = *(r1)&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1, r2,  &lt;/span&gt;#&lt;span style="color: red;"&gt;4 &lt;/span&gt;&lt;span style="color: #2040a0;"&gt;]&lt;/span&gt;&lt;span style="color: red;"&gt;!&lt;/span&gt;&lt;/pre&gt;You get the idea. Any registers r0-r15 can be used where r0, r1, and r2 are used in examples above.&lt;br /&gt;All those examples dealt with loading contents from memory to registers. For storing to memory, we use the STR opcode instead of the LDR opcode. The same addressing modes can be used to store values from registers into memory. Here are a few examples.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1], &lt;/span&gt;#&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;/pre&gt;Move the contents of r0 into memory pointed to by r1, and stores the value r1+4 in r1. This achieves *(r1) = r0, r1 = r1 + 1.  As before, variants where registers are used as offsets and shifted registers as offsets are valid.&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1]&lt;/span&gt;&lt;/pre&gt;Move contents of r0 into address pointed to by register r1 *(r1) = r0&lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;[r1], r2&lt;/span&gt;&lt;/pre&gt;Move contents of r0 into address pointed to by r1, and increment r1 by contents of r2. *r1 = r0, r1 = r1 + r2&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;References&lt;/span&gt;&lt;br /&gt;Register move instructions and indexing modes is perhaps the hardest part of ARM assembly. You should take solace in the fact that the addressing modes are considerably less complicated than the madness of segment registers on Intel processors.&lt;br /&gt;&lt;br /&gt;This is a basic introduction to the registers and addressing modes in ARM processors. In case you want more depth, &lt;a href="http://www.coranac.com/tonc/text/asm.htm"&gt;Jasper Vijn's excellent introduction to ARM assembly&lt;/a&gt;  covers these topics.&lt;br /&gt;&lt;br /&gt;The authoritative technical reference for the ARM architecture is the &lt;a href="http://vikram.eggwall.com/static/ARM-ARM.pdf"&gt;ARM Application Reference Manual&lt;/a&gt;. It contains valuable technical information on all instructions in the ARM instruction set.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s200/android.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3516767273920495553?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3516767273920495553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3516767273920495553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3516767273920495553'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html' title='Android ARM Assembly: Registers, Memory and Addressing Modes (Part 3)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-SJhAJgXzQ_8/TmgwehOrkoI/AAAAAAAAAR4/FeMBLFG_nWg/s72-c/android.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2594684997263865672</id><published>2011-09-05T16:03:00.000-07:00</published><updated>2011-09-13T06:26:35.529-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM Assembly: A trivial program (Part 2)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part two of a series on learning ARM assembly on Android. This part covers a walkthrough of a ARM assembly program.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Hello world assembly program &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The easiest program that most languages introduce is the Hello World program. If you had followed with &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part one&lt;/a&gt;, you typed the Hello World program in C. Now generate the assembly language for that example using the command given at the end of &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;part one&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here is the assembly language program in full:&lt;br /&gt;&lt;pre&gt; 1 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;cpu&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;arm9tdmi&lt;/span&gt;&lt;br /&gt; 2 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;fpu&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;softvfp&lt;/span&gt;&lt;br /&gt; 3 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;20&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 4 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;21&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 5 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;23&lt;/span&gt;, &lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;br /&gt; 6 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;24&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 7 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;25&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 8 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;26&lt;/span&gt;, &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt; 9 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;30&lt;/span&gt;, &lt;span style="color: red;"&gt;6&lt;/span&gt;&lt;br /&gt;10 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;18&lt;/span&gt;, &lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;br /&gt;11 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;file&lt;/span&gt;	&lt;span style="color: green;"&gt;"hello.c"&lt;/span&gt;&lt;br /&gt;12 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;section&lt;/span&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;rodata&lt;/span&gt;&lt;br /&gt;13 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;14 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;LC0&lt;/span&gt;:&lt;br /&gt;15 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;ascii&lt;/span&gt;	&lt;span style="color: green;"&gt;"Hello World\000"&lt;/span&gt;&lt;br /&gt;16 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt;17 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;18 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;br /&gt;19 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;	&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt;20 &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;:&lt;br /&gt;21 	@ &lt;b&gt;Function&lt;/b&gt; &lt;span style="color: #2040a0;"&gt;supports&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;interworking&lt;/span&gt;&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;br /&gt;22 	@ &lt;span style="color: #2040a0;"&gt;args&lt;/span&gt; = &lt;span style="color: red;"&gt;0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;pretend&lt;/span&gt; = &lt;span style="color: red;"&gt;0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;frame&lt;/span&gt; = &lt;span style="color: red;"&gt;8&lt;/span&gt;&lt;br /&gt;23 	@ &lt;span style="color: #2040a0;"&gt;frame_needed&lt;/span&gt; = &lt;span style="color: red;"&gt;1&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;uses_anonymous_args&lt;/span&gt; = &lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;24 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;&lt;br /&gt;25 	&lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;pc&lt;/span&gt;}&lt;br /&gt;26 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, #&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;br /&gt;27 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, #&lt;span style="color: red;"&gt;8&lt;/span&gt;&lt;br /&gt;28 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, [&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, #-&lt;span style="color: red;"&gt;16&lt;/span&gt;]&lt;br /&gt;29 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r1&lt;/span&gt;, [&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, #-&lt;span style="color: red;"&gt;20&lt;/span&gt;]&lt;br /&gt;30 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L3&lt;/span&gt;&lt;br /&gt;31 	&lt;span style="color: #2040a0;"&gt;bl&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;puts&lt;/span&gt;&lt;br /&gt;32 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, #&lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;33 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;&lt;br /&gt;34 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, #&lt;span style="color: red;"&gt;12&lt;/span&gt;&lt;br /&gt;35 	&lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt;36 	&lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;br /&gt;37 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L4&lt;/span&gt;:&lt;br /&gt;38 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;39 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L3&lt;/span&gt;:&lt;br /&gt;40 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;word&lt;/span&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;LC0&lt;/span&gt;&lt;br /&gt;41 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;size&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;-&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;br /&gt;42 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;ident&lt;/span&gt;	&lt;span style="color: green;"&gt;"GCC: (Debian 4.3.2-1.1) 4.3.2"&lt;/span&gt;&lt;br /&gt;43 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;section&lt;/span&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;note&lt;/span&gt;&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;GNU&lt;/span&gt;-&lt;span style="color: #2040a0;"&gt;stack&lt;/span&gt;,&lt;span style="color: green;"&gt;""&lt;/span&gt;,%&lt;span style="color: #2040a0;"&gt;progbits&lt;/span&gt;&lt;/pre&gt;As you can see, it is quite a lot of code for a simple program. Luckily, most of it is boilerplate.&amp;nbsp; Let's break it down piece by piece.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Declaration and options&lt;/span&gt;&lt;br /&gt;&lt;pre&gt; 1 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;cpu&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;arm9tdmi&lt;/span&gt;&lt;br /&gt; 2 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;fpu&lt;/span&gt; &lt;span style="color: #2040a0;"&gt;softvfp&lt;/span&gt;&lt;br /&gt; 3 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;20&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 4 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;21&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 5 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;23&lt;/span&gt;, &lt;span style="color: red;"&gt;3&lt;/span&gt;&lt;br /&gt; 6 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;24&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 7 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;25&lt;/span&gt;, &lt;span style="color: red;"&gt;1&lt;/span&gt;&lt;br /&gt; 8 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;26&lt;/span&gt;, &lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt; 9 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;30&lt;/span&gt;, &lt;span style="color: red;"&gt;6&lt;/span&gt;&lt;br /&gt;10 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;eabi_attribute&lt;/span&gt; &lt;span style="color: red;"&gt;18&lt;/span&gt;, &lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;br /&gt;11 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;file&lt;/span&gt;	&lt;span style="color: green;"&gt;"hello.c"&lt;/span&gt;&lt;/pre&gt;The first eleven lines are declarations of various options in the ARM cpu. You can ignore them for now. In case you are curious, we specify the CPU type, the way we want the Floating Point Unit (FPU) to operate, and then specify options for the &lt;a href="http://vikram.eggwall.com/static/arm-eabi.pdf"&gt;ARM Embedded Application Binary Interface&lt;/a&gt; (EABI). The filename is specified on line 11.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Declaring constants&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;12 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;section&lt;/span&gt;	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;rodata&lt;/span&gt;&lt;br /&gt;13 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;14 &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;LC0&lt;/span&gt;:&lt;br /&gt;15 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;ascii&lt;/span&gt;	&lt;span style="color: green;"&gt;"Hello World\000"&lt;/span&gt;&lt;/pre&gt;The string "Hello World" is specified as a constant in assembly on lines 12-15. It is in the Read Only DATA section (.section .rodata), it needs to be aligned on two-byte boundaries, and the string is specified as an ASCII string. Byte alignment is very important in assembly language programming.&amp;nbsp; You must pay careful attention to data that needs to be word aligned (2-byte), quad aligned (4-byte) or byte aligned (1-byte). In general, you can't go wrong with word alignment, so if you are uncertain, add a .align 2 at the top of data and functions.&lt;br /&gt;The data is specified as a string in assembly, though the assembler writes it out as bytes behind the scenes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Declaring functions&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;16 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt;17 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt;18 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;&lt;br /&gt;19 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;	&lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt;20 &lt;span style="color: #2040a0;"&gt;main&lt;/span&gt;:&lt;/pre&gt;The program consists of a single function called main. Program code is always in the text section, thus the declaration on line 16. It is word aligned (line 17). main is a global variable, and line 18 allows it to be visible elsewhere in the program. Finally, it is listed as a function, and line 20 is a label containing the name 'main'. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Registers and data&lt;/span&gt;&lt;br /&gt;Before we look at the function contents, it might be useful to know what the ARM architecture is like. ARM processors are an example of Reduced Instruction Set Computing (RISC). This means that there are few instructions, and most instructions operate on registers. For user programs, there are 16 registers, called r0, r1, r2, .., r15. Each register is 32 bits long. Registers correspond roughly to variables, though they don't have a data type. Most arithmetical and logical operations are performed on registers. The processor can also access the entire memory using load and store instructions.&lt;br /&gt;&lt;br /&gt;The registers r12-r15 are special:&lt;br /&gt;&lt;b&gt;r12: IP&lt;/b&gt;, or Intra-Procedure call stack register. This register is used by the linker as a scratch register between procedure calls. A procedure must not modify its value on return. This register isn't used by Linux gcc or glibc, but another system might.&lt;br /&gt;&lt;b&gt;r13: SP,&lt;/b&gt; or Stack Pointer. This register points to the top of the stack. The stack is area of memory used for local function-specific storage. This storage is reclaimed when the function returns. To allocate space on the stack, we subtract from the stack register. To allocate one 32-bit value, we subtract 4 from the stack pointer.&lt;br /&gt;&lt;b&gt;r14: LR&lt;/b&gt;, or Link Register. This register holds the return value of a subroutine. When a subroutine is called, the LR is filled with the program counter.&lt;br /&gt;&lt;b&gt;r15: PC&lt;/b&gt;, or Program Counter. This register holds the address of memory that is currently being executed.&lt;br /&gt;&lt;br /&gt;Here are some data move instructions:&lt;br /&gt;&lt;pre&gt;24 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;&lt;/pre&gt;This moves the value from sp (r13) to ip (r12). This achieves ip = sp. &lt;br /&gt;&lt;pre&gt;32 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, #&lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;/pre&gt;This moves the value 0 into r3. This achieves r3 = 0&lt;br /&gt;&amp;nbsp;In addition to moving values within registers, you can load values from memory into registers, and store registers into memory. Here are instructions that achieve this:&lt;br /&gt;&lt;pre&gt;28 	&lt;span style="color: #2040a0;"&gt;str&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, [&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, #-&lt;span style="color: red;"&gt;16&lt;/span&gt;]&lt;/pre&gt;This stores the contents of r0 into the memory location pointed to by (fp -16). Since memory is addressed by bytes, and registers are 4 bytes each, memory offsets are often multiples of 4. This is the same as the C statement *(fp - 4) = r0&lt;br /&gt;&lt;pre&gt;30 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0, [fp]&lt;/span&gt;&lt;/pre&gt;This loads the data from memory pointed to by register fp into register r0. This is the same as the C statement r0 = *(fp)&lt;br /&gt;&lt;pre&gt;25 	&lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;pc&lt;/span&gt;}&lt;/pre&gt;This is a multi-register move operation. This moves the registers FP,IP,LR,PCinto the area specified by the register SP. Since SP is the stack pointer, this is the same as pushing registers FP,IP,LR,PC to the top of the stack in a single operation. Once this is done, the stack pointer is updated since it has an exclamation mark.&lt;br /&gt;&lt;pre&gt;35 	&lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;/pre&gt;This is another multi-register move that undoes the action on line 25. This reads back the values that were written earlier, popping them from the stack. The combined effect of lines 25 and 35 is to store the important register values on the stack and then restore them. This allows the function to modify them in the main body. We don't restore IP &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Manipulating data&lt;/span&gt;&lt;br /&gt;Assembly instructions to manipulate data are very basic: you can do basic arithmetic operations: ADD, SUB, and basic logical operations: AND, OR. ARM Assembly language operations are of the type:OPERATION ARG1, ARG2, ARG3 This performs the operation ARG1 = ARG2 OPERATION ARG3. In the above program, you see some basic arithmetic.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;26 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, #&lt;span style="color: red;"&gt;4&lt;/span&gt;&lt;/pre&gt;This performs the action fp = ip - 4.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Function calls and returns&lt;/span&gt;&lt;br /&gt;Assembly language is written as a flat set of instructions: there is very little structure once the instructions are written to memory in the computer. In order to make code modular, functions can be written. Without the protection of the C compiler, assembly programs must manage their own function calling.&lt;br /&gt;The basic function call involves the following structure: &lt;br /&gt;&lt;pre&gt; 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;text&lt;/span&gt;&lt;br /&gt; 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;align&lt;/span&gt;	&lt;span style="color: red;"&gt;2&lt;/span&gt;&lt;br /&gt; 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;global&lt;/span&gt;	functionName&lt;br /&gt; 	&lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;b&gt;type&lt;/b&gt;	functionName, %&lt;b&gt;function&lt;/b&gt;&lt;br /&gt; functionName:&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;stmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;!, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;pc&lt;/span&gt;}&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;ip&lt;/span&gt;, #&lt;span style="color: red;"&gt;4&lt;/span&gt;  @ Space for local variables&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, #&lt;span style="color: red;"&gt;8&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: red;"&gt;&lt;perform computation=""&gt;&amp;nbsp;&lt;/perform&gt;&lt;/span&gt;&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;sub&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, #&lt;span style="color: red;"&gt;12&lt;/span&gt;&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;ldmfd&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, {&lt;span style="color: #2040a0;"&gt;fp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;sp&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;}&lt;br /&gt; 	&lt;span style="color: #2040a0;"&gt;bx&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;lr&lt;/span&gt;&lt;/pre&gt;Subroutines are required to preserve every register except for r0-r3. So if you need to use the other registers (r4 onwards), you should save them on the stack before over-writing them. The exact function call convention is listed in the &lt;a href="http://vikram.eggwall.com/static/arm-procedure-call-aaps.pdf"&gt;ARM procedure call standard&lt;/a&gt;.&lt;br /&gt;In order to call a function, you Branch and Link using the BL instruction. The return address is placed in the LR register. To return from a function, you call a branch on the LR register. This is a BX rather than a B to correctly move between  ARM and Thumb instructions. (Ignore ARM and Thumb differences for now, they will be made clear later).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Hello World functionality&lt;/span&gt;&lt;br /&gt;Put together, the lines 30-33 lines print out the message Hello ARM world. Let's break this down instruction-by-instruction to see how this is achieved. &lt;br /&gt;&lt;pre&gt;30 	&lt;span style="color: #2040a0;"&gt;ldr&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: red;"&gt;.&lt;/span&gt;&lt;span style="color: #2040a0;"&gt;L3&lt;/span&gt;&lt;br /&gt;31 	&lt;span style="color: #2040a0;"&gt;bl&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;puts&lt;/span&gt;&lt;br /&gt;32 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;, #&lt;span style="color: red;"&gt;0&lt;/span&gt;&lt;br /&gt;33 	&lt;span style="color: #2040a0;"&gt;mov&lt;/span&gt;	&lt;span style="color: #2040a0;"&gt;r0&lt;/span&gt;, &lt;span style="color: #2040a0;"&gt;r3&lt;/span&gt;&lt;/pre&gt;Line 30 loads the address of label .L3 into register r0. The function calling convention is that the first four arguments are stored in r0-r3, and subsequent arguments are stored on the stack. The function to put a value on the screen is called puts, and it accepts just one argument: the string to be printed. The address of this string is stored in the first register: r0.&lt;br /&gt;Line 31 calls the puts function, which consumes r0 and prints the value on the screen. After calling the function, we can expect the registers r0-r3 to be trashed. The return value of the puts is in r0, but we don't care for it.&lt;br /&gt;&lt;br /&gt;Line 32 and 33 put together achieve r0 = 0. This is the return value that the main method returns.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Final word&lt;/span&gt;&lt;br /&gt;You are now capable of reading ARM assembly and understanding the main elements in the program. As an exercise, you could try reducing the size of the code while keeping the functionality intact.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;In the next article, we can examine each piece in some detail.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s200/android.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2594684997263865672?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2594684997263865672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2594684997263865672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2594684997263865672'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html' title='Android ARM Assembly: A trivial program (Part 2)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s72-c/android.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5268119475183762822</id><published>2011-09-05T12:34:00.000-07:00</published><updated>2011-09-14T21:33:35.201-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Android ARM assembly: Device set up (Part 1)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is part one of a multipart series about learning ARM assembly programming with Android. This covers motivation and device set up. &lt;br /&gt;&lt;br /&gt;=&amp;gt; &lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html"&gt;Part 1: Motivation and device set up&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-trivial-program.html"&gt;Part 2: A walk-through of a simple ARM assembly program&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-registers-memory.html"&gt;Part 3: Registers, memory, and addressing modes&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-gcc-and-gdb-part-4.html"&gt;Part 4: Gnu tools for assembly; GCC and GDB&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-stack-and.html"&gt;Part 5: Stack and Functions&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-arithmetic-and.html"&gt;Part 6: Arithmetic and Logical Expressions&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-conditional.html"&gt;Part 7: Conditional Execution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html"&gt;Part 8: Assembly in Android code&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;The articles follow in series, each article builds on the previous.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Motivation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You might not realise it, but ARM processors are ubiquitous. When I look around my house, I can count eight ARM processors in routers, phones, eBook readers and web servers. There are more ARM processors in my house than Intel processors.&lt;br /&gt;&lt;br /&gt;ARM assembly language is perhaps the easiest assembly language in widespread use. The Intel instruction set was developed over years of CPU revisions, which made the Complex Instruction Set (CISC) even more complex. In case you want to learn assembly, the ARM instruction set is simple to learn. Once you know how to write ARM assembly, it is easier to learn Intel assembly.&lt;br /&gt;&lt;br /&gt;Finally, ARM processors are being used everywhere. Whether you like the iPhone or  Android, they both use ARM processors. ARM processors excel at low-power computing, which makes them valuable for mobile computing, and consumer electronic devices like routers, NAS storage, eBook readers, game consoles and cell phones. Unlike desktop computers, resources are very limited on mobile devices. On such devices optimisation makes the difference between a slow and unusable application and a fast and responsive one.&lt;br /&gt;&lt;br /&gt;Thanks to the profusion of Android devices, you can start programming ARM assembly within minutes and at low cost. You don't need to sign an NDA or pay for development tools. If you have an Android phone and a computer, you already have everything you need. Assembly language programming will not require the buttons or the touch-screen. Any device with a working USB port and with root access will do.&lt;br /&gt;&lt;br /&gt;Setting up an ARM device with Linux was a monumental effort: you had to buy a dev-kit which easily ran in the hundreds of dollars. Then you struggled to shoe-horn Linux onto the tiny device. With Android, you already get an ARM device running Linux. All the device drivers are in place. All you need is a Linux distribution that allows you to get the native development tools. This is considerably easier. It should take around an hour of effort.&lt;br /&gt;&lt;br /&gt;At this point, you have a choice. You can either go with setting up your own device, which lets you develop on a real ARM computer. Or you can download a prebuilt QEMU image.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Choice A: Emulation&lt;/span&gt;&lt;br /&gt;This is the easy choice. For this, you need a computer: Windows, Mac, Linux, all are good.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://wiki.qemu.org/Main_Page"&gt;QEMU&lt;/a&gt; is a full CPU emulator that can emulate an ARM computer. It is capable of running the full Android stack, and is shipped with the Android SDK. QEMU is much easier than setting up Linux on Android. To start, &lt;a href="http://wiki.qemu.org/Download"&gt;download and install QEMU&lt;/a&gt; on your system and a utility to extract &lt;a href="http://en.wikipedia.org/wiki/RAR_%28file_format%29"&gt;RAR files&lt;/a&gt;. I have prepared QEMU images with the full software development environment.&lt;br /&gt;&lt;br /&gt;Download all three files [&lt;a href="http://www.mediafire.com/file/rc1dzzp58qddb5t/arm-qemu.part1.rar"&gt;part 1&lt;/a&gt;], [&lt;a href="http://www.mediafire.com/file/sypa45cahh65o24/arm-qemu.part2.rar"&gt;part 2&lt;/a&gt;], [&lt;a href="http://www.mediafire.com/file/9x9ya2ak227u2ft/arm-qemu.part3.rar"&gt;part 3&lt;/a&gt;], and then run this command:&lt;br /&gt;&lt;pre&gt;$ &lt;b&gt; unrar x arm-qemu.part1.rar&lt;/b&gt;&lt;/pre&gt;This will create a directory called ARM. You can enter that directory and run the command runme.sh. It will start up the virtual machine. The virtual machine is slow, so be patient. The administrator has username "root" and password "root".&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Choice B: Using a real device &lt;/span&gt;&lt;br /&gt;In this case you install Linux on your Android phone.&lt;br /&gt;&lt;br /&gt;You need:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Android phone with 2GB free space on the SD card&lt;/li&gt;&lt;li&gt;Any computer with USB&lt;/li&gt;&lt;/ol&gt;Obtain an Android phone on which you can get root access. If you have a working Android phone, you can use that. Otherwise you can buy a used Android phone. Install Debian on it using &lt;a href="http://www.saurik.com/id/10"&gt;Jay Freeman's instructions on getting Debian on an Android phone&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Another option  is to buy an &lt;a href="http://www.eggwall.com/2011/08/1-watt-webserver.html"&gt;ARM device like this Zipit&lt;/a&gt;. &amp;nbsp;This is a harder option. Many devices have poor support, and installing Linux can be a herculean task. I would recommend sticking to an Android phone unless you have easy access to an ARM device and you know that you can install Linux on it easily.&lt;br /&gt;&lt;br /&gt;Once you have Debian working, you need to create a user and install ssh to allow easy access to the device from your laptop or desktop:&lt;br /&gt;&lt;pre&gt;phone$ &lt;span style="color: #006600;"&gt;sudo adduser&lt;/span&gt; # Create a normal user for dev purposes.&lt;br /&gt;phone$ &lt;span style="color: #006600;"&gt;sudo apt-get install openssh-server&lt;/span&gt;&lt;br /&gt;phone$ &lt;span style="color: #006600;"&gt;sudo /etc/init.d/ssh start&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #006600;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;You now have a working Debian installation that you can access using SSH. To ssh into your device, you can use port forwarding with the Android Debug Bridge (adb) to forward the desktop's port 2222 to port 22 on the phone as follows:&lt;br /&gt;&lt;pre&gt;desktop$ &lt;span style="color: #006600;"&gt;adb forward tcp:2222 tcp:22&lt;/span&gt;&lt;/pre&gt;Finally, you can login to your phone from your desktop as follows:&lt;br /&gt;&lt;pre&gt;desktop$ &lt;span style="color: #006600;"&gt;ssh user@localhost -p 2222&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Once the port forwarding is working correctly, you can also login from any computer on your network as follows:&lt;br /&gt;&lt;pre&gt;desktop$ &lt;span style="color: #006600;"&gt;ssh user@mydesktop -p 2222&lt;/span&gt;&lt;/pre&gt;This allows you to connect to your ARM device from any computer in your house. You can punch holes in your firewall by forwarding ports from the firewall to port 2222 on your desktop's IP address, and be able to access your ARM device from anywhere in the world. Even if the screen has turned off, you will be able to ssh into it, edit, compile and debug programs.&lt;br /&gt;&lt;br /&gt;Congratulations. You now have a completely silent ARM device which you can connect to from anywhere.&lt;br /&gt;&lt;br /&gt;Once you have Debian installed on your device, you can get the development system using apt-get:&lt;br /&gt;&lt;pre&gt;phone$ &lt;span style="color: #006600;"&gt;sudo apt-get install gcc gdb make vi emacs&lt;/span&gt;&lt;/pre&gt;Install the editor you prefer: vi or emacs. Now, your phone is a fully capable ARM dev environment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Test the development tools&lt;/span&gt;&lt;br /&gt;You can try a simple C program to verify the setup. &lt;br /&gt;&lt;pre&gt;&lt;span style="color: #7e7e7e;"&gt;/*&amp;nbsp;hello.c:&amp;nbsp;Hello&amp;nbsp;World&amp;nbsp;program&amp;nbsp;*/&lt;/span&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;int&lt;/span&gt; main(&lt;span style="color: #cc6600;"&gt;int&lt;/span&gt; argc, &lt;span style="color: #cc6600;"&gt;char&lt;/span&gt;* argv[]){&lt;br /&gt;&amp;nbsp;&amp;nbsp;printf(&lt;span style="color: #006699;"&gt;"Hello ARM World\n"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #cc6600;"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;You can compile this and run this as follows:&lt;br /&gt;&lt;pre&gt;phone$ &lt;span style="color: #006600;"&gt;gcc hello.c -o hello &amp;amp;&amp;amp; ./hello&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;If you have got this far, you can get a sneak peak at ARM assembly with the following command:&lt;br /&gt;&lt;pre&gt;phone$ &lt;span style="color: #006600;"&gt;gcc hello.c -S &amp;amp;&amp;amp; cat ./hello.s&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;This shows you the intermediate Assembly language from the Hello world program.&lt;br /&gt;&lt;br /&gt;Congratulations, you have turned your Android phone into a full-featured ARM dev kit. The next article will cover programming your device in Assembly language.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s1600/android.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s200/android.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5268119475183762822?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5268119475183762822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5268119475183762822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5268119475183762822'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/09/android-arm-assembly-device-set-up-part.html' title='Android ARM assembly: Device set up (Part 1)'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-rhOFFUZcHZc/TmUftmc-ECI/AAAAAAAAAR0/OZjOQKy4bTo/s72-c/android.png' height='72' width='72'/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5842643670002824631</id><published>2011-08-29T20:52:00.000-07:00</published><updated>2011-08-29T20:52:41.333-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>The Linux Programming Interface: a beautifully written technical book</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I have been reading, "&lt;a href="http://man7.org/tlpi/"&gt;The Linux Programming Interface&lt;/a&gt;" recently. It covers everything about the Linux programming environment: the layout of process space in memory, threads, signals, sockets. Nearly everything you can think of while programming Linux is covered here. Go get it. Now.&lt;br /&gt;&lt;br /&gt;It is a beautifully written book. The author, Michael Kerrisk, combines technical knowledge about Linux internals with a clear, precise writing style. This book is &lt;b&gt;fun&lt;/b&gt; to read. I have used Linux for many years now, and I found the chapters both illuminating and delightful. At first, I picked it up to learn about memory layout in Linux. I found the writing style so good that I read on, finishing not just that chapter, but many others. I have been reading a chapter at a time at random since. Each chapter deals with a single topic (e.g. Threads) and consists of roughly 25 pages. This is an excellent organisation: it lets you completely understand one area at a time in manageable chunks. Its 64 chapters are spread across 1500 pages, giving it unprecedented breadth and depth.&lt;br /&gt;&lt;br /&gt;Technical books are difficult to write. The subject matter can be dry and the terminology makes sentences verbose and difficult to parse. In addition, there is a problem of target audience. You can assume the reader knows too much, making the book inaccessible. Or you could assume too little, and require the reader to go through trivial material that they already know. In addition, technical books are often read with a purpose in mind. They need to answer the question, "How do I do X in Linux" in minimum time. Remarkably, this book does well along all these dimensions. It is a case study in pleasant, lucid writing.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XtLEj2buzYI/TlxYXD81i2I/AAAAAAAAARw/GqoEIrnGQxI/s1600/tlpi.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-XtLEj2buzYI/TlxYXD81i2I/AAAAAAAAARw/GqoEIrnGQxI/s320/tlpi.png" width="242" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If you do anything with Linux, and have ever programmed in Linux, get a copy now. Keep it on your shelf, and leaf through it when you are bored. You will enjoy the book, and learn more about Linux while doing so.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5842643670002824631?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5842643670002824631/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/linux-programming-interface-beautifully.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5842643670002824631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5842643670002824631'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/linux-programming-interface-beautifully.html' title='The Linux Programming Interface: a beautifully written technical book'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-XtLEj2buzYI/TlxYXD81i2I/AAAAAAAAARw/GqoEIrnGQxI/s72-c/tlpi.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7086227671620548048</id><published>2011-08-28T20:55:00.000-07:00</published><updated>2011-08-28T21:00:36.335-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Be more productive at work</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I have learned a few things about enhancing my productivity over the past few years, by observing my own productivity at work. These rules should work for anyone whose work requires concentration, creativity and thought.&lt;br /&gt;&lt;br /&gt;Here goes:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Get a &lt;b&gt;quiet room&lt;/b&gt;. If your job requires thinking of any kind, it needs to happen in a quiet place. In case you cannot get a quiet room, invest in a pair of good earplugs. I recommend the &lt;a href="http://www.amazon.com/Howard-Leight-Laser-Earplugs-Cords/dp/B0007XJOLG/ref=sr_1_10?ie=UTF8&amp;amp;qid=1314583952&amp;amp;sr=8-10"&gt;Howard Leight Laser Light&lt;/a&gt; earplugs. At $20 for 200 pairs, it is a steal. If you do get a box, hand them out to your co-workers to improve the entire team's productivity. Even if you think that a noisy room works for you, try out a pair of earplugs first. Chances are that you, like most of humanity, will prefer a quiet room. If you work in an enclosed office: you are lucky! Consider submitting &lt;a href="http://vikram.eggwall.com/static/vikram.pdf"&gt;my resume&lt;/a&gt; to your recruiters.&lt;/li&gt;&lt;li&gt;&lt;b&gt;No distractions&lt;/b&gt;. This is essential to keep you &lt;a href="http://en.wikipedia.org/wiki/Flow_%28psychology%29"&gt;in flow&lt;/a&gt;. What works for me is to wear my earplugs and display a sheet of paper that says, "Do not disturb". Yes, you look like a douche-bag and you feel anti-social, but the feeling quickly passes. Additionally, you can indicate that if people drop you an email, you will go by their desk when they are free. This reduces the chances of people mistaking you for a self-important jerk. Apologise in advance, and mention what you are working on. I use an IM status like this  "Do not Disturb. Need to finish Project Wallaby. Please email. Apologies :(" I also block off time on my calendar to focus on a single activity. This reduces the chance of someone scheduling you for a meeting when you're in the middle of a task.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Respect people's time&lt;/b&gt;. Meeting with people is essential. I choose to meet people in their office at a scheduled time. When I do meet someone, I avoid checking  email, and I avoid looking at my phone. If someone is spending time with you, respect their time in addition to yours. Ditto for meetings. If you are checking mail in a meeting: you should consider avoiding the meeting entirely.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Stop when done&lt;/b&gt;. I usually set a goal and try to finish the activity as soon as possible. When I am done, I stop and take a break. This is essential to getting a feeling of accomplishment. Plodding through the day is much easier if you get regular shots of satisfaction. Break up work into 2-3 hour chunks, and try to finish a task before allowing yourself to be distracted. Over time, you'll find that your productivity improves, so adjust your expectations. Once you are done, go for a short walk, or look outside. Give yourself some time to relax before tackling the next objective.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Beat inertia with a trivial task.&lt;/b&gt; I find it much easier to get back into work if I have something trivial that I can hammer out early. This could be a simple bug or a trivial feature. This allows you to get in the mode of work with minimal hassle and beats inertia.&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;b&gt;H&lt;/b&gt;&lt;b&gt;ardest job first&lt;/b&gt;. Once you have beaten inertia, go for the hardest task of the day. Concentration, focus, and decision-making are their best in the morning after a full night of rest. Once you've done the hardest task, you have the added benefit of knowing that the remaining day is easy.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Full night's sleep&lt;/b&gt;. &lt;a href="http://www.webmd.com/sleep-disorders/news/20030314/sleep-deprivation-leads-to-trouble-fast"&gt;Research suggests&lt;/a&gt; that a full night's sleep is critical to improving your concentration. If you are constantly tired at work, napping might help. Many managers frown upon napping, so exercise caution if you need to go down this route.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Love your work&lt;/b&gt;. It is easy to work hard at something when work is fun. It might be too late to change jobs, but try to find interesting projects and interesting people to work with. My productivity is  high when I work with peers whom I respect and from whom I can learn.&lt;/li&gt;&lt;/ol&gt;This wisdom is from personal experience, good books like "&lt;a href="http://www.amazon.com/Peopleware-Productive-Projects-Teams-Second/dp/0932633439"&gt;Peopleware&lt;/a&gt;" and "&lt;a href="http://www.amazon.com/Mythical-Man-Month-Software-Engineering-Anniversary/dp/0201835959/ref=pd_sim_b_1"&gt;The Mythical Man Month&lt;/a&gt;", &lt;a href="http://www.youtube.com/watch?v=oTugjssqOT0"&gt;Randy Pausch's talk&lt;/a&gt;, and many online resources.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-yfNEjviEs6A/TlsCvFu6eaI/AAAAAAAAARs/8Jhxu_YBhx4/s1600/ninja.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-yfNEjviEs6A/TlsCvFu6eaI/AAAAAAAAARs/8Jhxu_YBhx4/s1600/ninja.jpeg" /&gt;&lt;/a&gt;&lt;/div&gt;Many activities at home require concentration and focus, and work is no different. At home, I love reading a book or playing with computers. I think of the atmosphere that allows me to enjoy my home activities and I try to recreate the same atmosphere at work. You might consider trying&amp;nbsp;something&amp;nbsp;similar. Find an activity you love, and identify what atmosphere allows you to enjoy that activity completely. A similar atomsphere at work might help improve your productivity.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7086227671620548048?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7086227671620548048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/be-more-productive-at-work.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7086227671620548048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7086227671620548048'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/be-more-productive-at-work.html' title='Be more productive at work'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-yfNEjviEs6A/TlsCvFu6eaI/AAAAAAAAARs/8Jhxu_YBhx4/s72-c/ninja.jpeg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-1012369103373088933</id><published>2011-08-19T18:23:00.000-07:00</published><updated>2011-08-19T18:23:49.711-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Why software patents lead to poor usability</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I'm a big fan of usability. I think that usability is the next goal, not features. &lt;a href="http://www.eggwall.com/2011/07/age-of-technology-age-of-interface.html"&gt;Products are being distinguished based on how usable they are, rather than how many features they have&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In the physical world, usability is improved by&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Making the underlying process visible. An example is a small light that glows when a device is turned on. Glowing lights indicate that electricity is flowing through the device, which suggests that now the device is on.&lt;/li&gt;&lt;li&gt;Improving the mapping between the action and the object that causes the action. Switches have only two positions: on and off, corresponding to the two states of a lamp. Volume controls are dials that you rotate indicating a range of possibilities. Doors have handles that indicate which direction they can be pulled.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Good interfaces in the physical world rely on making the system clear to the user. When interfaces don't follow any logic, they have been standardised: all cars have driving controls in very similar locations.&lt;br /&gt;&lt;br /&gt;Computer usability is somewhat arbitrary, though. There is no real-world analogue for a menu-bar, or a right click, or a context menu. There is no real-world analogue for task-switching. The pioneers in computer design could adapt some real-world objects as metaphors for computing actions. Thus the pervasive 'desktop' metaphor for objects on the computer, even though it now has nothing to do with a real desktop. But metaphors are rare and  much of the interface was incidental and arbitrary. Like the use of the QWERTY keyboard for all English-language computers, and the arbitrary position of the menu bar (top of the window) and the status bar (bottom of the window).&lt;br /&gt;&lt;br /&gt;When usability cannot follow any logic, the easiest solution is to standardise. In his book, &lt;a href="http://en.wikipedia.org/wiki/Donald_Norman#User-centered_design"&gt;"The Design of Everyday Things", Donald Norman&lt;/a&gt; shows how the design of a wall clock is arbitrary and illogical. But around the world, every wall clock looks identical, which allows you to read a clock. The placement of the accelerator and brake pedals, and the control sticks on the car is similarly illogical. There is no good reason for the wiper control to lie to the right, and the light control to lie to the left of the steering wheel. But every car seems to follow this. The result is a breathtaking advance in usability. You can rent a Toyota Sienna or step into a Ford Focus and drive it without any instruction. Once you know one car, you can drive nearly every car.&lt;br /&gt;&lt;br /&gt;Computers aren't like that, here are the trash bins from Windows and Mac OS:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-UM_CCkyD70E/Tk77djQGvSI/AAAAAAAAARo/qdcXfboWYu4/s1600/ui.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="206" src="http://3.bp.blogspot.com/-UM_CCkyD70E/Tk77djQGvSI/AAAAAAAAARo/qdcXfboWYu4/s400/ui.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;They  both look pretty similar, but not exactly. A user who has been seeing a  clear glass recycle bin will look for something similar on OS X. It  takes some time to identify these similar features and their related mappings: 'Recycle bin' versus 'Trash can'. Trash cans are just the start of it. Computer systems differ along all these characteristics: the placement and position of the menu, the types of icons, the keyboard behaviours. Even turning off a computer has no agreement. Some computers have a physical off button on the keyboard, some have an icon on the top right, some have menu items. Software to perform the same action looks very different on different systems.&lt;br /&gt;&lt;br /&gt;Where computers have standardised, it has been a success. Computers all  use the same keyboard and mouse, thankfully. And some keystrokes  (Ctrl-C, Ctrl-V) are common across platforms and programs.&lt;br /&gt;&lt;br /&gt;The reason why software cannot look identical across products is due to software look-and-feel patents. Look-and-feel patents allow the patent holder to maintain exclusive right to how a user interface looks. A good example is the &lt;a href="http://www.appleinsider.com/articles/11/04/18/apple_sues_samsung_for_allegedly_copying_look_and_feel_of_iphone_ipad.html"&gt;recent patent litigation on a phone's look and feel&lt;/a&gt;. These patents have been around for a while now. So has the resulting litigation. Patents of this nature disallow someone from providing a similar look-and-feel of an established product, which makes it impossible to standardise on an interface.&lt;br /&gt;&lt;br /&gt;As a result, consumers have to deal with the explosion of interfaces. Using a new phone is much harder than using a new car!&lt;br /&gt;&lt;br /&gt;I don't want to highlight just one company: many companies are involved in this. Such litigation has existed for quite some time now. One of the early lawsuits between &lt;a href="http://en.wikipedia.org/wiki/Apple_Computer,_Inc._v._Microsoft_Corporation"&gt;Apple and Microsoft about the look-and-feel of the Windows system was filed in 1988&lt;/a&gt;. As a result, Windows could not look similar to Mac OS. Windows developed its features in isolation, which Mac users had to painfully adapt to when they switched to Windows. Many years later, Apple developed the popular OS X operating system and many users switched from Windows to Mac OS, they had to painfully learn the new interface.&lt;br /&gt;&lt;br /&gt;Innovation is key to generating new products, though radical innovation in the interface is harmful rather than helpful. Cars have had the same control mechanism for many years now. Yet they have had some  innovation within the confines of the interface. Cars are more comfortable, safer, and consume less fuel than those in 1960. Yet, you could probably step into a car from 1960 and drive it.&lt;br /&gt;&lt;br /&gt;While computers have become faster and more capable, they have not made much advance in standardising interfaces. New systems have their own bewildering interface that require learning. People dislike upgrading because they will have to learn the new interface to perform the same actions that they used to perform earlier.&lt;br /&gt;&lt;br /&gt;It is our responsibility as users to demand consistent interfaces. We can buy a new car and can safely transfer all our driving knowledge to it. We should be able to buy a new computer and be productive with it right away.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-1012369103373088933?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/1012369103373088933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/why-software-patents-lead-to-poor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1012369103373088933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1012369103373088933'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/why-software-patents-lead-to-poor.html' title='Why software patents lead to poor usability'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-UM_CCkyD70E/Tk77djQGvSI/AAAAAAAAARo/qdcXfboWYu4/s72-c/ui.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-9064037854333422793</id><published>2011-08-16T20:26:00.000-07:00</published><updated>2011-08-16T22:45:11.581-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>1 Watt webserver</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I recently bought a &lt;a href="http://en.wikipedia.org/wiki/Zipit_Wireless_Messenger_%28Z2%29"&gt;Zipit 2&lt;/a&gt; from an online store. It is a tiny device with an ARM CPU (XScale-PXA270) with 32MB of RAM, an SD card slot, and 802.11 networking. The device cost me $30 including shipping, which is a cheap price for the computing potential. My goal was to run Linux on it, and learn the ARM instruction set. There are many Linux distributions for the Z2, and I found &lt;a href="http://mozzwald.com/z2sid"&gt;Debian on the Z2&lt;/a&gt; to be perfect. The device is small, light and fits in the pocket of my jeans. Its battery lasts four hours when the screen is on.&lt;br /&gt;&lt;br /&gt;Installing Linux on it was trivial: you &lt;a href="http://russelldavis.org/2011/02/13/flashstock-v0-1/"&gt;flash a custom bootloader using FlashStock&lt;/a&gt;. This loads a new kernel on the small flash partition on the device, and it gives you the ability to boot from an SD card. Then, you download a Linux distribution for the z2 (I chose &lt;a href="http://mozzwald.com/z2sid"&gt;z2sid&lt;/a&gt;), copy the image to the SD card (using a raw copy tool like dd) and boot from it. I have an 8GB SD card in the Zipit. This Z2 is better than my first Pentium computer along every single dimension except screen size.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-X9Rtor4vZ9Y/TksqhKNyn7I/AAAAAAAAARc/SL0wX3zCOnw/s1600/IMG_20110816_193432.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-X9Rtor4vZ9Y/TksqhKNyn7I/AAAAAAAAARc/SL0wX3zCOnw/s400/IMG_20110816_193432.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Once Debian is installed on the Zipit, you have access to the 'apt-get' package management tool. After installing &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;vim&lt;/span&gt;, &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;gcc&lt;/span&gt;, &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;make&lt;/span&gt;, it turned into a fully functioning ARM development system. I did not want to type using the tiny keyboard, which is uncomfortable and lacks important keys. So I installed an ssh server called &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;dropbear&lt;/span&gt;. Now I can remotely log in to the device, copy files back and forth, and use it for development.&lt;br /&gt;&lt;br /&gt;Once it was set up, I wondered if I can serve web pages from it. After installing a webserver called &lt;a href="http://nginx.net/" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nginx&lt;/a&gt;, the zipit holds up very well. I'm serving three virtual hosts externally from it, and two  hosts internally. For a small amount of traffic, this is the perfect device.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Power consumption &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With the screen turned on, the Zipit consumes less than 2 watts of power. When the lid is shut, the screen turns off and power consumption drops to 1 watt. By comparison, a typical laptop consumes 30 Watts and a typical desktop consumes 100 watts. The device is dead silent and cold to the touch. Due to the low power consumption, it generates  no perceptible heat. You can leave it in the corner of a cramped closet, and it will chug away. Silently.&lt;br /&gt;&lt;br /&gt;There is a lot of potential in these low-power devices called &lt;a href="http://en.wikipedia.org/wiki/Plug_computer"&gt;plug computers&lt;/a&gt;. Plug computers and mobile devices have caused a resurgence of ARM processors due to their low power consumption. With improvements in processor technology, an entry-level ARM CPU can handle  tasks reserved for a "real" computer. Web serving, file serving and ssh-login don't require a beefy processor.&amp;nbsp; Rather than maintain a full computer, you can purchase a small, silent, and low-footprint computer to handle these tasks for you. Once it is set up, you can store it in a closet somewhere, completely out of sight. Low power consumption allows the device to run exclusively on solar power.&lt;br /&gt;&lt;br /&gt;You could use it as an entry point to a home network. Once the SD card is copied to a desktop, you can recover from a malicious attack by copying a known-good image back onto the card.&lt;br /&gt;&lt;br /&gt;Low-power computing holds a lot of promise. In the developed world, it can be used instead of power-hungry computers for routine tasks. In the developing world, it can be the first computer for a family.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-9064037854333422793?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/9064037854333422793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/1-watt-webserver.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9064037854333422793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9064037854333422793'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/1-watt-webserver.html' title='1 Watt webserver'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-X9Rtor4vZ9Y/TksqhKNyn7I/AAAAAAAAARc/SL0wX3zCOnw/s72-c/IMG_20110816_193432.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7373212865817047788</id><published>2011-08-10T21:00:00.000-07:00</published><updated>2011-08-10T21:56:05.977-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>The importance of staying mentally agile</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I am a software engineer, and I get paid to write software and design software systems. In my spare time I write other code: Arduino and microcontroller code and Android code for my phone. Over the past few days, I have been modifying my site's CSS and HTML to ensure it looks just right. Forget just right, I wanted it to look darn near perfect, even if it meant knowing everything about CSS layout.&lt;br /&gt;&lt;br /&gt;After a few days of not writing software or constructing anything, I get itchy. At the very least, I find reading technical documentation and learning about the innards of systems very liberating.&lt;br /&gt;&lt;br /&gt;I didn't understand why this is so until I was discussing mental agility with a friend. He mentioned that, in his job, he felt his skills were wasting away. He felt that he was getting slower. He thought he was taking longer to learn new systems. After this discussion, I realised that I am scared of losing mental agility. A lot of my home-hacking is done for fun: I love playing with an Arduino and electronics. But I suspect that deep down, I am also motivated by a fear of slowing down. I don't want to reach a point when I cannot learn something new, because my livelihood depends on learning new things quickly and in sufficient detail.&lt;br /&gt;&lt;br /&gt;Intelligence is more than just mental agility.&amp;nbsp;Intelligence includes quick learning, and also requires good communication and abstract thought.&amp;nbsp; But the ability to quickly learn a new area is&amp;nbsp;critical. &amp;nbsp;Even if I wasn't an engineer, I would be working in a profession that required quick mental thinking. &amp;nbsp;Learning an arcane instruction set won't make me smarter (more intelligent). However, I will get the mental rush of learning something new. And I'll know that I have the mental agility to learn something new to sufficient depth. In the future when I'm required to learn something completely new, I will be prepared for it.&lt;br /&gt;&lt;br /&gt;In the case of my friend, his fears are unfounded. The guy is a  talented engineer and a quick learner. He is certainly faster than I am at learning new things.&lt;br /&gt;&lt;br /&gt;Ironically, the people who are worried about slowing down are the ones that never slow down. They drive harder,  keep picking up new skills and keep sharpening their powers of learning.&lt;br /&gt;&lt;br /&gt;The people slowing down are the ones that aren't worried about slowing down. If you're worried about slowing down: you're probably doing fine.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-RXy-POJEF8o/TkNS1a3HbjI/AAAAAAAAARQ/xGsGNfTRTk0/s1600/agility.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-RXy-POJEF8o/TkNS1a3HbjI/AAAAAAAAARQ/xGsGNfTRTk0/s200/agility.jpg" width="132" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7373212865817047788?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7373212865817047788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/importance-of-staying-mentally-agile.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7373212865817047788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7373212865817047788'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/importance-of-staying-mentally-agile.html' title='The importance of staying mentally agile'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-RXy-POJEF8o/TkNS1a3HbjI/AAAAAAAAARQ/xGsGNfTRTk0/s72-c/agility.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8164739559842856789</id><published>2011-08-07T16:18:00.000-07:00</published><updated>2011-08-28T11:19:47.128-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Beautiful, professional resumes with LaTeX</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I love &lt;a href="http://en.wikipedia.org/wiki/LaTeX"&gt;LaTeX&lt;/a&gt;, but when it comes to resume writing, my skills at LaTeX fall short. This means that I have to load up OpenOffice, and spend hours tuning every single spacing and pagination problem.&lt;br /&gt;&lt;br /&gt;Enter &lt;a href="http://www.ctan.org/tex-archive/macros/latex/contrib/moderncv/"&gt;Moderncv, a class file for professional looking resumes&lt;/a&gt;. If you use LaTeX, it is the perfect document class for writing a resume.&lt;br /&gt;&lt;br /&gt;This is what &lt;a href="http://vikram.eggwall.com/static/vikram.pdf"&gt;my resume&lt;/a&gt; looks like:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-dzU29e7p08I/Tj8b2RL5egI/AAAAAAAAAQw/jwREqXc58VY/s1600/resume.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-dzU29e7p08I/Tj8b2RL5egI/AAAAAAAAAQw/jwREqXc58VY/s640/resume.png" width="454" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;You can download the &lt;a href="http://vikram.eggwall.com/static/vikram.pdf"&gt;resume in PDF&lt;/a&gt;. This resume was generated from &lt;a href="http://www.mediafire.com/file/25dwg2o4q7i5r5d/vikram.tex"&gt;this LaTeX source file&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The moderncv class is straightforward: you fill in the details and it generates a beautiful, professional resume for you. Once you fill in the critical details, the page layout is handled for you. So if one section is too big it is automatically shifted to the next page. You fill in the contents, LaTeX handles the rest.&lt;br /&gt;&lt;br /&gt;Itching to give it a try? To get started, download the &lt;a href="http://www.ctan.org/tex-archive/macros/latex/contrib/moderncv/"&gt;moderncv class from CTAN&lt;/a&gt;. Either use my resume as an example, or look through the examples directory for a file called '&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;template.tex&lt;/span&gt;'. On Ubuntu, you need the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;texlive&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;texlive-latex-extra&lt;/span&gt; packages.&lt;br /&gt;&lt;br /&gt;On Ubuntu or Debian machines, you can download all the packages with:&lt;br /&gt;&lt;pre&gt;$ &lt;span style="color: #006600;"&gt;sudo apt-get install texlive texlive-latex-extra&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&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/19163975-8164739559842856789?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8164739559842856789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/beautiful-professional-resumes-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8164739559842856789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8164739559842856789'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/beautiful-professional-resumes-with.html' title='Beautiful, professional resumes with LaTeX'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-dzU29e7p08I/Tj8b2RL5egI/AAAAAAAAAQw/jwREqXc58VY/s72-c/resume.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7329657283933492987</id><published>2011-08-07T07:37:00.000-07:00</published><updated>2011-08-07T09:23:34.937-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Lego NXT Mindstorm with Linux</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There  is a  lot  of documentation  on  the NXT  and  Linux on  the Internet.  A lot of it is very good, like this &lt;a href="http://bricxcc.sourceforge.net/nbc/doc/nxtlinux.txt"&gt;page showing Linux setup with NXT&lt;/a&gt;.  Unfortunately it is scattered all over  the place, making  it difficult  for a  complete newbie  to make headway with the Lego Mindstorms on Linux.  This page links to the major steps and will enable you to set up Linux-Mindstorms communication and the programming environment.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Why Linux?&lt;/h3&gt;Linux is better suited for Lego programming. It is essential if you have a  Linux machine, and don't  want to install Windows (or  MacOS) just for using the Mindstorm.  But the advantages  of Linux go beyond that.  Linux is a great programming environment, and interfacing it with  Mindstorms allows you  to  connect it to  other devices.   Linux machines have  a  good programming  interface  for  Bluetooth, GPS,  networking through  the  Internet,  sound,  display, and large-scale processing.&amp;nbsp; Connecting the NXT to a Linux device opens  up a lot of possibilities.&lt;br /&gt;&lt;br /&gt;Also, many       &lt;a href="http://en.wikipedia.org/wiki/Netbook"&gt;netbook computers&lt;/a&gt; are ideal robot  building blocks: they are  small, light and lack fragile  spinning  disks.   Linux is space efficient, and runs well on these devices.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Journey&lt;/h3&gt;These are the steps you need to be completely up and running with Linux and the NXT.   These pages are listed in order, and each page builds upon the previous work. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/2011/07/setting-up-nxt-bluetooth-support-on.html"&gt;Setting up the Linux-NXT Bluetooth connection&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/2011/07/setting-up-lego-programming-environment.html"&gt;Setting up the Linux-NXT NXC programming environment&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/2011/07/programming-nxt-to-communicate-with.html"&gt;Writing a program that demonstrates NXT Robot-Linux communication over Bluetooth&amp;nbsp;&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;With a little bit of setup, you can combine the flexibility and design of the Mindstorms with the power of Linux.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-6QSYih5w7ss/Tj6ijkR51zI/AAAAAAAAAQo/o-Zf1LDEElk/s1600/tux.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-6QSYih5w7ss/Tj6ijkR51zI/AAAAAAAAAQo/o-Zf1LDEElk/s320/tux.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7329657283933492987?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7329657283933492987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/lego-nxt-mindstorm-with-linux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7329657283933492987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7329657283933492987'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/lego-nxt-mindstorm-with-linux.html' title='Lego NXT Mindstorm with Linux'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-6QSYih5w7ss/Tj6ijkR51zI/AAAAAAAAAQo/o-Zf1LDEElk/s72-c/tux.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-4296885849576358721</id><published>2011-08-06T22:23:00.000-07:00</published><updated>2011-08-06T22:23:22.666-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>Alternate ways of viewing this site</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This site is hosted on Blogger, which allows alternate views on the same content. Here are some views you can try:&lt;br /&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/view/sidebar"&gt;Sidebar&lt;/a&gt;&amp;nbsp;view: the content takes the entire screen. The list of posts is in a left bar which is good for small laptop screens. This is my favorite alternate view.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/view/flipcard"&gt;Flipcard&lt;/a&gt;&amp;nbsp;view: all posts appear as two-sided cards. Clicking on the card takes you to the post. The top navigation allows different sorting methods.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/view/snapshot"&gt;Snapshot&lt;/a&gt;&amp;nbsp;view: all posts appear as instant-camera snapshots.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/view/timeslide"&gt;Timeslide&lt;/a&gt;&amp;nbsp;view: for seeing the entire site arranged by time with recent posts on the top.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;These views allow you to explore the blog in a more flexible way than traditional page views.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-hRkNYK9v4K0/Tj4gU-92n0I/AAAAAAAAAQk/sxNr4u0_gpg/s1600/simplicity.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="212" src="http://3.bp.blogspot.com/-hRkNYK9v4K0/Tj4gU-92n0I/AAAAAAAAAQk/sxNr4u0_gpg/s320/simplicity.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-4296885849576358721?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/4296885849576358721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/alternate-ways-of-viewing-this-site.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4296885849576358721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4296885849576358721'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/alternate-ways-of-viewing-this-site.html' title='Alternate ways of viewing this site'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-hRkNYK9v4K0/Tj4gU-92n0I/AAAAAAAAAQk/sxNr4u0_gpg/s72-c/simplicity.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-351753187282084226</id><published>2011-08-05T23:09:00.000-07:00</published><updated>2011-08-06T17:59:21.990-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>What to look for in a manager</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;After having worked with a few people, I have narrowed down the skills needed by a technical manager down to two qualities.&amp;nbsp;While these are observations from software engineering and business analysis, the lessons hold for other technical professions. Here are the two qualities.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;b&gt;Provide creative space&lt;/b&gt;. This is essential for technical areas like software development where creativity and risk-taking are essential. After confirming a general direction, the manager should be willing to let the employee explore and learn from mistakes. An excessive amount of top-down direction is frustrating and demeaning to a capable employee. This requires &lt;a href="http://www.eggwall.com/2011/04/technical-skill-in-engineering-managers.html"&gt;technical skill in the manager&lt;/a&gt;, so he can set general direction and realize the amount of work involved. &amp;nbsp;Providing creative space also means ensuring that the employee has a distraction-free atmosphere, and meetings are kept to a minimum.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;Without the freedom to make mistakes, a technical employee feels bored, demotivated, and does all his creative work elsewhere (at home, or with friends).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reward technical achievement&lt;/b&gt;. Many projects look deceptively simple from the outside, but require significant work to be successful. A person who ensures that technical work gets rewarded makes an excellent manager. This is critical when the employee's achievement might not yield immediate benefit: large-scale re-factoring of code leads to immense long-term gains and short-term discomfort. Therefore, strong managers understand the benefit of code hygiene and reward engineers for improving the quality of the system. &lt;br /&gt;&lt;br /&gt;Without recognition for hard work, employees settle for low-risk high-visibility projects. Over time, challenging technical work dries up, since nobody is willing to solve real problems. Once this happens, the team loses the ability to hire fresh talent, because they have no interesting projects. Also, a manager who either cannot recognize technical achievement or does not spend time rewarding achievement is seen as spineless. Such a manager quickly loses respect among skilled engineers.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the best teams, recognition flows downward and blame flows upward. A good manager shields a well-functioning team from missed deadlines and temporary failure. And when things work, he highlights individual engineers for their contributions and ensures recognition for them. Sounds too good to be true? Managers like this do exist.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Truly exceptional managers inspire confidence and motivate their employees. Work is fun because employees are interested in the problems they are solving.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You can judge a team's technical manager approximately by assessing two things.&lt;br /&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Quality of technical work: quality of code, and challenge in existing projects. Excellent technical work speaks for itself. It shows that the team values technical achievement and rewards it.&lt;/li&gt;&lt;li&gt;Amount of time employees spend dealing with fluff: number of hours spent in non-technical meetings is a great estimate. Any manager who frees his employees' time values their time and their contribution.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-fC4aR657oIM/TjzTElZntxI/AAAAAAAAAQM/fa-sQu6v9KU/s1600/leader.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-fC4aR657oIM/TjzTElZntxI/AAAAAAAAAQM/fa-sQu6v9KU/s320/leader.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-351753187282084226?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/351753187282084226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/08/what-to-look-for-in-manager.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/351753187282084226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/351753187282084226'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/08/what-to-look-for-in-manager.html' title='What to look for in a manager'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-fC4aR657oIM/TjzTElZntxI/AAAAAAAAAQM/fa-sQu6v9KU/s72-c/leader.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-7367807351202615046</id><published>2011-07-31T10:35:00.000-07:00</published><updated>2011-07-31T10:35:29.790-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>The age of technology? The age of the interface</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;When computers were new, they were capable of doing things that were labor intensive: calculating payroll, accounting and billing. People who were able to buy computers were also the people who could spend hours learning them. Early hackers were also engineers, or at least bored students with lots of free time who were happy to learn the minutiae of the system. They were happy to go through large volumes of programming manuals, datasheets. The rewards were rich: you got to be the master of a computing machine that did exactly what was told. Products at this time competed on features alone: new features might have been cumbersome to learn, but the customers didn't mind.&lt;br /&gt;&lt;br /&gt;That was the age of technology, and we aren't in it any more.&lt;br /&gt;&lt;br /&gt;Now, we're in the age of the interface. In the past few years, we have seen the rise of great products which aren't competing on feature-set alone. The iPhone is a perfect example of this: in functionality alone it was comparable to other devices in the market. What made it appealing was its ease-of-use, it's computer interface. The daily interaction with the device were much better than other cell-phones, and that convinced users to switch. I see this trend in many areas.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://arduino.cc/"&gt;Arduino&lt;/a&gt; is a microcontroller board and development software that allows you to attach physical objects to computers. The underlying microprocessor is made by Atmel, and it has been around for a lot of years. Arduino's contribution is to package the hardware and software in an easy-to-use, accessible package. You &lt;a href="http://www.google.com/search?client=ubuntu&amp;amp;channel=fs&amp;amp;q=arduino+uno&amp;amp;ie=utf-8&amp;amp;oe=utf-8#q=arduino+uno&amp;amp;hl=en&amp;amp;client=ubuntu&amp;amp;hs=PaF&amp;amp;channel=fs&amp;amp;prmd=ivnsr&amp;amp;source=univ&amp;amp;tbm=shop&amp;amp;tbo=u&amp;amp;sa=X&amp;amp;ei=_og1TqXfEcfjiAKXwv2vCA&amp;amp;ved=0CGoQrQQ&amp;amp;bav=on.2,or.r_gc.r_pw.&amp;amp;fp=e951f071ae6d2807&amp;amp;biw=1540&amp;amp;bih=887"&gt;buy the microcontroller board&lt;/a&gt;, download their &lt;a href="http://arduino.cc/en/Main/Software"&gt;free development software&lt;/a&gt;, and can have a programming running within minutes. Arduino makes it trivial to try out microcontroller hacking, and it has led to an explosion in creative hardware hacking. Arduino programs are called 'sketches' and the software makes it easy to share your sketches with others.&lt;/li&gt;&lt;li&gt;&lt;a href="http://processing.org/"&gt;Processing&lt;/a&gt; is a programming environment that makes it easy to visualize data. Processing is built on Java, and is much easier to learn than Java. Arduino and Processing are very similar. With Processing too, you &lt;a href="http://processing.org/download/"&gt;download free software&lt;/a&gt; which runs on all platforms. It allows for fast programming: a child can start programming graphics routines within minutes. Processing makes easy tasks trivial and hard tasks possible, all without having to teach a person the nuances of programming. Processing code compiles into four different programs: one each for Windows, Mac, Linux, and a Java applet. Processing also has an Android mode that allows you to run your processing code directly on an Android device.&lt;/li&gt;&lt;li&gt;&lt;a href="http://fritzing.org/"&gt;Fritzing&lt;/a&gt; is a development tool for electronic circuits. You can design the circuit as an physical layout (with bread-board, wires and components), or as a schematic diagram (big boxes rather than pictures). It does a splendid job of making hardware traces that can then be used to fabricate Printed Circuit Boards. Also, you can share your projects with other people by giving them a copy of your .fzz file. Fritizing makes it easy for a student to design a circuit board and have it mass-produced.&lt;/li&gt;&lt;/ol&gt;All these projects make it easy for a newbie to get started. They all provide software for Linux, Mac, and Windows, and they all make it easy to share your creation with the world. This has resulted in many more people getting involved with electronics and software hacking. It has opened this world up to people who were unwilling to read through thick programming manuals.&lt;br /&gt;&lt;br /&gt;People are no longer interested in feature-sets. The feature world has been saturated: people who care for spreadsheet features already have all the  features in their spreadsheet. Now, the goal is to make a spreadsheet that is accessible to the rest of the population.&lt;br /&gt;&lt;br /&gt;Fewer features, ease of use, and excellent design. Software engineers are learning that good products are easy to use and well designed rather than a random collection of good features. &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-NyyEMN8r0Yw/TjWQPm8XUNI/AAAAAAAAAQE/8eGUI3QQgvM/s1600/toolbars.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-NyyEMN8r0Yw/TjWQPm8XUNI/AAAAAAAAAQE/8eGUI3QQgvM/s1600/toolbars.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;Image courtesy &lt;a href="http://www.codinghorror.com/blog/2006/02/sometimes-a-word-is-worth-a-thousand-icons.html"&gt;Jeff Atwood&lt;/a&gt;.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-7367807351202615046?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/7367807351202615046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/age-of-technology-age-of-interface.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7367807351202615046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/7367807351202615046'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/age-of-technology-age-of-interface.html' title='The age of technology? The age of the interface'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-NyyEMN8r0Yw/TjWQPm8XUNI/AAAAAAAAAQE/8eGUI3QQgvM/s72-c/toolbars.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-9150491291337890515</id><published>2011-07-30T11:37:00.000-07:00</published><updated>2011-07-30T11:43:14.857-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>GPS datalogger with Arduino and SD card</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I recently finished making a GPS datalogger with an Arduino, a micro-SD card, and an old USB GPS unit. It continuously logs the position from a GPS unit to an SD card.&lt;br /&gt;&lt;br /&gt;The connections are trivial with a 3.3V Arduino, since the micro-SD card has an SPI interface which the ATmega328 supports natively. I used a SiRF GPS unit, which outputs NMEA sentences at 4800bps. This was connected directly to the serial pins on the Arduino. With a 2GB SD card, we can log everything that the GPS outputs for well over a year, so I didn't bother filtering the GPS output.&lt;br /&gt;&lt;br /&gt;The bill of materials is:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;3.3V Arduino, or appropriate level shifters for the SD card&lt;/li&gt;&lt;li&gt;GPS unit with a serial interface&lt;/li&gt;&lt;li&gt;SD card or micro-SD card slot and memory card&lt;/li&gt;&lt;li&gt;Some power source: car 12V plug, or USB, 9V battery&lt;/li&gt;&lt;/ol&gt;You can &lt;a href="http://www.mediafire.com/file/mi7qaxxjcwby8bd/GPSlogger.fzz"&gt;download the entire GPS datalogger Fritzing project&lt;/a&gt;. The connections and the schematic are shown below:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.mediafire.com/imgbnc.php/7ece3d6ecadf8e4e3014f0456174fb264139b9551b9f6201ae9110a13b994fa96g.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="242" src="http://3.bp.blogspot.com/-n2G5HdNRHGE/TjRJiL6eOVI/AAAAAAAAAP4/OJoGubn7A5w/s320/GPSlogger_bb.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.mediafire.com/imgbnc.php/a4f758c3f4d5578f7dd7f458ca9c36b1c15f961fd4fc75dda464083a3aacfe2f6g.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="223" src="http://1.bp.blogspot.com/-afuAo5vY5Kg/TjRJimq7OyI/AAAAAAAAAP8/3rDqjF7uiYs/s320/GPSlogger_schem.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The associated Arduino program is trivial:&lt;br /&gt;&lt;pre&gt;#include&amp;nbsp;&lt;span style="color: #006699;"&gt;"FileLogger.h"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;#define&amp;nbsp;HEADER&amp;nbsp;&lt;span style="color: #006699;"&gt;"Starting GPS logging.\r\n"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;unsigned&lt;/span&gt; &lt;span style="color: #cc6600;"&gt;long&lt;/span&gt; header_length = sizeof(HEADER)-1;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;byte&lt;/span&gt; header[] = HEADER;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;unsigned&lt;/span&gt; &lt;span style="color: #cc6600;"&gt;long&lt;/span&gt; data_length;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;byte&lt;/span&gt; gpsdata[128];&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;void&lt;/span&gt; &lt;span style="color: #cc6600;"&gt;&lt;b&gt;setup&lt;/b&gt;&lt;/span&gt;(&lt;span style="color: #cc6600;"&gt;void&lt;/span&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #cc6600;"&gt;&lt;b&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style="color: #cc6600;"&gt;begin&lt;/span&gt;(4800);&lt;br /&gt;&amp;nbsp;&amp;nbsp;FileLogger::append(&lt;span style="color: #006699;"&gt;"data.log"&lt;/span&gt;, header, header_length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;data_length&amp;nbsp;=&amp;nbsp;0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6600;"&gt;void&lt;/span&gt; &lt;span style="color: #cc6600;"&gt;&lt;b&gt;loop&lt;/b&gt;&lt;/span&gt;(&lt;span style="color: #cc6600;"&gt;void&lt;/span&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #cc6600;"&gt;if&lt;/span&gt; (&lt;span style="color: #cc6600;"&gt;&lt;b&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style="color: #cc6600;"&gt;available&lt;/span&gt;() &amp;gt; 0) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gpsdata[data_length]&amp;nbsp;=&amp;nbsp;&lt;span style="color: #cc6600;"&gt;&lt;b&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style="color: #cc6600;"&gt;read&lt;/span&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;++data_length;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #cc6600;"&gt;if&lt;/span&gt;(data_length &amp;gt; 127) { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileLogger::append(&lt;span style="color: #006699;"&gt;"data.log"&lt;/span&gt;, gpsdata, data_length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_length&amp;nbsp;=&amp;nbsp;0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;a href="http://www.seeedstudio.com/depot/seeeduino-stalker-atmega-328-p-600.html?cPath=77"&gt;Seeduino Stalker&lt;/a&gt; is an excellent Arduino-SD card combination that can be used for this project.&lt;br /&gt;&lt;br /&gt;This GPS datalogger can be powered from a 12V car plug  for continuous logging of a car's position. This is useful to monitor the driving habits of your teenage child, or to log the route of a long cross-country drive. Another use is for logging bicycle trips automatically (powered from solar energy and a 9V battery for backup).&lt;br /&gt;&lt;br /&gt;This device requires no user interaction. It starts logging when the device is powered on. If the Arduino has an LED connected to pin 13, it will blink when new data is being written to the card. At  the end of a month, you can copy the contents of the SD card to a  computer for analysis.&lt;br /&gt;&lt;br /&gt;Most of the Arduino pins are unused, so there is hacking potential.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-9150491291337890515?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/9150491291337890515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/gps-datalogger-for-arduino.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9150491291337890515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/9150491291337890515'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/gps-datalogger-for-arduino.html' title='GPS datalogger with Arduino and SD card'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-n2G5HdNRHGE/TjRJiL6eOVI/AAAAAAAAAP4/OJoGubn7A5w/s72-c/GPSlogger_bb.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3401833148161173349</id><published>2011-07-23T17:30:00.000-07:00</published><updated>2011-07-23T17:30:56.204-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>Whose advice do you trust?</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;One of the most difficult things about parenting (and pre-parenting) is knowing whose advice to trust. As a parent, many things are completely new and it is difficult to know the right way to do something. Many people offer to give advice, and while people are well-intentioned, their method might not work for you. The central problem is: whose advice do you trust?&lt;br /&gt;&lt;br /&gt;After listening to conflicting advice from many people, I have a reliable method of determining whose advice to trust:&lt;br /&gt;&lt;blockquote&gt;Trust the advice of people with &lt;b&gt;many friends from diverse backgrounds.&lt;/b&gt;&lt;/blockquote&gt;&lt;br /&gt;I arrived at this idea after looking at the people who have given us good advice in different scenarios. It seemed that the people with the best advice also had many diverse friends. &lt;br /&gt;&lt;br /&gt;Why? When a person has many diverse friends, it displays two qualities:&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Access to a wider variety of human experience. &lt;/li&gt;&lt;li&gt;An ability to handle criticism and a difference of opinion. Being able to hear someone out is good, but being able to patiently hear why you are wrong is a true skill. Being thin-skinned about a topic usually cuts short the conversation before you can see an alternative solution to a problem. &lt;/li&gt;&lt;/ol&gt;My friend calls this the "&lt;a href="http://en.wikipedia.org/wiki/PageRank"&gt;Pagerank&lt;/a&gt;" of human advice. While I had not thought of it in those terms, it makes complete sense. People are knowledgeable because of whom they know, not just what they know. When people have a lot of diverse friends, the increase in knowledge is not just linear.  It is exponential, as they can relate to how Mary had a similar problem that Bob is talking about, even though Mary and Bob have completely different backgrounds. This allows them to identify patterns of problems and patterns of solutions, which is more valuable than knowing a single solution for a single problem. Also, having a wider set of friends allows you to learn from others' mistakes before you face the same situation. &lt;br /&gt;&lt;br /&gt;Low sensitivity to criticism helps in accepting alternate methods of solving the same problem. Being receptive to new ideas allows us to identify new methods rather than being stuck in a rigidly defined solution. You can measure the receptivity of a person when you  decline their suggestion. A person who takes offence when you decline their suggestion has low levels of receptivity. Such people also have the poorest suggestions. The best advice is given by people whose interest is piqued when you say you are going to do things differently. They don't feel offended when someone declines their advice. Indeed, they want to know the alternatives because they actively seek other ways of solving the problem.&lt;br /&gt;&lt;br /&gt;My friend also pointed out that the two qualities listed above might be present in a person lacking diversity among their friends. This could happen when a person has lived in a homogeneous society and does not have  access to people of diverse backgrounds. I suspect that in such cases, the people will form lasting friendships with diverse people if they get a chance. I know some people who have grown up in homogeneous societies, and they still have a diverse  group of friends for  their limited surroundings. Their group might be homogeneous by some respects (ethnic background, religion, etc) but will be completely diverse in others (education, parenting, occupation, age...)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Zy-IBXzuDBE/TitOUuGTVQI/AAAAAAAAAPY/4BqPXNtgE-k/s1600/advice.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-Zy-IBXzuDBE/TitOUuGTVQI/AAAAAAAAAPY/4BqPXNtgE-k/s1600/advice.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3401833148161173349?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3401833148161173349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/whose-advice-do-you-trust.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3401833148161173349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3401833148161173349'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/whose-advice-do-you-trust.html' title='Whose advice do you trust?'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-Zy-IBXzuDBE/TitOUuGTVQI/AAAAAAAAAPY/4BqPXNtgE-k/s72-c/advice.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-5485448619868547031</id><published>2011-07-17T11:34:00.000-07:00</published><updated>2011-07-17T12:07:22.802-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Microcontroller driven LCD panel with voltage measurement, time, EEPROM  for computers</title><content type='html'>I just finished making a circuit to drive a four line LCD panel from an Arduino. The project started out as a way to drive the LCD to display arbitrary information, but then evolved into a way to tell the time, read and write the EEPROM from the Atmel 328p, and measure voltage. I'm using many existing libraries: the &lt;a href="http://www.arduino.cc/playground/Code/Time"&gt;Time library&lt;/a&gt;, and the &lt;a href="http://www.eggwall.com/2011/07/dual-hd-44780-controller-liquid-crystal.html"&gt;two Controller LCD library&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The final functionality is:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Commands are sent over USB using vi-line syntax. All commands start with ':' character.&lt;/li&gt;&lt;li&gt;Segments the 40x4 display into 8 segments of 20 chars each. Segment 0 is column 0, line 0. Segment 1 is column 20 line 0. This allows an easy way to display up to eight different status updates. To write "hello world" in segment 3, you write ":s3helloworld\n" to the serial port.&lt;/li&gt;&lt;li&gt;Read and write from EEPROM. The 1028 bytes of EEPROM is chunked into 8 segments of 128 bytes each. Segment 0 cannot be written to, which allows for 128 bytes of ROM. To write a segment 3, you index (:i3), then write (:wMySecretMessage\n). To read from EEPROM, you index first (:i3), then read the full segment (:r).&lt;/li&gt;&lt;li&gt;Time can be read from the device (:t) and the time can be set using Unix time (:T1310349445).&lt;/li&gt;&lt;li&gt;Voltage monitoring at analog pins can be toggled  (:a). Voltages are displayed on the LCD (display shows all six pins in decivolts: 5.0v is written 50) and written in raw form on serial (relative to 1023. 1023 = 5V, 0=0V)&lt;/li&gt;&lt;/ol&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HYXQFSkpdDU/TiMsJBNNfNI/AAAAAAAAAPU/pa64YMt1JJg/s1600/FourLine.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="194" src="http://3.bp.blogspot.com/-HYXQFSkpdDU/TiMsJBNNfNI/AAAAAAAAAPU/pa64YMt1JJg/s320/FourLine.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dS_rqrUN3oQ/TiMoARNNfDI/AAAAAAAAAPI/rhLSGztHxP4/s1600/IMG_20110717_100137.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-dS_rqrUN3oQ/TiMoARNNfDI/AAAAAAAAAPI/rhLSGztHxP4/s320/IMG_20110717_100137.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The entire &lt;a href="http://www.mediafire.com/file/65yjjn6l2jdtx1q/FourLinePanel.pde"&gt;Arduino source code is available as FourLinePanel.pde&lt;/a&gt;. It still has some debugging information left in, it prints the value of every new command it receives. This debugging could be removed. It supports a few commands:&lt;br /&gt;&lt;pre&gt;:t Displays the time&lt;br /&gt;:T&amp;lt;unix time&amp;gt; sets the time&lt;br /&gt;:l&amp;lt;message&amp;gt;\n Writes message to current position&lt;br /&gt;:sN&amp;lt;message&amp;gt;\n Writes message starting at segment N&lt;br /&gt;:a Turns on analog voltage monitoring on LCD and serial&lt;br /&gt;:r Reads 128 bytes from EEPROM at current location&lt;br /&gt;:iN Index into segment N of the EEPROM&lt;br /&gt;:w&amp;lt;data&amp;gt;\n Write data into EEPROM starting at current location&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This requires one Atmega microcontroller, an LCD panel, two 22pF ceramic capacitors, and one 16Mhz crystal. To interface it with USB, a &lt;a href="http://www.eggwall.com/2011/07/cost-effective-cheap-usb-serial-cable.html"&gt;USB to serial cable&lt;/a&gt; might be required. In my design, I'm driving the entire project using power from the USB port. This minimises the need for voltage regulation and additional components: power over USB is usually clean. You can &lt;a href="http://www.mediafire.com/file/efqw4tdx0x4ct04/FourLine.ps"&gt;download the schematic for the FourLinePanel here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;To interface with a computer, you  read and write to the serial port with 38400 bits per second, no flow control, and no parity bits. An example program to interface this with Python is given below.&lt;br /&gt;&lt;pre&gt;import serial, time&lt;br /&gt;# Set the time on the FourLinePanel for GMT+5hrs&lt;br /&gt;# offset from GMT: Add 5hrs&lt;br /&gt;offset = 5*3600&lt;br /&gt;port = "/dev/ttyUSB0"&lt;br /&gt;fourLine = serial.Serial(port, 38400);&lt;br /&gt;fourLine.write(":T" + &lt;br /&gt;               str((int)(time.time() + offset)))&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;There are five spare digital pins that could be used to drive a Real Time Clock or LEDs. These are marked as "Spare Digital (unused)" in the &lt;a href="http://3.bp.blogspot.com/-HYXQFSkpdDU/TiMsJBNNfNI/AAAAAAAAAPU/pa64YMt1JJg/s1600/FourLine.png"&gt;circuit diagram [png]&lt;/a&gt;, and &lt;a href="http://www.mediafire.com/file/efqw4tdx0x4ct04/FourLine.ps"&gt;circuit diagram [ps]&lt;/a&gt;. The analog voltage testers can be used as handy ways to measure voltage at the desk when a multimeter isn't handy, or to constantly monitor the voltage drop across a device (like a photovoltaic cell).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-5485448619868547031?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/5485448619868547031/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/microcontroller-driven-lcd-panel-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5485448619868547031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/5485448619868547031'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/microcontroller-driven-lcd-panel-with.html' title='Microcontroller driven LCD panel with voltage measurement, time, EEPROM  for computers'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-HYXQFSkpdDU/TiMsJBNNfNI/AAAAAAAAAPU/pa64YMt1JJg/s72-c/FourLine.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3912183416768180996</id><published>2011-07-15T06:53:00.000-07:00</published><updated>2011-07-23T17:59:44.317-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Who is Secret Labs, and why the Netduino project makes me nervous</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I'm a big fan of the &lt;a href="http://arduino.cc/"&gt;Arduino project&lt;/a&gt;. It is a micro-controller board that makes hardware programming fun. It is supported on all platforms, Windows, Mac and Linux, and works equally well on all of them. Arduino has fired off creativity in micro-controller hacking, and one product that caught my attention was the &lt;a href="http://netduino.com/"&gt;Netduino project&lt;/a&gt;. The board looks like the Arduino, but it uses the .NET framework by Microsoft.&lt;br /&gt;&lt;br /&gt;A lot of what I found about Netduino was suspicious, so I thought I'd share this in the hope that someone could clarify the situation.&lt;br /&gt;&lt;br /&gt;For an electronic project, Netduino is too good to be true.&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;The&amp;nbsp;&lt;a href="http://netduino.com/contact/"&gt;Netduino contact page is very sparse&lt;/a&gt;: it contains a physical address (Secret Labs LLC, 315 Bleecker St #308, New York, NY 10014), an email address (webmaster@netduino.com), and a link to the online forums.&amp;nbsp;The&amp;nbsp;&lt;a href="http://www.secretlabs.com/"&gt;Secret Labs LLC&lt;/a&gt;&amp;nbsp;website contains exactly this information. Almost nothing is known about them.&lt;/li&gt;&lt;li&gt;The only name associated with Secret Labs is a person called&amp;nbsp;&lt;a href="http://forums.netduino.com/index.php?/user/2-chris-walker/"&gt;Chris Walker&lt;/a&gt;.&amp;nbsp;He is&amp;nbsp;&lt;a href="http://forums.netduino.com/index.php?/user/2-chris-walker/"&gt;the only moderator of the Netduino forums&lt;/a&gt;. This is strange: I would expect Secret Labs to have a lot more than one technical contributor and a lot more people involved.&lt;/li&gt;&lt;li&gt;I couldn't tell any source of funding. Is Secret Labs making money from the Netduino product? Hardware margins are probably too small for this to work. How does Chris Walker pay his rent?&amp;nbsp;Do they have Venture Capital funding? I wasn't aware of open source hardware being a VC magnet.&lt;/li&gt;&lt;li&gt;They have designed and developed the entire product, and it is &lt;a href="http://www.sparkfun.com/products/10107"&gt;available for purchase at major electronics stores like Sparkfun&lt;/a&gt;. The design is polished and crisp, too crisp for a version 1 product by an unknown company.&lt;/li&gt;&lt;li&gt;The Netduino plus contains an ethernet port, for which they have &lt;a href="http://hwaddress.com/mac/5C864A-000000.html"&gt;5C:86:4A MAC address prefix&lt;/a&gt;. Applying for MAC addresses takes some effort, so it is impressive that Secret Labs LLC has done so much groundwork.&lt;/li&gt;&lt;li&gt;All their &lt;a href="http://netduino.com/downloads/"&gt;source code is available from files hosted at netduino.com&lt;/a&gt;. There is no public source code repository: no tracking of who made changes, and when. They claim to be an open source project, but if I want to submit improvements, there is no email address or contact in the source code. All source code is copyright Secret Labs LLC. A real hacker would love to get improvements from the community. The source code is not professional: comments are missing, and stale code is commented out when it didn't work. From the look and feel of the source code, I would guess a very small team, and a very hurried release. It was most probably developed in September 2010, which is very close to the release of the .NET Micro framework.&amp;nbsp;&lt;/li&gt;&lt;li&gt;From a cursory look through&amp;nbsp;&lt;a href="http://maps.google.com/maps?q=315+Bleecker+St+%23308+New+York+NY+10014&amp;amp;hl=en&amp;amp;ll=40.732877,-74.00396&amp;amp;spn=0.004975,0.009645&amp;amp;sll=40.732879,-74.003864&amp;amp;sspn=0.006295,0.006295&amp;amp;layer=c&amp;amp;cbp=13,92,,0,-12.72&amp;amp;cbll=40.732879,-74.003955&amp;amp;gl=us&amp;amp;z=17&amp;amp;panoid=u-AiGxuGr4eSYTI3XSk6mA"&gt;Google Maps, 315 Bleecker St. looks like a residential address&lt;/a&gt;.&amp;nbsp;&amp;nbsp;What's worse, the &lt;a href="http://www.bbb.org/NYC/business-reviews/payment-processing-service/simplepayclix-in-new-york-ny-115076/"&gt;Better Business Bureau lists 318 Bleecker St #308 as a Payment Processing Service called SimplePayClix&lt;/a&gt;, with the listing opened in March 18, 2010.&lt;/li&gt;&lt;li&gt;The domain netduino.com was first created on 16 January, 2009, while &lt;a href="http://searchdns.netcraft.com/?host=netduino.com&amp;amp;x=0&amp;amp;y=0"&gt;Netcraft first saw it in March 2009&lt;/a&gt;. This is very surprising. The netduino.com domain was registered before the Secret Labs LLC was created. &lt;a href="http://en.wikipedia.org/wiki/.NET_Micro_Framework"&gt;Microsoft announced that they would open source the .NET Micro Framework on 16 November, 2009&lt;/a&gt;. Did Secret Labs LLC work on a product even before they knew that the framework was going to be open sourced, or were they working on a different design that wasn't released? The owner on secretlabs.com is Chris Walker again, with address&amp;nbsp;cwalker@secretlabs.com.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;The Netduino project looks very impressive, and if it is the work of a few people, they are very smart and very capable indeed. But it doesn't look anything like a community-driven project. Only one person is visible, and I find it hard to believe that he has developed the hardware, the software, the book, the documentation, the video tutorials, the forums. All in isolation from the hacker community.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is entirely possible that Chris Walker is independently wealthy, is an expert electronics and software hacker, is amazing at website design, and has good relations with electronics manufacturers. But I smell a rat.&lt;br /&gt;&lt;br /&gt;Update (23 July 2011): Read the first comment for all the answers. &lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-3RD4hcifdew/TiBBBqTq_rI/AAAAAAAAAPE/t9BFXqtmX2U/s1600/suspicion.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-3RD4hcifdew/TiBBBqTq_rI/AAAAAAAAAPE/t9BFXqtmX2U/s320/suspicion.jpeg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;More about Chris Walker of Secret Labs: he has a&amp;nbsp;&lt;a href="http://channel9.msdn.com/Niners/cwalker_secretlabs"&gt;Channel 9 account 'cwalker_secretlabs'&lt;/a&gt;, created this year. He gave a&amp;nbsp;&lt;a href="http://www.developerfusion.com/media/91474/deeper-into-the-netduino-with-chris-walker-from-secret-labs/"&gt;podcast interview about the Netduino&lt;/a&gt;. OReilly is about to publish a book called&amp;nbsp;&lt;a href="http://www.amazon.com/Getting-Started-Netduino-Chris-Walker/dp/1449302459/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1307482202&amp;amp;sr=1-1"&gt;"Getting Started with Netduino" by Chris Walker&lt;/a&gt;, which will be released soon.&amp;nbsp;&lt;a href="http://channel9.msdn.com/coding4fun/articles/Tron-Disc-with-NET-Microframework"&gt;Chis Walker is listed as the CTO of Secret Labs&lt;/a&gt;&amp;nbsp;in one article.&amp;nbsp;There is what&amp;nbsp;&lt;a href="http://www.flickr.com/photos/psychlist1972/5895470332/in/photostream/"&gt;he looks like.&lt;/a&gt;&amp;nbsp; Later this year,&amp;nbsp;&lt;a href="http://www.oscon.com/oscon2011/public/schedule/speaker/108958"&gt;he is giving a talk&lt;/a&gt;&amp;nbsp;titled "&lt;a href="http://www.oscon.com/oscon2011/public/schedule/detail/18647"&gt;Connecting Devices to the Cloud on Open Source Hardware and Software&lt;/a&gt;", at Oreilly's OSCON on July 27, 2011. His co-speaker is&amp;nbsp;&lt;a href="http://www.oscon.com/oscon2011/public/schedule/speaker/108956"&gt;Colin Miller, who is a Product Manager for the .NET Micro Framework&lt;/a&gt;.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3912183416768180996?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3912183416768180996/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/who-is-secret-labs-and-why-netduino.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3912183416768180996'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3912183416768180996'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/who-is-secret-labs-and-why-netduino.html' title='Who is Secret Labs, and why the Netduino project makes me nervous'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-3RD4hcifdew/TiBBBqTq_rI/AAAAAAAAAPE/t9BFXqtmX2U/s72-c/suspicion.jpeg' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2426046440364479050</id><published>2011-07-13T19:50:00.000-07:00</published><updated>2011-07-13T19:50:19.757-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='india'/><title type='text'>Why is Bombay a target of bomb blasts?</title><content type='html'>There were another set of bomb blasts in Bombay. My heart is with the families of the affected people.&lt;br /&gt;&lt;br /&gt;Security in India is pretty bad. There is  a culture of lax security.&lt;br /&gt;&lt;br /&gt;In my experience, the police have been unhelpful and unable to enforce laws. The airport police are slightly more diligent than the regular force inside the city, but both are relatively incompetent. At the International airport, I have seen passengers walk away without their bags being scanned through the machines. On one occasion my bag was run through the scanner but there was nobody looking at the scanner to see what I was bringing in. It is easy to see how dangerous, explosive material could have been brought in. &lt;br /&gt;&lt;br /&gt;Inside the city, the police are equally lax. I do not remember approaching the police when there was any problem. The police were a nuisance rather than a service and a convenience. The police were happy to assert their authority and harass students and poor people, while avoiding their responsibility to enforce laws. The porous border with other countries combined with the lax enforcement  of laws make it  easy for criminals to cause mischief with little  consequence.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-TXL4Ic2lUbE/Th5U2ug5vzI/AAAAAAAAAPA/pnjMA6F0g_k/s1600/police.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="206" src="http://3.bp.blogspot.com/-TXL4Ic2lUbE/Th5U2ug5vzI/AAAAAAAAAPA/pnjMA6F0g_k/s320/police.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;A symptom of this is the &lt;a href="http://www.eggwall.com/2011/06/indian-traffic-fatalities-compared-to.html"&gt;high number of accidents and traffic fatalities in India&lt;/a&gt;. Traffic police are probably the least competent, but the indifference and incompetence of the traffic police points to a systemic problem in law enforcement everywhere: tax evasion, violations of human rights, and a lack of security. Citizens that pay taxes are paying the state to keep them safe, and to guarantee some basic dignity. The police are unable to provide this in Bombay.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This incident is truly unfortunate, and I share the sense of vulnerability such incidents cause. Unless we can address the core problem: the failure of enforcement of laws, we can never achieve the security that Bombay deserves.&lt;br /&gt;&lt;br /&gt;Image courtesy: &lt;a href="http://ihateindianpolice.blogspot.com/"&gt;blog on Indian police&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2426046440364479050?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2426046440364479050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/why-is-bombay-target-of-bomb-blasts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2426046440364479050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2426046440364479050'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/why-is-bombay-target-of-bomb-blasts.html' title='Why is Bombay a target of bomb blasts?'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-TXL4Ic2lUbE/Th5U2ug5vzI/AAAAAAAAAPA/pnjMA6F0g_k/s72-c/police.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8119713354343754386</id><published>2011-07-10T15:32:00.000-07:00</published><updated>2011-07-10T15:53:23.640-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Dual HD 44780 Controller Liquid Crystal Library for Arduino</title><content type='html'>I came across a four row LCD panel while browsing at an electronics store: the model name was WM-C4004A. I wasn't sure if I could drive it through an Arduino but decided to try. It was easy to drive once I hunted down &lt;a href="http://www.mediafire.com/file/fiv137k8e1a3rm4/LCD_40x4.2.pdf"&gt;the datasheet for the WM C4004A, a dual HD44780 controller&lt;/a&gt;, and understood the controller.&lt;br /&gt;&lt;br /&gt;There is a good &lt;a href="http://www.arduino.cc/en/Reference/LiquidCrystal"&gt;Arduino library for driving HD 44780 compatible controllers&lt;/a&gt; and I modified the LiquidCrystal library to  drive two separate controllers. The usage is identical to the LiquidCrystal library. You specify the Register Select (RS) and enable bits for both controllers, the data pins, and the rows and column per controller. Then you can seek() and write() through Arduino.&lt;br /&gt;&lt;br /&gt;My modifications are available as the&amp;nbsp; LiquidCrystalDual library. Download the library: &lt;a href="http://www.mediafire.com/file/bqaw9boqfsipabg/LiquidCrystalDual-2011-07-10.tar.gz"&gt;LiquidCrystalDual.tar.gz&lt;/a&gt; or &lt;a href="http://www.mediafire.com/file/z477daq0b89g4cq/LiquidCrystalDual-2011-07-10.zip"&gt;LiquidCrystalDual.zip&lt;/a&gt;. Unzip and place the contents in the libraries/ directory in the arduino installation.&lt;br /&gt;&lt;br /&gt;Here is a small example program (there is a detailed program in the examples/ menu in the Arduino IDE).&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#include &amp;lt;LiquidCrystalDual.h&amp;gt;&lt;br /&gt;&lt;br /&gt;// 2 controllers: RS, RW, EN1, EN2, D4, D5, D6, D7&lt;br /&gt;// We have the RS (RS=12) line, *no* RW line (RW=-1),&lt;br /&gt;// two enable lines (EN1=6, EN2=7),&lt;br /&gt;// four data lines (D4=11, D5=10, D6=9, D7=8)&lt;br /&gt;LiquidCrystalDual lcd(12, -1, 6, 7, 11, 10, 9, 8);&lt;br /&gt;&lt;br /&gt;void setup()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; // I have 40 characters and two lines per controller.&lt;br /&gt;&amp;nbsp; lcd.begin(40,2);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; // Move to the first column of second row.&lt;br /&gt;&amp;nbsp; lcd.setCursor(0,0);&lt;br /&gt;&amp;nbsp; lcd.print("Line 1: Hello");&lt;br /&gt;&amp;nbsp; lcd.setCursor(0, 1);&lt;br /&gt;&amp;nbsp; lcd.print("Line 2: World");&lt;br /&gt;&amp;nbsp; // Move to the second controller&lt;br /&gt;&amp;nbsp; lcd.setCursor(0, 2);&lt;br /&gt;&amp;nbsp; lcd.print("Line 3: Four...");&lt;br /&gt;&amp;nbsp; lcd.setCursor(0, 3);&lt;br /&gt;&amp;nbsp; lcd.print("Line 4! Lines!");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void loop()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; // Do nothing.&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-zBZCds4YYZk/ThomcFI3AII/AAAAAAAAAO8/smE6wHXLTVk/s1600/2_controller.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://1.bp.blogspot.com/-zBZCds4YYZk/ThomcFI3AII/AAAAAAAAAO8/smE6wHXLTVk/s320/2_controller.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-8119713354343754386?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8119713354343754386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/dual-hd-44780-controller-liquid-crystal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8119713354343754386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8119713354343754386'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/dual-hd-44780-controller-liquid-crystal.html' title='Dual HD 44780 Controller Liquid Crystal Library for Arduino'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-zBZCds4YYZk/ThomcFI3AII/AAAAAAAAAO8/smE6wHXLTVk/s72-c/2_controller.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8833765144951500454</id><published>2011-07-08T20:16:00.000-07:00</published><updated>2011-07-08T20:16:39.169-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='technology'/><title type='text'>What determines the success of a country: Nurturing creators</title><content type='html'>Why does a single area dominate one industry? Detroit with cars in the 1960s, Silicon companies in California in the 1980s, .... Before the computer revolution, there was no centre of electronics. A lot of work was done in the UK, Japan, the US, and other countries. And yet, most of the computer design is now centred in the US.&lt;br /&gt;&lt;br /&gt;I am beginning to think that the core reason why the US forged ahead with computers was that it had a large number of initial hobbyists and tinkerers. Many individuals tried different ideas. Most of the ideas made no commercial sense, but there were enough ideas that reached commercial success. The initial tinkering group found themselves employed at companies that were successful. Apple started out as a tinkering collection, with Steve Woz designing motherboards for sale for $666.66. He had worked previously at Hewlett Packard, and brought his impressive tinkering skills to bear on the Apple I and the Apple II. Dell, Compaq, Intel, they all had a core group of tinkering engineers who had a commercially viable idea. Everyone was producing things, and most were of dubious value. But for every hundred bad ideas, there was one Apple or one Microsoft. And that hit-rate was enough to sustain entire generations of engineers. The UK had some tinkerers but their total number was small compared to those in the US, so while they had some success, they couldn't sustain a lead.&lt;br /&gt;&lt;br /&gt;Something similar happened with the Web 2.0 boom. For a while, every college student in the US was making a Web 2.0 mashup, armed with an Apache server and a passing knowledge of Javascript. Not everything worked, but enough ideas were bounced around to give rise to a Twitter, a Facebook, a LinkedIn, a Youtube. All these sites were possible elsewhere.&lt;br /&gt;&lt;br /&gt;This is happening in the mobile world, all over again. College students in the US are making apps for their iPhone and Android devices. Most of them are failures, but enough are succeeding in the San Francisco area to create a virtuous cycle. Many college students are getting together to form two-person startups around their iPhone app.&lt;br /&gt;&lt;br /&gt;I think this  tinkering and production of ideas is the reason for phenomenal American success in computer hardware, Web 2.0, and mobile applications. One of reasons for this is cultural: American individuality recognises the lone wolf who is trying something new, even if the idea isn't mainstream. The other is the large payoff to a successful venture. The third is the general risk-loving attitude: students willingly take a year off from University to try out a startup, working families try a startup even if they know it might cause some hardship if the venture fails. College students are happy working on some idea they love.&lt;br /&gt;&lt;br /&gt;All these factors contribute to an environment where tinkering and idea creation is nurtured and idea creators are rewarded. Even if most projects fail, enough of them succeed that the job market is always looking for engineers and other tinkerers. Many people working at Apple or Google today have a varied history of trying out different ideas and learning from their mistakes.&lt;br /&gt;&lt;br /&gt;I see this trend most clearly in hobbyist hacking involving the &lt;a href="http://www.arduino.cc/"&gt;Arduino&lt;/a&gt; or other micro controllers. Again, a lot of tinkering is being done in the West. The difference is that there are a significant numbers of Chinese hobbyists involved. At first, this was because the manufacturing had moved off to China, and the Chinese engineers were exposed to a lot of Western products and ideas. Now, we see many Chinese engineers tinkering and experimenting. Unlike the Web or mobile applications, electronics hacking doesn't require an excellent command of English, and some Chinese electronic designs are approaching the best in their class.&lt;br /&gt;&lt;br /&gt;It seems to me that countries should focus on nurturing creators. It pays off in the long run.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-8833765144951500454?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8833765144951500454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/what-determines-success-of-country.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8833765144951500454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8833765144951500454'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/what-determines-success-of-country.html' title='What determines the success of a country: Nurturing creators'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-6177435280372656186</id><published>2011-07-05T12:02:00.000-07:00</published><updated>2011-07-10T15:34:04.774-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Fun with Assembly Language</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is  a quick  page about  my adventures  with  Linux assembly language, with links to resources, and some source code.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Why?&lt;/h2&gt;I won't fool  you into thinking that assembly  language is a useful tool: it isn't.   By and large, if you want to  get stuff done, you're much  better off  learning Python,  C or  Java.  Assembly  language is great if you're  a tinkerer, and want to know what  is going on inside your  computer.  Many  people have  written interesting  tiny programs using  assembly,  which  might  be  handy  on  embedded  environments. Finally,  there  are some  features  that  you  can only  get  through assembly:  low-level architecture  features,  getting around  compiler limitations and understanding  languages themselves.  For me, assembly is &lt;i&gt;just for fun&lt;/i&gt;!&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Resources&lt;/h2&gt;I  do all  my  programming on  Linux, and  it  is one  of the  best environments to learn  assembly.  The tools are  quite good, and there is some lovely documentation.  If you don't already have Linux, get a copy of &lt;a href="http://www.knoppix.net/"&gt;Knoppix&lt;/a&gt;, which is a live CD that lets you try out Linux without modifying your computer setup.  Here is a list of books that I highly recommend. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;[PGU] - &lt;a href="http://savannah.nongnu.org/projects/pgubook/"&gt;Programming From the Ground Up&lt;/a&gt;,  by Jonathan Bartlett: an excellent introduction to x86 assembly  language on Linux.  The entire book is free for download.   This one  book is all you need, initially.   &lt;/li&gt;&lt;li&gt;[PAL] - &lt;a href="http://books.google.com/books?id=ZFDqpSUPwAgC&amp;amp;dq=professional+assembly+language&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=X3PnSZ-JKqDItAOZ-oHpAQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4"&gt;Professional Assembly Language&lt;/a&gt;: another excellent introduction.   &lt;/li&gt;&lt;li&gt;[IPM] - &lt;a href="http://www.intel.com/products/processor/manuals/"&gt;Intel Programming Manuals&lt;/a&gt;:  complete, in-depth information on architecture and assembly language.   You're probably interested in Vol 1, 2A, 2B, 3A and 3B.  It is meant as a  reference: not a cover-to-cover read.   &lt;/li&gt;&lt;li&gt;[APM] - &lt;a href="http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_739_7044,00.html"&gt;AMD x86-64 Programming Manuals&lt;/a&gt;: complete, in-depth information from AMD.  Get all the volumes.   &lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Fun with Assembly&lt;/h2&gt;So you got yourself a copy of [PGU], and want a challenge? &lt;br /&gt;&lt;ol&gt;&lt;li&gt;We try to rewrite the first program from [PGU] as  &lt;a href="http://www.mediafire.com/file/phlflit5qg5a95r/01_exitValue.s"&gt;01_exitValue.s&lt;/a&gt;.  The expected return value is 999, but you get something else.     &lt;ol&gt;&lt;li&gt; Can you guess what the return value is without running the program?       &lt;/li&gt;&lt;li&gt; Can you explain why the return value is not 999?       &lt;/li&gt;&lt;li&gt; Can you write the program so that this problem can be caught by the assembler?       &lt;/li&gt;&lt;li&gt; &lt;a href="http://www.mediafire.com/file/q165fjs47tpuesd/01_exitValue_Solution.s"&gt;01_exitValue_Solution.s&lt;/a&gt;.       &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;We try to rewrite the second program from [PGU], using our understanding from the earlier problem, as &lt;a href="http://www.mediafire.com/file/fdykff3dkzsthnd/02_maximumValue.s"&gt;02_maximumValue.s&lt;/a&gt;.  The expected return value is 214, but you get something else.     &lt;ol&gt;&lt;li&gt; Can you guess what the return value is without running the program?       &lt;/li&gt;&lt;li&gt; Can you explain why the return value is not 214?       &lt;/li&gt;&lt;li&gt; Can you write the program so that this problem can be caught by the assembler?       &lt;/li&gt;&lt;li&gt; &lt;a href="http://www.mediafire.com/file/248z4k9808uszg1/02_maximumValue_Solution.s"&gt;02_maximumValue_Solution.s&lt;/a&gt;.       &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Here's an example for why you might &lt;i&gt;need&lt;/i&gt; assembly  language.  Your mission is breaking into a program to steal a secret  key.  Some experienced hackers have isolated where the secret key is  being passed to a secret function.     &lt;ol&gt;&lt;li&gt; &lt;tt&gt;secretFunction(char *useless, char *secret_key)&lt;/tt&gt; calls &lt;tt&gt;validate()&lt;/tt&gt; immediately upon starting.  You job is to print secret_key inside &lt;tt&gt;validate&lt;/tt&gt;.   As an example, the file &lt;a href="http://www.mediafire.com/file/s8ijvsuktncuikf/03_keyIsHere.o"&gt;03_keyIsHere.o&lt;/a&gt;  contains the secret function that has the second argument as a key.   You are only allowed to write a validate() method in a separate .s or .c  file.  Try not to modify the original object file.  You are assured  that the key is exactly 13 characters long.  Try writing an assembly  solution, and compile  and run with &lt;tt&gt;gcc 03_keyIsHere_Solution.s 03_keyIsHere.o -o 03_keyIsHere; ./03_keyIsHere &lt;/tt&gt;       &lt;/li&gt;&lt;li&gt; If the validate was called in the end, how does it change your solution?       &lt;/li&gt;&lt;li&gt; Can you use this trick to guess the local variables of &lt;tt&gt;secretFunction&lt;/tt&gt;?       &lt;/li&gt;&lt;li&gt; In case the object file doesn't work for you,  &lt;a href="http://www.mediafire.com/file/4r13955zyabp9gh/03_keyIsHere.c"&gt;03_keyIsHere.c&lt;/a&gt; contains the C source.  The solution must not modify it.       &lt;/li&gt;&lt;li&gt; &lt;a href="http://www.mediafire.com/file/er3tj5e49y1l2dj/03_keyIsHere_Solution.s"&gt;03_keyIsHere_Solution.s&lt;/a&gt;  Compile and run with &lt;tt&gt;gcc 03_keyIsHere_Solution.s 03_keyIsHere.c -o 03_keyIsHere; ./03_keyIsHere &lt;/tt&gt;       &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;This is a more sophisticated example compared to the previous  one.  Having moved on in your career, you are faced with a new program  that calls printf, and you have to inject code without a recompilation.   The program &lt;a href="http://www.mediafire.com/file/kje351f08fe5vh1/04_crackMe"&gt;04_crackMe&lt;/a&gt;  executes happily on its own.  You know that printf is being called in  it, and that on the first invocation, the calling function has a  secret-key as its second parameter.      &lt;ol&gt;&lt;li&gt; &lt;tt&gt;secretFunction(char *useless, char *secret_key)&lt;/tt&gt; calls &lt;tt&gt;printf()&lt;/tt&gt;  immediately upon starting.  You job is to print secret_key.   Most  probably, you'll want to inject code into printf.  The solution does not  require modifying the original binary.  You are assured that the key is  exactly 13 characters long.       &lt;/li&gt;&lt;li&gt; Can you do this while continuing to print the original messages?       &lt;/li&gt;&lt;li&gt; In case the object file doesn't work for you,  &lt;a href="http://www.mediafire.com/file/wp0cpdmogo8daby/04_crackMe.c"&gt;04_crackMe.c&lt;/a&gt; contains the C source.  Compile and run with  &lt;tt&gt;gcc 04_crackMe.c -o 04_crackMe; ./04_crackMe &lt;/tt&gt;.  Remember that the solution does not require modifying the 04_crackMe binary or the C source code.       &lt;/li&gt;&lt;li&gt; &lt;a href="http://www.mediafire.com/file/d406u72ckir7rrr/04_crackMe_Solution.s"&gt;04_crackMe_Solution.s&lt;/a&gt;.  Instructions on how to run it are inside the solution.       &lt;/li&gt;&lt;li&gt; Sufficiently pleased?  Good, now carry it over to the next level by visiting this awesome &lt;a href="http://neworder.box.sk/newsread.php?newsid=13857"&gt;page on making 13 equal to 17&lt;/a&gt;.       &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-6177435280372656186?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/6177435280372656186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/fun-with-assembly-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6177435280372656186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/6177435280372656186'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/fun-with-assembly-language.html' title='Fun with Assembly Language'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-1251527865837816109</id><published>2011-07-05T11:51:00.000-07:00</published><updated>2011-07-10T15:34:04.775-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Cost effective (cheap!) USB Serial cable for any project</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If you've been playing with microcontrollers, or hacking any sort of hardware, you know that it is great to be able to communicate with a computer. A usb cable is often the best option, since usb serial drivers are ubiquitous and easy to work with.  However, cheap usb cables are difficult to come by.  On this page, you will find instructions to build a very low cost USB serial cable, which can also supply +5V to a board.  This is ideal for breadboard arduinos, but will also work great for any microcontroller or TTL circuit.&lt;br /&gt;&lt;br /&gt;All instructions here are provided solely as a guide.  If you miswire the cable, you might end up burning your computer, your electronic gadgets, or your house.  I do not take personal responsibility for your actions.&lt;br /&gt;&lt;br /&gt;&lt;h2 style="font-weight: normal;"&gt;&lt;span style="font-size: large;"&gt;Cost, parts, and capability&lt;/span&gt;&lt;/h2&gt;You need a Nokia CA-42 cable, a soldering iron and some method of determining continuity.  A multimeter would be handy, but is not required.  Assuming you have the tools, the CA-42 cable sells for $3 including free shipping from many sellers on eBay and Amazon.  Since the cost of the cable is so low, online fraud is unlikely.  The total cost of the project is $3, and you don't need any extra parts. &lt;br /&gt;The final cable works on Linux, without requiring any extra drivers.  Most cheap CA-42 cables are made using a PL-2303 chip, which is a cheap RS232 convertor.  For data transmission, you only get two lines: RX and TX, but this is usually sufficient.  You get +3V and +5V, which are very well regulated and clean sources of power.  These could be directly attached to microcontroller boards.  I have seen drivers for PL-2303 on Windows and Mac, and you should search for these over the Internet.  You might need to mask the device ID, since the cable might announce itself as a Nokia phone cable.  You don't need any drivers if you only want to use the cable as a power source.&lt;br /&gt;&lt;br /&gt;&lt;h2 style="font-family: inherit; font-weight: normal;"&gt;&lt;span style="font-size: large;"&gt;Make it&lt;/span&gt;&lt;/h2&gt;The construction is trivial. This is what the cable looks like (image courtesy Timothy Small): &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-k6xW4Cvx_pc/ThNatzyDiUI/AAAAAAAAAOc/oCV8DWUfono/s1600/ca42.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-k6xW4Cvx_pc/ThNatzyDiUI/AAAAAAAAAOc/oCV8DWUfono/s1600/ca42.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="thumbnail"&gt;&lt;/div&gt;The pinout, from left to right is: &lt;br /&gt;&lt;ol&gt;&lt;li&gt;This is body of the cable, and is not connected   &lt;/li&gt;&lt;li&gt;The missing pin, no connection   &lt;/li&gt;&lt;li&gt;No connection   &lt;/li&gt;&lt;li&gt;+3.3V, might be as low as +3V   &lt;/li&gt;&lt;li&gt;No connection   &lt;/li&gt;&lt;li&gt;RX   &lt;/li&gt;&lt;li&gt;TX   &lt;/li&gt;&lt;li&gt;GND   &lt;/li&gt;&lt;/ol&gt;It might help to view the &lt;a href="http://buffalo.nas-central.org/wiki/Image:CA-42_DKU-5_pinout.jpg"&gt;pin out diagram (hosted at nas-central.org)&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;To create the cable, cut the head near the top of the cable, as shown.  When you cut the cable, try to match the color of the wire with the pinout given above.  I've found the following colors, though you should check your own cable: &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Black: Ground   &lt;/li&gt;&lt;li&gt;Red: 3V   &lt;/li&gt;&lt;li&gt;White: RX data   &lt;/li&gt;&lt;li&gt;Blue: TX data   &lt;/li&gt;&lt;li&gt;Green: no connection &lt;/li&gt;&lt;/ul&gt;Now, the cable has five wires: two are used for data (TX, RX), two are for power (+3.3, GND).  There is an extra wire in there, which is useless for our purposes.  So we repurpose this wire to carry the +5V connection from the USB port.  In my cables, this wire has always been green, though you should check which wire, if any, is unused in your cable.  The head of the cable comes off quite easily if you hold it and twist the metal USB connector as though it were a key.  Connect the far right metal lead from the USB connector to the green wire. The green wire should be disconnected from the body, but the +5V connect should &lt;i&gt;not&lt;/i&gt; be disconnected from the body: the PL-2303 requires +5V power to work. &lt;br /&gt;&lt;div class="thumbnail"&gt;&lt;/div&gt;&lt;div class="thumbnail"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Caf1f7tmIOE/ThNbCbnMLDI/AAAAAAAAAOw/lFCnx5HuqDg/s1600/tm_sd531479.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-Caf1f7tmIOE/ThNbCbnMLDI/AAAAAAAAAOw/lFCnx5HuqDg/s1600/tm_sd531479.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Here is the final soldered assembly.  In this image, the usb connector is the correct side up.  For your reference, here is &lt;a href="http://pinouts.ws/usb-pinout.html"&gt;pin-out for the USB A connector&lt;/a&gt;.  The soldering is done to the +5V wire. &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1OcX2-S_FGI/ThNbAUWMCII/AAAAAAAAAOk/NU8KsDwQ9BE/s1600/sd531488.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-1OcX2-S_FGI/ThNbAUWMCII/AAAAAAAAAOk/NU8KsDwQ9BE/s320/sd531488.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3 style="font-weight: normal;"&gt;&amp;nbsp;&lt;/h3&gt;&lt;h3 style="font-weight: normal; text-align: left;"&gt;Uses&lt;/h3&gt;The +5V and ground can be used to power an arduino or most Atmel Atmega AVR microprocessors.  The TX wire (colored blue in my cable) goes into the TXD pin of microcontrollers (Arduino: digital 1), and the RX wire (colored white in my cable) goes into the RXD pin of microcontrollers (Arduino: digital 0).  I've tested the power using an oscilloscope: the power in my cables is very clean.  This means that you can avoid using a 7805 and other circuitry that would provide a clean +5V signal.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Credit: The idea for this cable is due to the &lt;a href="http://buffalo.nas-central.org/wiki/Use_a_Nokia_Serial_Cable_on_an_ARM9_Linkstation"&gt;the ARM9 Linkstation hackers&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-1251527865837816109?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/1251527865837816109/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/cost-effective-cheap-usb-serial-cable.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1251527865837816109'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/1251527865837816109'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/cost-effective-cheap-usb-serial-cable.html' title='Cost effective (cheap!) USB Serial cable for any project'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-k6xW4Cvx_pc/ThNatzyDiUI/AAAAAAAAAOc/oCV8DWUfono/s72-c/ca42.jpg' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-8479915271035734589</id><published>2011-07-05T11:33:00.000-07:00</published><updated>2011-07-10T15:34:04.775-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Making your Linux computer silent</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;These are some notes I made back before Solid State Disks were popular. If I were doing this today, I'd get an Intel Atom processor with SSD disks, and no fans. These tips might still be relevant for desktop computers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While you  may not  realize it, your  computer is capable  of being silent, or at least quieter.  I collect some tips here which might help in reaching this goal.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Buy a  good power  supply.  A  lot of the  noise comes  from power supply  fans and  other fans  in  the system.   While the  CPU fan  is usually rather silent, some power  supply fans are very noisy.  If you want to make your existing fan quieter, a good way is to blow the dust out.  Dust  stuck in the  fans makes noise.   You could use  a bicycle pump to  force air through the  fan after switching  off the computer. Your mileage  may vary.   CPU heatsink fans  have the tendancy  to get very  dirty, and  dirt gets  accumulated in  the heatsink  fins.  I've found  cleaning these  fins to  make quite  a dramatic  change  in the amount of noise from the heatsink fan.&lt;/li&gt;&lt;li&gt;Use &lt;a href="http://noflushd.sourceforge.net/"&gt;noflushd&lt;/a&gt;: It is a user level daemon that prevents disk writes from spinning disks back up.&lt;/li&gt;&lt;li&gt;Don't use  journaling filesystems.   Ext3, reiserfs, xfs,  jfs are all  journaling filesystems  and  commit data  to  disk without  going through any  cache.  While journaling filesystems are  cooler and have much better recovery  and consistency: if you have  a noisy disk: they will make it spin almost continuously.  Turn off journaling with ext3, or change the  filesystem if you can.  Here is a  quick way to convert an  ext3 partition  to  ext2.  This  will work  even  if it  is the  / filesystem,  though nothing is  guaranteed.  First,  turn off  all the services possible, and  try to get almost no  processes running.  Then edit  /etc/fstab so  that the  ext3 filesystems  are changed  to ext2. Next, run the command  &lt;pre&gt;vi /etc/fstab  # &amp;lt;- change /dev/sdaXX from ext3 to ext2&lt;br /&gt;mount -o remount,ro /dev/sdaXX&lt;br /&gt;tune2fs -O ^has_journal /dev/sdaXX&lt;br /&gt;mount -t ext2 -o remount,rw /dev/sdaXX&lt;br /&gt;&lt;/pre&gt;After  these  commands, you  might  want to  reboot,  and  see if  the   filesystem is  now ext2. It  worked for my  iMac, where I  could not   reboot to another Linux distribution.  Again, your mileage may vary.  &lt;/li&gt;&lt;li&gt;Turn off  as many services  as you can.   If you don't  need mysql running all the time, switch it  off.  A lot of services want to write logs, and  you can  either change their  configuration to  disable log writing, or look at the next step. &lt;/li&gt;&lt;li&gt;If  you have directories  in which  frequent writes  are required, consider mounting them as a tmpfs.   This is a new filesystem in Linux which keeps  data on  RAM, and not  on disk.   This means that  if the machine goes down, your data is lost.  To avoid losing data, you might want to copy the data out to real disk when switching off the machine. This is a great way to write  log files, or put images from the webcam that you take  every second or so.  After all, when  you have the most recent image, you might not be  so interested in the older photos.  If your kernel is too old, you  might want to use the ramdisk module, but tmpfs is a better choice if you have it.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-8479915271035734589?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/8479915271035734589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/making-your-linux-computer-silent.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8479915271035734589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/8479915271035734589'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/making-your-linux-computer-silent.html' title='Making your Linux computer silent'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-415256989849593687</id><published>2011-07-05T11:26:00.000-07:00</published><updated>2011-07-10T15:34:04.776-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Programming the NXT to communicate with Linux</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is Part 3 of a three-part series on programming the Lego NXT through Linux.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/2011/07/setting-up-nxt-bluetooth-support-on.html"&gt;Part 1 to setup the NXT-bluetooth connection&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eggwall.com/2011/07/setting-up-lego-programming-environment.html"&gt;Part 2 to setup your programming environment&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;If you have followed along, you are now  ready to program in NXC.&lt;br /&gt;Let's write a simple C program for Linux, and an NXC program for the NXT that communicate through Bluetooth.  The interface of this program is totally dopey and unprofessional, but it demonstrates how to send information to the NXT and get information from it.  The ideas are borrowed by notes from the &lt;a href="http://www.cs.uleth.ca/%7Ebenkoczi/3720/"&gt;CPSC 3720 Software Engineering&lt;/a&gt; course at the University of Lethbridge, in particular &lt;a href="http://localhost/computers/www.cs.uleth.ca/%7Ebenkoczi/3720/data/NXT_Bluetooth_handout-jeremy.pdf"&gt;this handout&lt;/a&gt;.  Here are the steps you need to follow. &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Install Bluetooth libraries and GTK libraries on Linux.  On Ubuntu, the command is: &lt;br /&gt;&lt;pre&gt;$ sudo apt-get install libbluetooth-dev \&lt;br /&gt;       libgtk2.0-dev libc6-dev make gcc&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt; Make the Tribot from the Mindstorms quickstart.  This is the first project, the quick start. &lt;/li&gt;&lt;li&gt; Ensure that B is connected to the right motor, and C to the left motor.  Leave A unconnected. &lt;/li&gt;&lt;li&gt; Now download my &lt;a href="http://www.mediafire.com/file/a7fa6tdexxv9yyc/nxtBluetooth.tar.gz"&gt;nxtBluetooth.tar.gz package to demonstrate Linux Bluetooth communication&lt;/a&gt;.  Unpack it, and go through the files. &lt;/li&gt;&lt;li&gt; There are two programs: nx_soldier, which is the NX's program.   It listens on Bluetooth and obeys the commands of the commander.  The  pc_commander is a GTK application that allows you to specify commands  that the soldier will faithfully carry out. &lt;/li&gt;&lt;li&gt; There is a single place you have to edit to specify your NXT's  address.  Remember the times you changed 11:22:33:44:55:66 address  above?  Well, you need to open the &lt;tt&gt;pc_commander.c&lt;/tt&gt; file and change this address to that of your NXT again. &lt;/li&gt;&lt;li&gt; Attach your NXT using the USB cable.  Compile the programs with &lt;br /&gt;&lt;pre&gt;$ grep ADDRESS pc_commander.c       &lt;br /&gt;$ # Make sure you have the right address&lt;br /&gt;$ make nx_soldier.rxe&lt;br /&gt;$ make pc_commander &amp;amp;&amp;amp; ./pc_commander&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt; Run the nx_soldier program on the NXT. &lt;/li&gt;&lt;li&gt; Run the pc_commander on the Linux machine.  Press the buttons to make the soldier move according to your wishes. &lt;/li&gt;&lt;li&gt; When you ask the soldier for his status, he always replies he is fine. &lt;/li&gt;&lt;li&gt; This program makes a good starting point: the code is  reasonably well documented, and easy to adapt.  You could try putting the bumper sensor on the TriBot, and modifying the nx_soldier so  that he replies with "I am stuck" when it has hit a wall. &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-415256989849593687?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/415256989849593687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/programming-nxt-to-communicate-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/415256989849593687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/415256989849593687'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/programming-nxt-to-communicate-with.html' title='Programming the NXT to communicate with Linux'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-2908169765628020992</id><published>2011-07-05T11:25:00.000-07:00</published><updated>2011-07-10T15:34:04.776-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Setting up the Lego programming environment in Linux</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is Part 2 of programming the Lego NXT using Linux. &lt;a href="http://www.eggwall.com/2011/07/setting-up-nxt-bluetooth-support-on.html"&gt;Part 1 covers the Lego-Linux bluetooth connection.&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;If you're like me, you've used the graphical NXT programming environment for about twenty minutes before wrist pain and frustration sets in.  I did not enjoy the graphical programming at all, and the fact that it did not work on Linux was another factor.  Well, there is a very nice alternative, which is John Hansen's NXC language.  It is a C-like language which you can program the NXT in.  You'll hear a lot of references to BrixCC, which is an IDE for NBC and NXC.  It doesn't exist for Linux, but any text editor works quite well.  All features are supported, and you can write code that is more compact and faster than the graphical tool.  Also, you can use NXC to allow your robot to communicate with your Linux computer over bluetooth!  This is what you need to do to start using NXC. &lt;br /&gt;&lt;ul&gt;&lt;li&gt; Visit the   excellent &lt;a href="http://bricxcc.sourceforge.net/nbc/beta/index.html"&gt;NXC beta   release page &lt;/a&gt;.  There is no stable release as of March 2009, but   the beta is pretty rock solid.  Forget the source code, it is made   in Delphi and there is little documentation on how to compile it   under Linux.  Get the binary distribution.  It consists of some very   spare documentation and the &lt;tt&gt;nbc&lt;/tt&gt; executable.  Despite its   name, it is also the NXC compiler.  This will only work on x86   Linux.   &lt;/li&gt;&lt;li&gt;Run &lt;tt&gt;nbc -help&lt;/tt&gt; to learn the options.  Really, this program needs a man page!   &lt;/li&gt;&lt;li&gt;Visit the &lt;a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/index.html"&gt;NXC documentation page&lt;/a&gt; and get the &lt;a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_Guide.pdf"&gt;lovely NXC_Guide.pdf, a guide on how to program using NXC&lt;/a&gt;.  Download it but don't look at it yet.  It is a reference, not an introduction.   &lt;/li&gt;&lt;li&gt;The real document you're looking for is &lt;a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_tutorial.pdf"&gt;Danny Benedettelli's NXC tutorial&lt;/a&gt;, which is far more useful than the guide.  Download it, print it out, read it through and through.   &lt;/li&gt;&lt;li&gt;To set up the USB communication, download &lt;a href="http://www.mediafire.com/file/bp27pjpfq74o3ob/setupNxtUSB.sh"&gt;setupNxtUSB.sh: shell script to perform USB settings for Linux communication with NXT&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Run it by itself as follows&amp;nbsp;&lt;pre&gt;$ chmod +x ./setupNxtUSB.sh;&lt;br /&gt;$ ./setupNxtUSB.sh&lt;br /&gt;&lt;/pre&gt;This will prompt you for the root password when required.   The file follows instructions  from the &lt;a href="http://bricxcc.sourceforge.net/nbc/doc/nxtlinux.txt"&gt;page about Linux USB setup with NXT&lt;/a&gt;,  so all credit to them.  Feel free to edit the file if you suspect  something went wrong.  The script will prompt you with any errors that  it encountered.   &lt;/li&gt;&lt;li&gt;In case you aren't certain if the setup worked, plug in your  NXT.  You should see the word "USB" in the top left of the NXT display,  and the output of the command &lt;tt&gt;ls -l /dev/lego*&lt;/tt&gt; should show at least one device.  My output is given as a reference &lt;pre&gt;$ ls -l /dev/lego*&lt;br /&gt;lrwxrwxrwx 1 root root 15 2009-04-19 17:45 /dev/legonxt-2-1 -&amp;gt; bus/usb/002/042&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt; Write a sample program using Danny's guide.   &lt;/li&gt;&lt;li&gt;Compile your program with &lt;tt&gt;nbc your_program.nxc -d -S=usb&lt;/tt&gt;, where &lt;tt&gt;your_program.nxc&lt;/tt&gt; is the name of your program.   &lt;/li&gt;&lt;li&gt; Now the program has been compiled and loaded on to the NXT.   It should appear in the "My Files" -&amp;gt; "Software Files" area of the  NXT, from where you can run it!   &lt;/li&gt;&lt;li&gt; There, that wasn't so hard!  As you learn NXC, you'll  realize that it is feature complete, and is a much more elegant way of  programming the NXT. &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-2908169765628020992?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/2908169765628020992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/setting-up-lego-programming-environment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2908169765628020992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/2908169765628020992'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/setting-up-lego-programming-environment.html' title='Setting up the Lego programming environment in Linux'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3344452400624320842</id><published>2011-07-05T10:25:00.000-07:00</published><updated>2011-07-10T15:34:04.776-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hacking'/><title type='text'>Setting up NXT-Bluetooth support on Linux</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;So  you want your NXT device  to talk back to  your Linux machine? Perhaps you  want to control your  robot through your  computer.  As a first  step,   you  have  to  set   up  the  Linux   -  NXT  bluetooth connection. My setup is explained below. &lt;br /&gt;&lt;ul&gt;&lt;li&gt; Ubuntu Gutsy (7.10) Linux, though these instructions are not  version dependant.  The only instructions that depend on the   distribution are the ones related to package installation (apt-get).  If  you know your distribution's package manager, you should have no  trouble. &lt;/li&gt;&lt;li&gt;  An x86  computer.   Typically, you'll  want  a laptop  with bluetooth support, so you can  walk around with your NXT construction. A desktop will do just fine too.  You need an x86 because the nbc binary only works on an x86. &lt;/li&gt;&lt;li&gt; A &lt;a href="http://mindstorms.lego.com/"&gt;Lego Mindstorm NXT&lt;/a&gt;. &lt;/li&gt;&lt;li&gt; Bluetooth hardware on your linux machine. &lt;/li&gt;&lt;li&gt; The Linux packages: &lt;tt&gt;bluez-utils, python-bluez, bluez-hcidump, bluez-gnome, bluetooth&lt;/tt&gt; &lt;/li&gt;&lt;/ul&gt;Make sure you have all the packages installed.  On Ubuntu, you can run this command.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;sudo apt-get install bluez-utils \&lt;br /&gt;     python-bluez bluez-hcidump bluez-gnome bluetooth&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now, once all the packages are installed, make sure that your bluetooth  hardware is supported and is running fine.  One way to do this is to  check for the bluetooth icon in the taskbar of Gnome.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-9oHnSxxfkDY/ThNIaHS5aWI/AAAAAAAAAOM/rh90hJsuGgY/s1600/01.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-9oHnSxxfkDY/ThNIaHS5aWI/AAAAAAAAAOM/rh90hJsuGgY/s1600/01.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You should be able to click on that icon and get a list of preferences.   In case you are not sure if you device is getting recognized and used,  check for lines similar to the ones below in the output of  &lt;tt&gt;dmesg&lt;/tt&gt;&lt;br /&gt;&lt;tt&gt;&amp;nbsp;&lt;/tt&gt; &lt;br /&gt;&lt;pre&gt;[243203.060226] Bluetooth: HCI USB driver ver 2.9&lt;br /&gt;[243203.063512] usbcore: registered new interface driver hci_usb&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now that you have a working bluetooth setup, you need to pair it with  the NXT brick.  First, you need to ensure that the serial service is  started by selecting it in the preferences dialog from the bluetooth  icon. &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Izbl40VL5kk/ThNIiHz1NkI/AAAAAAAAAOQ/LBPfqOCpVCg/s1600/02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-Izbl40VL5kk/ThNIiHz1NkI/AAAAAAAAAOQ/LBPfqOCpVCg/s1600/02.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now turn on your NXT Brick, and enter bluetooth settings, and turn  bluetooth on.  You can verify that bluetooth is turned on by looking in  the top left of the NXT display.  It should have a bluetooth icon.  Now  run the command &lt;tt&gt;sudo hcitool scan&lt;/tt&gt; from a console.  The output  should contain a line for your NXT device.  My device is called Snow,  and I get the following output.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Scanning ...&lt;br /&gt; 11:22:33:44:55:66 Snow&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Great!.  This is definite proof that your bluetooth device works, and  that it can see your NXT.  Time to set them up for pairing.  Edit the  file &lt;tt&gt;/etc/bluetooth/rfcomm.conf&lt;/tt&gt; to contain the following block:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rfcomm0 {&lt;br /&gt;        # Automatically bind the device at startup&lt;br /&gt;        bind yes;&lt;br /&gt;&lt;br /&gt;        # Bluetooth address of the device&lt;br /&gt;        device 11:22:33:44:55:66;&lt;br /&gt;&lt;br /&gt;        # RFCOMM channel for the connection&lt;br /&gt;        channel 1;&lt;br /&gt;&lt;br /&gt;        # Description of the connection&lt;br /&gt;        comment "Snow Mindstorm";&lt;br /&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Change the address 11:22:33:44:55:66 to match the output of your &lt;tt&gt;hcitool scan&lt;/tt&gt; command that you made in the previous step.  Now run the command &lt;tt&gt;sudo /etc/init.d/bluetooth restart&lt;/tt&gt;, and then &lt;tt&gt;rfcomm&lt;/tt&gt;.  The output should contain your device's address.  A sample session is shown here:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$ sudo /etc/init.d/bluetooth restart&lt;br /&gt;   * Restarting bluetooth            [ OK ]&lt;br /&gt;$ rfcomm&lt;br /&gt;rfcomm0: 11:22:33:44:55:66 channel 1 clean&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now, you need to pair your device.  This is done with the following command  &lt;br /&gt;&lt;pre&gt;$ sudo l2ping 11:22:33:44:55:66&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;This will prompt the NXT to beep happily, asking for a passphrase.   The  number "1234" is already entered, so just accept it by pressing the  orange button.  Now your computer will want to know this passphrase.   Click on the button in the notification that pops up (example shown  below), and enter the same number as shown.  This is a one-time  procedure for each computer-NXT combination.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-lUT0euWahcA/ThNImMKoh3I/AAAAAAAAAOU/HY4j7qnUz5o/s1600/03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-lUT0euWahcA/ThNImMKoh3I/AAAAAAAAAOU/HY4j7qnUz5o/s1600/03.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-XffTXW-snRc/ThNIppQzKoI/AAAAAAAAAOY/W72P3mNwwCM/s1600/04.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-XffTXW-snRc/ThNIppQzKoI/AAAAAAAAAOY/W72P3mNwwCM/s1600/04.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;If you have a &lt;a href="http://en.wikipedia.org/wiki/Multiseat"&gt;multi-seat (or multi-terminal) setup&lt;/a&gt;,  this notification might be going to another seat, so check all  notification areas on every terminal.  If you don't know what multi-seat  or multi-terminal setup is, ignore the previous statement.  If all went  well, your ping command should be able to send packets back and forth  to the NXT.  A happy sample output is shown below. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Ping: 11:22:33:44:55:66 from 00:09:DD:50:67:CE (data size 44) ...&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 0 time 49.95ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 1 time 85.71ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 2 time 27.80ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 3 time 54.80ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 4 time 65.81ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 5 time 47.80ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 6 time 84.79ms&lt;br /&gt;4 bytes from 11:22:33:44:55:66 id 7 time 45.81ms&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Great!  So now your NXT is paired with the computer.  In order to communicate with the desktop, you need to download the &lt;a href="http://home.comcast.net/%7Edplau/nxt_python/"&gt;NXT Python library&lt;/a&gt;.   Once you have downloaded and installed it, enter the sample program,  and you should be able to get the NXT's name and ID.  If you have any  problems at this stage, try rebooting the NXT brick, it sometimes helps.   After running the sample program, you should see your hostname in the  "My Contacts" in the NXT's bluetooth menu.  This verifies that you can  connect with the NXT, and have the NXT talk back to the desktop  computer.&lt;br /&gt;&lt;br /&gt;(This is the stable home of the page that was earlier at vikram.eggwall.com) &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3344452400624320842?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3344452400624320842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/setting-up-nxt-bluetooth-support-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3344452400624320842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3344452400624320842'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/setting-up-nxt-bluetooth-support-on.html' title='Setting up NXT-Bluetooth support on Linux'/><author><name>Vikram Aggarwal</name><uri>http://www.blogger.com/profile/11194563536107656485</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://4.bp.blogspot.com/-kNtgjM1dEDU/TbRl5d_ksHI/AAAAAAAAAFU/5zjt8V3s5IY/s220/mugshot.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-9oHnSxxfkDY/ThNIaHS5aWI/AAAAAAAAAOM/rh90hJsuGgY/s72-c/01.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-3933484113642885503</id><published>2011-07-03T00:00:00.000-07:00</published><updated>2011-07-23T17:54:49.958-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hiking'/><title type='text'>Hiking: Portola Redwoods State Park, July 4, 2010</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;iframe frameborder="0" height="350" marginheight="0" marginwidth="0" scrolling="no" src="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=107963207143202025359.00048a875d92bf43f3539&amp;amp;ll=37.25757,-122.19829&amp;amp;spn=0.012247,0.037321&amp;amp;output=embed" width="425"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This was our first time  camping and hiking at the Portola Redwood State Park.  The  drive to Portola from San Jose is  almost as long as the drive to Big Basin - about  1 hour.  The park is nice, but we like Big Basin and Henry Cowell better. &lt;br /&gt;There's a short trail starting behind the camp office, the Sequoia Nature trail I  think, that takes you to a small  stream with a bridge running  across it.   This is  a great  place to  come by  for  a late evening walk from the campground. &lt;br /&gt;The  main hike  marked in the  map was  on the Slate  Creek trail. Took us a  while to get to  the trailhead, as you can  see.  We walked over 9 miles, spanning an elevation gain of 1000 - 1200 feet.  A large map of the hike can be found &lt;a href="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=107963207143202025359.00048a875d92bf43f3539&amp;amp;z=15"&gt; here&lt;/a&gt;.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-3933484113642885503?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/3933484113642885503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/hiking-portola-redwoods-state-park-july.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3933484113642885503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/3933484113642885503'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/hiking-portola-redwoods-state-park-july.html' title='Hiking: Portola Redwoods State Park, July 4, 2010'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-4076702905137436439</id><published>2011-07-01T00:00:00.000-07:00</published><updated>2011-07-23T17:56:41.855-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hiking'/><title type='text'>Hiking: Henry Coe State Park, Jun 26, 2010</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;iframe frameborder="0" height="350" marginheight="0" marginwidth="0" scrolling="no" src="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=107963207143202025359.000489f58cd224e2127ed&amp;amp;ll=37.19638,-121.537304&amp;amp;spn=0.022123,0.019875&amp;amp;output=embed" width="425"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The campgrounds at Henry Coe  are very nice.  There are just a few campgrounds,  so it's  a lot  quieter, and  the view  is great.   On a nearly-full-moon Friday  night in late June, it  was spectacular.  The facilities are primitive, but well maintained. &lt;br /&gt;We started  hiking  early, expecting  most  of the  trails to  be exposed to the  sun, but our path was reasonably  well shaded by trees and large shrubs.  Okay - here's  the 6.6 mile loop we did: started up the Monument Trail, made a left  on Hobbs road, right on the Frog Lake Trail  (there were many  tiny, camouflaged  frogs jumping  all over!), right on  the Middle Ridge  trail, right on  the Fish Trail,  and then back to  the Camp  Headquarters via the  Corral trail.  The  route was pretty well-marked all along. &lt;br /&gt;Oh, and apart from being on the lookout for poison oak, also be on the  lookout for  ticks.  Light  colored clothing  is probably  a good idea - makes them easier to spot and de-tick. &lt;br /&gt;A large map of the hike can be found &lt;a href="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=107963207143202025359.000489f58cd224e2127ed&amp;amp;z=15"&gt; here&lt;/a&gt;.  The route covered roughly  1800 feet of elevation gain over a 6.6  mile stretch,  but the uphill  stretches are  interspersed with easier  stretches.   Walking  the  same  route  in  an  anti-clockwise direction would probably be a lot more strenous.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19163975-4076702905137436439?l=www.eggwall.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.eggwall.com/feeds/4076702905137436439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.eggwall.com/2011/07/hiking-henry-coe-state-park-jun-26-2010.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4076702905137436439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19163975/posts/default/4076702905137436439'/><link rel='alternate' type='text/html' href='http://www.eggwall.com/2011/07/hiking-henry-coe-state-park-jun-26-2010.html' title='Hiking: Henry Coe State Park, Jun 26, 2010'/><author><name>Neha</name><uri>http://www.blogger.com/profile/06155605342414360995</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19163975.post-6187695704940343928</id><published>2011-06-30T00:00:00.000-07:00</published><updated>2011-06-30T00:00:09.457-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hiking'/><title type='text'>Hiking: Sanborn Skyline Country Park, Jun 5, 2010</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;iframe frameborder="0" height="350" marginheight="0" marginwidth="0" scrolling="no" src="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa
