pete > courses > CS 202 Spring 24 > Lecture 11: computer beginnings


Lecture 11: computer beginnings

Goals


we’ve built combination locks and traffic lights

we may not immediately think of such things as computers, per se

but the way we constructed the traffic light resulted in a sort of computer

where the light executed a sequence of instructions one by one

much like your computer executing a sequence of instructions in a Java or Python program, line by line

(yes, individual lines of Java and Python programs are more complicated than the traffic light analogy)


today marks the shift from Phase 1 of the course to Phase 2, where we take all the circuitry stuff from Phase 1 and try to build something that can perform computation like the programs you’ve written in the past

we’re going to take the first step today: we’ll look at a few lines of code that we could imagine being in a program written in, eg, Java or Python, and think about what circuit components we could use to achieve the intended result

we’ll start with a single line, come up with a circuit that implements it, and then add additional lines that do slightly different things, and modify the original circuit to support these other lines too

this is a common pattern used to develop solutions to big, complex problems: pick a single angle of the problem, come up with a solution for it, then pick another angle and modify the first solution to support it too; keep doing this until all the angles are accounted for

it is, of course, possible that one might encounter an angle that the current solution doesn’t support, forcing a return to the drawing board, but that is part of problem solving


here’s the first line:

x = y + z

there are three "things" going on here

do we have circuitry that can remember values such that we can later read them? yep: registers

and can we change the values stored in these registers? yep

can we do addition? yep


so what we need is at least three registers (one for each of x, y, and z)

we need an adder

we need to connect the output of two of the registers to the inputs of the adder

and the output of the adder to the input of the third register

then when we toggle the clock input on the register, the sum of y and z will be stored in the register we’ve designated to hold x

this is kind of awesome: we now have circuitry that performs computation that clearly resembles the exact kind of code you yourself have written


here’s the next line of code:

y = z + x

this introduces complications

we’re not going to be able to hard-wire the y register to the input of the adder

we have to be able to choose which registers get sent as inputs to the adder

likewise, we have to be able to choose with register gets the result of the adder

this is a job for muxes (one to select which register’s value is sent to the first input of the adder and a second to select which register’s value is sent to the second input of the adder)

and a decoder, to select which of the registers should be written (review the 4-by-3-memory circuit from lecture 07 to see how we did this)


next wrinkle is minor:

z = x + x

both operands might come from the same register!

fairly easy to implement in circuitry, though

in fact, the muxes we proposed previously magically take care of it

(in general, when we examine a new angle of the problem and it Just Works in our current solution, this can be a clue that we’re on the path to a good general purpose solution)


what about this one:

z = z + x

this works because we can let the z and x flow through the circuit such that the sum is ready on the wire leading to the z register, and then tick the clock

because the register stores a new value only on the rising edge, it grabs the result right then, before the new value of z can flow through the circuit

thus this line doesn’t present a problem either


this one is trickier:

y = z - x

how do we (efficiently) support operations other than addition?

good news: we can (and should) reuse the circuitry that allows us to choose operands

we do need a subtractor to perform the subtraction

but now that we have a second operation, we need some way to choose among outputs (ie, whether y reads its value from the adder or the subtractor)

so now we have both an adder and a subtractor, and we choose (mux!) which of those results we put on the wire leading to the registers’ data input (which, again, is enabled by the decoder we discussed a few minutes ago)


this is, in fact, how modern computers are organized

they have a bunch of registers, which we call a register file

they have a bunch of circuitry to perform operations, which we call an arithmetic-logic unit (ALU)

the register file is connected to the inputs of the ALU

and the outputs of the ALU are connected back to the register file

thus an instruction is executed by making sure the correct registers are chosen as inputs, the correct operation is chosen in the ALU, and the correct register is chosen to read its output

we execute these instructions in sequence and suddenly we’ve got a program


it’s probably difficult to see how we can go from this crazy-simple model of a computer to sending spaceships to Mars or figuring out how proteins behave or playing games

we’ve still got a few weeks left in the semester to get closer


but first, I want to talk about an issue I’ve been delaying for a few lectures now

namely, how we make these things happen without manually twiddling the clock input

we need some automated method to take care of that for us

some inexorable force that alternates between zero and one

the component that provides this for us is called a clock because it goes tick, tock, tick, tock

the alternating signal it provides is called a clock signal (though you’ll often hear it referred to as just the "clock")

Digital has such a component, and we can use it to replace the pushbutton in the traffic light circuit

likewise, computers have clocks within them that tick at a regular pace, one instruction executing during each clock cycle

(draw square wave, identify single cycle)


modern computer processors have clocks that tick upwards of 4 billion times per second

("gigahertz", abbreviated "Ghz", literally means "one billion times per second")

meaning that they execute one instruction like the ones we were playing with earlier every quarter of a nanosecond (literally)

I am no expert on how these clocks actually work, I’m just super-confident that they do

my very basic understanding is that materials oscillate (ie, wiggle back and forth) when electricity is applied to them

the speed with which they oscillate relative to the amount of electricity is predictable

thus by applying a particular voltage to a particular material, you can get a particular oscillation frequency

and then tick, tock

(this is a materials science issue and thus Outside the Scope of This Course)


now, back to the register file and ALU

because this is all hardware, we have to make some decisions before these things are actually manufactured

things like…

and in fact any manufacturer of computer processors has to decide this

a company like Intel may make different choice than a company like ARM

additionally, needs may change over time and one may wish for a new line of processors that has, eg, more and larger registers

as we’ll see, however, these choices have a direct effect on the way one writes software

all such choices are codified in what’s called the instruction set architecture (ISA)

thus chips produced by Intel have their particular ISA (they actually have a few, the most prevalent of which are IA-32 and IA-64, which we’ll talk about later in more detail) and ARM has a different ISA


once we figure out the answers to the aforementioned questions, we can bundle the control (or select) wires for each of the components into a big wire reminiscent of the big wire we used for the traffic light

thus we have instructions

we can, in fact, deduce an instruction that implements x = y + z


because Intel and ARM made different choices when it came to the aforementioned questions, instructions that work on Intel don’t work on ARM and vice versa

Last modified: