As someone who has a decent understanding of computer architecture (but not of electrical engineering) I've always wondered why computer circuits tend to have so many resistors, capacitors, and other small circuit elements. Computing logic is binary - either wires have electricity going through them or they don't. So why the need to store/reduce the flow of electrons in so many different places? I'm guessing it has something to do with delivering voltage to different circuit elements from the power supply, or maybe controlling the rapid oscillation of the CPU clock, but I'm not sure.
Resistors and caps have thousands of uses.
A couple primary uses for resistors you might see connected directly to the IC pins
Pull up/Pull down (100% a logic function ;)
Termination to prevent ringing or signal reflections on high-speed digital signals. (Computers would not work if this were not done)
Capacitors are used by the bucketload to 'bypass' the power. When your IC switches logic state (clocks), tons of transistors inside change at the same time. The result is a little 'gulp' of electricity required. Because the IC is some distance from the main power supply it can't supply electricity fast enough, you need a secondary supply very close to the IC to prevent the IC from starving for voltage. The caps right next to the IC's perform this function. It's alot like a water tower. The water tower keeps a constant pressure to everybody connected, regardless the instantaneous demand. If there were no water tower, as demand rises, and you had to pump water miles & miles from some remote reservoir, the resistance of the piping would cause pressure to drop by the time it got to your house.
There's obviously WAY WAY more complicated matters than the above, but I tried to keep it in simple terms.
Capacitors provide power supply bypassing for switching logic. Smaller capacitors have better high-frequency characteristics for this task, so they get used in abundance for computer boards; bigger values provide bulk filtering to keep the power supply steady.
Big, power-hungry chips will get carpet-bombed with a range of capacitor values to get the needed power-domain frequency response to knock down the chip’s switching noise.
Resistors show up on computer boards as termination, or for pulling signals up/down to known states. They’re not nearly as numerous as capacitors. Mixed-signal blocks, if present, use resistors for gain-setting or other signal conditioning.
And let’s not forget inductors. These deal with power, sometimes for filtering, but most often for DC-DC conversion, as energy-transfer devices to step down the supply to what the chips need. Big chips will use multi-phase converters, one inductor per phase, for core voltages that can hit hundreds of amps.
Basically, capacitors and resistors are there because they just "do stuff". The list is endless.
Computing devices don't just compute by themselves. For example they need power too, and clock signal to synchronize their computing elements, and communication buses that can be thought as transmission lines.
With every clock cycle there can be millions of logic gates toggling their states, and each gate takes a small gulp of current when toggling. A modern CPU can take 100W of power, which means that with 1 volt core supply, it takes 100 amps of current, on average. The amount of capacitance and number of small capacitors to be able to supply the CPU with low enough impedance to keep voltage stable is significant. There are a lot of other functions for capacitors as well than to stabilize power supplies, like AC coupling bus signals, AC termination, timing, compensation, filtering.
And the resistors are used for terminating transmission lines with proper impedance, to act as pull-ups or pull-downs for signals, for current limiting even for a LED, for dividing voltage to set regulator output, as shunt to measure current.
I think a big part is being missed in other answers here as to why you have these resistors on something like a motherboard.
Yes, the computer chips are digital, and work with 0s and 1s. But any modern system has a lot of analog functionality to work.
First, you have supplies. You need to somewhere generate all the supply voltages needed for your chip. This is done with analog (or at least partially analog) circuits that use those resistors to set gain, control feedback, etc.
Second, your system might simply have a lot of analog functionality to interface with the outside world. A microprocessor or SoC might have internal ADC and DACs to talk to other systems, be they audio, data, or other analog control signals. These all might need resistors and other analog components to work.
They have far more transistors than they do resistors and capacitors, it's just that the transistors are mostly intergrated as part of ICs (and when they aren't integrated there is little visual difference between a discrete transistor and a low pin count IC), so you don't really see them.
Resistors and capacitors on the other hand are difficult to effectively integrate on ICs, so they are more likely to be discrete components.
Capacitors are mostly used for keeping the power supply stable. Every time a logic gate switches it draws a spike of current, mostly due to charging and discharging the stray capacitance in the wiring and sometimes also due to both the top and bottom transistors switching partially on at the same time. Each clock edge causes a large amount of logic to switch at basically the same time, so the power supply to the chip as a whole also shows the spikes.
So "decoupling capacitors" are used to supply these current spikes and keep the power supply voltage stable. Due to the stray inductance of the PCB traces the capacitors must be close to the ICs they protect the power supply for, hence the large number of them.
Larger but slower (higher ESR and/or ESL) capacitors are often seen as part of the power circuitry where they serve to smooth out the variations in current from the switching action of the buck converters that step down the 12V from the power supply to the volt or so used by the core logic.
Resistors are much less common than capacitors, but they do have some important uses, one is terminating high-speed signal lines to prevent reflections from interfering with the signal. Another is providing "pull ups" or "pull downs" so that a signal goes to a known state when it is not actively driven. There is also a certain amount of "analog" circuitry (such as power supplies) which will likely need resistors.
One also sometimes sees "zero ohm links" which are sometimes classified as resistors. These are used when a designer wants to allow multiple options for building the board with slightly different connections.
Other answers have explained why resistors and capacitors are needed at all, but have not yet explained why they are on discrete components on the circuit board, external to the integrated circuits.
It certainly is possible to fabricate resistors and capacitors as part of ICs. Indeed, the first commercially-available IC was a resistor-transistor NOR gate. Many ICs today still have some resistors or capacitors fabricated on-chip.
However, resistors and capacitors take up a lot of chip space. IC resistors need to be long. Capacitance is proportional to area. Both components take up valuable chip area that could be used for large numbers of transistors instead. It is therefore more economical to place these devices external to the IC, as discrete components.
If I look at a modern PC mainboard I indeed see lots of capacitors, but very litlle (to none at all) resistors.
The capacitors are part of the power supply circuits, which are not just in the metal box, but also around for instance the main CPU. That power supply is definitely an analog circuit, not a digital one (even though this one it is switching). The capacitors are needed for smoothing, because
- the power is provided by the power supply circuit in bursts
- the CPU's power consumption can change very rapidly.