Inside your computer Bettina Bair

Do you remember when you first realized

that your computer was more

than just a monitor and keyboard?

That between the mouse click
and the video playing,

there was something
that captured your intention,

understood it,

and made it real?

What is that something?

Is it gremlins?

Let’s imagine that we can shrink down

to the size of an electron

and inject ourselves
into a click of a mouse.

If you took your mouse apart,

you’d see that it’s really
a very simple machine.

It has a couple buttons

and a system for detecting
motion and distance.

You might have an optical mouse

that makes these measurements
with lights and sensors,

but older ones did this
with a hard rubber ball

and some plastic wheels.

Same concept.

When you click the button on your mouse,

it sends a message to the computer

with information about its position.

When your mouse click is received,

it’s handled by the basic
input/output subsystem.

This subsystem acts like the eyes and ears

and mouth and hands of the computer.

Basically, it provides
a way for the computer

to interact with its environment.

But it also acts like a buffer

to keep the CPU from being
overwhelmed by distractions.

In this case, the I/O subsystem decides

that your mouse click is pretty important

so it generates an interrupt to the CPU.

“Hey, CPU! Got a click here.”

The CPU, or central processing unit,

is the brains of the whole computer.

Just like your brain doesn’t
take up your whole body,

the CPU doesn’t take
up the whole computer,

but it runs the show all the same.

And the CPU’s job, its whole job,

is fetching instructions from memory

and executing them.

So, while you’re typing, typing, typing,

maybe really fast,

like 60 words a minute,

the CPU is fetching and executing

billions of instructions a second.

Yes, billions every second:

instructions to move your mouse
around on the screen,

to run that clock widget on your desktop,

play your internet radio,

manage the files you’re
editing on the hard drive,

and much, much more.

Your computer’s CPU
is one heck of a multitasker!

“But oh my gosh

there’s a very important mouse click

coming through now!

Let’s drop everything now
and deal with that!”

There are programs for everything

that the CPU does.

A special program for the mouse,

for the clock widget,

for the internet radio,

and for dealing with letters
sent by the keyboard.

Each program was initially
written by a human

in a human-readable programming language,

like Java,

C++,

or Python.

But human programs take up a lot of space

and contain a lot of unnecessary
information to a computer,

so they are compiled and made smaller

and stored in bits of ones
and zeros in memory.

The CPU realizes that it
needs instructions

for how to deal with this mouse click,

so it looks up the address
for the mouse program

and sends a request
to the memory subsystem

for instructions stored there.

Each instruction
in the mouse device driver

is duly fetched and executed.

And that’s not nearly
the end of the story!

Because the CPU learns
that the mouse was clicked

when the cursor was over a picture

of a button on the monitor screen,

and so, the CPU asks memory
for the monitor program

to find out what that button is.

And then the CPU has to ask memory

for the program for the button,

which means that the CPU needs

the monitor program again

to show the video
associated with the button,

and so it goes.

And let’s just say there
are a lot of programs involved

before you even see
the button on the screen

light up when you clicked it.

So, just the simple task
of clicking your mouse

means visiting
all of the critical components

of your computer’s architecture:

peripherals,

the basic input-output system,

the CPU,

programs,

and memory,

and not one gremlin.

你还记得你第一次

意识到你的电脑

不仅仅是一个显示器和键盘吗?

在鼠标点击
和视频播放之间,

有什么东西
能抓住你的意图,

理解它

,让它成为现实吗?

那是什么东西?

是小精灵吗?

让我们想象一下,我们可以缩小

到一个电子的大小,

然后将自己
注入到点击鼠标中。

如果你把鼠标拆开,

你会发现它真的
是一台非常简单的机器。

它有几个按钮

和一个用于检测
运动和距离的系统。

您可能有一个光学鼠标

,可以
使用灯光和传感器进行这些测量,

但较旧的鼠标
使用硬橡胶球

和一些塑料轮子进行测量。

相同的概念。

当您单击鼠标上的按钮时,

它会向计算机发送一条消息,其中

包含有关其位置的信息。

当收到您的鼠标点击时,

它由基本
输入/输出子系统处理。

这个子系统就像计算机的眼睛、耳朵

、嘴巴和手一样。

基本上,它
为计算机提供了一种

与其环境交互的方式。

但它也起到了缓冲器的作用,

以防止 CPU
被分心所淹没。

在这种情况下,I/O 子系统

认为您的鼠标单击非常重要,

因此它会向 CPU 产生中断。

“嘿,CPU!点击这里。”

CPU,或中央处理单元,

是整个计算机的大脑。

就像你的大脑不会
占据你的整个身体一样

,CPU 也不会
占据整个计算机,

但它仍然运行着节目。

CPU 的工作,它的全部工作,

是从内存中获取指令

并执行它们。

所以,当你在打字、打字、打字时,

也许真的很快,

比如每分钟 60 个字

,CPU 每秒获取并执行

数十亿条指令。

是的,每秒数十亿:

指示
在屏幕上移动鼠标、

在桌面上运行时钟小部件、

播放网络收音机、

管理
正在硬盘上编辑的文件

等等。

您计算机的
CPU 是一个多任务处理程序!

“但是哦,天哪,

现在有一个非常重要的

鼠标点击!

让我们现在放下所有东西
并处理它!”

CPU 所做的一切都有程序。

用于鼠标

、时钟小部件

、网络收音机

和处理
键盘发送的字母的特殊程序。

每个程序最初
都是由

人类使用人类可读的编程语言编写的,

例如 Java、

C++

或 Python。

但是人类程序占用了大量空间,

并且包含大量对计算机不必要的
信息,

因此它们被编译并变得更小,

并以 1
和 0 的位存储在内存中。

CPU 意识到它
需要

关于如何处理鼠标点击的指令,

因此它查找
鼠标程序的地址

并向
内存子系统发送请求以

获取存储在那里的指令。

鼠标设备驱动程序中的每条指令都

被适当地获取和执行。

这还不
是故事的结局!

因为

当光标

在监视器屏幕上的按钮图片上时,CPU 得知鼠标被单击

,因此,CPU 向监视器程序请求内存

以找出该按钮是什么。

然后 CPU 必须

为按钮的程序请求内存,

这意味着 CPU

需要再次监视程序

来显示
与按钮相关的视频,

然后就可以了。

假设在

单击屏幕上的按钮

时它会亮起之前,涉及到很多程序。

因此,只需
单击鼠标这一简单任务就

意味着访问

计算机体系结构的所有关键组件:

外围设备

、基本输入输出系统

、CPU、

程序

和内存,

而不是一个小精灵。