need help with stack pointers

now before i begin, i am newbie to programming. i've never taken any typ of programming and i am in assembler language class. we're studyin motorola 6800 and ran into a question

the profesor tells us that when using such commands as bsr,rts, and movem the stack pointer value will change. he also tells that we have t subtract the offset value from the current stack pointer value to get th current value of the stack pointer.

is that true or is he mistaken? because i would think that you would hav to add the offset value.

for example in command movem d0-d5/d7/a0-a3, since there are 44 byte involved, the new stack pointer value would be 102C, i would think

44, converted into hex is 2C and 1000+2C= 102C
Reply to
350ZBOI
Loading thread data ...

According to these 68HC05 data sheets, the stack starts at a high address and grows downward. You can see evidence of this when the BSR instruction subtracts from the stack pointer as it pushes a return address, and the RTS instruction adds to the stack pointer as it pops that address back into PC.

So if you're going to establish a frame on "top" of such a stack, you have to avoid the higher addresses which are already in use, and put your frame in locations below the current SP value. It would be possible to locate a "frame base" one frame size below the SP value, get that in a register, and index up from there, but that wastes a register for no benefit. Simplest to index negative from the SP.

Mel.

Reply to
Mel Wilson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.