文字稿 · CC BY 4.0

计算机如何运作:从硅和 NAND 门到 RAM 和应用

本页标题、字幕、摘要和阅读笔记为已保存的 AI 译文,可能有误。时间戳与来源一致,可展开查看原始字幕,并对照原视频核对。

从底层出发,全面了解计算机如何运作,追溯硅晶体管和通用 NAND 门如何经由寄存器、缓存、基于电容的 RAM 和现代应用发挥作用。

Improbable Matter · 发布于 · 43 分钟 · 英语 · 许可证:CC BY 4.0 · 来源:在 YouTube 上观看

文字稿来源:创作者上传至 YouTube 的字幕。AI 标点由 Vidleaf 添加;原始措辞和时间戳锚点均保留。原始文字稿见下方。

AI 生成的摘要

本视频刻意简化地从零开始概述计算机的工作原理,每一节都以总结收尾,并在描述中链接了进一步解释;演讲者指出,大概没有人了解计算机如何构建和运行的每一个细节,而贝多芬第5交响曲的音效提示贯穿全片都存在大量过度简化。视频从电池—开关—灯泡电路和二进制开/关电压讲起,将 MOSFET 介绍为电压控制开关(N 沟道在高栅极电压下导通,P 沟道相反),并将它们配对为 CMOS 以产生反相输出,据称这构成了所有现代处理器的基础。从掺杂硅制造、光刻、沉积和蚀刻,在 P 掺杂晶片上构建数十亿个晶体管。讲解了布尔代数和门电路(NOT、OR、AND、XOR、NAND),其中 NAND 被描述为通用门;门电路实现二进制算术、位移、相等检查和通过 D 锁存器和寄存器实现的存储,并由时钟同步。视频随后涵盖内存层次结构(寄存器、缓存、RAM、硬盘)、32 位与 64 位地址、将指令存储为二进制数的冯·诺依曼架构,以及使循环和条件分支成为可能从而实现图灵完备的跳转指令。还描述了高级语言和编译器、共享库、LED 显示器和像素、Bresenham 画线、通过声卡发声,以及键盘和鼠标输入。

根据文字稿生成。请对照原始视频核查所链接的段落。

带时间戳的章节摘要

计算机如何工作:从零开始的概述

概述的范围与方法

  • [0:10] 本视频旨在从零开始广泛概述计算机的工作原理,在尽量保持简单的同时涉及一定的技术内容。
  • [0:22] 每一节都以总结收尾,进一步解释的链接在描述中。
  • [0:32] 演讲者指出,大概没有人了解计算机如何构建和运行的每一个细节。
  • [0:37] 贝多芬第5交响曲的音效提示表明正在做出大量过度简化,这一警告适用于整个视频。

作为电压控制开关的晶体管

基本电路与二进制电压状态

  • [1:04] 一个简单的电路可以由电池通过开关和灯泡连接回电池负极组成。
  • [1:13] 现代计算机组件通常在正极与地或负极之间提供 3.3 或 5 伏电压。
  • [1:24] 计算机根据电压是高还是低,将信息视为二进制——开或关、真或假、一或零。

按钮开关:接通与断开

  • [1:35] 示例电路中的关键组件是按钮开关,它有两种类型。
  • [1:37] 按下按钮式开关时,它会接通两个端子之间的电路,从而点亮灯泡。
  • [1:43] 按钮式断开开关的作用则正好相反。

MOSFET 的端子与沟道类型

  • [1:48] 图中所示的晶体管符号具体表示金属氧化物半导体场效应晶体管,即 MOSFET。
  • [1:56] MOSFET 的源极和漏极相当于开关的两个端子,但它还有第三个端子,称为栅极。
  • [2:05] N 沟道类型在栅极施加高电压时接通电路,如同按钮式接通开关;而 P 沟道类型在施加高电压时断开电路,如同按钮式断开开关。
  • [2:19] 因此,晶体管的作用类似于开关,只不过是通过施加电压而非由人按下。

CMOS 对与反相电路

  • [2:24] 现代计算机将这些晶体管成对使用,称为 CMOS(互补金属氧化物半导体),一对晶体管的栅极端子始终连接在一起以接收相同的输入。
  • [2:39] 当输入端为高电压或 1 时,N 沟道 MOSFET 在高电压与输出之间打开通路,而 P 沟道则关闭通往地的通路。
  • [2:52] 当输入端为低电压或 0 时,P 沟道打开通往地的通路。
  • [2:58] 第一种配置看似毫无意义,因为输出与输入相同,但将两个 MOSFET 互换后,高输入会打开通往低电压或 0 的通路,而 0 输入则在输出端产生 1。
  • [3:17] 无论输入端输入什么,输出端都会出现相反的结果,据说这构成了所有现代处理器的基础。

CMOS 晶体管与芯片的制造方式

通过掺杂硅形成 P 型和 N 型区域

  • [3:40] 硅是一种具有四个价电子的半导体,可与其他元素进行掺杂或混合。
  • [3:47] 镓有三个价电子,比硅少一个,使该区域更偏正电,即 P 型。
  • [3:54] 砷有五个价电子,比硅多一个,增加负电荷,使该区域成为 N 型。
  • [4:03] 这些掺杂剂的痕量,通常约为每百万个硅原子一个,通过化学扩散或从粒子加速器中轰击注入。

场效应晶体管与 MOSFET 结构

  • [4:14] 晶体管通过将一种掺杂剂的区域夹在另一种掺杂剂的两个区域之间制成,其中 N 沟道配置被更仔细地研究。
  • [4:22] N 沟道配置本身不导电,但施加的电场会形成导电沟道,因此得名场效应晶体管。
  • [4:31] 这可以理解为电场将电子从有盈余的 N 掺杂区吸引到有缺额的 P 掺杂区。
  • [4:44] 半导体叠层附近的导电端子在高电压下形成电场,使晶体管导通,但需要绝缘层来防止短路。
  • [4:53] 接触层是金属,绝缘层是氧化硅,掺杂半导体补全了整个叠层,因此称为 MOSFET。

光刻:在晶片上沉积与刻蚀

  • [5:03] 一台计算机需要数百万个相互连接的 CMOS 对,它们要小而紧密地靠在一起,以便电信号在它们之间快速传输。
  • [5:13] 处理器制造通常从一块称为晶片的 P 掺杂硅固体块开始,在其上通过光刻(意为“在石头上书写”)来制造晶体管。
  • [5:29] 沉积在整个晶片上化学地构建一层厚度受控且预先确定的层,例如在 P 掺杂晶片上涂覆 N 掺杂硅。
  • [5:43] 刻蚀通过向晶片顶部施加化学品或热等离子体来去除不需要的表面材料,多个步骤确保材料被选择性地去除。

光刻胶掩模与选择性刻蚀

  • [6:02] 一种称为光刻胶的化学品被沉积到晶片上,光线透过掩模照射以曝光预定区域。
  • [6:12] 曝光区域必须等于或大于所用光的波长,因此光刻使用波长极短的紫外光。
  • [6:23] 一种刻蚀方法只去除光刻胶的曝光区域,打开缺口,然后另一种刻蚀方法针对除未曝光光刻胶之外的所有部分。
  • [6:39] 最后剩余的的光刻胶被刻蚀掉,因此掩模上有缺口的地方材料都已被去除。

同时构建并连接所有晶体管

  • [6:48] 沉积与刻蚀结合使用,意味着晶片上所有晶体管的 N 型掺杂剂可以同时添加。
  • [6:58] 然后沉积并刻蚀氧化硅,最后沉积并刻蚀金属,在晶片顶部留下金属通道。
  • [7:06] 这些金属结构不仅构成晶体管的导电端子,还构成相当于导线的走线,按需连接各晶体管。
  • [7:16] 每个循环都沉积光刻胶、透过掩模曝光、打开缺口并刻蚀晶片,通过这种方法,数十亿个晶体管被组装并连接在一起。

计算机如何表示和处理信息

通过电压状态进行二进制表示

  • [7:40] 计算机以“一”和“零”来处理信息,这对应于电路中的高电压或低电压。

作为互补开关的晶体管

  • [7:48] 晶体管充当电子开关,在两种电压状态之间切换。
  • [7:52] 晶体管总是成对互补出现,因此当一对中的一半导通时,另一半就截止。

用于构建晶体管电路的光刻技术

  • [7:58] 光刻是一种工艺,通过它可以在硅块上构建出大量相互连接的晶体管。

布尔逻辑门与 CMOS 实现

布尔代数与单输入门

  • [8:10] 布尔代数是数学逻辑的一个分支,它解释了晶体管网络为何有用,这里用轻松的例子加以说明。
  • [8:28] 在餐厅的例子中,上汉堡时 Alice 就高兴,而不上汉堡时 Bob 就高兴。
  • [8:36] 逻辑门接收一个二进制输入(真或假、1 或 0)并返回一个二进制输出;这里的输入是是否上汉堡,输出是某人是否高兴。
  • [8:54] Alice 的门只是输出与输入相同的值,在电子学上这只是一条连线,而 Bob 的门是非门,用其常用符号表示。

多输入门:或门、与门和异或门

  • [9:14] 逻辑门可以有多个输入,它们的名称也很直白。
  • [9:22] 以披萨和面条为选项,只要至少上其中一种或两种都上,Alice 就高兴,这就是或门。
  • [9:35] Bob 希望菜单上披萨和面条都有,这就是与门。
  • [9:42] 如果上披萨或面条但不同时上,Charlie 就高兴,因为她认为不够专精的餐厅做不好;这就是异或门。

互补门与与非门行为

  • [9:53] 每个门都有一个互补版本,本质上是在同一个门后接一个非门,用输出端带圆圈的常用符号表示。
  • [10:01] 与非门在所有输入均为 0 时输出 1,否则输出 1。
  • [10:12] 对于计算机而言,这些门以及所有其他可能的门都必须通过 CMOS 对来实现。

CMOS 与非门的构建与通用性

  • [10:18] 如图所示将两对 CMOS 连接起来便构成一个与非门,其中 N 沟道和 P 沟道晶体管仍成对工作。
  • [10:26] 只有当两对输入端都施加高电压或 1 时,通往高电压的路径才会闭合、通往地的路径才会打开,输出 0,这正是与非门的行为。
  • [10:40] 与非门是通用门:只要有足够多的与非门,就能构造出任何其他门,不过某些门有更高效的实现方式。
  • [10:48] 本质上,这意味着通过 CMOS 对实现逻辑门的问题已经解决。

具有两个以上输入的门

  • [10:56] 门可以有三个、四个或任意多个输入。
  • [11:00] 例如,如图所示将两个与门连接起来,就简单地成为一个三输入与门,依此类推。

逻辑门与 CMOS 实现

逻辑门的定义

  • [11:10] 逻辑门是概念性的数学对象,允许基于二值真或假命题进行推理。
  • [11:18] 例如,如果“今天是星期六或今天是星期日”为真,那么“今天是周末”也为真。

用 CMOS 对进行实际实现

  • [11:24] 上一节中的 CMOS 对可用于在电子二值逻辑层面实际实现这些门。

计算机中的二进制算术与逻辑门

2 进制表示与位轨道

  • [11:39] 计算机处理数字,并使用逻辑门网络来执行算术运算。
  • [11:46] 10 进制使用数字 0–9 表示 10 的幂的倍数(1、10、100、1000),而现代计算机使用 2 进制,用数字 0 和 1 表示 2 的幂(1、2、4、8)。
  • [12:10] 在 10 进制中,953 等于 9×100 + 5×10 + 3×1;在二进制中,101 等于 1×4 + 0×2 + 1×1,即 10 进制中的 5,并且任何 10 进制数都能用 2 进制表示,反之亦然。
  • [12:28] 二进制数 101 可以用三条电压为开、关、开的电气轨道表示;每条轨道承载一位,因此三条轨道构成一个 3 位数,4 位数和 8 位数的定义类似。
  • [12:48] 4 位数 0101 等价于 3 位数 101。

用异或门和与门相加 1 位数

  • [12:56] 将 1 位数 A 和 B 相加得到 0+0=0 和 0+1=1,而 1+1 需要写 0 并进位 1,正如 10 进制中 5+5 那样。
  • [13:18] 为了存储 A 和 B 所有可能取值的结果,C 必须是一个 2 位数字。
  • [13:26] 当 A 或 B 中仅有一个为 1 时,C 的右位为 1,这正是异或门的行为;而只有当 A 和 B 都为 1 时,左位才为 1,这正是与门的行为。
  • [13:51] 相加超过 1 位的数字更为复杂,因为需要三输入门来处理来自 A 的一位、来自 B 的一位以及进位位;与非门是通用门,因此只要有足够多的与非门,就能实现任何所需的门网络。

