Skip to content

De Transistores a CPU

Prologo

Como "piensa" la computadora? Probablemente sabes que la CPU es el "cerebro" del ordenador, pero como funciona realmente? Como pasa de metal y plastico a un dispositivo inteligente capaz de ejecutar programas y procesar datos? Este capitulo te lleva desde los transistores mas basicos hasta entender los principios de construccion de la CPU.

Que aprenderas en este articulo?

  • Comprension de terminos: "frecuencia de CPU", "multinucleo", "set de instrucciones" ya no seran misterios
  • Perspectiva de ejecucion de codigo: ver como una linea de codigo pasa por fetch, decode, execute, writeback
  • Pensamiento en capas de abstraccion: entender como cada capa sirve a la superior
CapituloContenidoConcepto clave
Capitulo 1TransistoresInterruptores del mundo digital
Capitulo 2Puertas logicasImplementacion fisica de la logica booleana
Capitulo 3Unidades funcionalesSumadores, registros, multiplexores
Capitulo 4Nucleo CPUFetch, decode, execute, writeback

0. Vision general: De la arena a la inteligencia

La capacidad de "pensamiento" de las computadoras modernas proviene de algo muy simple: el interruptor.

Cuando la corriente pasa por un interruptor, esto representa "1"; cuando no pasa, "0". Si tenemos miles de millones de estos interruptores, y podemos hacer que la salida de uno controle a otro, podemos construir redes logicas increiblemente complejas.

La clave para entender los sistemas computacionales es la abstraccion. Desde la arena hasta la inteligencia, hay cuatro niveles:

Desglose por capas

  • Capa 1: Transistores (miles de millones) -- El "interruptor" mas basico. MOSFET: aplicar voltaje a la puerta permite el flujo entre fuente y drenaje
  • Capa 2: Puertas logicas (miles de millones) -- Transistores conectados forman AND, OR, NOT, XOR -- matematicas booleanas en circuitos
  • Capa 3: Unidades funcionales (cientos) -- Combinacion de puertas logicas: sumadores, multiplexores, registros
  • Capa 4: Nucleo CPU (1-128 nucleos) -- Centro de comando: fetch, decode, execute, writeback

1. Transistores: Interruptores del mundo digital

MOSFET transistor diagram -- click to toggle Gate voltage
Source
Source
Gate0
Open -> output 0
Drain
Drain
👆 Click to toggle Gate voltage

1.1 Que es un transistor?

Un transistor es un dispositivo semiconductor que podemos abstraer como un "interruptor" perfecto:

  • Fuente (Source) y Drenaje (Drain): como los dos extremos de una tuberia
  • Puerta (Gate): la valvula que controla el flujo

La diferencia clave: no controlamos con la mano, sino con voltaje. Cuando un interruptor puede ser controlado por la senal electrica de otro interruptor, cruzamos el abismo de la "intervencion humana" a la "computacion automatica".

1.2 Como representan 0 y 1?

  • Alto voltaje (ej: 3.3V) = logico 1 (True)
  • Bajo voltaje (cercano 0V) = logico 0 (False)

1.3 Evolucion del numero de transistores

AnoProcesadorTransistoresProceso
1971Intel 40042,30010um
1993Intel Pentium3.1M800nm
2006Core 2 Duo291M65nm
2020Apple M116B5nm
2023Apple M3 Max92B3nm

2. Puertas logicas: Calcular con interruptores

Four Basic Logic GatesThe building blocks of all digital computing
ANDAND gate
Operation:A ∧ B
Outputs 1 only when both inputs are 1
Series switches: both switches must be closed
Truth table
ABOutput
000
010
100
111
OROR gate
Operation:A ∨ B
Outputs 1 when at least one input is 1
Parallel switches: either switch can close the circuit
Truth table
ABOutput
000
011
101
111
NOTNOT gate
Operation:¬A
Inverts the input: 0 becomes 1, 1 becomes 0
Inverter: on becomes off, off becomes on
Truth table
AOutput
01
10
XORXOR gate
Operation:A ⊕ B
Outputs 1 only when the two inputs are different
Difference detector: different means true
Truth table
ABOutput
000
011
101
110
Core idea: Logic gates turn physical circuit on/off states into mathematical true/false operations. They are the bridge from hardware to software logic.

2.1 Puertas basicas

  • AND: Todas las entradas deben ser 1 para que la salida sea 1. Como dos llaves en serie.
  • OR: Si una entrada es 1, la salida es 1. Como llaves en paralelo.
  • NOT: Invierte la entrada. 1 se convierte en 0, 0 en 1.
  • XOR: La salida es 1 cuando las entradas son diferentes. "Detector de diferencia".

