I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.
Consider stack starting at address 0x5000 0000. The stack size is 0x1000.
If I add 0x1000 to current stack pointer(Register A10) and store result in A10, then I should get underflow error.
What might be the code in assembly to change stack pointer? something like following:
stw a10, 0x1000(a10) # I'm not sure if stw is correct opcode ?
what are other options to create stack undeflow exception?
Write a function... Call it from main... Whilst you are in the function call ASM and decrease the stack pointer, then a return to main will cause an underflow, BUT!! Its not catchable, the program will go haywire..
If the MPU has multiple cores, then you may have multithreading to create a supervisor thread..
The way you are describing is a stack overflow.. An underflow is on the way back down...
To create an underflow you need to pop more than you pushed!! So! to create a stack underflow you need to use ASM as there is no way of doing this in C... C should'nt allow the compilation of such a problem.
Register A10 is the hardware stack pointer.... In C the software stack is used!! There is no manipulation of the hardware stack at all!!
A C stack pointer is created by the compiler and is normally held in high ram... When using ASM its usually up to the programmer to keep his eye on the hardware stack... But us lowly C worshipers, the stack is abundant... as you see from your text The C stack is 0x1000 bytes ( 4096 ).. This can be made bigger but there is no need...