通过位移实现二进制乘法

  • [14:20] 在 2 进制中,乘以 10(二进制)或 2(10 进制)只需在末尾添加一个 0,因此在二进制中乘以 10、100 或 1000 会将每一位左移并在末尾追加一个 0,这称为位移。
  • [14:44] 在二进制中乘以任意数字(例如 11)等同于分别乘以 10 和 1 再将两者相加。
  • [14:53] 将 A 与任意 B 进行二进制乘法的方法是:从零开始,如果 B 的最右位为 1 则加上 A,然后将 A 位移一次,如果 B 的下一位为 1 则将其加到总数中,对 B 的每一位继续此过程。

使用同或门和与门进行相等比较

  • [15:11] 计算机依赖比较操作,例如 A 是否等于 B 或 A 是否大于 B,比如将存储为二进制 A 的当前时间(秒)与存储为 B 的闹钟时间进行比较。
  • [15:30] 为了检查相等性,计算机必须验证 A 的每一位都与 B 的对应位匹配;异或门在其输入不同时返回 1,而同或门(其补门)在其输入相同时返回 1。
  • [15:50] 对 A 和 B 的每一对位应用同或门可以指示这些位是否相等,而对同或门的输出应用与门则返回一个单比特,当且仅当 A 等于 B 时该比特为 1。

其他运算与数字范围

  • [16:08] 减法、除法和其他比较也可以用门网络实现;例如,向另一方向位移会将数字除以二,而这些都是使用蚀刻在芯片上的晶体管实现的。
  • [16:20] 在本视频中,“数字”指的是整数或完整数;分数可以以科学记数法的二进制版本存储,称为浮点数,其一般原理仍然适用,但其具体运作方式不在本视频讨论范围内。
  • [16:36] 总之,计算机使用二进制开/关电信号序列来表示 2 进制的数字,而不是人们日常使用的 10 进制;逻辑门网络可以对二进制数进行加法、减法和比较,再增加几个步骤即可实现乘法和除法。

电路除法与组合

除法电路

  • [16:53] 讲者指出,这些项目也应被划分。

电路的组成

  • [17:00] 讲者指出,由某些元件组成的电路已经过研究。

位、字节与有符号数表示

商用计算机中的固定位宽

  • [17:01] 晶体管可以对任意二进制位或比特的数实现加法及其他代数运算。
  • [17:09] 构建计算机需要精确选择用多少条电轨和多少个门来表示一个数,类似于一张印有固定数量方框、用于填写年龄的表格。
  • [17:22] 对于商用计算机,这个数始终是 8 的倍数,而 8 位被称为一个字节。
  • [17:27] 加法器电路以 1 字节(8 位)、2 字节(16 位)或 4 字节(32 位)的数作为输入。

符号位约定

  • [17:40] 无论一个数由多少字节组成,都可以留出其中一位来表示正号或负号。
  • [17:47] 当一个数以这种方式带符号时,首位为 0 表示该数为正,首位为 1 表示该数为负。

存储输入与输出

  • [17:55] 就像数学考试一样,保存你的解题过程很重要。
  • [18:00] 无论计算机执行哪种操作,输入和输出都必须以某种方式存储起来。

锁存器、寄存器与时钟同步

锁存器电路与数据存储

  • [18:06] 锁存器是一种电路,一旦锁存,就会长时间保持该状态,因此可以存储一位数据;8 个锁存器可存储一个字节。
  • [18:18] 由与非门构成的 D 锁存器,其输出会反馈到一个输入端,这种互连使门网络能够保持并维持其 0 或 1 的输出值。
  • [18:44] 除非 E 或使能输入为 1,否则不会发生任何变化;当使能为 1 时,施加到 D 上的任何位都会传播到输出。

加法电路中的寄存器

  • [18:55] 计算机执行加法等操作,使能锁存电路以存储输出,然后再次关闭使能,从而在需要的时间内保持结果。
  • [19:07] 8 个锁存器可以构成一个寄存器,只要需要就能存储一个字节的数据。
  • [19:11] 加法电路会配备寄存器,在相加之前存储输入,并配备一个寄存器来捕获结果。

时钟周期与同步

  • [19:23] 由于电信号传播以及晶体管完成切换需要一些虽小但不可忽略的时间,所有计算机都配有时钟,以确保在读取结果之前操作已完全执行完毕。
  • [19:36] 振荡晶体以非常特定的速率切换电压的通断;在视频拍摄时,处理器的典型时钟速度为 2 吉赫兹,即每秒 2 亿次切换。
  • [19:55] 一次完整的加法至少需要 3 个时钟周期:第一个周期数字加载到输入寄存器,接下来加法电路进行运算,第三个周期输出寄存器收到使能信号并存储结果。
  • [20:18] 大多数操作所需的时间远不止一个甚至三个时钟周期,例如需要多个加法步骤的乘法,但时钟仍然在操作开始到输出就绪的整个过程中进行同步。

算术逻辑单元的位置

  • [20:38] 所有所谓的算术逻辑,即执行加法和减法的逻辑门阵列,在物理上都与处理器的其余部分位于同一处。

计算机中的内存与存储

处理器寄存器与缓存

  • [20:46] 芯片上的寄存器被称为处理器或中央处理器。
  • [20:51] 称为缓存的电路如今可以存储数十千字节的数据,作为计算的中间阶段。

RAM 电容存储

  • [21:01] 需要一种容量更大、更长期的方式来存储远超寄存器和缓存所能容纳的字节数。
  • [21:08] 计算机配有独立的随机存取存储器(RAM)物理芯片,利用电容来存储数据。
  • [21:16] 充电的电容具有高电压,值为 1,而放电的电容相对于地电压为 0 伏,值为 0。
  • [21:24] 电荷会随时间泄漏,但只要计算机通电,内存电路就会不断补充。

RAM 容量与寻址

  • [21:31] 典型的笔记本电脑拥有数十吉字节,即数十亿字节的 RAM。
  • [21:37] RAM 中的每个字节都有自己的二进制地址,就像公寓楼里的信箱一样。
  • [21:44] RAM 中的晶体管构成门网络,返回存储在处理器所发送地址处的字节。

32 位与 64 位地址

  • [21:56] 直到最近,计算机通常最多只有 4 GB 的内存,因此内存地址是 32 位数字。
  • [22:04] 32 位数字最大只能表示略多于 4 十亿,这在过去已经足够。
  • [22:10] 当内存变大后,地址实际上就不够用了,因此现在内存地址使用 64 位数字。
  • [22:17] 这就是 32 位与 64 位程序之间的区别。

硬币钱包示例与硬盘

  • [22:22] 在电子游戏中,游戏会记录钱包总额所存储的地址。
  • [22:31] 再找到八枚硬币后,游戏会从该地址取出钱包数值,将其与 8 的二进制数一起加载到寄存器中,相加后再把结果写回。
  • [22:50] 计算机还会在硬盘上存储海量数据,一存就是几十年。

计算机内存、存储与处理能力的限制

硬盘磁存储机制

  • [22:55] 硬盘表面布满了微小的磁畴,它们朝上或朝下以表示 1 或 0,即使断电也能保持。
  • [23:04] 当磁盘旋转时,传感头可以被动读取磁体的方向作为比特,也可以主动翻转磁畴来写入数据。
  • [23:15] 每个字节也都有自己独立的地址,而一台笔记本电脑或个人计算机可以在硬盘上存储数百 GB 的数据。
  • [23:23] 还存在闪存和 DVD 等其他技术,但此处不予讨论。

光速限制与内存权衡

  • [23:29] 运算速度的根本限制是光速,光在一个典型时钟周期内大约传播 15 厘米或半英尺,因此更大的计算机需要多个周期才能取到数据。
  • [23:43] 实际上,晶体管的开关速度要慢得多,而硬盘还需要时间旋转和扫描才能读取数据。
  • [23:54] 缓存容量小但访问速度快,内存能存储多得多的字节但读取时间更长,而硬盘耗时最长,却能几乎永久地存储大量数据。
  • [24:04] 因此,在数据获取速度与可存储容量之间存在着权衡。

简化的单一内存池模型

  • [24:09] 在视频的剩余部分中,计算机被解释为拥有一个可以即时读取的单一内存池,尽管现实情况要复杂得多。

时钟、字节、寄存器和地址概述

  • [24:26] 时钟用于同步操作,确保在开始下一个操作之前有足够的时间完成当前操作。
  • [24:36] 计算机以 8 位为一组来处理二进制数,这一组称为一个字节。
  • [24:41] 寄存器在计算过程中存储数字,而在其他时候,数字则存储在缓存、随机存取存储器和硬盘中。
  • [24:49] 内存中的每个字节都有自己唯一的地址,地址本身也是一个二进制数。

操作控制的需求

  • [25:02] 二进制运算和结果存储已经实现,但计算机仍需要一种方式来确定进一步的操作。

内存中的指令与程序执行

指令编码与冯·诺依曼架构

  • [25:09] 指令指定使用哪种操作以及何时执行,例如将两个数相加或复制一个数。
  • [25:16] 在冯·诺依曼架构中,指令以二进制数的形式与其他数据一起存储在内存中。
  • [25:25] 例如,基数为 10 的指令编号 16,或二进制中的某个给定字节,可能表示将两个 8 位数字相加并存储结果,而指令 17 可能对 16 位数字执行相同的操作。
  • [25:41] 当计算机遇到一条指令时,比较电路会接通所需操作的逻辑电路,例如当该字节等于 16 时接通加法电路。

通过字节顺序区分指令

  • [25:54] 像 16 这样的字节可能是一条加法指令,也可能是电子游戏中的金币数量,其区别取决于字节在内存中出现的精确顺序。
  • [26:05] 指令字节排在最前面,其后是它所需的内存地址,例如加法操作的两个输入地址和一个输出地址。
  • [26:22] 在现代 64 位系统中,地址长度为 8 字节,因此一条加法指令总共占 25 字节(一个指令字节加上 24 字节的地址),而一条复制指令总共占 17 字节。
  • [26:45] 每种指令类型总是占用固定数量的字节,下一条指令紧接在上一条指令之后。

顺序执行与错误的后果

  • [26:54] 遇到加法指令后,计算机执行该指令,并知道下一条指令正好在 25 字节之后。
  • [27:01] 计算机最初将内存起始处的字节编号 0 解释为一条指令,此后便从一条指令转到下一条指令。
  • [27:11] 如果出现错误,导致下一条指令不在它应在的位置,计算机很可能会崩溃。

执行加法和多字节操作

  • [27:20] 对于加法,第一个地址中的数字被加载到一个输入寄存器,第二个地址中的数字被加载到另一个输入寄存器,加法电路被启用,经过足够的时钟周期后,结果从输出寄存器写入所需的内存地址。
  • [27:38] 要相加两个 16 位数字,计算机读取数字 A 处的字节及其紧随其后的字节,对数字 B 和结果 C 也做同样的操作。

程序示例:游戏中的钱包金币

  • [27:54] 计算机程序是按顺序执行的一系列指令和地址的集合,计算机逐条执行指令来运行程序。
  • [28:13] 在一个游戏示例中,字节 0 是一条加法指令,后面跟着钱包总额地址、刚找到的金币数量,以及再次作为输出的钱包地址,覆盖钱包总额。
  • [28:26] 然后计算机将字节 25 解释为另一条加法指令,把出售物品获得的金币加到钱包中,而下一条指令位于再往后 25 个字节处的字节 49。
  • [28:51] 由于钱包总额被频繁使用,它很可能除了保存在内存中,还会长期保存在处理器的缓存中,而当玩家保存游戏时,它会被写入硬盘上的存档文件。

实现图灵完备的跳转和条件指令

图灵完备性与线性指令限制

  • [29:36] 目前看到的指令都是线性工作的——复制一个数字、将两个数字相加——因此程序总是产生相同的结果,最终到达内存末尾并停止。
  • [29:48] 还需要几条指令才能使计算机图灵完备,这意味着它最终能够执行任何可能的计算,例如加载网页或渲染视频游戏。
  • [30:01] 两台图灵完备计算机之间唯一的区别在于它们执行这些计算的速度。

跳转(转到)指令与循环

  • [30:07] 首先需要的指令是跳转,有时称为转到,其后跟一个内存地址。
  • [30:13] 程序不会直接执行内存中的下一条指令,而是跳转到指定的内存地址并执行那里的指令。
  • [30:24] 这使程序能够执行循环;在视频游戏示例中,将金币加到钱包总额并更新游戏世界和图形的指令之后跟着一条跳回开头的跳转指令,因此游戏可以无限期地持续运行。

分支(条件)指令

  • [30:48] 另一种关键指令类型是分支或条件指令:如果满足给定条件,例如两个数字相等,则跳转到特定地址。
  • [31:00] 比较可以用逻辑门来实现,加入这种逻辑就能让跳转变成有条件的,从而根据目前完成的计算或键盘、鼠标等输入来执行不同的指令集。
  • [31:17] 有了条件跳转,计算机就是图灵完备的:只要时间足够,它就能完成任何计算。

