When program finishes final line, it will set register r0 to 0


I have code at the end of my program that is as follows:

        ldrb r2, [r1, #12] 
        sub r2, r2, #48
        cmp r2, r7 
        beq Check
        sub r0, r0, #1
Check   add r0, #1


If cmp r2, r7 decides r2 & r7 are equal, the program jumps to Check as should be expected. What is weird however is that after r1 has #1 added, it is then set to 0. The debugger shows the following in Disassembly:

0x00000088 E1A00000 NOP
that above line has a green icon to the left.
0x0000008C 30313338 EORCCS R3,R1,R8,LSR R3
0x00000090 30303135 EORCCS R3,R0,R5,LSR R1
0x00000094 30373338 EORCCS R3,R7,R8,LSR R3
the above three lines has an orange icon to the left.
0x00000098 0000008C ANDEQ R0,R0,R12,LSL #1
the above line has a light blue icon to the left.

How can I stop this from happening? (Running ARM7 (Big Endian))

asked on Stack Overflow Mar 2, 2015 by user3721428

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0