Chapter 1 - El

Architecture review
1. The unlimited register machine (URM)
Our mathematical idealization of a computer is called an unlimited register machine
(URM).
The URM has a infinite number of registers labeled R1, R2 , R3, … each of which at
any moment of time contains a natural number: we denote the number contained Rn
by rn . This can be represented as follows :
R1 R2
r1
r2
R3
R4
r3
r4
R5
r5
…
The contents of the registers may be altered by the URM in response to certain
instructions that it can recognize. These instructions correspond to very simple
operations used in performing calculations with numbers. A finite list of instructions
constitutes a program. The instructions are of four kinds, as follows :
Instruction
Form
Meaning
Zero
Z(n)
0Rn
or
rn:=0
Successor
S(n)
rn +1Rn
or
rn:= rn +1
Transfer
T(m,n)
rm Rn
or
rm:= rn
Jump
J(m,n,q)
If rm= rn jump to qth instruction
[1] Consider the following program:
I1:
J(1, 2, 6)
I2:
S(2)
I3:
S(3)
I4:
J(1, 2, 6)
I5:
J(1, 1, 2)
I6:
T(3, 1)
i) Carry out computation under this program with the initial configuration 8, 4,
2, 0, 0, 0, …
ii) Draw the flow diagram for the program
Initial
configuration
Final
configuration
R1 R2
8
4
R3 R4 R5
2
0
0
Next Instruction
…
I1
8
4
2
0
0
…
I2 (since r1 ≠ r2)
8
5
2
0
0
…
I3
8
5
3
0
0
…
I4
8
5
3
0
0
…
I5 (since r1 ≠ r2)
8
5
3
0
0
…
I2 (since r1 = r1)
8
6
3
0
0
…
I3
8
6
4
0
0
…
I4
8
6
4
0
0
…
I5 (since r1 ≠ r2)
8
6
4
0
0
…
I2 (since r1 = r1)
8
7
4
0
0
…
I3
8
7
5
0
0
…
I4
8
7
5
0
0
…
I5 (since r1 ≠ r2)
8
7
5
0
0
…
I2 (since r1 = r1)
8
8
5
0
0
…
I3
8
8
6
0
0
…
I4
8
8
6
0
0
…
I6 (since r1 = r2)
6
8
6
0
0
…
I7 : STOP
START
r1 = r2 ?
Typical Configuration
YES
x
y
z
NO
r2 := r2 + 1
r3 := r3 + 1
After k cycles round the loop
x
NO
y+k
z+k
r1 = r2 ?
YES
r3  R1
If x = y + k :
z+k
y+k
z+k
STOP
[2] Show that the following functions are computable by devising programs that
will compute them and draw a flow diagram for them :
 1 if x  0
0 if x  0
a) f (x)  
b) f ( x)  5
 1 if x  y
0 if x  y
c) f ( x, y)  
a) The following simple program computes f :
Z(2)
J(1, 2, 4)
J(1, 1, 5)
S(2)
T(2, 1)
START
r2 := 0
NO
Initial Configuration
x
0
…
k
k
…
r1 = r2 ?
YES
r2 := r2 + 1
r2  R1
STOP
b) The following simple program computes f :
Z(2)
S(2)
S(2)
S(2)
S(2)
S(2)
T(2, 1)
k equals 0 or 1
START
Initial Configuration
r2 := 0
x
0
…
5
5
…
r2 := r2 + 1
r2 := r2 + 1
r2 := r2 + 1
r2 := r2 + 1
r2 := r2 + 1
r2  R1
STOP
c) The following simple program computes f :
Z(3)
J(1, 2, 4)
J(1, 1, 5)
S(3)
T(3, 1)
START
r3 := 0
NO
Initial Configuration
x
y
…
0
r1 = r2 ?
YES
r3 := r3 + 1
r3  R1
k
y
k
k equals 0 or 1
STOP
2. Turing machine
A Turing machine M is a finite device, which performs operations on a paper
tape ([Cutland-1980], [Benenti-2004]). This tape is infinite in both directions, and is
divided into same-sized squares. At any given time each square of the tape is either
blank (B) or contains a single symbol from a fixed finite list of symbols s 1, s2 …, sn
that form the alphabet of M.
M has a reading head which at any given time scans or reads a single square of
the tape. M is capable of three kinds of simple operations: Replacing the symbol in
the square being scanned ay another symbol from the alphabet of M, Moving the
reading head one square to right, or Moving the reading head one square to left.
Current state
display window
qi
M
Reading Head
Tape
...
s1
s2
s1
s3
...
Square being scanned
Figure 3. Turing Machine
The action that M takes at any instant depends on the current state of M and the
symbol currently being scanned. This dependence is described in M’s specification
which consists of a finite set Q of quadruples, each of which takes one of the
following forms:
qi sj sk ql
q i s j R ql
q i s j L ql
 1  i, l  m 


0

j
,
k

n


Figure 4: A Turing machine specification
A quadruple qi sj  ql in Q specifies the action to be taken when the state is q i
and scanning the symbol sj , as follows:
1- Operate on the tape thus:
a)
if  = sk erase sj, and write sk n the square being scanned;
b)
if  = R move the reading head one square to the right:
c)
if  = L move the reading dean one square to the left:
2- Change into state ql.
Example: Performing Addition on a Turing-Machine
The Turing machine given by the following specification Turing-computes the
function x + y:
q1 1 B q 1
q1 B R q2
q2 1 B q 3
q2 B R q2
The tape representation of (x, y) contains x+y+2 occurrence of 1 symbol. The
machine is designed just to erase two of these occurrences from left. Here is a state
machine illustrating addition on a Turing machine.
1B
BR
q1
q2
BR
q3
1B
Figure 5: state machine for addition on a Turing machine
Note that arcs are labelled with a couple of symbols separated by an arrow in
the form:  which is read as: If  then .