高级语言、编译器和函数

高级语言隐藏了底层细节

  • [31:41] 程序员通常使用高级编程语言,这类语言隐藏了指令和内存地址的细节,让程序员的工作更轻松。
  • [31:53] 在 C 或 C++ 中,像“如果 A 大于 B 就把 Q 设为 A,否则设为 B”这样的代码是人类可读的,并且最终让 Q 保存 A 和 B 中较大的那个。

编译器把代码翻译成指令

  • [32:18] 编译器接收这段代码,把它整理成正确的指令集,决定变量存放在内存中的位置、在哪里跳转,以及使用 16 位还是 32 位数字。
  • [32:30] 这个过程被称为编译代码。

函数和方法是可复用的代码

  • [32:39] 函数或方法的概念是程序员最重要的简化手段之一;平方根是一个数学例子,但函数也可以是任意的,比如用于获取电子邮件。
  • [32:55] 像平方根这样被反复使用的函数,其指令只需在内存中存储一次;被调用时,计算机跳转到函数所在位置,执行指令,然后带着结果跳回来。
  • [33:16] 函数和方法可以编译成库,让不同时间和地点的程序员共享有用的代码,就像 Windows 上的 DLL 文件那样。

程序中的跳转和循环

  • [33:36] 计算机有一条指令可以跳转到某个内存地址并执行那里的任何指令,这让程序内部可以实现循环。
  • [33:45] 有些跳转只在满足条件时才会发生。

计算机如何用 LED 和字节驱动显示器

跳转机器的计算通用性

  • [33:47] 任何能够进行这种跳转的计算机,只要有足够的内存和时间,就能执行任何计算。

LED 亮度由电压控制

  • [34:10] 灯泡对于显示器来说太大了,但发光二极管(LED)更小、更高效。
  • [34:18] LED 两端的电压越高,它就越亮。
  • [34:20] 显示器根据来自计算机的数据,以电子方式改变每个 LED 两端的电压,从而改变其亮度。

基于字节的亮度标度

  • [34:30] 由于计算机以字节(即 8 个比特为一组)来处理数字,亮度被合理地标定为从 0 到 255,即一个字节所能表示的最大值。

红、绿、蓝三色 LED

  • [34:42] 人眼具有对红光、绿光和蓝光敏感的细胞。
  • [34:46] 使用红、绿、蓝三个 LED 组成一组,并改变每个 LED 的相对亮度,就能产生各种颜色。

计算机如何渲染像素、图形和声音

像素颜色混合与显示内存大小

  • [34:51] 通过混合颜色,可以欺骗人眼感知到完整的光谱:红光和绿光混合产生黄色和棕色,红光和蓝光混合产生粉色,三种光都以最大亮度混合产生白色,而部分亮度混合则产生灰色。
  • [35:07] 由三种颜色组成的小点,无论采用何种技术,都称为像素,而显示器将像素按行和列排列,形成一个 2 维网格。
  • [35:19] 示例视频在最大分辨率下宽为 1920 像素、高为 1080 像素,而在内存中填满一个显示器需要宽度乘以高度再乘以 3 个字节。
  • [35:34] 简而言之,计算机必须每秒 30 次或 60 次更新内存中这么多字节,并将结果发送到显示器。

像素坐标映射到内存地址

  • [35:49] 尽管显示图形看起来纯粹是艺术性的,但对计算机而言,它不过是到目前为止所介绍的门逻辑和指令而已。
  • [36:00] 每个像素都有一个 x 坐标和一个 y 坐标,对应其在内存中的位置。
  • [36:08] 在宽度恰好为一千像素的显示器上,从左上角像素向前移动三千字节,就会越过第一行的末尾,落到第二行最左边的像素上。

用循环和算术绘制桌面元素

  • [36:25] 许多算法或冗长的指令列表通过算术运算和操作内存中的字节来绘制窗口、按钮、文本和计算机图形。
  • [36:37] 一个循环通过反复复制定义颜色的三字节序列,用背景色填充每个像素;任务栏通过遍历具有特定 y 坐标的行来绘制;开始按钮则是一个由 x 和 y 坐标定义、填充了另一种颜色的矩形。
  • [36:59] 文本则通过为每个字母复制预先确定的像素图案,或通过某种其他算法,叠加到最上层。
  • [37:06] 显示一个窗口需要它的宽度、高度以及左上角像素的位置;将左侧的 x 值与宽度相加即可得到最右侧边缘像素,如果用户移动或调整窗口大小,所有这些计算都会重新进行,窗口也会重绘。

通过简单指令绘制线条、三角形和 3D 形状

  • [37:29] 最简单的计算机图形是两点之间的一条线,每个点都有自己的 (x,y) 坐标,而 bresenham 算法通过沿着学校里数学课上学过的直线 x-y 曲线循环来绘制这样一条线。
  • [37:44] 三条线构成一个三角形,可以用纹理填充、用模拟光源照亮,并与成千上万个其他三角形组合成 3D 形状。
  • [37:53] 无论变得多么复杂,归根结底都是编译成函数的加法、乘法和跳转指令。

声音作为来自扬声器的压力波

  • [38:00] 声音是计算机的另一种主要输出形式,由扬声器和耳机产生的在空气中传播的高压和低压波组成。

扬声器和麦克风的工作原理

通过线圈和磁铁实现扬声器机制

  • [38:09] 声音是通过来回移动膜片产生的。
  • [38:11] 附着在膜片上的永磁体位于固定的导电线圈内。
  • [38:15] 通过线圈的振荡电流将磁铁拉入和推出,使膜片振荡并产生声音。

数字到模拟的声音生成

  • [38:20] 计算机将时间划分为短步长,并通过向声卡发送二进制数来指定每一步的电流。
  • [38:29] 电子器件将数字二进制值转换为相应的电流。

麦克风作为逆过程

  • [38:33] 麦克风的工作方式正好相反。

计算机如何处理键盘和鼠标输入

内存中的输入消息

  • [38:41] 计算机处理输入的方式通常相同:输入会在内存中留下消息,这些消息是预设长度的字节组,用于标识设备和输入内容。
  • [38:53] 消息队列可能保存三条各八字节的消息,分别解码为一次按键、一次向右移动 30 像素的鼠标移动以及一次 Shift 键释放。

键盘矩阵和按键消息

  • [39:10] 按键排列成网格,按下某个键时会在横向和纵向的行之间形成电接触,从而识别出具体是哪个键。
  • [39:19] 在键盘与主板之间,宣告按键按下或释放的消息会被转发到计算机内存,以便计算机据此作出响应。

游戏动作的条件跳转

  • [39:29] 在一个电子游戏示例中,“B”键用于买入,“S”键用于卖出,在 Windows 中分别对应十进制数 66 和 83。
  • [39:42] 游戏根据最后一次按键使用条件跳转:值为 66 时跳转到买入指令,值为 83 时跳转到卖出指令。

鼠标跟踪与按钮命中检测

  • [39:56] 鼠标在平面上跟踪左右和上下方向的移动,以及哪些按钮被按下。
  • [40:05] 通常由操作系统通过加上或减去从鼠标接收到的位置变化量,来跟踪鼠标的 x 和 y 像素坐标。
  • [40:17] 当在活动窗口中按下左键时,程序会检查光标的 x 坐标是否位于按钮的左右边界之间,再检查 y 坐标是否在垂直方向上位于按钮内部;若两者都成立,则认为该按钮被按下。
  • [40:43] 屏幕上有 10 个按钮时,程序会依次检查每个按钮是否被按下。

从像素和声音到分层计算

显示与声音在内存中的表示方式

  • [40:53] 计算机显示器是由像素组成的网格,每个像素由红、绿、蓝三盏灯构成,其亮度由计算机内存中对应的字节设定。
  • [41:05] 因此一个像素可以呈现任意颜色,而一组像素共同构成一幅图像。
  • [41:10] 声音通过测量声波的运动并将其以二进制数保存到内存中来记录,播放时则采用相反的过程。

输入与计算的分层抽象

  • [41:18] 外部设备向计算机发送消息,这些消息被放入内存,使计算机能够识别按键或鼠标移动等输入,并据此作出响应。
  • [41:31] 演讲者觉得不可思议:在硅中掺入杂质元素并执行相对简单的逻辑运算,竟能让人们观看和创作视频、处理信息,甚至栖身于虚拟世界。
  • [41:44] 计算将较简单的概念逐层构建为更复杂的概念:CMOS 对构成与非门,与非门构成任意逻辑门,逻辑门构成指令,指令将算法变为函数,函数再构建出任意复杂度的程序。

计算机是刻板、不直观的执行者

  • [42:03] 这也意味着计算机非常笨:它们没有直觉,必须严格遵循程序,而程序中每一个可能发生的情况都被极其详细地写明。

阅读带时间戳的可用字幕,或转录播客、讲座和本地音频/视频。免费YouTube转录提取器。

需要提取其他公开视频的 SRT、TXT 或 Markdown 字幕?前往 YouTube 字幕提取工具。

前 3 段双语对照预览 · 免消耗额度

以下展示前 3 段已保存中文译文与英文原版字幕的逐段对照(零额度消耗):

[0:00]

[音乐] 在本视频中,我将尝试从最基础层面广泛概述计算机是如何工作的。提供字幕。内容会稍微涉及一些技术细节,但我会尽量保持简单。每个部分末尾都会有总结,描述中也会提供进一步解释的链接。希望这个概述能让你学到新东西,或让你对事物有新的视角。

[Music] In this video I will try to give a broad overview of how a computer works from the ground up. Subtitles are available. It will get a little bit technical, but I will try to keep things as simple as possible. There will be a summary at the end of every section and links to further explanations in the description. Hopefully this overview will teach you something new or give you a new perspective on things.

[0:32]

世界上大概没有人知道计算机是如何构建和运行的每一个细节。这就是为什么当你听到这个声音[贝多芬第5交响曲]时,那是一个警告:我正在做大量过度简化,我相信你会在评论中指出这一点。[贝多芬第5交响曲] 那是针对整个视频的警告。[音乐] 现代计算机的核心是电路。

Probably nobody in the world knows every single nuance of how a computer is built and operates. This is why when you hear this sound [Beethoven's 5th symphony] that is a warning that I am making massive oversimplifications which I'm sure you'll point out to me in the comments. [Beethoven's 5th symphony] That was the warning for the entire video. [Music] Modern computers at their core are electrical circuits.

[1:04]

一个非常简单的电路可能由电池连接到开关,再连接到灯泡,然后回到电池的负极端子组成。现代计算机组件通常在正极端子与地或负极端子之间提供3.3伏或5伏电压——如果你愿意这样理解的话。计算机将信息视为二进制:开或关、真或假、一或零,取决于电压是高还是低。我们这里电路中的重要组件是按钮开关,它有两种类型。

A very simple circuit might consist of a battery connected to a switch, then a light bulb, then back to the negative terminal of the battery. Modern computer components typically supply a voltage of 3.3 or 5 volts between the positive terminal and the ground or negative terminal if you like to think of it that way. Computers treat information as binary: on or off, true or false, one or zero, based on if the voltage is high or low. The important component in our circuit here is the push switch which. comes in two flavors.

[0:00] [音乐] 在本视频中,我将尝试从最基础层面广泛概述计算机是如何工作的。提供字幕。内容会稍微涉及一些技术细节,但我会尽量保持简单。每个部分末尾都会有总结,描述中也会提供进一步解释的链接。希望这个概述能让你学到新东西,或让你对事物有新的视角。

[0:32] 世界上大概没有人知道计算机是如何构建和运行的每一个细节。这就是为什么当你听到这个声音[贝多芬第5交响曲]时,那是一个警告:我正在做大量过度简化,我相信你会在评论中指出这一点。[贝多芬第5交响曲] 那是针对整个视频的警告。[音乐] 现代计算机的核心是电路。

[1:04] 一个非常简单的电路可能由电池连接到开关,再连接到灯泡,然后回到电池的负极端子组成。现代计算机组件通常在正极端子与地或负极端子之间提供3.3伏或5伏电压——如果你愿意这样理解的话。计算机将信息视为二进制:开或关、真或假、一或零,取决于电压是高还是低。我们这里电路中的重要组件是按钮开关,它有两种类型。

[1:37] 按下即接通,也就是人按下时,两个端子之间的电路被接通,灯泡亮起。按下即断开开关则正好相反。这是晶体管的符号:更具体地说,是金属氧化物半导体场效应晶体管,即 MOSFET。它的源极和漏极就像开关的两个端子,但它还有第三个端子,称为栅极。和开关一样,它有两种类型:N 沟道型在向栅极施加高电压时接通电路,就像按下即接通。P 沟道型在施加高电压时断开电路,就像按下即断开。

