0

I am working in a binary analysis project and I came across two different variants of ldmia arm assembly instruction.

ldmia.w sp, {r1, r2}

ldmia.w sp!, {r1, r2}

I know ldmia.w sp!, {r1, r2} is a synonym to pop {r1,r2}. but what about ldmia.w sp, {r1, r2}? . Am I using the value stored in sp as a memory address to load from into r1 and r2 which doesn't make much sense to me or am I poping from the stack without updating the value of the sp which also doesn't make sense.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
hany erfan
  • 95
  • 7

1 Answers1

3

Refer to the ARM Architecture Reference Manual for the meaning of the various parts of the ARM assembly language. The ! sign denotes that the new address is written back to the register. I.e. ldmia.w sp!, {r1, r2} adds 8 to sp but ldmia.w sp, {r1, r2} leaves sp unchanged.

old_timer
  • 69,149
  • 8
  • 89
  • 168
fuz
  • 88,405
  • 25
  • 200
  • 352
  • yes that i know... but what is the usage of each instruction?..is ldmia.w sp, {r1,r2} used to implement a stack pop without updating sp or is it a memory load taking sp as the base register?? – hany erfan Aug 26 '21 at 07:38
  • the reason why usage is important to me because I am translating each instruction to an LLIR and I have constructed my own memory and stack models..so I need to capture the effect of each instruction on my models. – hany erfan Aug 26 '21 at 07:42
  • 2
    @hanyerfan Each of these instructions can be used for a variety of purposes. You will not be able to uniquely assign a usage to each instruction. – fuz Aug 26 '21 at 07:58
  • 3
    @fuz *adds 4* - two 32-bit registers are read by ldmia.w sp!, {r1, r2}, so it adds 8, doesn't it? – tum_ Aug 26 '21 at 08:32
  • 1
    @tum_ Yes, indeed. – fuz Aug 26 '21 at 08:58
  • @fuz ..ill try to narrow down my question more... can the sp register be used in instructions other than those poping and pushing onto the stack? – hany erfan Aug 26 '21 at 09:08
  • 1
    @hanyerfan Yes of course. Why should it not? – fuz Aug 26 '21 at 09:51
  • yes i just realised i should have my stack model as part of my memory model.....one last question.. what happens to the memory space of a register being popped off the stack? – hany erfan Aug 26 '21 at 10:06
  • 3
    @hanyerfan Popping a register off the stack is a load operation. It does not modify memory. However, the memory location of the register is now below the stack pointer and thus can be overwritten by an interrupt handler or similar at any time. – fuz Aug 26 '21 at 10:23
  • 1
    ```ldmia.w sp, {r1, r2}```would just load the top item of the stack into both ```r1``` and ```r2```, and the stack pointer would remain pointing to the same value. – puppydrum64 Nov 03 '21 at 16:08
  • 1
    @hanyerfan The values popped off the stack are still there (for now), until some other function overwrites them when it pushes more values. Nearly all programs treat that memory as "gone" after you've popped it off the stack, and don't try to access it directly. – puppydrum64 Nov 03 '21 at 16:16