gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Stack Issues [Solved, but confused]

#168516 - Tyler24 - Sat May 02, 2009 5:10 am

I don't know what this syntax means, and my program doesn't work without it. I was googling after a lot of frustration and found that I needed to put an exclamation point after sp when using stmfd/ldmfd...

Code:
 stmfd sp!, {r9-r12, lr}
 bl drawpixel
 ldmfd sp!, {r9-r12, lr}


Edit: Okay, so it updates sp after the pushes occur... but why wouldn't something like that be assumed? Is there ever a time where you wouldn't want the sp to be updated after a push? I'm kind used to 80x86 assembly where you'd just push eax or something, and not have to worry about sp being updated like that.

#168518 - Ruben - Sat May 02, 2009 7:46 am

The reason for the write-back (exclamation mark) is because stmfd is not only used for sp; it can be used for any other register.

EDIT: Oh yeah, depending on your devkit, you may be able to use push {foo} and pop {foo}

#168525 - Tyler24 - Sat May 02, 2009 3:40 pm

Thanks.

I'm just using open source arm-eabi tools, not sure of their limitations.

Yeah, I realized it could be used in conjunction with any register (but is normally used with the sp), just can't think of why you wouldn't want to update the pointer after you copied stuff to it. :P

#168527 - Ruben - Sat May 02, 2009 3:49 pm

Consider this example...

Code:
@ r0: &MySoundChannel

ldmia r0, {r1-r4} @ Fetch data from the channel into r1-r4 but don't write back.

@ THen there's some huge loop that updates the registers

stmia r0!, {r1-r4} @ Store the modified data back and THEN writeback so I can go to the next channel in line


Or basically, you'll want to use that if you're going to modify stuff from the registers later on, unless you don't mind using sub/add.

#168529 - Tyler24 - Sat May 02, 2009 4:51 pm

Ok, that makes sense, thanks!