[2:19] 因此,晶体管的作用就像开关,只不过不是由人按下,而是施加电压。在现代计算机中,这类晶体管成对使用,称为 CMOS,即互补金属氧化物半导体。一对晶体管的栅极端子总是连接在一起,因此它们接收相同的输入。这里有一个简单例子:如果我们向输入端施加高电压或1,N 沟道 MOSFET 会打开高电压与输出之间的通路。P 沟道则关闭到地的通路。

[2:52] 如果在输入端施加低电压或 0,P 沟道就会打开一条接地的通路。好,那么这个电路看起来毫无意义,我们在输出端得到的东西和输入端一样,但让我们把这两个 MOSFET 对调一下。现在,当我们在输入端施加高电压或 1 时,N 型会打开一条通往低电压或 0 的通路。当我们在输入端施加 0 时,输出端会得到 1。无论我们在输入端输入什么,输出端都会得到相反的结果。稍后我们会回过头来讲这如何构成所有现代处理器的基础。要明白,正是像这样庞大的 CMOS 对网络让计算机能够思考。

[3:33] [贝多芬第 5 交响曲] 现在,让我们从基本层面看看晶体管网络是如何构成的。硅是一种半导体,具有四个价电子,它会被掺杂,也就是与其他元素混合。例如,镓有三个价电子——比硅少一个,因此更偏正电或 P 型。与此同时,像砷这样的元素有五个价电子——比硅多一个,因此增加负电荷,也就是 N 型。

[4:03] 这些元素的痕量——通常大约每一百万个硅原子对应一个——通过化学扩散或从粒子加速器中射出进行注入。晶体管是通过将一种掺杂剂的区域夹在另外两种掺杂剂之间制成的。让我们更仔细地看看 N 沟道配置。它本身并不导电,但当对它施加电场时,会形成一个导电沟道,因此得名:场效应晶体管。可以简单地把它理解为电场将电子从有盈余的 N 掺杂区吸引到有亏缺的 P 掺杂区。

[4:40] 在半导体叠层附近,我们有一个导电的电气端子。当它处于高电压时,会形成电场,晶体管导通,但为了防止短路,我们需要在它们之间添加一层绝缘层。接触点是金属,绝缘体是氧化硅,最后我们还有掺杂半导体,因此得名 MOSFET。对于计算机,我们需要数百万个互连的 CMOS 对,而且它们必须又小又彼此靠近,以便电信号能在它们之间快速传输。

[5:13] 制造处理器通常从一块称为晶圆的P型掺杂硅固体块开始。然后通过称为光刻的工艺在晶圆上创建晶体管:即“在石头上书写”。光刻中主要使用两种技术。第一种是沉积:在整个晶圆上以化学方式构建一层厚度受控且预先确定好的层。这意味着,例如可以在P型掺杂晶圆的整个顶部涂覆N型掺杂硅。然后通过第二种称为蚀刻的技术去除不需要的表面材料。这是通过将化学品或热等离子体施加到晶圆顶部来完成的。需要采取若干步骤来确保蚀刻针对特定区域,从而选择性地去除材料。

[6:02] 一种称为光刻胶的化学品被沉积到晶圆上。光线透过掩模照射,使光刻胶的预定区域曝光。曝光区域必须等于或大于所用光的波长,因此光刻使用波长非常短的紫外光。使用特殊的蚀刻方法仅去除已曝光的光刻胶区域,而不去除其他任何东西。这在光刻胶中打开缺口,然后使用另一种蚀刻方法,针对除未曝光光刻胶之外的所有区域。

[6:39] 最后,剩余的光刻胶被蚀刻掉。结果,掩模中任何存在缺口的地方,材料都已被去除。沉积和蚀刻这两种技术结合使用,意味着晶圆上所有晶体管的N型掺杂剂可以同时添加。接下来,沉积并蚀刻氧化硅,最后沉积金属并将其蚀刻掉,在晶圆顶部留下金属通道。这些金属特征不仅构成晶体管的导电端子,还构成相当于电路中导线的走线,按需连接晶体管。

[7:16] 每一次,光刻胶被沉积,通过掩模曝光,形成间隙并蚀刻出一个晶粒。最终,数十亿个晶体管通过这种方法组装并连接在一起。可能有三个具有三种不同输入的 CMOS 对,然后输出到其他地方的四个不同的 CMOS 对,如此等等。[贝多芬的5交响曲] 总结一下:计算机以壹和零处理信息,此时电路中的电压要么是高要么是低。

[7:48] 晶体管充当电子开关,在这两种状态之间切换。晶体管总是以互补对的形式出现,因此当对中的一半导通时,另一半截止。光刻是在一块硅片上构建大量互连晶体管的过程。[音乐] 要理解晶体管网络为何有用,我们需要讨论数学逻辑的一个分支——布尔代数。

[8:18] 与其深入那些血淋淋的数学细节,不如用一些不太严肃的例子来说明基本概念。假设几个朋友正在挑选餐厅。爱丽丝在餐厅供应汉堡时开心。鲍勃在餐厅不供应汉堡时开心。在这种情况下,我们可以把评估餐厅看作一种叫做“门”的东西:一个接受二进制输入真或假、1 或 0,并返回二进制输出的对象。在这里,输入是餐厅是否有汉堡,输出是某人对餐厅是否满意。

[8:54] 对爱丽丝来说,这个门很简单:输出与输入相同。用电子术语来说,该电路只是一条连接。对鲍勃来说,这个门就是所谓的非门(NOT gate)。这是通常用来表示它的符号。在上一节中,我们已经看到这个 CMOS 对如何充当非门。让我们考虑一个更有趣的例子,即逻辑门可以有多个输入。正如我们将看到的,这类门的名字相当直白。现在朋友们正在挑选可能供应披萨、面条、两者都供应或两者都不供应的餐厅。爱丽丝在餐厅至少供应两种选择之一或两者都供应时开心。这个想法由所谓的或门(OR gate)表示。这是它的符号。

[9:35] 鲍勃想要选择,所以他希望菜单上既有披萨又有面条,因此是与门(AND gate)。查理喜欢餐厅供应披萨或面条但不同时供应两者:假设她认为如果餐厅不够专精,就做不好。对应的门称为异或门,简称 XOR。这些门各自也有一个互补门:基本上就是同一个门后面接一个非门。例如,与非门(NAND gate)在其所有输入都为 1 时输出 0,否则输出 1。

[10:08] 这些互补门在输出端用一个圆圈加上通常的符号来表示。对于计算机而言,这些门以及所有其他可能的门都必须通过 CMOS 对来实现。按如下方式连接两对晶体管即可构成一个与非门。N 沟道和 P 沟道晶体管仍然成对工作。只有当两对输入端都施加高电压或 1 时,通往高电压的路径才会关闭,通往地的路径才会打开,从而输出一个 0。这正是与非门的行为。

[10:40] 与非门之所以重要,是因为它被称为通用门:这意味着只要有足够多的与非门,任何其他门都可以由与非门构建出来。当然,制造某些门有更高效的方法,但本质上这意味着通过 CMOS 对实现逻辑门的问题已经解决。此外还有具有三个、四个或任意多个输入的门。例如,取两个与门按此处所示连接,它们就简单地变成了一个三输入与门,依此类推。[贝多芬《5交响曲》] 总结一下:逻辑门是概念性的数学对象,使我们能够基于二值的真或假陈述进行推理。

[11:18] 例如,如果“今天是星期六或今天是星期日”为真,那么“今天是周末”也为真。我们现在已经看到上一节中的 CMOS 对如何被用来以电子二值逻辑实际实现这些门。[音乐] 现在我们将看到计算机如何处理数字,并使用逻辑门网络进行算术运算。我们都习惯了 10 进制数字,这意味着有从 10 到 0 的 9 个数字。

[11:51] 这些数字表示 10 的幂的倍数,即 1、10、100、1000 等等。现代计算机使用 2 进制数字,只有 2 个数字:0 和 1。二进制数字是 2 的幂的倍数,即:1、2、4、8 等等。例如,在 10 进制中,数字 953 是 9 乘以 100 加上 5 乘以 10 加上 3 乘以 1。在二进制中,数字 1 0 1 是 1 乘以 4 加上 0 乘以 2 加上 1 乘以 1,也就是 5 进制中的 10。

[12:25] 10 进制中的任何数字都可以用 2 进制中的数字表示,反之亦然。要表示数字 1 0 1 3,按顺序排列的电气轨道将具有开、关、开、关的电压。每条这样的轨道携带一个二进制数字,即一个比特。有三条电气轨道时,这被称为 3 位数字。类似地还有 4 位数字、8 位数字等等。当然,4 位数字 0 1 0 1 等价于 3 位数字 1 0 1。

[12:56] 让我们考虑将一对 1 位数字 A 和 B 相加得到 C。0 + 0 = 0 0 + 1 = 1。当我们尝试在二进制中计算 1 + 1 时会发生什么?与我们在常规 10 进制中计算 5 + 5 时发生的情况相同。没有足够大的数字,因此我们在该列放置一个 0,并将 1 进位到下一列。因此,为了保证能够存储 A 和 B 任意可能值的结果,结果 C 必须是一个 2 位数字。右边的位在 A 或 B 为 1 时为 1,但不能同时为两者:如果你还记得上一节中的 Charlie,这就是 XOR 门的行为。

[13:35] 左边的位仅在 A 和 B 都为 1 时才为 1,因此是 AND 门。所以 C 是通过将 A 和 B 连接到这样的门来获得的。当相加大于 1 位的数字 A 和 B 时,由于现在有三个输入门——来自 A 的一位、来自 B 的一位以及一个进位位——情况变得更加复杂。正如我在上一节中所说:NAND 门是通用的,这意味着任何所需的门网络都可以用足够多的 NAND 门来实现。

[14:17] [贝多芬第 5 交响曲] 在 10 进制中,乘以 10 很简单:只需在你的数字末尾添加一个 0。在 2 进制中,乘以 10(二进制)或 2(10 进制)也是如此。因此,在二进制中乘以数字 10、100、1000 只需将每一位向左移动并在末尾放一个 0,这被难以想象地称为位移。那么乘以一个任意数字呢,比如二进制中的 11?

[14:48] 这等同于乘以 10、乘以 1 然后将两者相加。因此,将 A 乘以任意数字 B 的二进制乘法如下进行:从零开始。如果 B 的最右位为 1,则加上 A。将 A 位移一次,如果 B 的下一位为 1,则将其加到总数中。对 B 的每一位继续此过程。计算机还依赖于对数字进行比较,例如:A 等于 B 吗?A 大于 B 吗?

[15:18] 等等。计算机可能将当前时间以秒为单位存储为二进制数字 A,每秒更新一次,并将设置闹钟的时间存储为 B。当 A 等于 B 时,闹钟将被触发。为此,计算机必须检查数字 A 的每一位是否与 B 的对应位相同。因此,当 XOR 门的一个输入为 1 而另一个输入为 0 时,即当其输入不同时,它返回 1。XNOR 门是 XOR 的补门,意味着它返回与 XOR 相反的结果,因此当其输入相同时返回 1。将一堆 XNOR 门应用于 A 和 B 的每一对位,即可返回这些位是否相等。

[15:57] 当与门的全部输入均为 1 时,它会返回 1。因此,将其应用于 XNOR 门会返回单个比特,当且仅当 A 等于 B 时该比特为 1。此外,还有使用门网络实现减法、除法和其他比较的方法。例如,向另一方向进行位移会将一个数除以二。这些都是使用蚀刻在芯片上的晶体管实现的。请注意:在本视频中,我所说的“数”指的是整数或完整数。还有一种方法可以用科学记数法的二进制版本存储分数,称为浮点数或 float。

[16:32] 我不会深入讲解它们的工作原理,但这里概述的一般原理仍然适用。总结一下:计算机使用一系列二进制的开、关电信号来表示以 2 为基数的数,而不是人们日常使用的以 10 为基数的数。逻辑门网络可用于对二进制数进行加、减和比较,再经过一些额外步骤,还可以对它们进行乘法和除法。[音乐] 我们已经看到,由晶体管组成的电路如何用于对任意二进制位或比特的数实现加法和其他代数运算。

[17:09] 如果你想制造一台计算机,我们必须确切选择有多少条电轨和多少个门可用于表示一个数。这就像你填写表格时,表格上印有固定数量的方框供你填写年龄。对于商用计算机,这始终是 8 的倍数。8 位称为一个字节。计算机会有我在上一节中描述的那些类型的加法器电路等,它们接受 1 字节或 8 位数字、2 字节或 16 位数字、4 字节或 32 位数字作为输入。

[17:40] 无论一个数由多少字节组成,都可以留出其中一个比特来表示正号或负号。当一个数以这种方式带符号时,如果前导位为 0,则该数为正。如果前导位为 1,则该数为负。任何参加过数学考试的人都知道:保存你的解题过程很重要。无论计算机执行哪种操作,输入和输出都必须以某种方式存储。为此,需要使用一种称为锁存器的电路。

