Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

THUMB push/pop instructions

I'm trying to create a factorial method using THUMB instructions, and I'm basically there.

I just have one question about the PUSH/POP opcodes: if I stored the value of r0 in the stack using push (so push {r0}), can I later use pop {r1} to pull it out or do I need to specify the same register as it was in to begin with? Thanks for your help.

like image 749
user1798522 Avatar asked May 07 '26 00:05

user1798522


1 Answers

Yes, you can since push/pop actually expand to store/load multiple, which are generic instructions operating on registers and memory, so

push {r0}

is equivalent to

stmdb sp!, {r0}  @ or stmfd sp!, {r0} in alt notation

and

pop {r1}

is the same as

ldmia sp!, {r1}  @ or ldmfd sp!, {r1}
like image 53
Nikolai Fetissov Avatar answered May 10 '26 05:05

Nikolai Fetissov