General Computer Science 320201 GenCS I & II Lecture ... - Kwarc
General Computer Science 320201 GenCS I & II Lecture ... - Kwarc
General Computer Science 320201 GenCS I & II Lecture ... - Kwarc
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Our notion of time is in this construction is very simplistic, in our analysis we assume a series<br />
of discrete clock ticks that synchronize all events in the circuit. We will only observe the circuits<br />
on each clock tick and assume that all computational devices introduced for the register machine<br />
complete computation before the next tick. Real circuits, also have a clock that synchronizes events<br />
(the clock frequency (currently around 3 GHz for desktop CPUs) is a common approximation<br />
measure of processor performance), but the assumption of elementary computations taking only<br />
one click is wrong in production systems.<br />
We will now instantiate this general register machine with a concrete (hypothetical) realization,<br />
which is sufficient for general programming, in principle. In particular, we will need to identify a<br />
set of program operations. We will come up with 18 operations, so we need to set n ≥ 5. It is<br />
possible to do programming with n = 4 designs, but we are interested in the general principles<br />
more than optimization.<br />
The main idea of programming at the circuit level is to map the operator code (an n-bit binary<br />
number) of the current instruction to the control input of the ALU and the MMU, which will then<br />
perform the action encoded in the operator.<br />
Since it is very tedious to look at the binary operator codes (even it we present them as hexadecimal<br />
numbers). Therefore it has become customary to use a mnemonic encoding of these in simple word<br />
tokens, which are simpler to read, the “assembler language”.<br />
Assembler Language<br />
Idea: Store program instructions as n-bit values in program store, map these to control inputs<br />
of ALU, MMU.<br />
Definition 445 assembler language (ASM)as mnemonic encoding of n-bit binary codes.<br />
instruction effect P C comment<br />
LOAD i ACC : = P (i) P C : = P C +1 load data<br />
STORE i P (i): = ACC P C : = P C +1 store data<br />
ADD i ACC : = ACC +P (i) P C : = P C +1 add to ACC<br />
SUB i ACC : = ACC −P (i) P C : = P C +1 subtract from ACC<br />
LOADI i ACC : = i P C : = P C +1 load number<br />
ADDI i ACC : = ACC +i P C : = P C +1 add number<br />
SUBI i ACC : = ACC −i P C : = P C +1 subtract number<br />
c○: Michael Kohlhase 276<br />
Definition 446 The meaning of the program instructions are specified in their ability to change<br />
the state of the memory of the register machine. So to understand them, we have to trace the<br />
state of the memory over time (looking at a snapshot after each clock tick; this is what we do<br />
in the comment fields in the tables on the next slide). We speak of an imperative programming<br />
language, if this is the case.<br />
Example 447 This is in contrast to the programming language SML that we have looked at<br />
before. There we are not interested in the state of memory. In fact state is something that we<br />
want to avoid in such functional programming languages for conceptual clarity; we relegated all<br />
things that need state into special constructs: effects.<br />
To be able to trace the memory state over time, we also have to think about the initial state of the<br />
register machine (e.g. after we have turned on the power). We assume the state of the registers<br />
and the data store to be arbitrary (who knows what the machine has dreamt). More interestingly,<br />
we assume the state of the program store to be given externally. For the moment, we may assume<br />
(as was the case with the first computers) that the program store is just implemented as a large<br />
array of binary switches; one for each bit in the program store. Programming a computer at that<br />
time was done by flipping the switches (2n) for each instructions. Nowadays, parts of the initial<br />
154