Branching

ARM assembler in Raspberry Pi – Chapter 5

Branching

Until now our small assembler programs execute one instruction after the other. If our ARM processor were only able to run this way it would be of limited use. It could not react to existing conditions which may require different sequences of instructions. This is the purpose of the branch instructions.

A special register

In chapter 2 we learnt that our Raspberry Pi ARM processor has 16 integer general purpose registers and we also said that some of them play special roles in our program. I deliberately ignored which registers were special as it was not relevant at that time.

But now it is relevant, at least for register r15. This register is very special, so special it has also another name: pc. It is unlikely that you see it used as r15 since it is confusing (although correct from the point of view of the ARM architecture). From now we will only use pc to name it.

What does pc stand for? pc means program counter. This name, the origins of which are in the dawn of computing, means little to nothing nowadays. In general the pc register (also called ip, instruction pointer, in other architectures like 386 or x86_64) contains the address of the next instruction going to be executed.

When the ARM processor executes an instruction, two things may happen at the end of its execution. If the instruction does not modify pc (and most instructions do not), pc is just incremented by 4 (like if we did add pc, pc, #4). Why 4? Because in ARM, instructions are 32 bit wide, so there are 4 bytes between every instruction. If the instruction modifies pc then the new value for pc is used.

Once the processor has fully executed an instruction then it uses the value in the pc as the address for the next instruction to execute. This way, an instruction that does not modify the pc will be followed by the next contiguous instruction in memory (since it has been automatically increased by 4). This is called implicit sequencing of instructions: after one has run, usually the next one in memory runs. But if an instruction does modify the pc, for instance to a value other than pc + 4, then we can be running another instruction of the program. This process of changing the value of pc is called branching. In ARM this done using branch instructions.

Unconditional branches

You can tell the processor to branch unconditionally by using the instruction b (for branch) and a label. Consider the following program.

1
2
3
4
5
6
7
8
9
/* -- branch01.s */
.text
.global main
main:
    mov r0, #2 /* r0 ← 2 */
    b end      /* branch to 'end' */
    mov r0, #3 /* r0 ← 3 */
end:
    bx lr

If you execute this program you will see that it returns an error code of 2.

$ ./branch01 ; echo $?
2

What happened is that instruction b end branched (modifying the pc) to the instruction at the label end, which is bx lr, the instruction we run at the end of our program. This way the instruction mov r0, #3 has not actually been run at all (the processor never reached that instruction).

At this point the unconditional branch instruction b may look a bit useless. It is not the case. In fact this instruction is essential in some contexts, in particular when linked with conditional branching. But before we can talk about conditional branching we need to talk about conditions.

Conditional branches

If our processor were only able to branch just because, it would not be very useful. It is much more useful to branch when some condition is met. So a processor should be able to evaluate some sort of conditions.

Before continuing, we need to unveil another register called cpsr (for Current Program Status Register). This register is a bit special and directly modifying it is out of the scope of this chapter. That said, it keeps some values that can be read and updated when executing an instruction. The values of that register include four condition code flags called N (negative), Z (zero), C (carry) and V (overflow). These four condition code flags are usually read by branch instructions. Arithmetic instructions and special testing and comparison instruction can update these condition codes too if requested.

The semantics of these four condition codes in instructions updating the cpsr are roughly the following

  • N will be enabled if the result of the instruction yields a negative number. Disabled otherwise.
  • Z will be enabled if the result of the instruction yields a zero value. Disabled if nonzero.
  • C will be enabled if the result of the instruction yields a value that requires a 33rd bit to be fully represented. For instance an addition that overflows the 32 bit range of integers. There is a special case for C and subtractions where a non-borrowing subtraction enables it, disabled otherwise: subtracting a larger number to a smaller one enables C, but it will be disabled if the subtraction is done the other way round.
  • V will be enabled if the result of the instruction yields a value that cannot be represented in 32 bits two’s complement.

So we have all the needed pieces to perform branches conditionally. But first, let’s start comparing two values. We use the instruction cmp for this purpose.

cmp r1, r2 /* updates cpsr doing "r1 - r2", but r1 and r2 are not modified */

This instruction subtracts to the value in the first register the value in the second register. Examples of what could happen in the snippet above?

  • If r2 had a value (strictly) greater than r1 then N would be enabled because r1-r2 would yield a negative result.
  • If r1 and r2 had the same value, then Z would be enabled because r1-r2 would be zero.
  • If r1 was 1 and r2 was 0 then r1-r2 would not borrow, so in this case C would be enabled. If the values were swapped (r1 was 0 and r2 was 1) then C would be disabled because the subtraction does borrow.
  • If r1 was 2147483648 (the largest positive integer in 32 bit two’s complement) and r1 was -1 then r1-r2 would be 2147483649 but such number cannot be represented in 32 bit two’s complement, so V would be enabled to signal this.

How can we use these flags to represent useful conditions for our programs?

  • EQ (equal) When Z is enabled (Z is 1)
  • NE (not equal). When Z is disabled. (Z is 0)
  • GE (greater or equal than, in two’s complement). When both V and N are enabled or disabled (V is N)
  • LT (lower than, in two’s complement). This is the opposite of GE, so when V and N are not both enabled or disabled (V is not N)
  • GT (greather than, in two’s complement). When Z is disabled and N and V are both enabled or disabled (Z is 0, N is V)
  • LE (lower or equal than, in two’s complement). When Z is enabled or if not that, N and V are both enabled or disabled (Z is 1. If Z is not 1 then N is V)
  • MI (minus/negative) When N is enabled (N is 1)
  • PL (plus/positive or zero) When N is disabled (N is 0)
  • VS (overflow set) When V is enabled (V is 1)
  • VC (overflow clear) When V is disabled (V is 0)
  • HI (higher) When C is enabled and Z is disabled (C is 1 and Z is 0)
  • LS (lower or same) When C is disabled or Z is enabled (C is 0 or Z is 1)
  • CS/HS (carry set/higher or same) When C is enabled (C is 1)
  • CC/LO (carry clear/lower) When C is disabled (C is 0)

These conditions can be combined to our b instruction to generate new instructions. This way, beq will branch only if Z is 1. If the condition of a conditional branch is not met, then the branch is ignored and the next instruction will be run. It is the programmer task to make sure that the condition codes are properly set prior a conditional branch.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* -- compare01.s */
.text
.global main
main:
    mov r1, #2       /* r1 ← 2 */
    mov r2, #2       /* r2 ← 2 */
    cmp r1, r2       /* update cpsr condition codes with the value of r1-r2 */
    beq case_equal   /* branch to case_equal only if Z = 1 */
case_different :
    mov r0, #2       /* r0 ← 2 */
    b end            /* branch to end */
case_equal:
    mov r0, #1       /* r0 ← 1 */
end:
    bx lr

If you run this program it will return an error code of 1 because both r1 and r2 have the same value. Now change mov r1, #2 in line 5 to be mov r1, #3 and the returned error code should be 2. Note that case_different we do not want to run the case_equal instructions, thus we have to branch to end (otherwise the error code would always be 1).

That’s all for today.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

, , , ,

22 thoughts on “ARM assembler in Raspberry Pi – Chapter 5

  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-888">
            February 7, 2013 at 11:25 pm</a>        </div>
    
        <p>Hi </p>
    

    I though that you can manipulate the cpsr directly, isn’t the commands MSR and MRS meant for that ? (Source: Arm v6 reference manual: http://www.scss.tcd.ie/~waldroj/3d1/arm_arm.pdf)

    The text says that direct manipulation of cpsr is not possible.

    Thanks for the great series, I have got so much out of it. I started by studying the arm instructions at http://www.davespace.co.uk/arm/introduction-to-arm/index.html and after that your article series adds to that information nicely by showing how to use the commands in real life

    Keep up the good work

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=888#respond" onclick="return addComment.moveForm( &quot;div-comment-888&quot;, &quot;888&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Mikael Hartzell">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-895">
                <div id="div-comment-895" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-0" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">rferrer</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-895">
            February 8, 2013 at 11:27 pm</a>        </div>
    
        <p>Hi Mikael,</p>
    

    thanks for the comment!

    You are right. I’ll reword the text, just to make clear that while it can be modified it is out of the scope of this chapter.

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=895#respond" onclick="return addComment.moveForm( &quot;div-comment-895&quot;, &quot;895&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to rferrer">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • Fernando says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1085">
            March 21, 2013 at 11:12 pm</a>        </div>
    
        <p>Still reading… very nice tutorial, I must say. I think I’m really learning a lot, just by playing with your examples and reading the text.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1085#respond" onclick="return addComment.moveForm( &quot;div-comment-1085&quot;, &quot;1085&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Fernando">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
        <li class="comment odd alt thread-even depth-1 parent" id="comment-1281">
                <div id="div-comment-1281" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://2.gravatar.com/avatar/259bc0bc4762f6a53a9807d0289ba730?s=54&amp;d=mm&amp;r=g" srcset="http://2.gravatar.com/avatar/259bc0bc4762f6a53a9807d0289ba730?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-259bc0bc4762f6a53a9807d0289ba730-0" originals="32" src-orig="http://2.gravatar.com/avatar/259bc0bc4762f6a53a9807d0289ba730?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Damien</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1281">
            May 12, 2013 at 1:05 am</a>        </div>
    
        <p>I tried modifying the program counter directly, but it doesn’t do what I expect:<br>
    

    main: mov r0, #1 add pc, pc, #4 mov r0, #2 mov r0, #3 end: bx lr </p>

    This gives me 1 (it jumped to end directly, while I was expecting that the r0←3 would get executed (I shifted the normal behavior of pc by the length of one instruction only, not two)

    Another hypothesis I had was that since it’s modifying pc, it would not increment it, but I guess only the branching instructions have that behavior…

    Any insights?

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1281#respond" onclick="return addComment.moveForm( &quot;div-comment-1281&quot;, &quot;1281&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Damien">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor even depth-2 parent" id="comment-1282">
                <div id="div-comment-1282" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-1" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">rferrer</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1282">
            May 12, 2013 at 8:43 am</a>        </div>
    
        <p>Hi Damien,</p>
    

    you are experiencing what, in my opinion, is a «quirk» in the ARM architecture (this is: the contract between the CPU designer and the software developer on how the CPU behaves).

    Ideally one would expect, when reading the pc register in an instruction, to have the address of the current instruction.

    Imagine that the instruction add pc, pc, #4 is in address 0x1000. You would expect, at the end of the instruction pc be 0x1004. As usual in ARM, since pc got modified in the instruction, you would not add 4 bytes to it (as in implicit sequencing) but directly jump to 0x1004. So the next instruction run would be the one at the address 0x1004.

    Well, this is where the ARM quirk comes into play. When you read the pc register in an instruction its value is the current instruction plus 8 bytes.

    For instance, the following code,
    mov r1, #0 current: mov pc, pc plus4: add r1, r1, #1 plus8: add r1, r1, #2 plus12: add r1, r1, #3 end:

    Here r1 will at end have the value 5 (2+3) instead of 6 (1+2+3). Why? Because in instruction mov pc, pc, pc did not have the address current, it was current + 8 which in the example is plus8. Since the instruction does modify pc, the ARM processor does not do pc ← pc + 4 before starting the next instruction but just keeps the pc as is. So by simply updating the pc to itself we were able to skip 1 instruction.

    This is what is happening to you: in the add pc, pc, #4 instruction you are reading a pc of the instruction mov r0, #3. If you add to it 4 more bytes, it is the address of the bx lr.

    This quirk may be a bit annoying, just remember that when you directly read pc it will always be the current instruction plus 8.

    Is this a problem most of the time? No, if you use labels in your branches, the assembler internally fixes everything for you.

    I cannot explain the reason of this behaviour in ARM. I think this issue has historical roots in the earlier ARM designs where it probably happened that the pc was read at a point in the processor state where it had already been implicitly advanced by 8 bytes. This seems to be a very ARM specific thing (a similar sequence of code like the one above in other architectures would set r1 to 6).

    I hope this answers your question.

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1282#respond" onclick="return addComment.moveForm( &quot;div-comment-1282&quot;, &quot;1282&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to rferrer">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment odd alt depth-3 parent" id="comment-1349">
                <div id="div-comment-1349" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://2.gravatar.com/avatar/588d8ef87925eb384a1589bc451a2690?s=54&amp;d=mm&amp;r=g" srcset="http://2.gravatar.com/avatar/588d8ef87925eb384a1589bc451a2690?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-588d8ef87925eb384a1589bc451a2690-0" originals="32" src-orig="http://2.gravatar.com/avatar/588d8ef87925eb384a1589bc451a2690?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">mirz</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1349">
            May 26, 2013 at 10:03 pm</a>        </div>
    
        <p>AFAIK, this behaviour is due to pipelining, isn’t it?</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1349#respond" onclick="return addComment.moveForm( &quot;div-comment-1349&quot;, &quot;1349&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to mirz">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor even depth-4" id="comment-1358">
                <div id="div-comment-1358" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-2" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">rferrer</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1358">
            May 28, 2013 at 5:54 pm</a>        </div>
    
        <p>I think so. </p>
    

    My guess is that in earlier (and simpler) iterations of the ARM architecture in the alu stage when you read the pc you were reading the pc of the instruction-after-the-next-one (the value that the physical register had at that stage).

    Probably ARM had to preserve this architectural behaviour in later versions of the architecture, so the quirk remained. Note, though, there is no technical reason that prevents the alu stage to have the address of the current instruction when reading the operands.

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1358#respond" onclick="return addComment.moveForm( &quot;div-comment-1358&quot;, &quot;1358&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to rferrer">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li> </ul> </li> </ul> </li>

  • Damien says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-1287">
            May 13, 2013 at 4:03 pm</a>        </div>
    
        <p>Yup, thanks </p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=1287#respond" onclick="return addComment.moveForm( &quot;div-comment-1287&quot;, &quot;1287&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Damien">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
        <li class="comment even thread-even depth-1 parent" id="comment-110792">
                <div id="div-comment-110792" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/15bf4b40214bb6e542b3c90722ec2bd1?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/15bf4b40214bb6e542b3c90722ec2bd1?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-15bf4b40214bb6e542b3c90722ec2bd1-0" originals="32" src-orig="http://1.gravatar.com/avatar/15bf4b40214bb6e542b3c90722ec2bd1?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Randy</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-110792">
            April 2, 2014 at 1:00 pm</a>        </div>
    
        <p>FYI, I think there is an error in this tutorial.</p>
    

    For BGE, the branch condition is when N=V, not N=Z.

    I looked it up in the ARM documentation when I considered that N=Z should be impossible. Zero has a sign bit of zero, and any calculation that results in zero should not have the N bit set.

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=110792#respond" onclick="return addComment.moveForm( &quot;div-comment-110792&quot;, &quot;110792&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Randy">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-110795">
                <div id="div-comment-110795" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-3" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">rferrer</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-110795">
            April 5, 2014 at 9:40 pm</a>        </div>
    
        <p>Hi Randy,</p>
    

    you’re right. I made a typo in GE and then I propagated it to LT.

    I fixed the post. Thanks a lot.

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=110795#respond" onclick="return addComment.moveForm( &quot;div-comment-110795&quot;, &quot;110795&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to rferrer">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • blahyo says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-150045">
            June 7, 2014 at 7:10 pm</a>        </div>
    
        <p>It should be “vs” instead of “os(overflow set)” I believe.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=150045#respond" onclick="return addComment.moveForm( &quot;div-comment-150045&quot;, &quot;150045&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to blahyo">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-151442">
                <div id="div-comment-151442" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-4" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">rferrer</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-151442">
            June 9, 2014 at 12:09 pm</a>        </div>
    
        <p>Yes, thanks. Another typo that I accidentally propagated. It should be right now.</p>
    

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=151442#respond" onclick="return addComment.moveForm( &quot;div-comment-151442&quot;, &quot;151442&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to rferrer">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • Smasher says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950560">
            November 10, 2015 at 5:30 pm</a>        </div>
    
        <p>I think there is a mistake in this chapter. According to ARM Documentation the condition not-equal is NE and not NEQ.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950560#respond" onclick="return addComment.moveForm( &quot;div-comment-950560&quot;, &quot;950560&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Smasher">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-950588">
                <div id="div-comment-950588" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-5" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Roger Ferrer Ibáñez</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950588">
            November 10, 2015 at 8:15 pm</a>        </div>
    
        <p>Hi Smasher,</p>
    

    you are right. I’ve already fixed the post.

    Thank you very much.

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950588#respond" onclick="return addComment.moveForm( &quot;div-comment-950588&quot;, &quot;950588&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Roger Ferrer Ibáñez">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • Smasher says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950725">
            November 11, 2015 at 12:45 pm</a>        </div>
    
        <p>Hey Roger,</p>
    

    I noticed this because “bneq end_of_loop” threw an error.

    I am glad to make a small contribution to your great tutorial, which I am going through with excitement and pleasure by learning asm

    I also hope the subject will stay understandable for me to the last chapter. May I contact you If some questions will remain open after that?

    Regards.

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950725#respond" onclick="return addComment.moveForm( &quot;div-comment-950725&quot;, &quot;950725&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Smasher">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment odd alt depth-2 parent" id="comment-950726">
                <div id="div-comment-950726" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://0.gravatar.com/avatar/9b6de309a0c99eab0b048bf8f4408ead?s=54&amp;d=mm&amp;r=g" srcset="http://0.gravatar.com/avatar/9b6de309a0c99eab0b048bf8f4408ead?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-9b6de309a0c99eab0b048bf8f4408ead-2" originals="32" src-orig="http://0.gravatar.com/avatar/9b6de309a0c99eab0b048bf8f4408ead?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Smasher</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950726">
            November 11, 2015 at 12:46 pm</a>        </div>
    
        <p>This should be an answer to your answer above so you may want to move that comment.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950726#respond" onclick="return addComment.moveForm( &quot;div-comment-950726&quot;, &quot;950726&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Smasher">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor even depth-3" id="comment-950780">
                <div id="div-comment-950780" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-6" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Roger Ferrer Ibáñez</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950780">
            November 11, 2015 at 7:17 pm</a>        </div>
    
        <p>No worries.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950780#respond" onclick="return addComment.moveForm( &quot;div-comment-950780&quot;, &quot;950780&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Roger Ferrer Ibáñez">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • Roger Ferrer Ibáñez says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-950778">
            November 11, 2015 at 7:14 pm</a>        </div>
    
        <p>Hi Smasher,</p>
    

    yes of course. Feel free to ask in the comments section of each chapter where you have questions.

    I also hope next chapters are easy to understand as well

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=950778#respond" onclick="return addComment.moveForm( &quot;div-comment-950778&quot;, &quot;950778&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Roger Ferrer Ibáñez">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • Matt Miller says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-951917">
            November 17, 2015 at 4:44 am</a>        </div>
    
        <p>The work subtraction is spelled substraction in this post.</p>
    
        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=951917#respond" onclick="return addComment.moveForm( &quot;div-comment-951917&quot;, &quot;951917&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Matt Miller">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-951928">
                <div id="div-comment-951928" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-8" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Roger Ferrer Ibáñez</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-951928">
            November 17, 2015 at 6:45 am</a>        </div>
    
        <p>Hi Matt,</p>
    

    Oops! I scattered this typo all over the blog.

    Thank you for the heads-up.

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=951928#respond" onclick="return addComment.moveForm( &quot;div-comment-951928&quot;, &quot;951928&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Roger Ferrer Ibáñez">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li>

  • John Ganci says:
  •     <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-963942">
            April 5, 2016 at 4:11 am</a>        </div>
    
        <p>In the “Unconditional branches” section, the code sample is named branch01.s. However, the sample execution that follows the code is</p>
    

    $ ./compare01 ; echo $?

    Should be ./branch01 ; echo $?

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=963942#respond" onclick="return addComment.moveForm( &quot;div-comment-963942&quot;, &quot;963942&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to John Ganci">Reply</a></div>
                </div>
        <ul class="children">
        <li class="comment byuser comment-author-rferrer bypostauthor odd alt depth-2" id="comment-963948">
                <div id="div-comment-963948" class="comment-body">
                <div class="comment-author vcard">
            <img alt="" src="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=54&amp;d=mm&amp;r=g" srcset="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=64&amp;d=mm&amp;r=g 2x" class="avatar avatar-32 photo grav-hashed grav-hijack" height="32" width="32" id="grav-a779b8290b1ca104fdf84d8016fd010b-9" originals="32" src-orig="http://1.gravatar.com/avatar/a779b8290b1ca104fdf84d8016fd010b?s=32&amp;d=mm&amp;r=g" scale="1.5">            <cite class="fn">Roger Ferrer Ibáñez</cite> <span class="says">says:</span>        </div>
    
        <div class="comment-meta commentmetadata"><a href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#comment-963948">
            April 5, 2016 at 5:24 am</a>        </div>
    
        <p>Hi John,</p>
    

    thank you. I already fixed the post.

    Kind regards,

        <div class="reply"><a rel="nofollow" class="comment-reply-link" href="http://thinkingeek.com/2013/01/19/arm-assembler-raspberry-pi-chapter-5/?replytocom=963948#respond" onclick="return addComment.moveForm( &quot;div-comment-963948&quot;, &quot;963948&quot;, &quot;respond&quot;, &quot;447&quot; )" aria-label="Reply to Roger Ferrer Ibáñez">Reply</a></div>
                </div>
        </li><!-- #comment-## -->
    

    </ul> </li> </ul>

    <p></p>
        <div id="respond" class="comment-respond">
        <h3 id="reply-title" class="comment-reply-title">Leave a Reply <small><a rel="nofollow" id="cancel-comment-reply-link" href="/2013/01/19/arm-assembler-raspberry-pi-chapter-5/#respond" style="display:none;">Cancel reply</a></small></h3>            <form action="http://thinkingeek.com/wp-comments-post.php" method="post" id="commentform" class="comment-form">
                <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p><p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p><p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" aria-required="true" required="required"></p>
    

    </p>

    </form> </div> </div> </div>