--- /dev/null
+hello_world
--- /dev/null
+/*#include<stdio.h>
+#include<stdint.h>
+*/
+void* fopen(const char* path, const char* mode);
+int fclose(void* fp);
+int fscanf(void* fp, const char* fmt, ...);
+
+int printf(const char* fmt, ...);
+
+int main()
+{
+ void* fp = fopen("1.txt", "r");
+ if (!fp) {
+ printf("fp: %p\n", fp);
+ return -1;
+ }
+
+ char* s[64];
+
+ int n = fscanf(fp, "%s", s);
+
+ printf("s: %s, n: %d\n", s, n);
+
+ fclose(fp);
+ return 0;
+}
--- /dev/null
+
+int printf(const char* fmt, ...);
+
+/* C 全局数据
+
+ 1,函数都是全局的,在.text段
+
+ 2, 字符串常量
+
+ 3,全局变量
+
+ a 和 p 都在 .data段,可写
+----------------------
+ 进程的内存排布
+
+ .text 代码段, R E,可读可执行
+ .rodata 只读数据段, R,
+ .data 数据段, R, W, 可读可写
+ -------------------
+ 堆 heap
+ ------------------ brk,数据段末尾
+ (空白区)
+ ------------------ rsp, 栈顶
+ 栈
+ ------------------
+ */
+
+int a = 123;
+int* p = &a;
+
+int main()
+{
+ printf("a: %d, p: %p\n", a, p);
+ return 0;
+}
--- /dev/null
+// 汉诺塔,递归算法
+
+int printf(const char* fmt, ...);
+
+int count = 0;
+
+void hanoi(int n, char a, char b, char c)
+{
+ if (1 == n)
+ printf("count: %d, n: %d, %c->%c\n", count++, n, a, c);
+ else {
+ hanoi(n-1, a, c, b); // 递归
+ printf("count: %d, n: %d, %c->%c\n", count++, n, a, c);
+ hanoi(n-1, b, a, c); // 递归
+ }
+}
+
+int main()
+{
+ hanoi(5, 'A', 'B', 'C');
+ return 0;
+}
--- /dev/null
+
+/* hello world 程序
+
+ 1,对库函数的调用,printf()
+
+ 2, 对常量字符串的寻址,"hello world\n"
+
+ 常量字符串是只读的,放在.rodata段
+
+ 3,分段是为了权限控制(读、写、运行),为了信息安全
+ */
+
+int printf(const char* fmt, ...);
+
+int main()
+{
+ printf("hello world\n");
+ return 0;
+}
--- /dev/null
+
+int printf(const char* fmt, ...);
+
+#define A(x) #x
+
+int main()
+{
+ int z = 1;
+
+ printf("%s: %d\n", A(z), z);
+ return 0;
+}
--- /dev/null
+#include<stdio.h>
+#include<unistd.h>
+#include<pthread.h>
+
+int xchg(int* mutex)
+{
+ int ret;
+
+ asm volatile(
+ "xchg %0, (%1)\n\t"
+ :"=r"(ret)
+ :"r"(mutex), "0"(1)
+ :
+ );
+
+ return ret;
+}
+
+void lock(int* mutex)
+{
+ while (1 == xchg(mutex))
+ sched_yield();
+}
+
+void unlock(int* mutex)
+{
+ *mutex = 0;
+}
+
+int g_mutex = 0;
+int g_count = 0;
+
+void* thread(void* arg)
+{
+ int i;
+ for (i = 0; i < 1000 * 1000; i++) {
+
+ lock(&g_mutex);
+ g_count++;
+ unlock(&g_mutex);
+ }
+ return 0;
+}
+
+int main()
+{
+ pthread_t tid;
+ pthread_create(&tid, NULL, thread, NULL);
+
+ int i;
+ for (i = 0; i < 1000 * 1000; i++) {
+ lock(&g_mutex);
+ g_count++;
+ unlock(&g_mutex);
+ }
+
+ pthread_join(tid, NULL);
+
+ printf("g_count: %d\n", g_count);
+ return 0;
+}
--- /dev/null
+int printf(const char* fmt, ...);
+
+int sort(int* a, int m, int n)
+{
+ if (m >= n)
+ return 0;
+
+ int i = m;
+ int j = n;
+ int t;
+
+ t = a[i];
+ while (i < j) {
+
+ while (i < j && t <= a[j])
+ j--;
+ a[i] = a[j];
+ a[j] = t;
+
+ while (i < j && a[i] <= t)
+ i++;
+ a[j] = a[i];
+ a[i] = t;
+ }
+
+ sort(a, m, i - 1);
+ sort(a, i + 1, n);
+ return 0;
+}
+
+int main()
+{
+ int a[20] = {1, 3, 5, 7, 9, 8, 4, 2, 6, 0,
+ 11, 13, 15, 17, 19, 18, 16, 14, 12, 10};
+
+ sort(a, 0, 19);
+
+ int i;
+ for (i = 0; i < 20; i++)
+ printf("%d\n", a[i]);
+
+ return 0;
+}