增加复习资料

This commit is contained in:
Kagura 2024-07-01 20:16:50 +08:00
parent 3aeb42d256
commit 7b369b1217
8 changed files with 1509 additions and 0 deletions

48
复习资料/.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,48 @@
{
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
],
"env": {}
}
],
}

22
复习资料/A.aux Normal file
View file

@ -0,0 +1,22 @@
\relax
\providecommand\hyper@newdestlabel[2]{}
\providecommand*\HyPL@Entry[1]{}
\HyPL@Entry{0<</S/D>>}
\@writefile{toc}{\contentsline {section}{\numberline {1}数据表示与存储}{1}{section.1}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}数据的类型及大小}{1}{subsection.1.1}\protected@file@percent }
\@writefile{lot}{\contentsline {table}{\numberline {1}{\ignorespaces 数据的类型及大小}}{1}{table.1}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {1.2}计算值域}{1}{subsection.1.2}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {1.3}补码}{1}{subsection.1.3}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {1.4}GDB查看数据}{1}{subsection.1.4}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {1.5}浮点数}{2}{subsection.1.5}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.1}规格化数 $ \text {exp} \ne 0$$\text {exp} \ne 11 \dots 1$}{2}{subsubsection.1.5.1}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.2}非规格化数 $\text {exp} = 0 $}{2}{subsubsection.1.5.2}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.3}舍入(到偶数)}{2}{subsubsection.1.5.3}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {2}程序的机器级表示}{3}{section.2}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}计算数组元素的地址}{3}{subsection.2.1}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}其他内容}{3}{subsection.2.2}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {3}链接}{3}{section.3}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}符号表 (.symtab)}{3}{subsection.3.1}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}链接顺序}{3}{subsection.3.2}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}重定位}{3}{subsection.3.3}\protected@file@percent }
\gdef \@abspage@last{3}

1126
复习资料/A.log Normal file

File diff suppressed because it is too large Load diff

16
复习资料/A.out Normal file
View file

@ -0,0 +1,16 @@
\BOOKMARK [1][-]{section.1}{\376\377\145\160\143\156\210\150\171\072\116\016\133\130\120\250}{}% 1
\BOOKMARK [2][-]{subsection.1.1}{\376\377\145\160\143\156\166\204\174\173\127\213\123\312\131\047\134\017}{section.1}% 2
\BOOKMARK [2][-]{subsection.1.2}{\376\377\213\241\173\227\120\074\127\337}{section.1}% 3
\BOOKMARK [2][-]{subsection.1.3}{\376\377\210\145\170\001}{section.1}% 4
\BOOKMARK [2][-]{subsection.1.4}{\376\377\000G\000D\000B\147\345\167\013\145\160\143\156}{section.1}% 5
\BOOKMARK [2][-]{subsection.1.5}{\376\377\155\156\160\271\145\160}{section.1}% 6
\BOOKMARK [3][-]{subsubsection.1.5.1}{\376\377\211\304\150\074\123\026\145\160\000\040\000\040\000e\000x\000p\000\040\000=\0000\000\040\116\024\000\040\000e\000x\000p\000\040\000=\0001\0001\000\040\040\046\0001}{subsection.1.5}% 7
\BOOKMARK [3][-]{subsubsection.1.5.2}{\376\377\227\136\211\304\150\074\123\026\145\160\000\040\000e\000x\000p\000\040\000=\000\040\0000\000\040}{subsection.1.5}% 8
\BOOKMARK [3][-]{subsubsection.1.5.3}{\376\377\202\015\121\145\000\050\122\060\120\166\145\160\000\051}{subsection.1.5}% 9
\BOOKMARK [1][-]{section.2}{\376\377\172\013\136\217\166\204\147\072\126\150\176\247\210\150\171\072}{}% 10
\BOOKMARK [2][-]{subsection.2.1}{\376\377\213\241\173\227\145\160\176\304\121\103\175\040\166\204\127\060\127\100}{section.2}% 11
\BOOKMARK [2][-]{subsection.2.2}{\376\377\121\166\116\326\121\205\133\271}{section.2}% 12
\BOOKMARK [1][-]{section.3}{\376\377\224\376\143\245}{}% 13
\BOOKMARK [2][-]{subsection.3.1}{\376\377\173\046\123\367\210\150\000\040\000\050\000.\000s\000y\000m\000t\000a\000b\000\051}{section.3}% 14
\BOOKMARK [2][-]{subsection.3.2}{\376\377\224\376\143\245\230\172\136\217}{section.3}% 15
\BOOKMARK [2][-]{subsection.3.3}{\376\377\221\315\133\232\117\115}{section.3}% 16

