Listing 2

// ARM assembly code interleaved with the C source for the simple
// linear search program shown in Listing 1
#include <stdio.h>

#define DIM(x) (sizeof(x) / sizeof(x[0]))

/* search() returns 1 if the key is found and 0 if it is not found. */
int search(int *array, int array_len, int key)
{
    int i;
                STMDB         SP!, {R8,R9}
    for(i=0; i<array_len; i++) {
                MOV           R3 <i>, 0
                B             0x20(search+0x30 (0xd8))
    if(array[i] == key)
                MOV           IP, R3 <i>
                MOV           IP, IP, LSL 2
                ADD           IP, IP, R0 <array>
                LDR           IP,[IP]
                CMP           IP, R2 <key>
                BNE           0x4(search+0x2c (0xd4))
        return 1;
                MOV           R0 <array>, 1
                B             0xc(search+0x3c (0xe4))
                ADD           R3 <i>, R3 <i>, 1
                CMP           R3 <i>, R1 <array_len>
                BLT           0xffffffd0(search+0xc (0xb4))
    }
    return 0;
                MOV           R0, 0
}
                LDMIA         SP!, {R8,R9}
                MOV           PC, LR
int main(int argc, char *argv[])
{
                STMDB         SP!, {R4,R5,R8,R9,LR}
                SUB           SP, SP, 40
                MOV           R2, R0
    int found = 0;
                MOV           R4 <found>, 0
    int fib_seq[] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 };
                MOV           IP, SP
                LDR           R5,[PC,92](0x164)
                LDMIA         R5!, {R2,R3}
                STMIA         IP!, {R2,R3}
                LDMIA         R5!, {R2,R3}
                STMIA         IP!, {R2,R3}
                LDMIA         R5!, {R2,R3}
                STMIA         IP!, {R2,R3}
                LDMIA         R5!, {R2,R3}
                STMIA         IP!, {R2,R3}
                LDMIA         R5, {R2,R3}
                STMIA         IP, {R2,R3}
    if( search( fib_seq, DIM(fib_seq), 3 ) )
                MOV           R0, SP
                MOV           R2, 3
                MOV           R1, 10
                BL            0xffffff68(search (0xa8))
                MOV           R1, R0
                CMP           R1, 0
                BEQ           0x0(main+0x60 (0x14c))
    found++;
                ADD           R4 <found>, R4 <found>, 1
    printf("Number found: %d\n", found);
                MOV           R1, R4 <found>
                LDR           R0,[PC,16](0x168)
                BL            0x24(printf (0x180))
    return 0;
                MOV           R0, 0
}
                ADD           SP, SP, 40
                LDMIA         SP!, {R4,R5,R8,R9,PC}