Skip to content

Instantly share code, notes, and snippets.

@IvanaGyro
Last active March 15, 2018 02:08
Show Gist options
  • Save IvanaGyro/0e14badaf30e859e99ed0619b5331bdb to your computer and use it in GitHub Desktop.
Save IvanaGyro/0e14badaf30e859e99ed0619b5331bdb to your computer and use it in GitHub Desktop.
Print the values of the register sp
#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