Last active
March 15, 2018 02:08
-
-
Save IvanaGyro/0e14badaf30e859e99ed0619b5331bdb to your computer and use it in GitHub Desktop.
Print the values of the register sp
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
#include <stdio.h> | |
void print_sp(int startOffset, endOffset) | |
{ | |
int i; | |
unsigned *pp = (unsigned*)&p; | |
register unsigned sp asm ("sp"); | |
pp = (unsigned*)sp; | |
for (i = startOffset; i <= endOffset; i+=4) { | |
if (i < 0) { | |
printf("*(sp%d): %x\n", i, *(pp+i)); | |
} else if (i == 0) { | |
printf("*(sp): %x\n", *(pp+i)); | |
} else { // i > 0 | |
printf("*(sp+%d): %x\n", i, *(pp+i)); | |
} | |
} | |
} | |
int main() | |
{ | |
int startOffset = -20, endOffset = 20; | |
print_sp(a, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment