A register is
a row of switches
一个寄存器,
就是一排开关

No hardware background needed. About four minutes to read. 不需要硬件基础。这一页大约 4 分钟讲明白。

芯片里的一排开关 a row of switches inside 这根脚接着一颗灯 this leg drives a lamp
A 32-bit register is 32 of these switches in one row. All of them are in your hand at once. 一个 32 位的寄存器,就是这样的 32 个开关排成一行——一次全在你手里。

What is that row like? 这一排开关像什么?

寄存器 registerregister a row of switches — flip one, the chip acts differently 芯片上一排能拨的开关;拨一下,芯片就换个做法

A building's breaker box gives each room its own switch. This row does the same, one slot per job. 楼道里的配电箱,一格开关管一个房间。芯片上这一排也一样,一格管一件事。

It's like…就像……

A dorm's breaker box: a row of small switches, one per room. If one room is dark, you flip that room's slot. 宿舍楼的配电箱:一排小开关,一格只管一个房间。谁的灯不亮,就拨谁那一格。

配电箱 the breaker box 芯片里的一排 the row inside the chip
Up there one slot means one room; down here one slot means one job. The violet slot is bit 5, the one later screens change; it is still 0 here. Only the rightmost 8 of the 32 slots are drawn — bits 7 down to 0. The next screen has all 32. 上面一格管一个房间,下面一格管芯片的一件事。紫色那一格就是后面几屏要改的第 5 位,现在还是 0。这里只画了最右边 8 格,也就是第 7 位到第 0 位。下一屏才是完整的 32 格。

Which bit drives which pin? 哪一位管哪根引脚?

位 bitbit one switch: it can only sit at 0 or at 1 一个开关的一格:只有 0 和 1 两个位置
引脚 pinpin a metal leg on the chip's edge — one wire hangs on each 芯片边上伸出来的金属脚,一根挂一条线

Bit numbers run right to left; the rightmost slot is bit 0, the ones place. Bit 5 drives pin 5. 位号从右往左数,最右边那一格是第 0 位,也就是个位。第 5 位管的就是 5 号引脚。

31 5 0 0 1 输入:只听着 input: it listens 输出:往外送电 output: it drives 5 号引脚上的灯 the lamp on pin 5
Convention here: bit numbers run right to left; bit 0 is the lowest bit, the ones place. 0 = input, 1 = output — some chips have it backwards. Your code reaches this row by its address — a house number for the row. The pad must first be switched to GPIO — pin muxing — before this bit does anything. This bit only decides listen or drive; a separate register decides whether it drives 0 or 1. Some chips spend two bits per pin, written [11:10], high bit first, so read the manual. 本页约定:位号从右往左数,第 0 位是最低位,也就是个位。0 = 输入,1 = 输出;有的芯片反过来。你的程序靠地址找到这一排,地址就是它的门牌号。这根脚还得先切给 GPIO 用(引脚复用),方向位才管得着。这一位只决定这根脚是听还是送;送 0 还是送 1,另一个寄存器管。也有的一根引脚要两位来配,那一段写成 [11:10],高位在前,动手前查手册。

Changing one bit takes three steps 只改一位,要走三步

读-改-写read-modify-write read the row, change one slot, write it back 读出整排,改一格,再整排写回去
1

Read the current value 读出当前值

2

Change only my bit 只改我要的那一位

3

Write the whole row back 整排写回去

芯片里还是老样子 the chip still holds the old row
Whole rows only, so one bit costs three steps. A set/clear pair, where a chip ships one, skips them. Only the rightmost 8 of the 32 slots are drawn. 芯片只认整排读写,所以改一位得走完三步。有的芯片另给一对置位、清位寄存器,写它就不用走这三步。图上只画出最右边 8 格。

Why not just write one number? 为什么不能直接写一个数?

Writing one number flips all 32 switches at once. Slots other code depends on quietly go back to listening. 直接写一个数,等于把 32 个开关一起拨。别人正在用的那几格,会被你顺手关掉。

你写进去的那个数 the number you write 其余 31 位全是 0 the other 31 bits are 0 芯片里一整排被换掉 the whole row is replaced 别人在用的灯灭了 that lamp goes dark
The number you write names only bit 5, so the other 31 arrive as 0. Read-modify-write is not one step either. An interrupt — an urgent job the chip cuts in — or another core can lose your change. That set/clear pair from the last screen exists for exactly this. Again only the rightmost 8 of the 32 slots are drawn. 写进去的那个数只点了第 5 位,其余 31 位就都是 0。读-改-写也不是一步。中间被中断(芯片插进来的急事)或另一个核插进来,改动会丢。上一屏那对置位、清位寄存器,就是为这件事准备的。图上同样只画最右边 8 格。