[18:10] 一旦它锁存,就会长时间保持该状态,因此可用于存储一位数据。8 个锁存器存储一个字节,依此类推。这是一个由与非门构成的所谓 D 锁存器的例子。你可能会注意到这看起来相当奇怪:之前我们看到的门电路都是严格按顺序排列的,一个门的输出直接连接到另一个门。现在,一个门的输出连接到另一个门的输入,但随后输出又直接返回。正是这种互连方式使得这个门网络能够保持并保留其输出值 0 或 1。

[18:44] 除非 E 或使能输入为 1,否则什么都不会改变。当使能为 1 时,施加到 D 上的任何位都会传播到输出。计算机会执行一个操作,例如加法,使一组锁存电路存储输出,然后再次关闭使能。结果将在所需的时间内保持在那里。8 个这样的锁存器可以组成寄存器,在需要时存储一个字节的数据。我们在上一节中看到的那种加法电路会有这样的寄存器,用于在加法发生之前存储输入,以及一个寄存器来捕获加法的结果。

[19:23] 电信号传播、晶体管完成切换等需要一些微小但显著的时间。为了保证在尝试读出答案之前操作已完全执行,所有计算机都有一个时钟。简单来说,一个振荡晶体以非常特定的速率开关电压,开开关关。在本视频制作时,计算机处理器的典型时钟速度为 2 吉赫兹,意味着时钟每秒开关 2 十亿次。

[19:55] 规律的切换使事件得以同步。要完全执行一次加法操作,至少需要 3 个时钟周期。在第一个时钟周期,数字会被加载到输入寄存器中,然后加法电路可以在下一个时钟周期工作。最后在第三个时钟周期,输出寄存器收到使能信号并存储结果。实际上,大多数操作执行所需的时间远超过一个甚至三个时钟周期。我们在上一节中已经看到,乘法需要几个加法步骤才能完成。

[20:30] 然而,无论需要一个还是上百个周期,时钟仍然用于同步操作的开始直到输出就绪。所有所谓的算术逻辑,即:所有执行加减法的逻辑门阵列,在物理上都与寄存器一起位于一个称为处理器或中央处理单元的芯片上。那里还有称为缓存的电路,如今可以存储数十千字节的数据,作为计算的中间阶段等。

[21:01] 需要一种更大、更长期的方式来存储比寄存器和缓存多得多的字节数据。计算机有独立的随机存取存储器或 RAM 物理芯片,利用电容器来存储这些数据。如果电容器充电,它具有高电压,因此值为 1。如果它放电,相对于地它就有 0 伏特,因此为 0。电荷会随时间泄漏或丢失,但只要计算机通电,内存电路就会补充它。

[21:31] 一台典型的笔记本电脑有数十千兆字节或数十亿字节的 RAM。存储在 RAM 中的每个字节都有自己的地址,就像公寓楼里的邮箱。地址本身就是一个二进制数。RAM 有许多晶体管构成门网络,确保当它从处理器接收到二进制格式的地址时,返回存储在该地址的字节。直到最近,计算机通常不会有超过 4 千兆字节的 RAM。每个字节都需要一个唯一地址,所以内存地址是 32 位数字。这样的 32 位数字最高可达略超过 4 十亿,所以过去是没问题的。

[22:10] 当 RAM 变得更大时,实际上地址就不够用了,所以现在内存地址使用 64 位数字。这就是 32 位和 64 位程序之间的区别。那么,假设你在玩一个电子游戏,钱包里有一些硬币。电子游戏会跟踪钱包总额存储的地址。如果你又找到了八个硬币,游戏会从该地址获取你钱包中当前的数字,将其加载到寄存器中,将一个对应于 10 进制中 8 的二进制数加载到另一个寄存器中,将它们相加,并将结果放回钱包总额的地址中。

[22:47] 我们将在下一节中更详细地探讨这一点。计算机还能将海量数据在硬盘上存储数十年之久,即使没有电源。硬盘表面布满了微小的磁畴,它们可以朝上或朝下,分别对应 1 或 0。当磁盘旋转时,传感头可以被动地读取磁体的方向作为比特,或主动翻转磁畴的方向以将数据写入磁盘。每个字节也都有自己独立的地址。

[23:19] 一台笔记本电脑或个人计算机可以在硬盘上存储数百吉字节。还有其他技术,如闪存、DVD 等,我在这里不再赘述。计算机执行操作速度的根本限制是光速,在一个典型的计算机时钟周期内,光大约可以行进 15 厘米或半英尺,因此对于比这更大的计算机来说,获取任何数据都需要多个周期。实际上,晶体管的切换速度要慢得多,而硬盘需要时间旋转起来并扫描以读取数据。就计算机内存的类型而言:缓存很小,但访问速度快;RAM 存储的字节数多得多,但读取时间更长;硬盘读取时间最长,但几乎可以永久存储大量数据;因此,在数据检索的速度和可存储的数据量之间存在权衡。在本视频接下来的部分中,我将把计算机解释为只有单一内存池,可以即时读取。实际上情况更复杂,

[24:20] 正如我刚才所描述的。[贝多芬第 5 交响曲]。总结一下:计算机有一个时钟,它同步正在执行的操作,并确保在开始另一个操作之前有足够的时间完成一个操作。计算机以 8 位为一组处理二进制数,称为一个字节。寄存器用于在计算过程中存储数字,其他时候数字存储在缓存、随机存取存储器和硬盘中。内存中的每个字节都有自己唯一的地址,该地址本身也是一个二进制数。

[24:56] [音乐] 我们有办法实现二进制运算并存储结果,但计算机需要一种方法来确定使用哪个操作以及何时使用。这称为指令。指令包括:将两个数字相加,以及复制这个数字。计算机使用所谓的冯·诺依曼架构,这意味着指令作为二进制数与其他数据一起存储在内存中。例如,指令编号 16 和基数 10,或者这个字节的二进制形式,可能意味着:将两个 8 位数字相加并存储结果。

[25:34] 指令编号 17 可能含义相同,但针对的是 16 位数字,以此类推。当计算机遇到一条指令时,它会使用我们在前面章节中介绍过的比较电路来接通执行所需运算的逻辑电路。如果该字节等于 16,就接通加法电路。计算机如何知道一个字节是不是指令呢?16 可能是加法指令,也可能是电子游戏中的金币数量。嗯,这一切都与字节在内存中出现的精确顺序有关。首先是指令字节。

[26:08] 如果指令是加法,计算机就需要被加数的两个内存地址以及存放结果的内存地址。请记住,内存就像一栋大型公寓楼里的信箱,每个字节都有一个唯一的地址。在现代 64 位系统中,地址长度为 8 字节。因此,整个加法指令包含一个指令字节和 24 字节的地址,总共 25 字节。另一方面,如果指令是复制一个数字,它只需要后面跟着源地址和目标地址,这意味着整个过程总共占用 17 字节。

[26:45] 诀窍在于,每种类型的指令总是占用固定数量的字节,而且关键在于,下一条指令紧接在上一条指令之后。因此,当计算机遇到加法指令时,它不仅会执行该指令,还知道下一条指令正好在 25 字节之后。一开始,计算机将编号为 0 的字节(即内存最开头的那个字节)解释为指令,此后便一条指令接一条指令地执行下去。反过来,如果出现了错误,下一条指令不在它应该在的位置,那就自认倒霉吧!计算机很可能会崩溃。计算机实际上是如何执行加法指令的呢?

[27:22] 来自第一个地址的数字被加载到一个输入寄存器中,第二个地址的数字被加载到另一个输入寄存器中。加法电路被启用并执行加法运算。然后,经过足够数量的时钟周期后,结果可以从输出寄存器写入内存中所需的地址。如果指令是将两个 16 位数字相加呢?计算机只需转到数字 A 的地址,不是只取一个字节,而是取该字节以及紧随其后的一个字节。数字 B 和结果 C 也是如此。[贝多芬第 5 交响曲] 计算机程序是按顺序执行的一系列指令(和地址)的集合。计算机从一条指令转到下一条指令来运行程序。让我们看一个具体的例子:游戏的一部分——毕竟游戏本身就是一个程序——其中玩家有一个装有硬币的钱包。

[28:10] 内存内容可能看起来是这样的。字节编号 0 是加法指令。然后是两个地址:钱包总额的地址和玩家刚找到的硬币数量。第三个地址又是钱包。加法之后,钱包总额将被覆盖。无论如何,计算机现在会将内存中编号为 25 的字节解释为一条指令。这是另一条加法指令。钱包的地址和玩家通过出售物品获得的硬币数量是输入。

[28:40] 钱包地址再次作为输出。下一条指令位于再往后 25 个字节处,即字节 49。程序继续执行,还需要数百万条其他指令才能使游戏正常运行。在这种情况下,钱包总额被频繁使用,因此它很可能除了保存在 RAM 中之外,还会长期保存在处理器的缓存中。当玩家保存游戏时,它将被写入计算机硬盘上的存档文件。总结一下:计算机将内存中的某些字节解释为执行何种操作的指令。

[29:15] 计算机程序存储在内存中。它们只是由指令、内存地址和数字组成的大型序列。计算机像钟表一样从一条指令转到下一条指令,始终根据当前指令的类型知道下一条指令在何处。[音乐] 到目前为止,我们看到的指令都是以线性方式工作的:复制一个数字、将两个数字相加等等。程序总是会产生相同的结果,最终它会到达内存的末尾并停止。

[29:48] 我们还需要几条指令,才能让计算机达到所谓的图灵完备。图灵完备意味着它最终能够执行任何可能的计算:加载网页、渲染电子游戏等等。两台图灵完备计算机之间的唯一区别,就是它们执行这些计算的速度。计算机需要的第一类指令叫做跳转,有时也叫转到。指令字节后面跟着一个内存地址。顾名思义,程序不会直接去执行内存中的下一条指令,而是跳转到指定的内存地址,并执行那里的指令。

[30:24] 这意味着程序现在可以执行循环了。在我们的电子游戏示例中,我们已经看到指令如何把金币数量加到钱包中保存的总数上。这些指令以及更新游戏世界、渲染图形等所需的所有其他指令,后面都会跟着一条跳转回起始位置的指令。这样游戏就可以无限期地持续运行。计算机需要的另一类关键指令是分支指令或条件指令。如果满足给定条件,例如两个数相等,就跳转到某个特定地址。

[31:00] 我们已经看到如何用逻辑门实现比较。加入这样的逻辑后,跳转就变成了条件跳转,从而可以根据此前执行的计算,或来自键盘、鼠标等计算机输入的信号,执行不同的指令集。有了条件跳转,计算机就是图灵完备的:只要时间足够,它就能完成任何计算。说到这里,值得提一下真实程序实际上可能是怎样编写的。如果你觉得到目前为止事情相当令人困惑,那你并没有错。要记住哪条指令做什么、哪个内存地址存了什么数据、跳转到哪里等等。

[31:38] 这些都很难跟踪。程序员通常使用所谓的高级编程语言来工作。这意味着指令和内存地址的所有细节都被隐藏起来,从而让程序员的工作更轻松。例如,这是一段 C 或 C++ 语言的代码。这段代码人类可以读懂。如果 A 大于 B,就把 Q 设为 A;否则,当 B 大于或等于 A 时,就把 Q 设为 B。换句话说,数字 Q 最终会是 A 或 B 中较大的那个数。

[32:14] 这对程序员以及任何试图阅读它的人来说都很容易理解。一个称为编译器的程序会接收这段代码,并将其整理成正确的指令集,安排好变量在内存中的存储位置、跳转位置、是否需要使用 16 位或 32 位数字等等。这就是所谓的编译代码。编程语言有许多方面可以简化程序员的工作,但其中最重要的之一是函数或方法的概念。在数学中,平方根就是一个函数,它接收一个数字并返回另一个数字。当然,计算机代码中有平方根函数的实现,但也有更随意的函数和方法,例如用于获取电子邮件等。

[32:55] 假设一个程序需要反复计算不同数字的平方根。构成平方根函数的指令只需在内存中存储一次。每当需要使用或调用该函数时,计算机会跳转到该函数在内存中的位置,执行指令,然后带着结果跳回程序中离开的位置。函数和方法可以编译成库,这样程序员们无论何时何地都能共享他们编写的有用代码。如果你在 Windows 上见过 DLL 文件,那就是这种东西。一旦一个函数或方法被高效地编写出来,其他程序员就可以使用它,而无需花费太多时间。

[33:34] [贝多芬第 5 交响曲] 总结一下:计算机有一条指令可以跳转到某个内存地址并执行那里的任何指令。这使得程序中的循环成为可能。有些跳转只在满足条件时才会发生。任何能够进行这种跳转的计算机,只要有足够的内存和时间,就能执行任何计算。[音乐] 你很可能正在某种显示器上观看这个视频。过去和现在有许多技术被用于计算机显示器,所以我将笼统地讲。

