<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.local-guru.net,2005:/blog/tag/helloworld</id>
  <link type="text/html" href="http://www.local-guru.net" rel="alternate"/>
  <link type="application/atom+xml" href="http://www.local-guru.net/blog/tag/helloworld.atom" rel="self"/>
  <title>GuruBlog : Articles about helloworld</title>
  <subtitle>local-guru.net</subtitle>
  <updated>2009-03-03T04:25:00+01:00</updated>
  <generator>GuruBlog engine</generator>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/129</id>
    <published>2009-03-03T04:25:00+01:00</published>
    <updated>2009-03-03T04:25:00+01:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2009/3/3/handassembled-java-bytecode" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">Handassembled java bytecode</title>
    <category term="java" scheme="http://www.local-guru.net/blog/tag/java"/>
    <category term="machinelanguage" scheme="http://www.local-guru.net/blog/tag/machinelanguage"/>
    <category term="helloworld" scheme="http://www.local-guru.net/blog/tag/helloworld"/>
    <category term="asm" scheme="http://www.local-guru.net/blog/tag/asm"/>
    <content type="html">&lt;p&gt;motivated by my &lt;a href="http://www.local-guru.net/blog/2009/02/25/machine-language-hello-world-in-120-bytes"&gt;hand written x86 machinecode&lt;/a&gt;, i decided
that i had to take it to the next level.&lt;/p&gt;

&lt;p&gt;i worte some handassembled java bytecode. run the file below as&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;./dump.sh &amp;gt; HelloAsm 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and run the programm with&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;java HelloAsm
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/128</id>
    <published>2009-02-25T05:37:00+01:00</published>
    <updated>2009-02-25T05:37:00+01:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2009/2/25/machine-language-hello-world-in-120-bytes" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">Machine language Hello-World in 120 bytes</title>
    <category term="machinelanguage" scheme="http://www.local-guru.net/blog/tag/machinelanguage"/>
    <category term="helloworld" scheme="http://www.local-guru.net/blog/tag/helloworld"/>
    <category term="asm" scheme="http://www.local-guru.net/blog/tag/asm"/>
    <category term="x86" scheme="http://www.local-guru.net/blog/tag/x86"/>
    <content type="html">&lt;p&gt;a while ago i read the really cool &lt;a href="http://lab16.axiosmedia.org/2009/02/programming-your-pdp-11-part-0/trackback/"&gt;tutorial on programming a pdp11&lt;/a&gt;.
after typing the "hello world" example into the simulator, i startet to search for
instructions how to write the machine code for the pdp11 myself.&lt;/p&gt;

&lt;p&gt;after a while coding in raw octal numbers, i wanted to take it to the next level and
searched for a way to write machine code by hand for my linux box&lt;/p&gt;

&lt;p&gt;So i downloaded
&lt;a href="http://developer.intel.com/design/pentiumii/manuals/243191.htm"&gt;Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference Manual&lt;/a&gt;
and wrote a shell script that can be used to dump the raw machine code into a
file. of course my dualcore-pentium-mega-bla processor in far more sophisticated than
the pdp11 cpu was. so it can't be programmed in octal numbers - i used hexadezimal numbers :-)&lt;/p&gt;

&lt;p&gt;execute the shellscript and pipe it into a file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sh dump.sh &amp;gt; hello
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;make it executable and - TATAAAA - a hello world programm in 120 bytes (including the
elf header - which adds 80 bytes all by himself)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# write a elf header in the file
echo -ne "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
echo -ne "\x02\x00\x03\x00\x01\x00\x00\x00\x54\x80\x04\x08\x34\x00\x00\x00"
echo -ne "\x80\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x28\x00"
echo -ne "\x03\x00\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x04\x08"
echo -ne "\x00\x80\x04\x08\x6f\x00\x00\x00\x6f\x00\x00\x00\x05\x00\x00\x00"
echo -ne "\x00\x10\x00\x00"


echo -ne "\x31\xc0"  # clear eax
echo -ne "\x50"  # push 0 on the stack
echo -ne "\x68rld\x0a"  # push the string onto the stack in reverse order, 4 bytes a time
echo -ne "\x68o Wo"
echo -ne "\x68Hell"

echo -ne "\x89\xe1"  # move stackpointer to ecx ( the start of our string )
echo -ne "\xb0\x04"  # move 4 to al ( eax is already 0 because auf line one )
echo -ne "\x33\xc3\xb3\x01"  # xor ebx and move 1 to bl
echo -ne "\x32\xc2\xb2\x0c"  # xor edx and move 12 onto dl (length of the string )
echo -ne "\xcd\x80"  # int 0x80
echo -ne "\xb0\x01"  # move 1 into al
echo -ne "\xcd\x80"  # int 0x80
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
</feed>

