Assembly

Started by
10 comments, last by Tiger99 21 years, 1 month ago
Look a few posts up. A7 is the stack pointer. If you write meaningless values to it, you can expect your program to crash on function return.

I cannot fix this problem for you.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
1) the direction of the move is incorrect if the comments are correct - to save the SSP, a7 needs to be on the left. The code as it stands moves from the sr variable into a7 which re-writes the SSP with the value in that variable.


2) it pays to be explicit, if you mean SSP rather than USP, use SSP (assuming your assembler supports the proper names for the registers).


3) That code will only work when the CPU is in supervisor mode, since there's an RTE in there I'll assume the code is started from a trap or IRQ which is ok. But don't call that code from user mode, say with a jsr.


4) the rte returns from the function - so the re-enable interrupts line should be BEFORE that!


5) where does that code return to? - if you need to return somewhere surely you should have a couple of "movem"s in there to save the current registers - particularly because the C code is likely to trash other registers.


6) moving 7 into the interrupt status bits of the SSR will prevent the interrupt from the CPUs point of view - depending on your hardware there may be more work required to also disable the source of the interrupts.


7) The 680x0 CPU requires the address for any long/word read/writes must be on an even address or you'll get a privilege violation.


8) Is NullPCB intended to be your new stack?, if so:

a. that move.l should be an "lea" to get the address of that rather than the value. Alternatively the address should be prefixed with a #

b. the address needs to be at the _end_ of the memory for your stack (just to make sure that the value is)

c. bear in mind that C and C++ use tons more stackspace than handcoded assembly - if that's 255 bytes, then IMO it's too small


--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - s1ca on March 23, 2003 7:48:44 PM]

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement