Last active
December 16, 2015 17:40
-
-
Save MrTrick/5472030 to your computer and use it in GitHub Desktop.
Abusing the stack pointer for fun and profit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* StackManipulation.c | |
* | |
* Created: 27/04/2013 2:34:22 PM | |
* Author: MrTrick | |
*/ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <inttypes.h> | |
uint8_t depth = 8; | |
void cancel() { | |
SP = RAMEND; //Completely clear the stack | |
cli(); | |
run(); //Run never returns | |
} | |
void funcx() { | |
if (--depth==0) { | |
depth = 8; | |
cancel(); | |
} | |
funcx(); | |
} | |
void run(void) { | |
while(1) | |
{ | |
//Some pointless assignations to occupy the controller | |
PORTC = 0xF0; | |
PORTB = 0x0F; | |
//This function just takes too long... so it'll be cancelled | |
//after a few recursions, and execution will restart at the top of runMain() | |
funcx(); | |
} | |
} | |
int main(void) | |
{ | |
//init stuff... | |
// | |
run(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment