Thread: [Tutorial] The Concept of ASM
View Single Post
Old August 10th, 2013 (9:01 AM).
Kurapika's Avatar
Kurapika Kurapika is offline
Join Date: Feb 2013
Location: Lavendar Town - Morocco
Gender: Male
Nature: Naughty
Posts: 406
Originally Posted by karatekid552 View Post
This is a very good question. Let me explain:

The stack pointer always points to the location of the last pushed item. But, let's say we need to access an item we pushed two pushes ago, but don't want to disturb the other pushed items. sub SP, #0x4 or add SP, SP, #0x4 is how you would do that. When an item is pushed, the SP is DECREASED by 4. (Just enforcing that we no make the mistake that pushing, adds. The stack is actually upside-down if you think about it.) So, let's look at some code:

push {r1}
push {r2}
push {r3}
mov r1, #0x0
mov r2, #0x0
mov r3, #0x0
add sp, #0x8
mov r1, [sp]
sub sp, #0x8

So, what is on r1?

The original value of r1!

So, all of them are still stored in the stack, but now we have recovered the value of r1 without poping. This is useful if you push {r4, lr}. but then later need to recover r4, but don't want to pop r14. Do you understand?
I see, thank you for the good explanation!
Reply With Quote