BIN
复习资料/A.pdf Normal file

Binary file not shown.

BIN
复习资料/A.synctex.gz Normal file

Binary file not shown.

282
复习资料/A.tex Normal file
View file

@ -0,0 +1,282 @@
\documentclass[UTF8,punct=kaiming]{ctexart}
\usepackage{amsmath}
\usepackage[a4paper,left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage[type={CC},modifier={by-sa},version={4.0},lang={chinese-utf8}]{doclicense}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[many]{tcolorbox}
\usepackage{multirow}
\usepackage{listings}
\input{insbox}
\setlength{\parindent}{0pt}
\hypersetup{hidelinks,
colorlinks=false,
allcolors=black,
pdfstartview=Fit,
breaklinks=true}
\pagestyle{fancy}
\fancypagestyle{myfancypagestyle}{
\fancyhf{}
\fancyhead[L]{计算机系统基础\uppercase\expandafter{\romannumeral1\relax} 考试用资料}
\fancyhead[R]{Made with $\heartsuit$ by \href{https://kagurach.uk/}{kagura} and \href{https://nkid00.name/}{nkid00} \& licensed under \doclicenseNameRef}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{myfancypagestyle}
\tcbuselibrary{listings}
\tcbset{colback=white,boxrule=0.3mm,enhanced}
\lstset{basicstyle=\ttfamily,columns=fullflexible}
\columnseprule=0.4pt
\begin{document}
\section{数据表示与存储}
\subsection{数据的类型及大小}
\begin{table}[h]
\caption{数据的类型及大小}
\begin{tabular}{|c|c|c|c|c|}
\hline
类型 & 字节数 & 最小值 & 最大值(signed) & 最大值(unsigned) \\ \hline
\texttt{char} & 1 & -128 & 127 & 255\\ \hline
\texttt{short} & 2 & -32768 & 32767 & 65535\\ \hline
\texttt{int} & 4 & -2147483648 & 2147483647 & 4294967295 \\ \hline
\texttt{long} & \multirow{2}{*}{8} & \multirow{2}{*}{-9223372036854775808} & \multirow{2}{*}{9223372036854775807} & \multirow{2}{*}{18446744073709551615} \\
\cline{1-1} \texttt{void*} & & & & \\ \hline
\texttt{float} & 4 & 1.17549$\times10^{-38}$ & 3.40282$\times10^{38}$& \\ \hline
\texttt{double} & 8 & 2.22507$\times10^{-308}$ & 1.79769$\times10^{308}$ & \\ \hline
\end{tabular}
\end{table}
\subsection{计算值域}
T: 用 $n$ 位表示数字
\begin{align*}
\text{(signed) T} \quad & \text{可表示} \quad -2^{n-1} \sim ~ 2^{n-1}-1 \\
\text{(unsigned) T} \quad & \text{可表示} \quad 0 \sim 2^{n}-1
\end{align*}
\subsection{补码}
\begin{multicols}{2}
\qquad 对应正数补码的“各位取反、末位加1”
\begin{align*}
+23 & = 00010111 \\
\text{按位取反} & = 11101000 \\
& + \hspace{1.8cm} 1 \\
-23_{\text{补码}} & = 11101001
\end{align*}
\columnbreak
\qquad 模($2^n$)减去该负数的绝对值
\begin{align*}
100000000 & \\
-00010111 & \\
\rule{2.5cm}{0.02em} \\
11101001
\end{align*}
\end{multicols}
\subsection{GDB查看数据}
\begin{multicols}{2}
\texttt{>(gdb) x/4xb} \\
b - byte (8-bit value)\\
h - halfword (16-bit value) \\
w - word (32-bit value) \\
g - giant word (64-bit value)
\columnbreak
o - octal \\
x - hexadecimal \\
d - decimal \\
u - unsigned decimal \\
t - binary \\
f - floating point \\
a - address \\
c - char \\
s - string \\
i - instruction
\end{multicols}
\newpage
\subsection{浮点数}
\vspace{-1cm}
\InsertBoxR{0}{\tcbox[blank]{\begin{tabular}{|c|c|c|c|c|}
\hline 二进制位数 & s 符号位 & exp 指数 & frac 尾数 & 总计 \\
\hline \texttt{float} & 1 & 8 & 23 & 32 \\
\hline \texttt{double} & 1 & 11 & 52 & 64 \\
\hline
\end{tabular}}}
\vspace{1cm}
浮点数表示为 $(-1)^s \cdot M \cdot 2^E$
\InsertBoxR{1}{\tcboxmath{\begin{matrix}
\multicolumn{2}{c}{\text{偏置值 Bias}} \\
\texttt{float} & 127 \\
\texttt{double} & 1023 \\
\end{matrix}}\hspace{3cm}}
\subsubsection{规格化数 $ \text{exp} \ne 0$$\text{exp} \ne 11 \dots 1$}
$\text{(unsigned)} \ \text{exp} \ = \ E \ + \text{Bias}$
$\text{Bias (偏置值)} = 2^{k-1}-1$ , k 为 $exp$ 的二进制位数
\begin{multicols}{2}
例1:十进制整数$\rightarrow$二进制浮点数
\begin{align*}
\text{float} \ F &= 15213.0 \\
\text{化为二进制数:} \\
15213_{10} &= 11101101101101_{2} \\
&= 1.1101101101101_{2} \ \times \ 2^{13} \\
\text{计算 frac:} \\
M &= 1.\underbar{1101101101101}_{2} \\
\text{frac} &= \underbar{1101101101101}0000000000_{2}\\
\text{计算 exp:} \\
E &= 13 \qquad \text{来自化为二进制时的指数} \\
\text{Bias} &= 127 \\
\text{exp} &= 140 = 10001100_{2}
\end{align*}
结果:\\
\(\begin{matrix}
0 & 10001100 & 11011011011010000000000 \\
\text{s} & \text{exp} & \text{frac}
\end{matrix}\)
\columnbreak
例2:二进制浮点数$\rightarrow$十进制数\\
无符号数4位阶码(Bias=7)3个小数位
\begin{align*}
1001 \quad 111 \\
exp \quad frac \\
\text{计算E:} \\
E &= exp - Bias \\
&= 1001_2 - 7_{10} \\
&= 2_{10} \\
\text{计算M:} \\
M = 1.\underbar{frac} &= 1.\underbar{111} \\
\text{化为十进制:} \\
1.111 \times 2^2 &= 111.1_2 \quad \text{小数点右移2位} \\
&= 7\frac{1}{2} = \frac{15}{2}
\end{align*}
\end{multicols}
\InsertBoxR{1}{\tcboxmath{\begin{matrix}
\text{非规格化数} \ E = 1 - \text{Bias} \\
\begin{matrix}
\texttt{float} & -126 \\
\texttt{double} & -1022 \\
\end{matrix}
\end{matrix}}\hspace{2cm}}
\subsubsection{非规格化数 $\text{exp} = 0 $}
frac \(= 00\dots0\) 表示 0
frac \(\ne 00\dots0\) 表示接近 0 的小数 $(-1)^s \cdot M \cdot 2^{E}$
\subsubsection{舍入(到偶数)}
\begin{table}[h]
\begin{tabular}{|ccc|}
\hline
末两位 & 动作 & 例子(保留一位小数) \\ \hline
01 && $11.0\underbar{01}_2 \to 11.0_2$ \\ \hline
11 && $10.0\underbar{11}_2 \to 10.1_2$ \\ \hline
10 & \makecell[c]{强迫结果为偶数(末尾为0)\\010舍 , 110入} &\makecell[c]{$10.0\underbar{10}_2 \to 10.0_2$ \\ $10.1\underbar{10}_2 \to 11.0_2$} \\ \hline
\end{tabular}
\end{table}
\pagebreak
\section{程序的机器级表示}
\subsection{计算数组元素的地址}
\begin{multicols}{2}
计算 \texttt{T* D[R][C]} 元素 \texttt{D[i][j]}的地址: \\
\(\texttt{\&D[i][j]} = \texttt{\&D[0][0]} + \texttt{sizeof(T)} \times \left(C \cdot i + j\right)\) \\
假设 \texttt{sizeof(T) = k}, 将 \texttt{D[i][j]} 复制到 \%eax 中 \\
\texttt{asm: D in \%rdi , i in \%rsi , j in \%rdx }
\columnbreak
\texttt{1 \ leaq (\%rsi,\%rsi,\$C-1), \%rax \\
2 \ leaq (\%rdi,\%rax,\$k), \%rax \\
3 \ movl (\%rax,\%rdx,\$k), \%rax \\
}
结果为 \texttt{D+ k $\cdot$ C $\cdot$ i + k $\cdot$ j} \\
\texttt{D + sizeof(T) $\times$ (C $\cdot$ i + j)}
\end{multicols}
\vspace{-1cm}
\subsection{其他内容}
\vspace{-2mm}
\begin{table}[h]
\begin{tabular}{c|c|c|c} \hline
内容 & 操作数计算方式&&gdb常用操作\\ \hline
页码 & P121&P164&P194 \\
\hline
\end{tabular}
\end{table}
\vspace{-5mm}
\section{链接}
\subsection{符号表 (.symtab)}
\begin{table}[h]
\begin{tabular}{l|c|c|c|c}
\hline
C语言表示 & 类型 & 符号强度 && 说明\\ \hline
\texttt{void swap();} & 全局 && \texttt{.text} & 函数在.text \\ \hline
\texttt{extern int buf[];} & 外部 & --- & 实际定义所在位置 & 默认\texttt{UND}(未解析的引用符号) \\ \hline
\texttt{int *bufp0 = \&buf[0]} & 全局 && \texttt{.data} & 初始化的全局变量\\ \hline
\texttt{int *bufp1;} & 全局 && \texttt{COMMON} & 未初始化的全局变量 \\ \hline
\begin{lstlisting}[language=C,gobble=8]
void p() {
static int i = 1; }
\end{lstlisting}
& 局部 & \makecell[c]{\ ,不同\\函数可重} & \texttt{.data}\texttt{.bss} & \makecell[l]{未初始化或初始化为0在 \ \texttt{.bss}\\初始化为其他在 \ \texttt{.data}} \\ \hline
\begin{lstlisting}[language=C,gobble=8]
void q() {
int j = 2; }
\end{lstlisting}
& 都不是 & --- & 节里没有,在栈里 & 链接器不看局部\underbar{变量} \\ \hline
\end{tabular}
\end{table}
\subsection{链接顺序}
\texttt{\$ gcc -static -o prog2c main2.o ./libvector.a} \\
E 将被合并以组成可执行文件的所有目标文件集合\\
U 当前所有未解析的引用符号的集合\\
D 当前所有定义符号的集合\\
开始 E、U、D为空首先扫描 \texttt{main2.o},将其加入 E将未找到的符号加入 U, 定义的符号加入 D。 \\
再扫描 \texttt{./libvector.a},将匹配到的 U 中的符号转移到 D 并加入到 E 同时将未找到的符号加入 U。 \\
最后搜索标准库 \texttt{libc.a},处理完\texttt{libc.a}U一定是空的D中符号唯一否则错误。
\subsection{重定位}
PC相对地址下重定位值计算公式\\
\texttt{ADDR(r.symble)-((ADDR(.text)+r.offset)-r.addend)}\\
在asm中表示为 \texttt{4004de: e8 \underbar{05 00 00 00} \quad callq 4004e8 <sum>}
\pagebreak
\end{document}

15
复习资料/missfont.log Normal file
View file

@ -0,0 +1,15 @@
mktextfm font
mktextfm font
mktextfm font
mktextfm font/BI
mktextfm font
mktextfm font/B
mktextfm font
mktextfm font/I
mktextfm font
mktextfm font
mktextfm font
mktextfm
mktextfm
mktextfm
mktextfm