历史
结构种类:
X86 AMD64 ARM MIPS IA64 X86-64CPU
分为:精简指令集(risv)该指令集编程相对复杂,复杂指令集(cisv)
ARM手机芯片 MIPS嵌入式路由器
基础知识--字节
基础知识--总线
冯诺依曼理论---计算机组成----总线
总线是单向的。
基础知识--编译过程
文本到可以执行的程序。
过程:预编译-->编译-->汇编-->链接
gcc -E xxx.c -o xxx.i
gcc -S xxx.i -o xxx.s
gcc -c xxx.s -o xxx.o
gcc --static xxx.o -o xxx
预编译:头文件进行展开。留下正确的宏,删除不需要的分支,展开嵌套。
编译:将预处理之后的文件转化为汇编语言,
汇编:将汇编语言转化为机器语言。
链接:静态链接,自己带lib库,动态链接调用第三方的lib库
案例:
demo.c
#include <stdio.h>
int main() {
printf("hello word");
return 0;
}
将demo.c预编译
gcc -E demo.c -o demo.i
查看编译的内容
[root@localhost ~]# cat demo.i|more
# 1 "demo.c"
# 1 "<built-in>"
# 1 "<命令行>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<命令行>" 2
# 1 "demo.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 375 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 392 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 393 "/usr/include/sys/cdefs.h" 2 3 4
# 376 "/usr/include/features.h" 2 3 4
# 399 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4
# 10 "/usr/include/gnu/stubs.h" 3 4
# 1 "/usr/include/gnu/stubs-64.h" 1 3 4
# 11 "/usr/include/gnu/stubs.h" 2 3 4
# 400 "/usr/include/features.h" 2 3 4
# 28 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stddef.h" 1 3 4
# 212 "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stddef.h" 3 4
typedef long unsigned int size_t;
# 34 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/include/bits/types.h" 1 3 4
# 27 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 28 "/usr/include/bits/types.h" 2 3 4
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
.......
将预编译的文件进行编译,转化为汇编语言。
gcc -S demo.i -o demo.s
查看编译后的内容
[root@localhost ~]# cat demo.s|more
.file "demo.c"
.section .rodata
.LC0:
.string "hello word"
.text
.globl main
.typ