[34:10] 像视频开头那样的灯泡太大了,但发光二极管或 LED 更小、更高效。LED 两端的电压越高,它就越亮。显示器能够根据来自计算机的数据,以电子方式改变其每个 LED 两端的电压,从而改变它们的亮度。由于计算机以字节处理数字,换句话说就是 8 位一组,因此亮度按从 0 到 255 的刻度递增是合理的——这是字节能取的最大值。

[34:42] 人眼中有对红、绿、蓝光敏感的细胞。通过使用红、绿、蓝三种 LED,改变每种 LED 的相对亮度,就能欺骗人眼,使其感知到完整的光谱。红绿混合产生黄色和棕色。红蓝混合产生粉色。三种颜色全亮度混合产生白色,部分亮度混合产生灰色,以此类推。像这样由三种颜色组成的小点,无论采用什么技术,都称为像素。

[35:14] 显示器上的像素按行和列排列,形成 2 维网格。例如,这个视频在最大分辨率下宽度为 1920 像素,高度为 1080 像素。在内存中填满一个显示器所需的字节数是宽度乘以高度再乘以 3。简单来说,计算机必须每秒在内存中更新这么多字节 30 或 60 次,并将结果发送到显示器。因此,举例来说,如果你以最大分辨率全屏播放这个视频,每一帧在内存中就会占用这么多字节。

[35:49] 虽然显示图形和图像看起来像是一项纯粹的艺术工作,从某种意义上说也确实如此,但实际上对计算机而言,它不过是我们目前所见过的门逻辑和指令。每个像素都有一个水平或 x 坐标和一个垂直或 y 坐标,对应其在内存中的位置。例如,假设你的显示器宽度恰好是一千像素,你从左上角像素开始,如果在内存中向前移动三千字节,或相当于一千像素,你就会越过第一行的末尾,来到第二行最左边的像素。

[36:25] 有许多算法或长长的指令列表,用于绘制窗口、按钮、文本和计算机图形,全都通过这种算术运算和操作内存中的字节来实现。要显示一个简单的桌面环境,一个循环会通过反复复制唯一确定该颜色的三字节序列,用背景色填充每个像素。任务栏通过仅遍历具有特定 y 坐标的像素行来绘制。开始按钮则通过用另一种颜色填充给定 x 和 y 坐标范围内的矩形来创建。

[36:59] 文本是通过为每个字母复制预先确定的像素图案或通过某种其他算法叠加在上面的。要显示一个窗口,必须知道其具体的宽度和高度以及其左上角像素的当前位置。将左侧像素的 x 值与宽度进行简单的算术相加,即可得到最右侧边缘像素。然后就可以绘制标题栏,以及边框文本等等。如果用户移动窗口或调整其大小,所有这些算术都必须重新进行,并重新绘制窗口。

[37:29] 最简单的计算机图形涉及在两点之间绘制一条线,这两点各自都有一组坐标(x,y)。bresenham 算法包含一个循环,它通过沿着一条从学校数学中熟悉的直线 x-y 曲线来绘制这样一条线。画三条线就得到一个三角形,它可以填充纹理、被模拟光源照亮,并与成千上万个其他三角形组合成一个 3D 形状。无论多么复杂,归根结底都是编译成函数的加法、乘法和跳转指令。

[38:00] 声音是计算机的另一种主要输出形式。声音是在空气中传播的高压和低压波。扬声器和耳机通过来回移动膜片来产生声音。在固定的导电线圈内部,有一个永磁体附着在膜片上。通过线圈的振荡电流将磁体拉入和推出,使膜片振荡并产生声音。计算机将时间分解为短步骤,并通过向声卡发送二进制数来指定每个时间步骤的电流。电子器件将数字二进制值转换为适当的电流。

[38:33] 麦克风的工作方式正好相反。有许多输入设备,但计算机处理输入的方式通常是相同的。输入会在内存中留下所谓的消息,这些消息是预设长度的字节组,用于标识设备以及输入的确切内容。例如,一个消息队列可能有三条每条八字节的消息:解码后,第一条表明某个键已被按下;第二条表明鼠标向右移动了 30 个像素;第三条表明键盘上的 shift 键已被释放。

[39:10] 按键排列成网格。当按下某个键时,它会在水平行和垂直行之间形成电接触,从而可以识别出具体是哪个键。在键盘和计算机主板之间,按键按下或松开的消息会被转发到计算机内存,使计算机能够据此做出响应。在我们的电子游戏示例中,假设“B”键用于购买物品,“S”键用于出售。在 Windows 中,这些按键有对应的十进制数字。分别为 66 和 83。就指令而言,游戏会根据最后一次按键的值进行条件跳转。

[39:46] 如果按键值为 66,计算机就会跳转到与购买对应的一组指令;如果是 83,就会跳转到与出售对应的指令。计算机鼠标会跟踪它在平面上向左或向右、向上或向下移动了多远,以及按下了哪些按钮。程序(通常是计算机的操作系统)通过加上或减去从鼠标接收到的位置变化,来跟踪鼠标的 x 和 y 像素坐标。

[40:17] 假设当用户按下鼠标左键时,一个带有按钮的窗口当前处于活动状态,程序会将鼠标光标的 x 坐标与按钮的尺寸进行比较。如果 x 大于或等于按钮的左侧,且小于或等于按钮的右侧,那么点击在水平方向上位于按钮内部,程序随后再检查 y 坐标是否也在垂直方向上位于按钮内部。如果两者都为真,则认为按钮被按下。如果屏幕上任意时刻有 10 个按钮,程序会依次检查每个按钮是否被按下。

[40:51] [贝多芬第 5 交响曲] 总结一下:计算机显示器是由像素组成的网格。每个像素都是一组红光、绿光和蓝光。每种光的亮度由计算机内存中对应的一个字节设定。因此,一个像素具有任意颜色,一组像素组合在一起就构成图像。声音通过测量声波的运动并作为二进制数保存在内存中来录制。播放声音时则使用相反的过程。外部设备向计算机发送消息,这些消息被放入内存,使计算机能够识别输入,例如某个键被按下或鼠标被移动,然后据此采取行动。

[41:29] 最后,我想对整个视频做个总结。我认为这很了不起:通过向硅中掺杂杂质元素并执行相对简单的逻辑运算,我们就能观看和制作视频、处理信息,甚至栖身于虚拟世界。计算的核心就是通过构建更简单的概念来实现更复杂的概念。如果你有 CMOS 对,你就能做出与非门;如果你有与非门,你就能做出任何逻辑门;如果你有逻辑门,你就能做出指令;如果你有指令,你就能把算法变成函数;从函数出发,你就能构建出任意复杂的程序。

[42:03] 这也意味着计算机非常笨:它们没有直觉,必须严格遵循程序,而程序中每一个可能发生的情况都被极其详细地写明。

查看英文原始字幕

[0:00] [Music] In this video I will try to give a broad overview of how a computer works from the ground up. Subtitles are available. It will get a little bit technical, but I will try to keep things as simple as possible. There will be a summary at the end of every section and links to further explanations in the description. Hopefully this overview will teach you something new or give you a new perspective on things.

[0:32] Probably nobody in the world knows every single nuance of how a computer is built and operates. This is why when you hear this sound [Beethoven's 5th symphony] that is a warning that I am making massive oversimplifications which I'm sure you'll point out to me in the comments. [Beethoven's 5th symphony] That was the warning for the entire video. [Music] Modern computers at their core are electrical circuits.

[1:04] A very simple circuit might consist of a battery connected to a switch, then a light bulb, then back to the negative terminal of the battery. Modern computer components typically supply a voltage of 3.3 or 5 volts between the positive terminal and the ground or negative terminal if you like to think of it that way. Computers treat information as binary: on or off, true or false, one or zero, based on if the voltage is high or low. The important component in our circuit here is the push switch which comes in two flavors.

[1:37] push to make that's when a person presses down and the circuit is completed between the two terminals and the bulb lights up. The push to break switch is exactly the opposite. This is the symbol for a transistor: more specifically, it's a Metal Oxide Semiconductor Field Effect Transistor or MOSFET. Its source and drain are like the two terminals of a switch, but it has a third terminal called a gate. just like switches there are two types: the N-channel type makes a circuit when a high voltage is applied to the gate, like a push to make. The P-channel breaks the circuit when a high voltage is applied like a push to break.

[2:19] So, transistors act like switches except instead of a person pressing it down a voltage is applied. In modern computers, these types of transistors are used in pairs referred to as CMOS or Complementary Metal Oxide Semiconductor. The gate terminals of a given pair are always connected together so they receive the same input. Here is a simple example: if we apply a high voltage or 1 to the input the N-channel MOSFET opens a route between high voltage and the output. The P-channel closes the root to ground.

[2:52] If we apply a low voltage or 0 at the input the P-channel opens a path to ground. OK, so this circuit seems pointless we got the same thing at the output as we did at the input, but let's swap around the two MOSFETs. Now, when we apply a high voltage or 1 to the input the N-type opens a route to low voltage or 0. When we apply a 0 to the input we get a 1 at the output. Whatever we put in at the input, we get the opposite at the output. Later we will come back to how this forms the basis of all modern processors. Understand that it is vast networks of CMOS pairs like these which allow computers to think.

[3:33] [Beethoven's 5th symphony] For now, let's see how transistor networks are made in basic terms. Silicon is a semiconductor with four valence electrons which is doped, or mixed with, other elements. Gallium, for example, has three valence electrons - one less than silicon, hence more positive or P-type. Meanwhile, an element like arsenic has five valence electrons - one more than silicon, therefore adding a negative charge, hence N-type.

[4:03] Trace amounts of these elements typically one for every million silicon atoms or so are implanted by chemical diffusion or by firing them out of a particle accelerator. Transistors are made by sandwiching a region of one of the dopants between two of the other. Let's look more closely at the N-channel configuration. This by itself does not conduct electricity, but when an electric field is applied to it a conducting channel forms, hence the name: Field Effect Transistor. This can be thought of in simple terms as the electric field attracting electrons from the N-doped region, which has a surplus, to the P-doped region, which has a deficit.

[4:40] Near the semiconductor stack we have a conducting electrical terminal. When it's at high voltage, an electric field forms and the transistor conducts, but to stop a short circuit we need to add an insulating layer between them. The contact is metal, the insulator is silicon oxide and finally we have the doped semiconductor, hence the term MOSFET. For a computer we need millions of interconnected CMOS pairs and they must be small and close together so that electrical signals can travel between them quickly.

[5:13] Making a processor typically begins with a solid block of P-doped silicon called a die. Transistors are then created on top of the die by a process called lithography: "writing on stone". There are two main techniques used in lithography. The first is deposition: chemically building up a layer of controlled, predetermined thickness across the entire die. This means that, for example N-doped silicon can be coated all over the top of the P-doped die. Unwanted surface material is then removed by a second technique called etching. This is done by applying chemicals or hot plasma to the top of the die. several steps are taken to ensure that the etching is targeted at specific areas and therefore material is removed selectively.

[6:02] A chemical termed a photoresist is deposited onto the die. light is shined through a mask exposing predetermined areas of the photoresist. The exposed areas must be the same size or larger than the wavelength of light used, hence very short wavelength ultraviolet light is used for the lithography. A special etching method is used to remove only regions of photoresist which were exposed and nothing else. This opens up gaps in the photoresist and then another etching method is used which targets everything except the unexposed photoresist.

[6:39] Finally, the remaining photoresist is etched away. As a result, material has been removed wherever there are any gaps in the mask. The two techniques of deposition and etching used in conjunction mean that the N-type dopants for all the transistors on the die can be added simultaneously. Next, the silicon oxide is deposited and etched and finally metal is deposited and etched away to leave metal channels on top of the die. These metal features form not just the conducting terminals of the transistors, but also the tracks equivalent to wires in a circuit which connect the transistors as required.

[7:16] Every time, photoresist is deposited, exposed through a mask, gaps are made and a die is etched. Finally, the billions of transistors are assembled and connected together by this method. There may be three CNOS pairs with three different inputs then going out to four different CMOS pairs somewhere else and so on and so on. [Beethoven's 5th symphony] To summarize: computers handle information as ones and zeros when voltage in an electrical circuit is either high or low.

[7:48] Transistors act as electronic switches, changing between these two states. The transistors always come in complementary pairs, so when one half of the pair opens, the other closes. Lithography is the process by which huge numbers of interconnected transistors are built up on a block of silicon. [Music] To understand why transistor networks are useful, we need to talk about a branch of mathematical logic called Boolean algebra.

[8:18] Rather than go into the full gory mathematical details, I will just illustrate the basic concepts with some not too serious examples. Let's say some friends are choosing a restaurant. Alice is happy when the restaurant serves burgers. Bob is happy when the restaurant does not serve burgers. We can think of evaluating restaurants in this case as something called a gate: an object which takes a binary input true or false, 1 or 0 and returns a binary output. In this case, the input is whether the restaurant has burgers and the output is if someone is happy with the restaurant.

[8:54] For Alice the gate is simple: the output is the same as the input. In electronic terms the circuit is just a connection. For Bob the gate is what's unimaginably called a NOT gate. This is a symbol typically used to denote it. In the previous section we have seen how this CMOS pair acts as a NOT gate. Let's consider a more interesting example, when the logic gates can have multiple inputs. Such gates have pretty straightforward names as we'll see. Now the friends are choosing restaurants which might serve pizza, noodles, both or neither. Alice is happy when the restaurant serves at least one of the two options or both. This idea is represented by what is called an OR gate. This is the symbol.

[9:35] Bob wants choice, so he wants both pizza and noodles on the menu, hence the AND gate. Charlie likes it if the restaurant serves pizza or noodles but not both: let's say she thinks that they wouldn't do a good job if they weren't specialized enough. The corresponding gate is called exclusive or XOR for short. Each of these gates also has a complementary gate: basically the same gate with a NOT gate after it. For example the NAND gate gives a 0 when all its inputs are 1, and gives a 1 otherwise.

[10:08] These complementary gates are denoted by the usual symbol with a circle at the output. For a computer, these and all other possible gates must be implemented through CMOS pairs. Connecting two pairs as follows creates a NAND gate. The N-channel and P-channel transistors still work in pairs. Only when a high voltage or 1 is applied to both pairs of inputs do the paths to high voltage close and the path to ground opens so a 0 is output. This is exactly the behavior of a NAND gate.

[10:40] The NAND gate is important because it's what's called universal: this means that any other gate can be created out of NAND gates as long as there are enough of them. Now, there are more efficient ways to make certain gates, but in essence this means that the problem of implementing logic gates through CMOS pairs is solved. There are also gates with three, four, or as many inputs as necessary. For example, take two AND gates connected as shown here and they simply become a three input AND gate and so on and so forth. [Beethoven's 5th symphony] To summarize: logic gates are conceptual mathematical objects which allow us to make deductions based on binary true or false statements.

[11:18] For example if it's true that today is Saturday or today is Sunday, then it's also true that today is the weekend. We have now seen how the CMOS pairs from the last section can be used to practically implement these gates in terms of electronic binary logic. [Music] Now we shall see how computers handle numbers and use logic gate networks to do arithmetic. We are all used to base 10 numbers meaning that there are 10 digits from 0 to 9.

[11:51] The digits represent multiples of powers of 10 which are 1, 10, 100, 1000, and so on. Modern computers use base 2 numbers with just 2 digits: 0 and 1. Binary digits are multiples of powers of 2 which are: 1, 2, 4, 8 and so on. For example, in base 10 the number 953 is 9 times 100 plus 5 times 10 plus 3 times 1. In binary, the number 1 0 1 is 1 times 4 plus 0 times 2 plus 1 times 1 which is 5 in base 10.

[12:25] Any number in base 10 can be represented by a number in base 2 and vice versa. To represent the number 1 0 1 3 electrical tracks in order would have their voltage on off on. Each of these tracks carries a binary digit or bit. With three electrical tracks this is called a 3-bit number. There are similarly 4-bit numbers 8-bit numbers and so on. Of course the 4-bit number 0 1 0 1 is equivalent to the 3-bit number 1 0 1.

[12:56] Let's consider adding together a pair of 1-bit numbers A and B to get C. 0 + 0 = 0 0 + 1 = 1. What happens when we try to add 1 + 1 in binary? The same thing as happens when we add 5 + 5 in regular base 10. There is no digit big enough, so we put a 0 in that column and carry the 1 to the next column. so to guarantee being able to store the result for any possible values of A and B the result C must be a 2-bit number. The bit on the right is 1 when A or B is 1, but not both: this is the behavior of the XOR gate if you recall Charlie from the last section.

[13:35] The bit on the left is 1 only if A and B are 1, ergo the AND gate. Therefore C is obtained by connecting A and B to gates like this. When adding numbers A and B larger than 1-bit things get more complicated with three input gates because there is now a bit from A, a bit from B and a carried bit. As I said in the previous section: NAND gates are universal, meaning any required gate network can be implemented using enough of them.

[14:17] [Beethoven's 5th symphony] In base 10, multiplying by 10 is easy: just add a 0 onto the end of your number. In base 2 the same is true for multiplying by 10 in binary or 2 in base 10. So, multiplying by the numbers 10, 100, 1000 in binary just involves shifting each bit to the left and putting a 0 on the end, which is unimaginably called a bit shift. What about multiplying by an arbitrary number, say for example 11 in binary?

[14:48] This is the same as multiplying by 10 multiplying by 1 and adding the two together. So, binary multiplication of A by an arbitrary number B works as follows: begin with zero. If the rightmost bit of B is 1, add A. Bit shift A once and if the next bit of B is 1, add this to the total. Continue for every bit of B. Computers also rely on making comparisons of numbers, such as: Is A equal to B? Is A greater than B?

[15:18] And so on. The computer might have the current time in seconds stored as a binary number A updated every second and the time to set up an alarm stored as B. The alarm would be made to go off when A is equal to B. To do this, the computer must check that every bit of the number A is the same as the corresponding bit of B. So, the XOR gate returns 1 when an input is 1 and the other input is 0, in other words when its inputs are different. The XNOR gate which is the complement of the XOR meaning it returns the opposite to the XOR therefore returns a 1 when its inputs are the same. A bunch of XNOR gates applied to each pair of bits of A and B return whether those bits are equal or not.

[15:57] The and gate returns a 1 when all its inputs are 1. So applying it to the XNOR gates returns a single bit which is 1 if and only if A is equal to B. There are also ways to implement subtraction, division and other comparisons all using gate networks. For example bit shifting the other way divides a number by two. These are all implemented using transistors etched on a chip. Just a note: when I say the word number in this video I am referring to an integer or whole number. There is also a way to store fractions in a binary version of scientific notation called floating point numbers or floats.

[16:32] I won't go into how they work but the general principle outlined here still applies. To summarize: a sequence of binary on off electrical signals is used by computers to represent a number in base 2 as opposed to base 10 which is used by people day to day. Networks of logic gates can be used to add, subtract and compare binary numbers, and with a few extra steps multiply and divide them too. [Music] We have seen how circuits composed of transistors can be used to implement addition and other algebra for any number with arbitrary binary digits or bits.

[17:09] If you want to build a computer we would have to choose exactly how many electrical tracks and gates to have available for representing a number. This is like when you're filling in a form and it has a set number of boxes physically printed on it for putting in your age. For commercial computers this is always a multiple of 8. 8 bits are called a byte. The computer will have adder circuits and so on with the types I described in the last section which take 1 byte or 8-bit numbers, 2 byte or 16-bit numbers, 4 byte or 32-bit numbers as inputs.

[17:40] No matter of how many bytes a number is comprised one of its bits can be set aside to denote a plus or minus sign. When a number is signed in this way, if the leading bit is 0 then the number is positive. If the leading bit is 1 then the number is negative. As anyone who has ever taken a mathematics exam knows: it's important to store your workings. Whichever operation a computer undertakes, the inputs and outputs must be somehow stored. To do this, a type of circuit called a latch is used.

[18:10] Once it has latched, it will stay that way for a long time and can therefore be used to store a bit of data. 8 latches store a byte and so on. This is an example of what's called a D-latch comprised of NAND gates. You may notice that this looks rather strange: before we've seen gates in a strictly sequential manner where the output of one gate goes directly to another. Now there is an output from one going to the input of another, but then the output comes right back. It is this kind of interconnection that allows this network of gates to hold and retain its output value 0 or 1.

[18:44] Nothing will change unless the E or enable input is 1. When enable is 1, whatever bit is applied to D will propagate to the output. The computer will carry out an operation, addition for example, enable a bunch of latch circuits to store the output and then switch the enable back off. The result will then be held there as long as is required. 8 of these latches can form register which will store a byte of data as long as it's required. An add circuit of the type we looked at in the previous section would have such registers to store the inputs before the addition takes place and a register to capture the result of the addition.

[19:23] It takes some small but significant amount of time for electrical signals to propagate, for transistors to finish switching and so on. To guarantee that the operation is fully carried out before attempting to read out the answer, all computers have a clock. In basic terms an oscillating crystal switches the voltage on and off, on and off, at a very specific rate. At the time when this video was made computer processors have typical clock speeds of 2 Gigahertz, meaning that the clock switches at 2 billion times a second.

[19:55] The regular switching allows events to be synchronized. To fully carry out an addition operation it will take at least 3 clock cycles. On the first clock cycle numbers would be loaded into the input registers, then the addition circuit can work over the next clock cycle. Finally on the third clock cycle the output register gets an enable signal and stores the result. Actually, most operations take much longer than one or even three clock cycles to carry out. We have seen in the previous section that multiplication takes several adding steps to accomplish.

[20:30] Nonetheless, whether it takes one or a hundred cycles the clock is still used to synchronize when an operation begins until the output is ready. All the so-called arithmetic logic, that is: all the arrays of logic gates which do addition and subtraction is physically located together with the registers on a chip called the processor or Central Processing Unit. There are also circuits in there called the cache, which nowadays can store tens of kilobytes of data as the intermediate stages of calculations for example.

[21:01] There is a need for a larger and longer term way to store many more bytes of data than the registers and the cache. Computers have separate physical chips of random access memory or RAM which makes use of capacitors to store this data. If a capacitor is charged, it has a high voltage and therefore a value of 1. If it's discharged it has 0 volts relative to ground and so is 0. The charge leaks or is lost over time, but is topped up by the memory circuits as long as the computer is powered.

[21:31] A typical laptop computer has tens of gigabytes or billions of bytes of RAM. Every byte stored in RAM has its own address like a post box in an apartment block. The address is itself a binary number. The RAM has many transistors forming gate networks which ensure that when it receives the address in binary format from the processor, it then returns the byte stored at that address. Until recently, computers wouldn't usually have more than 4 gigabytes of RAM. Each of those bytes requires a unique address, so memory addresses were 32-bit numbers. Such 32-bit numbers go up to just over 4 billion so that used to be fine.

[22:10] When RAM got bigger there effectively weren't enough addresses, so now 64-bit numbers are used for memory addresses. This is the difference between 32 and 64-bit programs. So, let's say you're playing a video game where you have a number of coins in your wallet. The video game will keep track of the address where the wallet total is stored. If you found eight more coins, the game will fetch the number currently in your wallet from that address, load it into the register, load a biary number corresponding to 8 in base 10 into the other register, add them together and put the results back into the address with the wallet total.

[22:47] We will look at this in more detail in the next section. Computers also store huge volumes of data on hard disk for decades at a time even without power. A hard disk is covered in tiny magnetic domains which can point up or down corresponding to 1 or 0. As the disk spins, a sensor head can either passively read off the orientation of the magnets as bits, or actively flip the orientation of the magnetic domains to write data onto the disk. Each of the bytes also has its own separate address.

[23:19] A laptop or personal computer can store hundreds of gigabytes on a hard disk. there are other technologies like flash memory, DVDs and so on that I won't go into here. The fundamental limit on how fast a computer can do operations is the speed of light, which can go about 15 centimeters or half a foot during a typical computer clock cycle so it would take multiple cycles for a computer larger than that to fetch any data. Realistically, transistors switch much slower than that, while a hard disk takes time to spin up and scan to read the data. In terms of types of computer memory: the cache is small, but quick to access; the RAM stores many more bytes of data, but takes longer to read; the hard disk takes the longest to read, but stores a lot of data almost permanently; so, there is a trade-off between how quickly the data can be retrieved and how much can be stored. From now on in this video, I will explain things as if the computer just has a single pool of memory which it can instantly read In reality things are more complicated,

[24:20] as I've just described [Beethoven's 5th symphony] To summarize: computers have a clock which synchronizes the operations being performed and ensures that there is enough time to finish performing one operation before starting another. Computers process binary numbers in groups of 8 bits called a byte. Registers are used to store numbers during computations and at other times numbers are stored in the cache, in random access memory and on a hard disk. Each byte in memory has its own unique address which is itself a binary number.

[24:56] [Music] We have a way of implementing binary operations and storing the results, but the computer needs a way to determine which operation to use and when. This is called an instruction. There are instructions such as: add two numbers, and copy this number. Computers use what's known as the von Neumann architecture, which means that the instructions are stored in memory as binary numbers amongst other data. For example, the instruction number 16 and base 10 or this byte in binary might mean: add together two 8-bit numbers and store the result.

[25:34] Instruction number 17 might mean the same thing but for 16-bit numbers and so on. When the computer encounters an instruction, it will use a comparison circuit which we looked at in a previous section to switch on the logic circuit for the necessary operation. If the byte is equal to 16, switch on the add circuit. How does the computer know when a byte is an instruction or not? 16 might be the instruction to add, or it might be the number of coins in a video game. Well, everything has to do with a precise order in which the bytes appear in memory. First comes the instruction byte.

[26:08] If the instruction is to add, the computer will need the two memory addresses of the things being added and the memory address where the result is to be stored. Remember that memory is like post boxes for a big apartment building with a unique address on each byte. In the case of modern 64-bit systems addresses are 8 bytes long. Therefore, the entire add instruction has one instruction byte and 24 bytes of addresses; 25 in total. On the other hand, if the instruction is to copy a number, it just needs to be followed by the origin and destination addresses, meaning the whole thing takes 17 bytes in total.

[26:45] The trick is that each type of instruction always takes up a set number of bytes and - crucially - the next instruction immediately follows on after the previous one. So, when the computer encounters the add instruction not only does it carry it out, but it knows that the next instruction is precisely 25 bytes along. To start with, the computer interprets byte number 0 - the one at the very start of memory - as an instruction and thereafter goes from instruction to instruction. Conversely, if there has been an error and the next instruction is not where it's supposed to be - tough luck! The computer will probably crash. How does the computer actually carry out an add instruction?

[27:22] The number from the first address is loaded into one input register and the second address into another input register. The add circuit is enabled and it does the addition. Then, after a sufficient number of clock cycles, the result can be written from the output register to the required address in memory. What happens if the instruction is to add two 16-bit numbers together? The computer simply goes to the address of number A and instead of getting just one byte, it gets that byte and then one immediately after. The same for number B and the result C. [Beethoven's 5th symphony] A computer program is a collection of instructions (and addresses) to be done in order. The computer goes from instruction to instruction to make the program run. Let's look at a specific example: part of the game, which is just a program after all, where the player has a wallet with coins in.

[28:10] This is what the contents of memory might look like. Byte number 0 is the instruction to add. Then come two addresses: the address of the wallet total and the number of coins the player has just found. The third address is the wallet again. after the addition the wallet total will be overwritten. No matter what, the computer will now interpret byte number 25 in memory as an instruction. It is another add instruction. The addresses of the wallet and the amount of coins the player has made from selling items are the inputs.

[28:40] The wallet address is the output again. The next instruction is 25 bytes further along at byte 49. The program keeps going on with millions of other instructions required to make the game function. In this case, the wallet total is being used a lot, so it will probably be held long term in the processor's cache as well as the RAM. When the player saves the game it will be written to a save file on the computer's hard disk. To summarize: the computer interprets certain bytes in memory as instructions for which operation to carry out.

[29:15] Computer programs are stored in memory. They are just large sequences of instructions, memory addresses and numbers. The computer goes from instruction to instruction like clockwork, always knowing based on the type of the current instruction how far along the next one is. [Music] So far, we've looked at instructions which work in a linear manner: copy a number, add two together and so on. The program would always produce the same result and eventually it would just get to the end of memory and stop.

[29:48] We need a few more instructions to make a computer what's known as Turing complete. Being Turing complete means that it can eventually carry out any possible computation: load a web page, render video game and so on. The only difference between two Turing complete computers is how fast they are at doing those computations. The first type of instruction a computer needs is what's called a jump or sometimes called a go to. Following the instruction byte is a memory address. As the name suggests, instead of going directly to the next instruction in memory, the program jumps to the specified memory address and carries out the instruction there.

[30:24] This means that the program can now do a loop. In our video game example, we have seen how instructions are used to add numbers of coins to a total kept in a wallet. These instructions and all the others required to update the game world, render the graphics and so on are followed by a jump instruction back to the start. This way the game can keep running indefinitely. The other crucial type of instruction that a computer needs is a branching or conditional instruction. If a given condition is met, for example if two numbers are equal, then jump to a particular address.

[31:00] We have already seen how a comparison can be implemented with logic gates. Adding such logic makes a jump conditional, allowing different sets of instructions to be executed based on calculations performed so far, or inputs to the computer such as a keyboard or mouse. With conditional jumps the computer is Turing complete: given enough time it can do any calculation. At this point it's worth mentioning how a real program might actually be written. If you thought that things were quite confusing so far, you're not wrong. Remembering which instruction does what, which memory addresses have what data stored in them, where jumps go and so on.

[31:38] This is all hard to keep track of. Programmers typically work with what are referred to as high level programming languages. This means that all the nuts and bolts of instructions and memory addresses are hidden away and instead life is made easier for the programmer. For example this is a bit of code in the C or C++ language. This code is readable by humans. If A is greater than B, set Q to be A; otherwise, when B is greater or equal to A, set Q to be B. In other words, the number Q will end up with whichever number is larger out of A or B.

[32:14] This is easy to understand for the programmer and anyone who tries to read it. A program called a compiler will take this code and arrange it into the correct set of instructions, sort out where the variables are stored in memory, where to jump, do we need to use 16-bit or 32-bit numbers and so on. This is what's referred to as compiling the code. There are many aspects of programming languages which simplify the job of the programmer, but one of the most important is the idea of a function or method. In mathematics, the square root is a function which takes a number and returns another. Certainly there are implementations of the square root function in computer code, but there are also more arbitrary functions and methods such as for fetching emails and so on.

[32:55] Say that a program needs to evaluate the square root of different numbers repeatedly. The instructions which comprise the square root function need only be stored in memory once. Whenever the function needs to be used, or called, the computer will jump to the function's location in memory, carry out the instructions and jump back with the result to the place in the program where it left off. Functions and methods can be compiled into libraries so that programmers across time and space can share useful code that they've written. If you've ever seen a DLL file on Windows, that's what that is. Once a function or method has been written efficiently, other programmers can use it without needing to spend much time on it.

[33:34] [Beethoven's 5th symphony] To summarize: computers have an instruction to jump to a memory address and carry out whatever instruction is there. This allows loops within programs. Some jumps only happen when a condition is met any computer that is capable of such jumps can carry out any computation as long as it has enough memory and time to do so. [Music] Chances are, you're watching this video on some sort of display. There are many technologies past and present which have been used for computer monitors, so I will speak in generalities.

[34:10] Light bulbs like at the start of the video are too large, but light emitting diodes or LEDs are smaller and more efficient. The higher the voltage across an LED, the brighter it is. A display is capable of electronically changing the voltage across each of its LEDs and therefore their brightness according to data from the computer. Since computers handle numbers in bytes, in other words groups of 8 bits, it makes sense to have the brightness go up on a scale from 0 to 255 - the largest value a byte can take.

[34:42] The human eye has cells sensitive to red green and blue light. By using a set of three LEDs: red, green and blue, varying the relative brightness of each one, the human eye can be tricked into perceiving the full spectrum of light. A mix of red and green gives yellows and browns. Red and blue gives pinks. All three colors at full brightness give white and at partial brightness give grey and so on. A little spot composed of three colors like this, no matter what technology is used, is called a pixel.

[35:14] A display has pixels arranged in rows and columns to form a 2-dimensional grid. For example, this video at maximum resolution is 1920 pixels in width by 1080 pixels in height. The number of bytes it takes to fill a display in memory is 3 times the width times the height. In simplest terms, the computer must update this many bytes in memory 30 or 60 times per second and send the result to the display. So, for example, if you full screen this video in its maximum resolution, each frame would take up this many bytes in memory.

[35:49] While displaying graphics and images may seem like a purely artistic undertaking, and in some sense it is, in actual fact for a computer it is nothing more than gate logic and instructions we have seen so far. Each pixel has a horizontal or x coordinate and a vertical or y coordinate which corresponds to its position in memory. For example, let's say your display is exactly a thousand pixels wide and you start with the top left pixel, if you move forward three thousand bytes in memory or the equivalent of a thousand pixels, you'll go off the end of the top row and onto the left pixel of the second row.

[36:25] There are many algorithms or long lists of instructions to draw windows, buttons, text and computer graphics all by using this kind of arithmetic and manipulating bytes in memory. To display a simple desktop environment, a loop fills every pixel with the background color by repeatedly copying the sequence of three bytes that uniquely defines the color. The taskbar is drawn by looping over only rows of pixels with specific y coordinates. A start button is created by filling a rectangle with a given range of x and y coordinates with another color.

[36:59] Text is added on top by copying pre-determined patterns of pixels for each letter or through some other algorithm. To display a window, it's necessary to know its specific width and height and the current position of its top left pixel. Adding the x value of the left pixel and the width by simple arithmetic gives the rightmost edge pixel. A title bar can then be drawn, along with a border text and so on. If the user moves or resizes the window, all of this arithmetic has to be redone and the window redrawn.

[37:29] The simplest computer graphic involves drawing a line between two points both with their own set of coordinates (x,y). The bresenham algorithm involves a loop which draws just such a line by following a straight x-y curve familiar from school mathematics. Draw three lines and you have a triangle which can be filled with textures, illuminated by simulated light sources and combined with thousands of others to make a 3D shape. No matter how complicated it all comes down to addition, multiplication and jump instructions compiled into functions.

[38:00] Sound is the other major form of output from a Computer. Sounds are waves of high and low pressure moving through the air. Speakers and headphones produce sounds by moving a membrane back and forth. There is a permanent magnet attached to the membrane inside a fixed conducting coil. An oscillating current through the coil pulls the magnet in and out making the membrane oscillate and creating a sound. The computer breaks up time into short steps and specifies the current at every step in time by sending a binary number to a sound card. Electronics turn the digital binary values into the appropriate current.

[38:33] A microphone works in exactly the opposite way. There are many input devices out there, but the way a computer deals with inputs is usually the same. The inputs leave so-called messages in memory, which are groups of bytes of preset length, identifying the device and what exactly the input consists of. For example, a message queue may have it three messages of eight bytes each: when decoded, the first one states that the a key has been pressed down; the second states that the mouse has moved 30 pixels to the right; and the third that the shift key has been released on a keyboard.

[39:10] The keys are arranged into a grid. When a key is pressed, it makes an electrical contact between a horizontal and vertical row, allowing the precise key to be identified. Between the keyboard and the computer's motherboard, the message announcing when a key is pressed down or released is relayed to computer memory, allowing the computer to act on it. In our video game example, imagine that the 'B' button is used to buy things and the 'S' button is used to sell. In Windows, these key presses have corresponding decimal numbers 66 and 83 respectively. In terms of instructions, the game would have conditional jumps based on the value of the last keystroke.

[39:46] If the keystroke value is 66, then a computer would jump to a set of instructions corresponding to buy; if 83, it would jump to instructions corresponding to sell. A computer mouse tracks how far left or right and up or down it has moved along a flat surface and also which buttons have been pressed. A program, typically the computer's operating system, keeps track of the x and y pixel coordinates of the mouse by adding or subtracting any changes in position received from the mouse.

[40:17] Say that a window with a button is currently active when a user presses down the left mouse button the program will check the x coordinate of the mouse cursor against the dimensions of the button. If x is greater or equal to the left side of the button and less than or equal to the right side of the button then the click is horizontally inside the button the programs then check the y-coordinate is vertically inside the button too. If both are true the button is considered pressed. If at any moment you have 10 buttons on screen, the program will check every button in turn if it's been pressed down or not.

[40:51] [Beethoven's 5th symphony] To summarize: a computer display is a grid of pixels. Each one a group of a red, a green and a blue light. The brightness of each light is set by a corresponding byte in computer memory. A pixel therefore has an arbitrary color and a group of them together makes an image. Sound is recorded by measuring the motion of sound waves and saving them as binary numbers in memory. The reverse process is used to play back the sounds. External devices send messages to the computer, which are placed into memory allowing the computer to identify inputs, such as when a key has been pressed or the mouse has been moved, and then act upon them.

[41:29] Finally, I want to take stock of the entire video. I think it's amazing how doping silicon with impurity elements and performing relatively simple logical operations allow us to watch and create videos process information and even inhabit virtual worlds. Computing is all about building up simpler concepts to achieve more complicated ones. If you've got CMOS pairs, you can make a NAND gate; if you've got NAND gates, you can make any logic gate; if you have logic gates, you can make instructions; if you have instructions, you can make algorithms into functions; from functions you can build up programs as complicated as you like.

[42:03] This also means that computers are very dumb: they have no intuition and must rigidly follow programs which have every possible eventuality spelled out in great detail.

在 Vidleaf 工作台中打开

搜索转录文本、选择行、复制带时间戳的引文、翻译。

署名

《计算机如何工作——从硅到应用》,作者 Improbable Matter(https://www.youtube.com/@improbablematter),依据 CC BY 4.0 许可(https://creativecommons.org/licenses/by/4.0/)。源视频:https://www.youtube.com/watch?v=5f3NJnvnk7k。本页是该视频的文本转录,添加了段落分隔和时间戳;创作者与 Vidleaf 无关联,也不为其背书。Vidleaf 添加了 AI 标点和 AI 生成的摘要;原始措辞仍可在本页查看。

您是创作者或权利持有人吗?请求更正或移除:copyright@vidleaf.app(参见关于这些页面)。

最后更新于