2.2 Sumar con puertas logicas

Un XOR (para la suma) + un AND (para el acarreo) = semisumador (Half Adder).

Half Adder -- Interactive DemoClick inputs A and B to see the result for one binary column
+=00
▲ Carry: pass a 1 to the column on the left ▲ Sum: the digit written in this column
0 + 0 = 0. Write 0 in this column, with no carry.
All possible cases
ABWrite (sum)Carry
0000
0110
1010
1101

Look closely at the table and two patterns appear:

  • The sum column is 1 only when A and B are different. This is XOR.
  • The carry column is 1 only when A and B are both 1. This is AND.
The circuit is connected like this:
A = 0
B = 0
XOR gate
Different -> 1
Output: 0
AND gate
All 1 -> 1
Output: 0
Sum
0
Carry
0

El semisumador solo acepta dos entradas. Para sumas multinumero necesitamos el sumador completo (Full Adder) que acepta tres entradas (A, B, y el acarreo anterior).

Full Adder -- Interactive DemoA full adder adds one more input: carry-in (Cin) from the lower bit. Click the three inputs to try it.
++=01
ABCarry-inCarrySum
1 + 0 + 0 = 1. Write 1 in this column, with no carry.
Compared with a half adder: A full adder adds a third input: carry-in (Cin). In multi-bit addition, each column adds A, B, and the carry from the column on the right.
All 8 cases (3 inputs -> 2³ = 8)
ABCinSumCarry
00000
00110
01010
01101
10010
10101
11001
11111
Inside a full adder = two half adders in series
Step 1: Half adder 1
First calculate A + B
A = 1B = 0
Intermediate sum: 1Carry 1: 0
Step 2: Half adder 2
Add the intermediate sum and carry-in
Intermediate sum = 1Cin = 0
Sum: 1Carry 2: 0
Step 3: Merge carries
If either carry path is 1, carry 1 into the next higher bit.
Carry 1 = 0Carry 2 = 0
Final carry: 0

Encadenando multiples sumadores completos obtenemos sumas de multiples bits:

Ripple Carry AdderCascade multiple full adders to perform multi-bit binary addition
CascadeLower-bit Cout connects to higher-bit Cin
RippleCarry propagates bit by bit like a wave
OverflowThe highest bit produces a carry beyond the range
Bits:
+=13
A0111(7)
B0110(6)
=1101(13)
Adder cascadeHover to inspect each bit calculation
Bit 0Half adder
A1B0
Sum1Cout0
Bit 1Full adder
A1B1Cin0
Sum0Cout1
Bit 2Full adder
A1B1Cin1
Sum1Cout1
Bit 3Full adder
A0B0Cin1
Sum1Cout0
Overall calculation
Input:A = 7 (0111), B = 6 (0110)
Process:Start at bit 0, compute each sum and carry, and propagate carries toward higher bits.
Result:1101 = 13
Core idea: Carry ripples from the lowest bit to the highest bit, which is why this circuit is called a ripple carry adder. More bits increase delay, but the circuit stays simple.
Complete Adder DemoFrom logic gates to multi-bit addition -- abstraction layer by layer
Layer 1: Logic gates
The basic operation units. Each gate performs one Boolean operation.
AND gateOutputs 1 only when all inputs are 1
OR gateOutputs 1 when any input is 1
XOR gateOutputs 1 when inputs differ
&
AND gateA AND B
0001
>=1
OR gateA OR B
0111
=1
XOR gateA XOR B
0110
1
NOT gateNOT A
10
Core idea: Logic gates turn voltage levels (0/1) into Boolean operations (false/true). They are where hardware starts implementing math.
Abstraction layers
Logic gates
Half adder
⊞⊞Full adder
[]Multi-bit adder
CPUALU/CPU

3. Unidades funcionales: Combinacion de puertas logicas

ModuloMisionAnalogia
SumadorMotor aritmeticoAbaco incansable
Multiplexor (MUX)Control de flujo de datosDesvio de ferrocarril
DecodificadorTraducir instrucciones binariasDescifrador de claves
Flip-FlopRegistrar estadoSube y baja que mantiene posicion
Common Functional Units -- switch modules to see how they work
Multiplexer (MUX): like a railway switch, it uses the select signal to decide which data input passes through.
Data 0 (D0)
Data 1 (D1)
MUX
Select (Sel)
Output (Out)0

The select signal is 0, so the output equals data 0 (D0): 0

3.1 Registros: Almacenamiento de datos

