Created
March 23, 2018 19:30
-
-
Save JoshCheek/ba1260f4f0899dcf6d2042319c371850 to your computer and use it in GitHub Desktop.
omg.c
This file contains 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> | |
/* $ ./a.out Erin | |
// registers (stored on the CPU) | |
stack pointer: 0x02 | |
base pointer: 0x00 | |
program counter: 0043 | |
// "the stack" ("working" memory, ie for a given function) | |
0 | 0002 <-- argc \ | |
1 | 1000 <-- argv / | |
2 | 0043 <-- return to here | |
3 | 0000 <-- old base pointer | |
4 | 1020 <-- "num args: %d\n" | |
5 | 0002 <-- argc | |
6 | 0000 | |
... | |
// "the heap" (memory that sticks around) | |
1000 | 1002 \ <-- argv | |
1001 | 1010 / | |
1002 | 0046 <-- '.' | |
1... | 0047 <-- '/' | |
1... | 0097 <-- 'a' | |
1... | 0046 <-- '.' | |
1... | 0111 <-- 'o' | |
1... | 0117 <-- 'u' | |
1... | 0116 <-- 't' | |
1010 | 0069 <-- 'E' | |
1... | 0114 <-- 'r' | |
1... | 0105 <-- 'i' | |
1... | 0110 <-- 'n' | |
*/ | |
/* 0x1010 has 0069 ('E'), a char */ | |
/* 0x1001 has 1010, a char* */ | |
/* 0x0001 has 1000, a char** */ | |
int main(int argc, char** argv) { | |
printf("num args: %d\n", argc); | |
int i; | |
for(i = 0; i < argc; ++i) { | |
char* s1 = argv[i]; | |
char* s2 = *(argv + i); | |
printf("arg %d: %s\n", i, s1); | |
printf(" %s\n", s2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment