-2

What is the meaning of the following assembly instructions set:

flashEraseSector:
00005f24:   push    {r7, lr}
00005f26:   sub     sp, #24
00005f28:   add     r7, sp, #0
00005f2a:   str     r0, [r7, #4]
 17                   temp1 = (locat << 8);
00005f2c:   ldr     r3, [r7, #4]
00005f2e:   lsls    r3, r3, #8
00005f30:   str     r3, [r7, #20]
 18                   temp1 = temp1 >> 24;
00005f32:   ldr     r3, [r7, #20]
00005f34:   asrs    r3, r3, #24
00005f36:   str     r3, [r7, #20]
 19                   temp2 = (locat << 16);
00005f38:   ldr     r3, [r7, #4]
00005f3a:   lsls    r3, r3, #16
00005f3c:   str     r3, [r7, #16]
 20                   temp2 = temp2 >> 24;
00005f3e:   ldr     r3, [r7, #16]
00005f40:   asrs    r3, r3, #24
00005f42:   str     r3, [r7, #16]
 21                   temp3 = (locat << 24);

Here is my c code which has been compiled and

        temp1 = (locat << 8);
        temp1 = temp1 >> 24;
        temp2 = (locat << 16);
        temp2 = temp2 >> 24;
        temp3 = (locat << 24);
        temp3 = temp3 >> 24;

It would be great if someone explains what is happening here. Why are these storing 20,20,16,16? They have to store -4,4,12,20 right?

00005f30:   str     r3, [r7, #20]
00005f36:   str     r3, [r7, #20]
00005f3c:   str     r3, [r7, #16]
00005f42:   str     r3, [r7, #16]

Thanks in advance.

user8540390
  • 143
  • 1
  • 10
  • Looks like you compiled some C with optimization disabled so your compiler loads / shifts / stores separately for each instruction. That's why the code is so redundant. – Peter Cordes Jun 06 '18 at 11:50

1 Answers1

2

0x00000800 is the address of the function flashLocat. Next, the first column represents the address in the memory where the instruction is, the second column represents the instrucion and the third the arguments. Anything after ";" represents a comment.

J0rdan
  • 56
  • 4
  • What is meant by the line ` 00005cea: movs r3, #128 ; 0x80`?Is it moving the value 128 into r3 register? – user8540390 Jun 06 '18 at 11:08
  • @user8540390 Yes, exactly. – fuz Jun 06 '18 at 18:51
  • so the line 00005cea: movs r3, #128 ; 0x80` means: at the address 00005cea lays an instruction. The instruction says to move 0x80(which in decimal means 128, that's why the # is there, means the number is in decimal base) to register r3. Please ask if something is still unclear. – J0rdan Jun 07 '18 at 07:42