CPU Register FileHigh-speed storage inside the CPU
Special Registers
PC
0x00401000
Program counter
IR
0x8B450008
Instruction register
MAR
0x00401000
Memory address register
MDR
0x00000000
Memory data register
ACC
0x0000001A
Accumulator
General Purpose Registers
RAX
0x00000000
Return value
RBX
0x00000000
Base register
RCX
0x00000000
Counter register
RDX
0x00000000
Data register
RSI
0x00000000
Source index
RDI
0x00000000
Destination index
RBP
0x00000000
Base pointer
RSP
0x7FFDE000
Stack pointer
Program Status Word (PSW / FLAGS)
CF0Carry flag
PF0Parity flag
AF0Auxiliary carry
ZF0Zero flag
SF0Sign flag
OF0Overflow flag
Registers vs Memory
FeatureRegisterMemory (RAM)
LocationInside the CPUOutside the CPU
Access speedFastest (< 1ns)Slower (50-100ns)
CapacityTiny (bytes)Large (GB)
RoleHold instructions, operands, and resultsStore programs and data

La memoria se crea mediante retroalimentacion: la salida vuelve a la entrada, creando un ciclo cerrado que mantiene el estado. Cuando 32 o 64 flip-flops se alinean bajo la misma senal de reloj, obtenemos un registro.

From Flip-Flops to Registers: The Feedback Loop of Memory
Change the data and observe it: without a clock signal, the output feeds back to the input and the closed loop preserves memory.
Data Bus (Data Input)
1
0
1
0
Gate
🔒
4-bit Register (Stored State)
0
0
0
0
Control Center
Try changing the left-side input. The register value is locked while the feedback loop is closed.

4. Arquitectura CPU: De unidades funcionales al procesador

4.1 Componentes principales

  • ALU (Unidad Aritmetica Logica): ejecuta operaciones
  • Banco de registros: almacenamiento temporal ultra-rapido
  • Bus interno: transporte de datos entre modulos
  • Unidad de control: lee instrucciones, genera senales de control
CPU Internal Microarchitecture
Click a module to see its subcircuits and how it works
CPU Core (Central Processing Unit)
Address Bus
Data Bus

Control Unit

Program Counter (PC)
Instruction Register (IR)
Instruction Decoder
Clock Generator
Control signals ↓

Register File

General Registers R0-R3
Accumulator (ACC)

Arithmetic Logic Unit (ALU)

Adder Circuit
Status Flags
Control Bus
🖱️

Click a module in the CPU diagram to explore its circuit-level implementation.

4.2 Como ejecuta instrucciones la CPU?

  1. Fetch: Leer la instruccion de memoria
  2. Decode: Analizar que operacion realizar
  3. Execute: Realizar la operacion en la ALU
  4. Write Back: Escribir el resultado en registro o memoria
Detailed CPU Instruction Cycle Demo
CPU
Control Unit CU
PC256Program Counter
IRInstruction Register
MARMemory Address Register
MDRMemory Data Register
Arithmetic Logic Unit ALU
ACC0Accumulator
General Register File
R00
R10
R20
R30
Address Bus
Data Bus
Control Bus
Main Memory
0x100LOAD R0, [0x200]
 0x101LOAD R1, #7
 0x102ADD R0, R1
 0x103STORE [0x201], R0
Data Area
 0x51242
 0x5130
FetchFetch
DecodeDecode
ExecuteExecute
Write BackWrite Back
Step 0 / 32
Click "Clock Pulse" to step through execution, or "Auto Run" to play continuously.

Pipeline: Buscando la maxima eficiencia

En lugar de esperar a que una instruccion complete las 4 etapas antes de comenzar la siguiente, el pipeline permite superponerlas: mientras la instruccion A se ejecuta, la B se decodifica y la C se busca.


5. Resumen: A traves de las capas de abstraccion

  1. Fisica macro: Arena (dioxido de silicio)
  2. Fisica micro: Miles de millones de transistores
  3. Algebra digital: Puertas logicas AND/OR/NOT
  4. Modulos microarquitectonicos: Unidades funcionales
  5. Arquitectura compleja: CPU
  6. Reino de aplicaciones: Software e Internet

Reflexion final

El llamado poder de computo no es mas que una enorme cantidad de interruptores reorganizandose en un espacio cerrado; al compas del reloj, completan calculos complejos en esta pequena oblea de silicio.

"Cantidad conduce a salto cualitativo" -- esta frase se verifica continuamente en la arquitectura de computadoras.


Lectura adicional

  • Libro clasico: "Computer Organization and Design" - Patterson & Hennessy
  • Simulacion logica digital: Construir un sumador de 8 bits
  • Arquitectura avanzada: Cache multinivel, ejecucion fuera de orden, GPU
  • Lenguaje ensamblador: Entender como el codigo de alto nivel se convierte en instrucciones maquina