Next: An Example
Up: Ceng-111 9798 Fall Homework-1
Previous: REGULATIONS
In this homework you will be experimenting with a given process on number sequences.
This process resemble the action of a simplified Von Neumann Machine. You will
observe that the number sequence (which will change from problem to problem)
acts like a machine code program loaded into the memory of a Von Neumann machine.
The two registers
,
and the instruction pointer
, the only three
internals of the process, carry out the functions of the
data, address, condition and the instruction
registers of a Von Neumann machine.
Our process (lets name it from now on as the HW-1 machine) works on a sequence
of integers each of which are in the range [-127,+127]. Here is an example for
such a sequence:
If we are speaking about the value of the 3rd element in the sequence then
we will denote this by enclosing the 3 into square brackets, like [3].
In the example above [3] is 33.
Furthermore, the HW-1 machine has three registers which we name as
,
an
.Each one of
and
can hold an integer in the range [-127,+127]. Storing
negative
values into
is not allowed, it can hold any integer in the range [0,+255]
(though in your exercises the values of
will be about 10-30, at most).
The square bracket notation applies for these registers as well. Namely
means the
content of the
th element in the sequence. So, for instance, if
has at
any moment the value 3 and if at that moment the 3rd sequence element is 33
(as it is in the example above) then
refers that 33.
The interesting point is that the values in the sequence as well as the values
in the registers can be changed freely to new values. When this is the case the former
value is erased and the new value is substituted in that place. We will call this
action an assignment and will represent it by the following notation:
place
new value
Here are some assignment examples:
 |
is set to the value 5 |
 |
is set to the same value is holding now.
(Attention: This does
not mean that any following changes on will effect the
value stored in ) |
![${\cal R}_2\leftarrow [2] $](img11.gif) |
is set to the 2nd value in the sequence. |
![$[0] \leftarrow {\cal R}_1$](img12.gif) |
The 0th (zeroth) value in the sequence is changed to be the
same value that is in . |
 |
The content of is incremented by one. |
The number of changes is not limited and can be performed as many times as desired
on any register or sequence element.
Given a sequence, HW-1 starts with the
register having 0 (zero)
value and
the other two registers having arbitrary values. It works by
repeatatively going through a process cycle until a halt instruction is
executed. A process cycle is:
- 1.
- Take
as an instruction.
- 2.
- If this instruction is the halt instruction then terminate the process,
- 3.
- else perform the action associated with that instruction.
- 4.
- Continue with step (1).
If any instruction described in the following two pages
computes a result (at any cycle) that falls out of the
limits then the machine automatically halts.
The HW-1 accepts 17 instructions which are explained below. Instructions are
recognized as integers [0,1,...,16].
- Instruction
-
Halt the process..
- Instruction
-
Load
with the next number in the sequence.
![\begin{displaymath}
{\cal R}_1\leftarrow [{\cal I}+1] \;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img17.gif)
- Instruction
-
Load
with the next number in the
sequence.
![\begin{displaymath}
{\cal R}_2\leftarrow [{\cal I}+1] \;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img19.gif)
- Instruction
-
Load
with the sequence element which is at
the position given as the next number in the sequence.
![\begin{displaymath}
{\cal R}_1\leftarrow [[{\cal I}+1]] \;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img21.gif)
- Instruction
-
Load
with the sequence element which is at
the position given as the next number in the sequence.
![\begin{displaymath}
{\cal R}_2\leftarrow [[{\cal I}+1]] \;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img23.gif)
- Instruction
-
Load
with the content of
.

- Instruction
-
Load
with the sequence element which is at the position
.
![\begin{displaymath}
{\cal R}_1\leftarrow [{\cal R}_2] \;,\quad {\cal I}\leftarrow {\cal I}+ 1 \end{displaymath}](img27.gif)
- Instruction
-
Change the sequence element which is at the position
to be the content of
.
![\begin{displaymath}[{\cal R}_1]
\leftarrow {\cal R}_2\;,\quad {\cal I}\leftarrow {\cal I}+ 1 \end{displaymath}](img29.gif)
- Instruction
-
Change the sequence element which is at the position given as the next
number in the sequence to the content of
.
![\begin{displaymath}[[{\cal I}+1]
]\leftarrow {\cal R}_1\;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img31.gif)
- Instruction
-
Take the sequence element which is at the position given as the next
number in the sequence as the next instruction to be performed.
![\begin{displaymath}
{\cal I}\leftarrow [{\cal I}+ 1] \end{displaymath}](img33.gif)
- Instruction
-
If
contains zero continue with the sequence element following the
next one as
the next instruction to be performed, otherwise act like the
instruction 9.
![\begin{displaymath}
\begin{array}
{l@{\quad:\quad}l}
\mbox{if}\;\;{\cal R}_1=0 ...
...box{otherwise} & {\cal I}\leftarrow [{\cal I}+1]
\end{array} \end{displaymath}](img35.gif)
- Instruction
-
Increment
by the content of
.

- Instruction
-
Decrement
by the content of
.

- Instruction
-
Multiply
by the content of
.

- Instruction
-
Divide
by the content of
(integer division).

- Instruction
-
Change the sign of the value in
.

- Instruction
-
Compare the content of
with the content of
.

Next: An Example
Up: Ceng-111 9798 Fall Homework-1
Previous: REGULATIONS