This commit is contained in:
Kagura 2024-07-01 21:13:39 +08:00
parent 5fbcb06991
commit cdfdf3fea7
3 changed files with 84 additions and 51 deletions

View file

@ -10,8 +10,9 @@
\@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 {subsubsection}{\numberline {1.5.2}非规格化数 $\text {exp} = 0$}{2}{subsubsection.1.5.2}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.3}特殊值 $\text {exp} = 11 \dots 1$}{2}{subsubsection.1.5.3}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.5.4}舍入(到偶数)}{2}{subsubsection.1.5.4}\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 }

Binary file not shown.

View file

@ -37,7 +37,8 @@
\lstset{basicstyle=\ttfamily,columns=fullflexible}
\columnseprule=0.4pt
\setlength{\columnsep}{1cm}
\setlength{\columnseprule}{0.4pt}
\begin{document}
@ -70,45 +71,45 @@ T: 用 $n$ 位表示数字
\begin{multicols}{2}
\qquad 对应正数补码的“各位取反、末位加1”
\begin{align*}
+23 & = 00010111 \\
\text{按位取反} & = 11101000 \\
& + \hspace{1.8cm} 1 \\
-23_{\text{补码}} & = 11101001
+23 & = \texttt{00010111} \\
\text{按位取反} & = \texttt{11101000} \\
& + \hspace{0.3em}\phantom{0000000}\texttt{1} \\
-23_{\text{补码}} & = \texttt{11101001}
\end{align*}
\columnbreak
\qquad 模($2^n$)减去该负数的绝对值
\begin{align*}
100000000 & \\
-00010111 & \\
\rule{2.5cm}{0.02em} \\
11101001
& \texttt{100000000} \\
- \hspace{0.5em} & \phantom{\texttt{0}}\texttt{00010111} \\[-1em]
& \hspace{-1em}\rule{2.5cm}{0.02em} \\[-0.5em]
& \phantom{\texttt{0}}\texttt{11101001}
\end{align*}
\end{multicols}
\subsection{GDB查看数据}
\texttt{>(gdb) x/4xb} \\[1em]
\begin{minipage}{12cm}
\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
\texttt{b} - byte (8-bit value) \\
\texttt{h} - halfword (16-bit value) \\
\texttt{w} - word (32-bit value) \\
\texttt{g} - giant word (64-bit value) \\
\texttt{o} - octal \\
\texttt{x} - hexadecimal \\
\texttt{d} - decimal \\
\texttt{u} - unsigned decimal \\
\texttt{t} - binary \\
\texttt{f} - floating point \\
\texttt{a} - address \\
\texttt{c} - char \\
\texttt{s} - string \\
\texttt{i} - instruction
\end{multicols}
\end{minipage}
\newpage
@ -127,12 +128,14 @@ i - instruction
浮点数表示为 $(-1)^s \cdot M \cdot 2^E$
\InsertBoxR{1}{\tcboxmath{\begin{matrix}
\InsertBoxR{0}{\tcboxmath{\begin{matrix}
\multicolumn{2}{c}{\text{偏置值 Bias}} \\
\texttt{float} & 127 \\
\texttt{double} & 1023 \\
\end{matrix}}\hspace{3cm}}
\vspace{-1em}
\subsubsection{规格化数 $ \text{exp} \ne 0$$\text{exp} \ne 11 \dots 1$}
$\text{(unsigned)} \ \text{exp} \ = \ E \ + \text{Bias}$
@ -161,37 +164,69 @@ $\text{Bias (偏置值)} = 2^{k-1}-1$ , k 为 $exp$ 的二进制位数
\end{matrix}\)
\columnbreak
例2:二进制浮点数$\rightarrow$十进制数\\
无符号数4位阶码(Bias=7)3个小数位
\begin{align*}
1001 \quad 111 \\
exp \quad frac \\
\text{计算E:} \\
E &= exp - Bias \\
例2: 二进制浮点数$\rightarrow$十进制数
无符号数4位阶码(Bias\(=7\))3个小数位 \\
\quad \(\begin{matrix}
1001 & 111 \\
\text{exp} & \text{frac}
\end{matrix}\) \\[0.5em]
\(\begin{aligned}
\text{计算} \space E &= \text{exp} - \text{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*}
&= 2_{10}
\end{aligned}\) \\[0.5em]
计算 \(M = 1.\underbar{frac} = 1.\underbar{111}\) \\[0.5em]
化为十进制:
\(\begin{aligned}
1.111 \times 2^2 & = 111.1_2 \quad \text{小数点右移2位} \\
& = \frac{15}{2} = 7.5
\end{aligned}\)
\end{multicols}
\InsertBoxR{1}{\tcboxmath{\begin{matrix}
\InsertBoxR{0}{\tcboxmath{\begin{matrix}
\text{非规格化数} \ E = 1 - \text{Bias} \\
\begin{matrix}
\texttt{float} & -126 \\
\texttt{double} & -1022 \\
\end{matrix}
\end{matrix}}\hspace{2cm}}
\end{matrix}}
\hspace{2cm}}
\vspace{-5mm}
\subsubsection{非规格化数 $\text{exp} = 0 $}
\vspace{-0.3em}
\subsubsection{非规格化数 $\text{exp} = 0$}
frac \(= 00\dots0\) 表示 0
frac \(\ne 00\dots0\) 表示接近 0 的小数 $(-1)^s \cdot M \cdot 2^{E}$
\vspace{-0.3em}
\subsubsection{特殊值 $\text{exp} = 11 \dots 1$}
\begin{multicols}{2}
frac \(= 00\dots0\) 表示 \(\infty\)
frac \(\ne 00\dots0\) 表示 NaN
\columnbreak
\(1.0 / 0.0 = 1.0 / 0.0 = + \infty\)
\(1.0 / 0.0 = - \infty\)
\(\sqrt{1.0} = \infty - \infty = \infty \times 0 = \text{NaN}\)
\end{multicols}
\subsubsection{舍入(到偶数)}
\begin{table}[h]
@ -276,7 +311,4 @@ D 当前所有定义符号的集合\\
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}