<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hbr</title>
	<atom:link href="http://brnz.org/hbr/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://brnz.org/hbr</link>
	<description>Hint for Branch (r-form)</description>
	<lastBuildDate>Sun, 25 Mar 2012 20:56:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Processor architectures: seeking source material</title>
		<link>http://brnz.org/hbr/?p=1086</link>
		<comments>http://brnz.org/hbr/?p=1086#comments</comments>
		<pubDate>Sun, 25 Mar 2012 20:56:43 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[processor architectures]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1086</guid>
		<description><![CDATA[To satisfy my own curiosity I want to do some writing about CPU architectures &#8211; analysis, comparison, origins, history/evolution, variants, etc. I envision writing blog posts, possibly many &#8212; it depends on how things go. CPUs/families that I&#8217;d like to know more about include (off the top of my head) x86, ppc, arm, mips, m68k/coldfire, [...]]]></description>
			<content:encoded><![CDATA[<p>To satisfy my own curiosity I want to do some writing about CPU architectures &#8211; analysis, comparison, origins, history/evolution, variants, etc. I envision writing blog posts, possibly many &#8212; it depends on how things go.</p>
<p>CPUs/families that I&#8217;d like to know more about include (off the top of my head) x86, ppc, arm, mips, m68k/coldfire, z80, 6502, SuperH, sparc, alpha, m88k. (to start with &#8212; there&#8217;s many more with interesting stories :)</p>
<p>Before I write about these, I want to be well informed. As such, I&#8217;m looking for recommendations of enlightening things to read. In many cases I can look at technical documentation provided by vendors, but these usually don&#8217;t provide a lot of background, context or history of an architecture.</p>
<p>What has been written about these (or other) CPU architectures? I&#8217;m keen to know about the origins and evolution of architectures. What forces (technical, financial, marketing, etc) influenced designs? How have they changed over time? I&#8217;m interested in comparisons between architectures, implementation details, extensions, variations, anything that will illuminate the reasons, benefits, deficiencies, and more about a design.</p>
<p>So, what should I be reading? (or who should I talk to? :D)</p>
<p>[I've asked the same question over on <a href="https://plus.google.com/106076942907002179702/posts/FTtKZiB3Q9t">google plus</a>, and I will be collating answers there]</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1086</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of Careers in Gamedev presentations  [aka Memoirs of a Career Motivational Speaker (retired)]</title>
		<link>http://brnz.org/hbr/?p=1072</link>
		<comments>http://brnz.org/hbr/?p=1072#comments</comments>
		<pubDate>Fri, 02 Mar 2012 06:53:00 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1072</guid>
		<description><![CDATA[In my previous post, I wrote about my outline and intent for talking about getting into a career in game development (or elsewhere). In the end, I delivered the presentation ten times at five different high schools. Here are my recollections and reflection on the experience. High School 1 The first high school was a [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I wrote about my outline and intent for talking about getting into a career in game development (or elsewhere). In the end, I delivered the presentation ten times at five different high schools. Here are my recollections and reflection on the experience.</p>
<h2>High School 1</h2>
<p>The first high school was a lot of fun. As I mentioned in the previous post, I was somewhat uncertain about what would constitute an appropriate pitch and this was my first such talk to a group of unknown teenagers &#8212; which makes it exciting/scary/fun :)</p>
<p>I talked to two groups of around 40 students back to back. There was a mix of grades (7-10) and a pretty good balance of male/female. The room was smallish for the group, which I like as it makes it all feel nice and cosy, and helps focus attention. Unfortunately, there was limited ventilation, so it did get a bit stuffy through the talks. I got lots of good questions throughout the presentation. There were dead patches (combination of stuffiness and me talking for too long), but overall I was very happy with these sessions. The majority of questions came from younger students, with fewer from those in grade 9 and 10, though those seemed to be (at least) weighing up what I had to say.</p>
<p>I don&#8217;t recall giving the same presentation back-to-back before, and due to my talk-about-things-as-I-get-to-them style, at various stages in the second talk I lost track of whether I was repeating myself to the group. Fortunately, I had the Pathway Planning Officer present in the room (sitting among the group) who asked some useful leading questions from time to time, which seemed to work well.</p>
<p>Also, I had some pacman-shaped keychains from the UTas School of Computing. They were popular ;)</p>
<p>Feedback: see the comment <a href="http://brnz.org/hbr/?p=1062#comment-40962">here</a>.</p>
<h2>High School 2</h2>
<p style="text-align: left;">After being advertised to other high schools around the state, I was contacted about visiting another one nearby. The original suggestion was that I would talk to the ICT class(es) &#8212; I pushed back against this, suggesting that it would be far better to talk to students with some interest in the industry, and this was agreed to.</p>
<p style="text-align: left;">The presentation was &#8212; I believe &#8212; advertised to students, and they could opt in. The group was 40+ students, mostly year 9 and 10, some 7 and 8, and included one female.</p>
<p style="text-align: left;">The setting was a larger area in an open-plan building, which meant attention was less focussed inwards. I would describe this talk as being &#8220;more work&#8221;. I got far fewer questions and less interaction, which resulted in me talking more. I don&#8217;t like that &#8212; it tends to be a cycle that is hard to break. That said, I still got a number of good questions. Particularly, some of the younger guys were very keen and were making games. At this school I was asked for suggestions about how to get into gamedev when you don&#8217;t have a computer or internet access outside of school.</p>
<p style="text-align: left;">At one stage in the presentation, I was certain that I saw a look of horror on the face of one of the staff due to something I&#8217;d said. Not sure what it was (or &#8212; in hindsight &#8212; if I&#8217;d read it correctly), but it stood out and amused me just a bit.</p>
<h2 style="text-align: left;">High School 3</h2>
<p style="text-align: left;">Another room full of guys, opted-in, nicely structured seating, great attention, lots of questions and engagement. Grades 7&#8211;10 (iirc). Turned out that this school uses GameMaker as part of the ICT curriculum, and these were a particular eager and interested bunch.</p>
<p style="text-align: left;">After the presentation, one asked to show me a game he had been working on, which was absolutely fantastic to see &#8212; I got to see it in action, hear his plans for what he wanted to do with it, offer some ideas. Also, some days afterwards, one of the students sent me a thank-you card! :D</p>
<h2 style="text-align: left;">High School 4</h2>
<p style="text-align: left;">This place was hard work. Three sessions, each to a different grade computing class (against my stated preference). Included students who were vocally opposed to being there, and consequently an environment where it was difficult to get engagement (answers to questions or questions from the audience). Sessions were held in computing classrooms, with PCs around the outside of the room, and chairs clustered (somewhat awkwardly) in the middle.</p>
<p style="text-align: left;">It wasn&#8217;t a total loss &#8212; there were certainly students interested in gamedev careers, and there were others that (I&#8217;m pretty sure) heard enough about what I had to say about career preparation in general that it might be of benefit.</p>
<p style="text-align: left;">The second session was with the grade 10 class, who were very short on questions. There were a number in this group who were clearly a lot more thoughtful and calculating &#8212; there were looks of concentration on and consideration of what I had to say. Also, the couple of teachers in the room threw in some questions to help focus the content on what was relevant to this age group &#8212; questions of subject selection for college and later came up from teachers a few times through the talk. My answer to that is do what is useful for the sort of career you want &#8212; there are potential benefits to both broader and narrower paths.</p>
<p style="text-align: left;">The three talks at this school were spread out over a whole school day, and the last group, at the end of the day were grade 7 and 8s. There was not a lot of focussed attention in the room. There were a number that were distracted and distracting for most of the session. In the end, it kind of devolved into me asking for games people had played recently and me providing a quick fact/anecdote/news headline about the game/mechanic/developer/development process/whatever. In hindsight, I&#8217;m not sure what it was the best way to round out the session &#8212; it kept their attention, but probably wasn&#8217;t all that useful.</p>
<p style="text-align: left;">There was a cool conclusion to the day &#8212; after the last session, one of the students demoed some gameplay extensions he&#8217;d made to a game he&#8217;d downloaded from @notch&#8217;s website (I think it was <a href="http://www.mojang.com/notch/ld12/breaking/">this</a>). Getting to meet students with this kind of interest and enthusiasm (and this wasn&#8217;t the only time it happened) was the high point for me of the whole series of presentations.</p>
<h2 style="text-align: left;">High School 5</h2>
<p style="text-align: left;">Final school, another three presentations. This time, I spoke to all of the grade 10 students (and one grade 9 guy who was super keen). I was a bit worried that this one would be another one stifled by objectors, but overall things went very well. The students were interested and engaged, and mostly the dynamic within the room was comfortable/amiable. It was a great place to finish.</p>
<p style="text-align: left;">The school has a large kitchen operated by students, and I was provided lunch from there which was also pretty cool &#8212; students eager, active and making stuff (eats!) was consistent with what I was trying to encourage and a delight to see :D</p>
<h2 style="text-align: left;">Summing up</h2>
<p style="text-align: left;">Themes of questions did tend to vary from school to school &#8212; I do recall answering different styles of questions at different schools, though it&#8217;s hard to generalise what the differences were. I did get quite a few questions about what my favourite game is that I was not well prepared for &#8212; &#8220;I like lots of different types of games&#8221; is not a satisfying answer, even to me.</p>
<p style="text-align: left;">I had very little with me in terms of props &#8212; a whiteboard, upon which I wrote my name and wrote the 5 points as I went through them, and my Touchpad (containing notes, in case of catastrophic memory failure). My name &#8212; deliberately written out in full &#8212; tended to lead to some banter between myself and those gathered before the presentation regarding its pronunciation, which worked as a starting ice breaker. I did try chatting with the students beforehand in most cases to try to help lower the barrier to interaction during the talk.</p>
<p style="text-align: left;">Another stand-out was arriving early at one of the schools and getting to hear a couple of pieces performed by the small male choir, which was very impressive :)</p>
<p style="text-align: left;">Was it worth it? What was the benefit? Would I do it again? I enjoyed delivering the presentations, and the experience overall &#8212; but that wasn&#8217;t the point of the exercise. The feedback I have received is that there were students who were impacted by what I had to say &#8212; there were consequences. Students (and teachers) gained a slightly better understanding of the industry. I didn&#8217;t sugar-coat it &#8212; I presented what I think was a fair summary of risk and reward. I told no one to go into gamedev &#8212; rather, encouraged them to work for what they&#8217;re passionate about, to choose to do things that will help, and maybe to aspire a little higher than they otherwise might do. Given the chance, I would be very happy to do this sort of thing again.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1072</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting into gamedev [aka Career Motivational Speaker]</title>
		<link>http://brnz.org/hbr/?p=1062</link>
		<comments>http://brnz.org/hbr/?p=1062#comments</comments>
		<pubDate>Sun, 22 Jan 2012 22:45:14 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1062</guid>
		<description><![CDATA[Before departing Tasmania, I visited several high schools where I talked about getting into a career in gamedev. That was the premise, at least &#8212; I really talked more about what you can do to get a job doing what you like. Lots of high school students like games and I was getting ready to [...]]]></description>
			<content:encoded><![CDATA[<p>Before departing Tasmania, I visited several high schools where I talked about getting into a career in gamedev. That was the premise, at least &#8212; I really talked more about what you can do to get a job doing what you like. Lots of high school students like games and I was getting ready to move for a gamedev job, so it was a good hook.</p>
<p>The opportunity came about from a conversation (with a high school student) about my upcoming move, what I was doing and how it had come about, and about what part of my experience was relevant to his own. The conversation was had while the Pathway Planning Officer for a local school was nearby, and she invited me to the school to talk to some of the students there.</p>
<p>The problem then became how to turn a spontaneous conversation into something sufficiently well-prepared and engaging that I could talk to a room of teenagers for up to an hour. I enjoy presenting to/speaking with groups, particularly on topics that I&#8217;m passionate about, but I have little experience talking to teenagers and was somewhat uncertain about what I&#8217;d need to do to get and keep their attention. I like to keep presentations interactive and flexible &#8212; I&#8217;d rather talk about what interests the listeners than about my own prepared material. For that reason, I don&#8217;t tend to use slides and try to be interesting, engaging and memorable all on my own. (there&#8217;s always a risk leaving out something &#8220;important&#8221; &#8212; but as there&#8217;s always far more material than I can cover in a single presentation, if the audience has been interested it&#8217;s probably a nett win :P)</p>
<p>For all my desire to keep it free-flowing and interactive, to give a talk without a clear idea of what I want to talk about and how it fits together in a coherent and plausible manner, I&#8217;m going to struggle to impart any useful information/knowledge to the students that have so generously taken time out from their Social Science class (or whatever). It&#8217;s hard to evoke passion without passion. I find it easier to convey my excitement and passion for something when I&#8217;m well prepared to talk about it.</p>
<p>I did some reading in preparation of the talk to make sure that I wouldn&#8217;t be talking nonsense. While I was about to start in the industry, I had not worked in the industry. While I didn&#8217;t think I had many incorrect preconceptions or invalid assumptions about the industry (who would?), my lack of experience was one thing that cropped up repeatedly through recent job applications. I thought it appropriate to do my best to make sure what I had to say would be generally useful.</p>
<p>I read what I could find, but a couple of sites stood out in particular: there&#8217;s a lot of the great advice on <a href="http://tinysubversions.com">tinysubversions.com</a>, particularly the material on <a href="http://tinysubversions.com/2005/10/effective-networking-in-the-games-industry-introduction/">effective networking in the games industry</a>.  Linked from there, I found a link to a list of <a href="http://www.chrishecker.com/New_Year%27s_Resolutions_for_Game_Industry_Newbies">New Year&#8217;s Resolutions for Game Industry Newbies (or people who want to eventually be one)</a>,  which I basically ripped off to form the core of my presentation (many thanks to Chris Hecker and Jonathan Blow for the list).</p>
<p>Here&#8217;s an outline of what I talked about:</p>
<ul>
<li>who I am</li>
<ul>
<li>always good for the audience to know the name of the guy they&#8217;re listening to.</li>
<li>talk about my education and work history with emphasis on what are likely to be common points of reference &#8212; educated/live in local area, personal history back to the age of the audience</li>
<li>upcoming move &#8212; mention Insomniac and the games they&#8217;ve made, find out how many people in the room knew Insomniac IP (lots)</li>
<li>(made the point that my own education history is not being held up as any ideal for how to get into the industry &#8212; far from it)</li>
</ul>
<li>why I like gamedev (or talk about the sort of gamedev role I aspire to&#8230;)</li>
<li>the diversity of careers available in gamedev</li>
<ul>
<li>used this to kick of some interaction &#8212; ask the audience &#8220;What goes into making a game? What sort of jobs are there in gamedev?&#8221;</li>
<li>purpose was to emphasise diversity of opportunity. It&#8217;s not just programmers. (more on that later, though)</li>
</ul>
<li>nature of the industry &#8211;</li>
<ul>
<li>games are popular</li>
<ul>
<li>high % of people play electronic games of one kind or another</li>
<li>lots of money spent on games</li>
</ul>
<li>often unreliable working situation</li>
<ul>
<li>recent history of  gamedev studios in .au (and elsewhere) is not good</li>
</ul>
<li>not many Australian gamedevs</li>
<ul>
<li>estimates of &lt;3,000 gamedevs in .au</li>
<li>contrast: &gt;300,000 teachers in .au (not sure if it was a useful stat, but I like it :)</li>
</ul>
<li>opportunity in smaller scale</li>
<ul>
<li>low entry options to making games</li>
<li>no guarantees of success&#8230;</li>
<li>the indie life is not for everyone</li>
</ul>
</ul>
<li>invite questions</li>
<li>on to five points (taken from the New Year&#8217;s Resolutions post &#8212; see more there)</li>
<ol>
<li>make things</li>
<ul>
<li>build experience, build portfolio</li>
<li>good idea, regardless of specialisation or desired industry</li>
</ul>
<li>play games</li>
<ul>
<li>play for purpose of critique, understanding</li>
<li>what makes this game good? why do I hate this one? how could it be better?</li>
<li>tie back to point 1 &#8212; make things based on what you&#8217;ve played, remake, modify, extend</li>
</ul>
<li>learn things</li>
<ul>
<li>generally a good idea :)</li>
<li>learn things that will help get to your desired career &#8212; be selective</li>
<li>I spruiked the UTas Bachelor of Computing (Games Technology) degree as one option</li>
<li>more learning -&gt; more understanding (hopefully). Helps with 1 and 2.</li>
<li>what you know matters</li>
</ul>
<li>people</li>
<ul>
<li>who you know matters</li>
<li>work with people locally with similar interests &#8212; opportunity now! Useful with 1, 2, 3</li>
<li>be active in the wider gamedev community e.g. follow gamedevs on twitter. Caveat: don&#8217;t be an annoying fanboi. Read, watch, learn, interact in a civil fashion.</li>
<li>being visible to people can help when applying for jobs</li>
</ul>
<li>learn to program</li>
<ul>
<li>presented as &#8220;optional&#8221;</li>
<li>useful skill no matter what &#8212; understand how computers work and how to bend them to your will</li>
</ul>
</ol>
<li>answer questions until time/questions run out</li>
</ul>
<p>For all the game-related content in the presentation, it was presented to make clear that these things will work outside the gamedev industry, too &#8212; do things that will help get you a job doing what you want, here are some things that can help.</p>
<p>Prepare yourself &#8212; opportunities come along from time to time. While you typically can&#8217;t make them happen, you can encourage their arrival. Don&#8217;t expect you can get a job with no experience/training/portfolio/etc &#8211; rather, do what you can to be as ready as you can be for when opportunities arrive.</p>
<p>(Additional: I was interested to hear TJ Fixman talk about similar ideas when recounting his own gamedev career path in a recent <a href="http://www.g4tv.com/videos/56800/feedback-looking-ahead-to-2012">Feedback</a> episode)</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1062</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Assembly Primer Part 7 — Working with Strings — ARM</title>
		<link>http://brnz.org/hbr/?p=1001</link>
		<comments>http://brnz.org/hbr/?p=1001#comments</comments>
		<pubDate>Wed, 20 Jul 2011 10:33:19 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Assembly]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1001</guid>
		<description><![CDATA[These are my notes for where I can see ARM varying from IA32, as presented in the video Part 7 — Working with Strings. I&#8217;ve not remotely attempted to implement anything approximating optimal string operations for this part &#8212; I&#8217;m just working my way through the examples and finding obvious mappings to the ARM arch [...]]]></description>
			<content:encoded><![CDATA[<p>These are my notes for where I can see ARM varying from IA32, as presented in the video <a href="http://securitytube.net/Assembly-Primer-for-Hackers-%28Part-7%29-Working-with-Strings-video.aspx">Part 7 — Working with Strings</a>.</p>
<p>I&#8217;ve not remotely attempted to implement anything approximating optimal string operations for this part &#8212; I&#8217;m just working my way through the examples and finding obvious mappings to the ARM arch (or, at least what seem to be obvious). When I do something particularly stupid, leave a comment and let me know :)</p>
<h2>Working with Strings</h2>
<pre escaped="true" lang="txt">.data
     HelloWorldString:
        .asciz "Hello World of Assembly!"
    H3110:
        .asciz "H3110"

.bss
    .lcomm Destination, 100
    .lcomm DestinationUsingRep, 100
    .lcomm DestinationUsingStos, 100</pre>
<p>Here&#8217;s the storage that the provided example <a href="http://code.securitytube.net/StringBasics.s">StringBasics.s</a> uses. No changes are required to compile this for ARM.</p>
<h3>1. Simple copying using movsb, movsw, movsl</h3>
<pre escaped="true" lang="txt">    @movl $HelloWorldString, %esi
    movw r0, #:lower16:HelloWorldString
    movt r0, #:upper16:HelloWorldString

    @movl $Destination, %edi
    movw r1, #:lower16:Destination
    movt r1, #:upper16:Destination

    @movsb
    ldrb r2, [r0], #1
    strb r2, [r1], #1

    @movsw
    ldrh r3, [r0], #2
    strh r3, [r1], #2

    @movsl
    ldr r4, [r0], #4
    str r4, [r1], #4</pre>
<p>More visible complexity than IA32, but not too bad overall.</p>
<p>IA32&#8242;s <strong>movs</strong> instructions implicitly take their source and destination addresses from <strong>%esi</strong> and <strong>%edi</strong>, and increment/decrement both. Because of ARM&#8217;s load/store architecture, separate load and store instructions are required in each case, but there is support for indexing of these registers:</p>
<h4>ARM addressing modes</h4>
<p>According to ARM A8.5, memory access instructions commonly support three addressing modes:</p>
<ul>
<li><strong>Offset addressing</strong> &#8212; An offset is applied to an address from a base register and the result is used to perform the memory access. It&#8217;s the form of addressing I&#8217;ve used in previous parts and looks like <strong>[rN, offset]</strong></li>
<li><strong>Pre-indexed addressing</strong> &#8212; An offset is applied to an address from a base register, the result is used to perform the memory access and also written back into the base register. It looks like <strong>[rN, offset]!</strong></li>
<li><strong>Post-indexed addressing</strong> &#8212; An address is used as-is from a base register for memory access. The offset is applied and the result is stored back to the base register. It looks like <strong>[rN], offset</strong> and is what I&#8217;ve used in the example above.</li>
</ul>
<h3>2. Setting / Clearing the DF flag</h3>
<p>ARM doesn&#8217;t have a DF flag (to the best of my understanding). It could perhaps be simulated through the use of two instructions and conditional execution to select the right direction. I&#8217;ll look further into conditional execution of instructions on ARM in a later post.</p>
<h3>3. Using Rep</h3>
<p>ARM also doesn&#8217;t appear to have an instruction quite like IA32&#8242;s <strong>rep</strong> instruction. A conditional branch and a decrement will be the long-form equivalent. As branches are part of a later section, I&#8217;ll skip them for now.</p>
<pre escaped="true" lang="txt">    @movl $HelloWorldString, %esi
    movw r0, #:lower16:HelloWorldString
    movt r0, #:upper16:HelloWorldString

    @movl $DestinationUsingRep, %edi
    movw r1, #:lower16:DestinationUsingRep
    movt r1, #:upper16:DestinationUsingRep

    @movl $25, %ecx # set the string length in ECX
    @cld # clear the DF
    @rep movsb
    @std

    ldm r0!, {r2,r3,r4,r5,r6,r7}
    ldrb r8, [r0,#0]
    stm r1!, {r2,r3,r4,r5,r6,r7}
    strb r8, [r1,#0]</pre>
<p>To avoid conditional branches, I&#8217;ll start with the assumption that the string length is known (25 bytes). One approach would be using multiple load instructions, but the <strong>load multiple</strong> (<strong>ldm</strong>) instruction makes it somewhat easier for us &#8212; one instruction to fetch 24 bytes, and a <strong>load register byte </strong>(<strong>ldrb</strong>) for the last one. Using the <strong>!</strong> after the source-address register indicates that it should be updated with the address of the next byte after those that have been read.</p>
<p>The storing of the data back to memory is done analogously. <strong>Store multiple</strong> (<strong>stm</strong>) writes 6 registers×4 bytes = 24 bytes (with the <strong>!</strong> to have the destination address updated). The final byte is written using <strong>strb</strong>.</p>
<h3>4. Loading string from memory into EAX register</h3>
<pre escaped="true" lang="txt">    @cld
    @leal HelloWorldString, %esi
    movw r0, #:lower16:HelloWorldString
    movt r0, #:upper16:HelloWorldString

    @lodsb
    ldrb r1, [r0, #0]

    @movb $0, %al
    mov r1, #0

    @dec %esi  @ unneeded. equiv: sub r0, r0, #1
    @lodsw
    ldrh r1, [r0, #0]

    @movw $0, %ax
    mov r1, #0

    @subl $2, %esi # Make ESI point back to the original string. unneeded. equiv: sub r0, r0, #2
    @lodsl
    ldr r1, [r0, #0]</pre>
<p>In this section, we are shown how the IA32 <strong>lodsb</strong>, <strong>lodsw</strong> and <strong>lodsl</strong> instructions work. Again, they have implicitly assigned register usage, which isn&#8217;t how ARM operates.</p>
<p>So, instead of a simple, no-operand instruction like <strong>lodsb</strong>, we have a <strong>ldrb r1, [r0, #0]</strong> loading a byte from the address in r0 into r1. Because I didn&#8217;t use post indexed addressing, there&#8217;s no need to dec or subl the address after the load. If I were to do so, it could look like this:</p>
<pre escaped="true" lang="txt">    ldrb r1, [r0], #1
    sub r0, r0, #1

    ldrh r1, [r0], #2
    sub r0, r0, #2

    ldr r1, [r0], #4</pre>
<p>If you trace through it in gdb, look at how the value in r0 changes after each instruction.</p>
<h3>5. Storing strings from EAX to memory</h3>
<pre escaped="true" lang="txt">    @leal DestinationUsingStos, %edi
    movw r0, #:lower16:DestinationUsingStos
    movt r0, #:upper16:DestinationUsingStos

    @stosb
    strb r1, [r0], #1
    @stosw
    strh r1, [r0], #2
    @stosl
    str r1, [r0], #4</pre>
<p>Same kind of thing as for the loads. Writes the letters in r1 (being &#8220;Hell&#8221; &#8212; leftovers from the previous section) into DestinationUsingStos (the result being &#8220;HHeHell&#8221;). String processing on little endian architectures has its appeal.</p>
<h3>6. Comparing Strings</h3>
<pre escaped="true" lang="txt">    @cld
    @leal HelloWorldString, %esi
    movw r0, #:lower16:HelloWorldString
    movt r0, #:upper16:HelloWorldString
    @leal H3110, %edi
    movw r1, #:lower16:H3110
    movt r1, #:upper16:H3110

    @cmpsb
    ldrb r2, [r0,#0]
    ldrb r3, [r1,#0]
    cmp r2, r3

    @dec %esi
    @dec %edi
    @not needed because of the addressing mode used

    @cmpsw
    ldrh r2, [r0,#0]
    ldrh r3, [r1,#0]
    cmp r2, r3

    @subl $2, %esi
    @subl $2, %edi
    @not needed because of the addressing mode used
    @cmpsl
    ldr r2, [r0,#0]
    ldr r3, [r1,#0]
    cmp r2, r3</pre>
<p>Where IA32&#8242;s <strong>cmps</strong> instructions implicitly load through the pointers in <strong>%edi</strong> and <strong>%esi</strong>, explicit loads are needed for ARM. The compare then works in pretty much the same way as for IA32, setting condition code flags in the <strong>current program status register</strong> (<strong>cpsr</strong>). If you run the above code, and check the status registers before and after execution of the <strong>cmp</strong> instructions, you&#8217;ll see the zero flag set and unset in the same way as is demonstrated in the video.</p>
<p>The condition code flags are:</p>
<ul>
<li>bit 31 &#8212; negative (N)</li>
<li>bit 30 &#8212; zero (Z)</li>
<li>bit 29 &#8212; carry (C)</li>
<li>bit 28 &#8212; overflow (V)</li>
</ul>
<p>There&#8217;s other flags in that register &#8212; all the details are on page B1-16 and B1-17 in the ARM Architecture Reference Manual.</p>
<p>And with that, I think we&#8217;ve made it (finally) to the end of this part for ARM.</p>
<h3>Other assembly primer notes are linked <a href="../?page_id=737">here</a>.</h3>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1001</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>{1,2,3,4}</title>
		<link>http://brnz.org/hbr/?p=1025</link>
		<comments>http://brnz.org/hbr/?p=1025#comments</comments>
		<pubDate>Thu, 24 Mar 2011 12:46:00 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[spu]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[SPU]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1025</guid>
		<description><![CDATA[(This is wonderfully obtuse, but amused me :) Neil Henning (@sheredom) asked: SPU gurus of twitter unite, want a vector unsigned int with {1, 2, 3, 4} in each slot, without putting it in as elf constant, any ideas? Interesting question. The SPU ISA generally doesn&#8217;t help build vectors with different values in each slot. [...]]]></description>
			<content:encoded><![CDATA[<p>(This is wonderfully obtuse, but amused me :)</p>
<p>Neil Henning (<a href="http://twitter.com/sheredom">@sheredom</a>) <a href="http://twitter.com/sheredom/status/50865948349046784">asked</a>:</p>
<blockquote><p>SPU gurus of twitter unite, want a vector unsigned int with {1, 2, 3, 4} in each slot, without putting it in as elf constant, any ideas?</p></blockquote>
<p>Interesting question. The SPU ISA generally doesn&#8217;t help build vectors with different values in each slot. In this case, there are only very small values required in each register, so it can be done with a neat little trick.</p>
<p>My answer:</p>
<pre escaped="true" lang="c">    fsmbi r4, 0x7310  # r4 = {0x00ffffff, 0x0000ffff, 0x000000ff, 0x00000000}
    clz r5, r4        # r5 = {8,16,24,32}
    rotmi r6, r5, -3  # r6 = {1,2,3,4}</pre>
<p>Instructions are:</p>
<ul>
<li><strong>fsmbi</strong> &#8212; form select mask byte immediate. Creates a 128 bit mask from a 16 bit value, expanding each bit of input to 8 bits of output.</li>
<li><strong>clz</strong> &#8212; count leading zeroes. Counts the number of leading zeros in each word.</li>
<li><strong>rotmi</strong> &#8212; rotate and mask word immediate (logical shift right by negative immediate). Shifts each word right by the negation of number of bits specified.</li>
</ul>
<p>This solution is entirely self contained, required no pre-set state (unlike my first attempt utilising the cbd instruction). In terms of raw instruction size, it&#8217;s a whole eight bytes smaller than storing the vector in memory and loading it when needed (that being 16+4 bytes), and a little slower than using a load instruction.</p>
<p>(On a cursory re-examination of the SPU ISA, fsmbi is the only instruction that will construct a different value in each word of a register. A specific pattern may be generated with cbd/cbx that can be used for this problem, but it depends on the contents of another register which limits its already limited usefulness. Combining fsmbi with other immediate instructions allows for a wide range of values to be constructed independent of register state and without access to storage)</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1025</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TTYtter for the N900</title>
		<link>http://brnz.org/hbr/?p=1007</link>
		<comments>http://brnz.org/hbr/?p=1007#comments</comments>
		<pubDate>Sat, 12 Mar 2011 14:06:24 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[scratchbox]]></category>
		<category><![CDATA[ttytter]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1007</guid>
		<description><![CDATA[A quick documenting of how I got TTYtter running on the N900/Maemo5. 0. Missing curl TTYtter requires curl for OAuth, but curl isn&#8217;t packaged in the maemo5 repositories (libcurl is &#8212; which is frustrating. The particular reason for the frustration will be made clear later&#8230;) That being the case, let&#8217;s build curl! I grabbed the [...]]]></description>
			<content:encoded><![CDATA[<p>A quick documenting of how I got <a href="http://www.floodgap.com/software/ttytter/">TTYtter</a> running on the N900/Maemo5.</p>
<h2>0. Missing curl</h2>
<p>TTYtter requires curl for OAuth, but curl isn&#8217;t packaged in the maemo5 repositories (libcurl is &#8212; which is frustrating. The particular reason for the frustration will be made clear later&#8230;)</p>
<p>That being the case, let&#8217;s build curl! I grabbed the sources for the version of curl that matched installed libcurl from the relevant source package page on <a href="http://maemo.org/packages/source/view/fremantle_sdk_free_source/curl/7.18.2-8maemo6+0m5/">maemo.org</a>, unpacked the tarball and patch -p1&#8242;d the gunzipped patch.</p>
<h2>1. What didn&#8217;t work</h2>
<p>The first half-hearted attempt was to build curl using the cross toolchain I have installed on my gentoo desktop (built with <strong>crossdev -t arm-linux-gnueabi</strong>). I had little hope that this would just work, and a quick <strong>./configure &#8211;host=arm-linux-gnueabi &#8211;prefix=/home/user/local &amp;&amp; make &amp;&amp; make install &amp;&amp; scp -r /home/user/local n900:</strong> (or something like it) later, it didn&#8217;t &#8212; the foremost hurdle being that maemo5 uses an antiquated glibc-2.5 (2005, yeah!), and my toolchain uses (and thus generates programs that expect) glibc-2.11.3.</p>
<p>Persisting with my all-too-modern toolchain seemed likely to be a whole lot of effort &#8212; I decided to go with what appeared to be the Official method &#8212; the probability of success seemed marginally higher.</p>
<h2>2. What worked</h2>
<p>I installed <a href="http://www.scratchbox.org">scratchbox</a> and built it there.</p>
<h3>i. Installing scratchbox</h3>
<p>I first found <a href="http://www.janerob.com/rob/MaemoOnGentoo.html">this MaemoOnGentoo outline</a> which was got me started. Rather than the emerge command listed on that page, I ended up needing something like:</p>
<p><strong>emerge scratchbox scratchbox-devkit-debian scratchbox-devkit-perl \<br />
scratchbox-devkit-cputransp scratchbox-devkit-doctools \<br />
scratchbox-toolchain-cs2007q3-glibc2_5 scratchbox-devkit-qemu\<br />
scratchbox-devkit-git scratchbox-devkit-svn</strong></p>
<p>As per that page, I needed to re-emerge xorg-server with the kdrive USE flag to build xephyr.</p>
<p>Started scratchbox with <strong>/etc/init.d/scratchbox start</strong></p>
<p>From that point on, the <a href="http://wiki.maemo.org/Documentation/Maemo_5_Final_SDK_Installation#Manual_Installation">Manual Installation instructions for the SDK from maemo.org</a> generally worked &#8212; I added a user with <strong>/scratchbox/sbin/sbox_adduser</strong>, added my user account to the <strong>sbox</strong> group. (Actually, not really knowing what I was doing, after doing that, I ran the <a href="http://repository.maemo.org/stable/5.0/maemo-sdk-install_5.0.sh">maemo-sdk-install_5.0.sh</a> script, which seemed to do the right thing)</p>
<p>I needed to manually install the Nokia binaries/apps as per the Manual Installation instructions.</p>
<p>That done, I was able to <a href="http://wiki.maemo.org/Documentation/Maemo_5_Final_SDK_Installation#Starting.2FShutting_down_the_SDK_UI">start the SDK UI inside a xephyr window</a>. i.e. <strong>Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac</strong> and (inside a scratchbox prompt) <strong>DISPLAY=:2 af-sb-init.sh start</strong></p>
<p>(Having the UI running is the Hello, world! &#8216;proof&#8217; of functionality &#8212; it may not count for much, but it&#8217;s nice to see)<strong><br />
</strong></p>
<h3><strong>ii. Building it there</strong></h3>
<p>Once there&#8217;s a functional scratchbox environment, the next thing to do is to build the package.</p>
<p>I naively followed the relevant parts of <a href="http://wiki.maemo.org/Packaging#A_concrete_example_-_hello">the example from the Packaging guide on maemo.org</a>.</p>
<p>Taking the source (as mentioned before &#8212; de-tarballed sources with patch applied) it became apparent that the necessary configuration was already in place to build the desired .deb (so much of the guide was unneeded for this task). In fact, from what I recall, the only command from that guide that was necessary was <strong>dpkg-buildpackage -sa -rfakeroot -k&lt;my email address&gt;</strong> (run using the FREMANTLE_ARMEL tool config)</p>
<p>End result: a bunch of files, including <strong>curl_7.18.2-8maemo6+0m5_armel.deb</strong> &#8212; the frustration mentioned earlier was that the config exists to build this, and that packaging curl for maemo5 would have been approximately zero extra effort.</p>
<p>(Nothing is ever actually zero extra effort. I know this.)</p>
<p><strong>scp curl_7.18.2-8maemo6+0m5_armel.deb n900:</strong>, and install with <strong>dpkg &#8211;install curl_7.18.2-8maemo6+0m5_armel.deb</strong> and TTYtter gets the curl.</p>
<h2>3. The final bit</h2>
<p>TTYtter starts, but it&#8217;s not quite working yet. Maemo5 has a prehistoric perl-5.8.3 (2004, woo!) which appears to lack the kind of UTF8 support that TTYtter wants.</p>
<p>To work around this, start TTYtter with the <strong>-seven</strong> option.</p>
<h2>4. Too long; don&#8217;t care</h2>
<p><strong>The package is here: </strong><a href="http://brnz.org/f/maemo5/curl_7.18.2-8maemo6+0m5_armel.deb"><strong>curl_7.18.2-8maemo6+0m5_armel.deb</strong></a><br />
(<a href="http://brnz.org/f/maemo5/">The original source is here with it</a>)<strong> </strong></p>
<p>As root, install the package (<strong>dpkg -i curl_7.18.2-8maemo6+0m5_armel.deb</strong>) and then (as the regular user) grab and run <strong>ttytter -seven</strong></p>
<p>TTYtter is by far the best Twitter client I&#8217;ve used on this phone &#8212; not least because it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1007</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smokey Beef Chili with Guinness</title>
		<link>http://brnz.org/hbr/?p=992</link>
		<comments>http://brnz.org/hbr/?p=992#comments</comments>
		<pubDate>Sat, 05 Mar 2011 01:07:51 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[chili]]></category>
		<category><![CDATA[Guinness]]></category>
		<category><![CDATA[recipe]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=992</guid>
		<description><![CDATA[This is a recipe I obtained via twitter. I didn&#8217;t make a note of the source, and it was shared as text in an image which I printed. I am now unable to locate the original. I&#8217;m re-posting it the original text here (none of the comments within are mine) for the people that have [...]]]></description>
			<content:encoded><![CDATA[<p>This is a recipe I obtained via twitter. I didn&#8217;t make a note of the source, and it was shared as text in an image which I printed. I am now unable to locate the original.</p>
<p>I&#8217;m re-posting it the original text here (none of the comments within are mine) for the people that have asked me about it with thanks to whoever was responsible &#8212; it was enjoyed by my whole family :D</p>
<p style="padding-left: 30px;"><strong>Smokey Beef Chili with Guiness</strong></p>
<p style="padding-left: 30px;">500 grams of gravy beef<br />
100 grams of streaky bacon<br />
3 celery stalks<br />
2 red chilies<br />
2 red onions<br />
2 green capsicums<br />
8 garlic cloves<br />
1 can of diced tomatoes<br />
2 cans of red kidney beans<br />
150g of tomato paste<br />
500ml beef stock<br />
Dried oregano<br />
Smoked paprika<br />
Ground cumin<br />
Tabasco sauce<br />
Sugar to taste (usually between 1 and 4 teaspoons)<br />
200ml of Guinness<br />
(Optional) 1 can of smoked chipotle peppers</p>
<p style="padding-left: 30px;">Roughly dice onion, chilies, capsicum and bacon. Finely dice garlic and celery. Add to hot pot with good slug of olive oil and cook until onion becomes semi-transparent.</p>
<p style="padding-left: 30px;">Meanwhile, cut gravy beef (or chuck steak, or skirt steak) into large chunks. Whack in a food processor and pulse until half the steak has disintegrated and half has been carved up into various random shapes of random size.</p>
<p style="padding-left: 30px;">Once onion is browned (important) add big teaspoon of smoked paprika, flat teaspoon of cumin, 2 teaspoons of dried oregano and solid few shakes of Tabasco sauce. Cook and stir for a few minutes until mixture becomes coloured from the spices cooking through it.</p>
<p style="padding-left: 30px;">Add meat and cook until brown.</p>
<p style="padding-left: 30px;">Add tomato paste and diced chipotle peppers and cook out until it just starts to caramelise on the walls of the pot. Add the adobo sauce from the chipotle can to taste now as well (warning &#8211; hot!)</p>
<p style="padding-left: 30px;">Add can of diced tomatoes (drained) and kidney beans (drain and rinse well first). Cook for a few minutes.</p>
<p style="padding-left: 30px;">Add Guinness. Cook until most of the beer has evaporated.</p>
<p style="padding-left: 30px;">Add beef stock. Bring to boil. Add sugar until the mix in the pot is slightly less sweet than you want it to be (the sauce will reduce and sweetness will increase at the end). Alternatively, add the sugar when you add the tomato paste (it will add a little to the caramelisation of the paste and add a bit of extra flavour &#8211; best for second time you cook it, so you know how much you need)</p>
<p style="padding-left: 30px;">Taste the mix after it starts to boil. Add a teaspoon of dried oregano and a little extra smoked paprika if the mix isn&#8217;t as smokey in flavour as you&#8217;d like. Add tabasco sauce for extra heat.</p>
<p style="padding-left: 30px;">Simmer uncovered for 1.5 hours and add the lid when the mix is just a bit wetter than you want. (e.g. you want it wetter for serving with rice than you do for tacos or nachos). Let stand for at least 1/2 hour with heat off and lid on before serving (you can give it a reheat before serving if needed and add a little water to the simmering if it starts to dry out.)</p>
<p style="padding-left: 30px;">Some folks stir fresh oregano and diced chili through before serving. It doesn&#8217;t float my boat, but it may well yours.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=992</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembly Primer Parts 6 — Moving Data — ARM</title>
		<link>http://brnz.org/hbr/?p=975</link>
		<comments>http://brnz.org/hbr/?p=975#comments</comments>
		<pubDate>Wed, 02 Mar 2011 13:05:13 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Assembly]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=975</guid>
		<description><![CDATA[My notes for where ARM differs from IA32 in the Assembly Primer video Part 6 &#8212; Moving Data. (There is no separate part 5 post for ARM &#8212; apart from the instructions, it&#8217;s identical to IA32. There&#8217;s even support for the .bss section, unlike SPU and PPC) Moving Data We&#8217;ll look at MovDemo.s for ARM. [...]]]></description>
			<content:encoded><![CDATA[<p>My notes for where ARM differs from IA32 in the <a href="http://securitytube.net/Assembly-Primer-for-Hackers-(Part-6)-Moving-Data-video.aspx">Assembly Primer video Part 6 &#8212; Moving Data</a>.</p>
<p>(There is no separate part 5 post for ARM &#8212; apart from the instructions, it&#8217;s identical to IA32. There&#8217;s even support for the .bss section, unlike SPU and PPC)</p>
<h2>Moving Data</h2>
<p>We&#8217;ll look at <a href="http://code.securitytube.net/MovDemo.s">MovDemo.s</a> for ARM. First, the storage:</p>
<pre escaped="true" lang="asm">.data

    HelloWorld:
        .ascii "Hello World!"

    ByteLocation:
        .byte 10

    Int32:
        .int 2
    Int16:
        .short 3
    Float:
        .float 10.23

    IntegerArray:
        .int 10,20,30,40,50</pre>
<p>It&#8217;s the same as for IA32, PPC and SPU. Like the first two, ARM will cope with the unnatural alignment.</p>
<h3>1. Immediate value to register</h3>
<pre escaped="true" lang="asm">.text
.globl _start
_start:
    @movl $10, %eax

    mov r0, #10</pre>
<p>Move the value 10 into register r0.</p>
<p>Something to note: the ARM assembly syntax has some slightly differences. Where others use <strong>#</strong> to mark the start of a comment, ARM has <strong>@</strong> (although <strong>#</strong> works at the start of a line). Literal values are prefixed with <strong>#</strong>, which confuses the default syntax highlighting in vim.</p>
<h3>2. Immediate value to memory</h3>
<pre escaped="true" lang="asm">    @movw $50, Int16

    mov r1, #50
    movw r0, #:lower16:Int16
    movt r0, #:upper16:Int16
    strh r1, [r0, #0]</pre>
<p>We need to load the immediate value in a register (r1), the address in a register (r0) and then perform the write. To quote the Architecture Reference Manual:</p>
<blockquote><p>The ARM architecture &#8230; incorporates &#8230; a load/store architecture, where data processing operations only operate on register contents, not directly on memory contents.</p></blockquote>
<p>which is like PPC and SPU, and unlike IA32 &#8212; and so we&#8217;ll see similarly verbose alternatives to the IA32 examples from the video.</p>
<p>I&#8217;m using <strong>movw</strong>, <strong>movt</strong> sequence to load the address, rather than <strong>ldr</strong> (as mentioned in the previous installment).</p>
<p><strong>strh</strong> is, in this case, <strong>Store Register Halfword (immediate)</strong> &#8212; writes the value in r1 to the address computed from the sum of the contents of r0 and the immediate value of 0.</p>
<h3>3. Register to register</h3>
<pre escaped="true" lang="asm">    @movl %eax, %ebx

    mov r1,r0</pre>
<p><strong>mov</strong> (<strong>Move</strong>) copies the value from r0 to r1.</p>
<h3>4. Memory to register</h3>
<pre escaped="true" lang="asm">    @movl Int32, %eax

    movw r0, #:lower16:Int32
    movt r0, #:upper16:Int32
    ldr r1, [r0, #0]</pre>
<p>Load the address into r0, load from the address r0+0. Here <strong>ldr</strong> is <strong>Load Register (immediate)</strong>.</p>
<h3>5. Register to memory</h3>
<pre escaped="true" lang="asm">    @movb $3, %al
    @movb %al, ByteLocation

    mov r0, #3
    movw r1, #:lower16:ByteLocation
    movt r1, #:upper16:ByteLocation
    strb r0, [r1, #0]</pre>
<p>Once again the same kind of thing &#8212; load 3 into r0, the address of ByteLocation into r1, perform the store.</p>
<h3>6. Register to indexed memory location</h3>
<pre escaped="true" lang="asm">    @movl $0, %ecx
    @movl $2, %edi
    @movl $22, IntegerArray(%ecx, %edi, 4)

    movw r0, #:lower16:IntegerArray
    movt r0, #:upper16:IntegerArray
    mov r1, #2
    mov r2, #22
    str r2, [r0, r1, lsl #2]</pre>
<p>A little more interesting &#8212; here <strong>str</strong> is <strong>Store Register (register) </strong>which accepts two registers and an optional shift operation and amount. Here <strong>lsl</strong> is <strong>logical shift left</strong>, effectively multiplying r1 by 4 &#8212; the size of the array elements.</p>
<p>(GCC puts <strong>asl</strong> here. Presumably identical to logical shift left, but there&#8217;s no mention of <strong>asl</strong> in the Architecture Reference Manual. <strong>Update:</strong> ASL is referenced in the list of errors <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0496c/CACHCBBJ.html">here</a> as an obsolete name for LSL)</p>
<p>Two source registers and a shift is still shy of IA32&#8242;s support for an calculating an address from a base address, two registers and a multiply.</p>
<h3>7. Indirect addressing</h3>
<pre escaped="true" lang="asm">    @movl $Int32, %eax
    @movl (%eax), %ebx

    movw r0, #:lower16:Int32
    movt r0, #:upper16:Int32
    ldr r1, [r0, #0]

    @movl $9, (%eax)

    mov r2, #9
    str r2, [r0, #0]</pre>
<p>More of the same.</p>
<h2>Concluding thoughts</h2>
<p>In addition to the cases above, ARM has a number of other interesting addressing modes that I shall consider in more detail in the future &#8212; logical operations, auto-{increment, decrement} and multiples. Combined with conditional execution, there are some very interesting possibilities.</p>
<h3>Other assembly primer notes are linked <a href="http://brnz.org/hbr/?page_id=737">here</a>.<a href="../../?page_id=737"><br />
</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=975</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembly Primer Part 4 — Hello World — ARM</title>
		<link>http://brnz.org/hbr/?p=955</link>
		<comments>http://brnz.org/hbr/?p=955#comments</comments>
		<pubDate>Mon, 14 Feb 2011 05:49:20 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Assembly]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=955</guid>
		<description><![CDATA[On to Assembly Primer &#8212; Part 4. This is where we start writing a small assembly program for the platform. In this case, I don&#8217;t know the language and I don&#8217;t know the ABI. Learning these from scratch ranges from interesting to tedious :) Regarding the language (available instructions, mnemonics and assembly syntax): I&#8217;m using [...]]]></description>
			<content:encoded><![CDATA[<p>On to <a href="http://www.securitytube.net/Assembly-Primer-for-Hackers-(Part-4)-Hello-World-video.aspx">Assembly Primer &#8212; Part 4</a>. This is where we start writing a small assembly program for the platform. In this case, I don&#8217;t know the language and I don&#8217;t know the ABI. Learning these from scratch ranges from interesting to tedious :)</p>
<p>Regarding the language (available instructions, mnemonics and assembly syntax): I&#8217;m using the <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406b/index.html">ARM Architecture Reference Manual</a> as my reference for the architecture (odd, I know). It&#8217;s very long and the documentation for each instruction is extensive &#8212; which is good because there are a lot of instructions, and many of them do a lot of things at once.</p>
<p>Regarding the ABI (particularly things like argument passing, return values and system calls): there&#8217;s the <a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CBIQFjAA&amp;url=http%3A%2F%2Finfocenter.arm.com%2Fhelp%2Ftopic%2Fcom.arm.doc.ihi0042d%2FIHI0042D_aapcs.pdf&amp;ei=HbxYTafHCIXCvgPUkun2BA&amp;usg=AFQjCNGR3tBewfkIff4HMlI6mz2s_d4CsA">Procedure Call Standard for the ARM Architecture</a>, and there are a few other references I&#8217;ve found, such as the <a href="http://wiki.debian.org/ArmEabiPort">Debian ARM EABI Port wiki page</a>.</p>
<blockquote><p>&#8220;EABI is the new &#8220;Embedded&#8221; ABI by <a href="http://www.arm.com/">ARM ltd</a>. EABI is actually a family of ABI&#8217;s and one of the &#8220;subABIs&#8221; is GNU EABI, for Linux.&#8221;</p>
<p>- from Debian ARM EABI Port</p></blockquote>
<h2>System Calls</h2>
<p>To perform a system call using the GNU EABI:</p>
<ul>
<li>put the system call number in r7</li>
<li>put the arguments in r0-r6 (64bit arguments must be aligned to an even numbered register i.e. in r0+r1, r2+r3, or r4+r5)</li>
<li>issue the <strong>Supervisor Call</strong> instruction with a zero operand &#8212; <strong>svc #0</strong></li>
</ul>
<p>(<strong>Supervisor Call</strong> was previously named <strong>Software Interrupt</strong> &#8212; <strong>swi</strong>)</p>
<h2>Just Exit</h2>
<p>Based on the above, it&#8217;s not difficult to reimplement <strong>JustExit.s </strong>(<a href="http://code.securitytube.net/JustExit.s">original</a>) for ARM.</p>
<pre style="padding-left: 30px;" lang="asm">.text

.globl _start

_start:
        mov r7, #1
        mov r0, #0
        svc #0
</pre>
<p><strong>mov</strong> here is <strong>Move (Immediate)</strong> which puts the <strong>#</strong>-prefixed literal into the named register.</p>
<h2>Hello World</h2>
<p>Likewise, the conversion of <strong>HelloWorldProgram.s</strong> (<a href="http://code.securitytube.net/HelloWorldProgram.s">original</a>) is not difficult:</p>
<pre style="padding-left: 30px;" lang="asm">.data 

HelloWorldString:
      .ascii "Hello World\n"

.text 

.globl _start 

_start:
      # Load all the arguments for write () 

      mov r7, #4
      mov r0, #1
      ldr r1,=HelloWorldString
      mov r2, #12
      svc #0

      # Need to exit the program 

      mov r7, #1
      mov r0, #0
      svc #0
</pre>
<p>This includes the <strong>load register</strong> pseudo-instruction, <strong>ldr</strong> &#8212; the compiler stores the address of <strong>HelloWorldString</strong> into the literal pool, a portion of memory located in the program text, and the 32bit address is loaded from the literal pool (<a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0100a/armasm_bgbbfgia.htm">more details</a>).</p>
<p>When compiling a similar C program with <strong>-mcpu=cortex-a8</strong>, I notice that the compiler generates <strong>Move (immediate)</strong> and <strong>Move Top</strong> &#8212; <strong>movw</strong> and <strong>movt</strong> &#8212; instructions to load the address directly from the instruction stream, which is presumably more efficient on that architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=955</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembly Primer Parts 1, 2 and 3 &#8212; ARM</title>
		<link>http://brnz.org/hbr/?p=932</link>
		<comments>http://brnz.org/hbr/?p=932#comments</comments>
		<pubDate>Fri, 11 Feb 2011 14:21:58 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Assembly]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=932</guid>
		<description><![CDATA[I had started a series of posts on assembly programming for the Cell BE PPU and SPU, based on the assembly primer video series from securitytube.net. I have recently acquired a Nokia N900, and so thought I might take the opportunity to continue the series with a look at the ARM processor as well. Wikipedia [...]]]></description>
			<content:encoded><![CDATA[<p>I had started a <a href="http://brnz.org/hbr/?page_id=737">series of posts on assembly programming</a> for the Cell BE PPU and SPU, based on the <a href="http://tools.securitytube.net/index.php?title=Open_Security_Training">assembly primer video series from securitytube.net</a>. I have recently acquired a Nokia N900, and so thought I might take the opportunity to continue the series with a look at the ARM processor as well.</p>
<p>Wikipedia lists the N900&#8242;s processor as a Texas Instruments OMAP3430,	600MHz 	ARMv7 Cortex-A8. I&#8217;m not at all familiar with the processor family, so I&#8217;ll be attempting to find out what all of this means as I go :P</p>
<p>I&#8217;ve set up a cross compiler on my desktop machine using Gentoo&#8217;s neat crossdev tool (built using <strong>crossdev -t arm-linux-gnueabi</strong>). The toolchain builds a functional Hello, World!</p>
<p>(I note that scratchbox appears to be the standard tool/environment used to build apps for Maemo &#8212; I may take a closer look at that at a later date)</p>
<p>I have whatever the latest public &#8216;stable&#8217; Maemo 5 release is on the N900 (PR 1.3, I think),  with an <strong>apt-get install</strong> <strong>openssh</strong> <strong>gdb</strong> &#8212; thus far, enough to &#8220;debug&#8221; a functional Hello, World!</p>
<p>What follows are some details of the Cortex-A8 architecture present in the N900, particularly in how it differs from IA32, as presented in the videos <a href="http://www.securitytube.net/Assembly-Primer-for-Hackers-%28Part-1%29-System-Organization-video.aspx">Part 1 &#8212; System Organisation</a>, <a href="http://www.securitytube.net/Assembly-Primer-for-Hackers-%28Part-2%29-Virtual-Memory-Organization-video.aspx">Part 2 &#8212; Virtual Memory Organization</a> and <a href="http://www.securitytube.net/Assembly-Primer-for-Hackers-%28Part-3%29-GDB-Usage-Primer-video.aspx">Part 3 &#8212; GDB Usage Primer</a>. I&#8217;ve packed them all into this post because gdb usage and Linux system usage are largely the same on ARM as they are on PPC and IA32.</p>
<p>Most of the following information comes from the <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406b/index.html">ARM Architecture Reference Manual</a>.</p>
<p>(The number of possible configurations of ARM hardware makes it interesting at times to work out exactly which features are present in my particular processor. From what I can tell, the N900&#8242;s Cortex-A8 is ARMv7-A and includes VFPv3 half, single and double precision float support, and NEON (aka Advanced SIMD). I expect I&#8217;ll find out more when I actually start to try and program the thing. As to which gcc -march, -mcpu or -mfpu options are most correct for the N900 &#8212; I have no idea.)</p>
<h2>1. Registers</h2>
<h3>Integer</h3>
<p>There are sixteen 32bit ARM core registers, R0 to R15, where R0&#8211;R12 are for general use. R13 contains the stack pointer (SP), R14 is the link register (LR), and R15 is the program counter (PC).</p>
<p>The current program status register (CSPR) contains various status and control bits.</p>
<h3>VFPv3 (Floating point) &amp; NEON (Advanced SIMD)</h3>
<p>There are thrirty two doubleword (64bit) registers, that can be referenced in a number of ways.</p>
<p>NEON instructions can access these as thirty two doubleword registers (D0&#8211;D31) or as sixteen quadword registers (Q0&#8211;Q15), able to be used interchangeably.</p>
<p>VFP instructions can view the same registers as 32 doubleword registers (again, D0&#8211;D31) or as 32 single word registers (S0&#8211;S31). The single word view is packed into the first 16 doubleword registers.</p>
<p>Something like this pic (click to embiggen):</p>
<p style="text-align: center;"><a href="http://brnz.org/hbr/wp-content/uploads/2011/02/ARMv7_VFPv3_NEON_extension_registers.png"><img class="size-large wp-image-935 aligncenter" style="border: 1px solid black;" title="ARMv7_VFPv3_NEON_extension_registers" src="http://brnz.org/hbr/wp-content/uploads/2011/02/ARMv7_VFPv3_NEON_extension_registers-540x89.png" alt="" width="540" height="89" /></a></p>
<p style="text-align: left;">VFP in this core (apparently) supports single and double precision floating point data types and arithmetic, as well as half precision (possibly in two different formats&#8230;).</p>
<p style="text-align: left;">NEON instructions support accessing values in extension registers as</p>
<ul>
<li>8, 16, 32 or 64bit integer, signed or unsigned,</li>
<li>16 or 32bit floating point values, and</li>
<li>8 or 16bit polynomial values.</li>
</ul>
<p>There&#8217;s also a floating point status and control register (FPSCR).</p>
<h2>2. Virtual Memory Organisation</h2>
<p>On this platform, program text appears to be loaded at <strong>0x8000</strong>.</p>
<p>After an <strong>echo 0 &gt; /proc/sys/kernel/randomize_va_space</strong>, the top of the stack appears to be <strong>0xbf000000</strong>.</p>
<h2>3. SimpleDemo</h2>
<p>Compared to the video, there are only a couple of small differences when running SimpleDemo in gdb on ARM.</p>
<p>Obviously, the disassembly is not the same as for IA32. Rather than the <strong>call</strong> instructions noted in the video, you&#8217;ll see <strong>bl</strong> (Branch with Link) for the various functions called.</p>
<p>Where the return address is stored on the stack for IA32, the link register (<strong>lr</strong> in <strong>info registers</strong> output) stores the return address for the current function, although <strong>lr</strong> will be pushed to the stack before another function is called.</p>
<p>(From a cursory googling, it seems that to correctly displaying all VFP/NEON registers requires gdb-7.2 &#8212; I&#8217;m running the 6.8-based build from the maemo repo. crossdev will build me a gdb I can run on my desktop PC &#8212; <strong>crossdev -t arm-linux-gnueabi &#8211;ex-gdb</strong> &#8212; but I believe I still need to build a newer <strong>gdbserver</strong> to run on the N900.)</p>
<h3>Other assembly primer notes are linked <a href="../?page_id=737">here</a>.<a href="../?page_id=737"><br />
</a></h3>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 861px; width: 1px; height: 1px; overflow: hidden;"><!-- p { margin-bottom: 0.21cm; } --></p>
<p class="western" style="margin-bottom: 0cm; page-break-before: always;"><strong><span style="font-family: Calibri,sans-serif;"><span style="font-size: medium;">Proposed updates for praypal.org.au					   2011/02/11</span></span></strong></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=932</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

