Up: Ceng-111 9697 Fall Homework-1
Previous: PROBLEM
Homework Page: Ceng-111 Homework's
If HW-1 is submitted
the below given sequence, it will compute the sum of its 2nd and 3rd elements, then
compare this sum with the 4th element. If the sum equals the 4th element then
the 5th element of the sequence is changed to 1 else it is changed
to 0.

We will go through each cycle of the process and explain it:
- Cycle 1
-
The machine starts now. So the registers are as follows:
Since
contains , the th (zeroth) element of the sequence,
is fetched. This will be our current instruction. Looking at the sequence you
may realize that this element is 9. Look at the definition of the
instruction 9 (given on the previous page), you will see that the action of the
instruction 9 is:
![\begin{displaymath}
{\cal I}\leftarrow [{\cal I}+ 1] \end{displaymath}](img33.gif)
is 1 and therefore
is simply [1], in other words
the 1st element of the sequence. That is 6. So the value in
is changed by the assignment operation to be 6. And now the registers are:
- Cycle 2
-
contains 6. The machine fetches [6] which is 3.
Instruction 3 is defined as:
![\begin{displaymath}
{\cal R}_1\leftarrow [[{\cal I}+1]] \;,\quad {\cal I}\leftarrow {\cal I}+ 2 \end{displaymath}](img21.gif)
The first assignment will change the content of
to be
.
Now do not panic!
was holding a value of 6 therefore the inner brackets
are nothing else but
![\begin{displaymath}[\;\underbrace{[{\cal I}+1]
}_{[6+1]}\;]
\qquad
\mbox{which is} \quad
[[7]] \end{displaymath}](img55.gif)
[7] is the 7th element of the sequence, namely 2. So
[[7]] is nothing but [2]. As you must have got used to it by now, this is
the 2nd element of the sequence, we go and fetch it. It is 12.
Since the first
assignment was
this value found on the right hand
side of the assignment, namely the 12, will be stored into
.
The second assignment increments the value of
by 2. Thus
is now
6+2 which is 8. At the end of this cycle the register contents are:
- Cycle 3
-
Since
is containing 8 we fetch [8] as the instruction of this cycle.
The 8th element of the sequence is 4. The instruction 4 is defined
similar to the instruction 3 but now it is the
register that receives
the value and not
. Going through a very similar argumentation
that we did for cycle 2,
we conclude that
will be assigned the value [3] which is 27.
Following this assignment, due to the second assignment in the definition of
instruction 4,
will be incremented by 2. That is how the registers look
like:
- Cycle 4
-
This cycle's instruction is [10]. Looking at the sequence we see that
this is the instruction 11. An instruction which adds the content of
to the content of
and assigns the sum to
(Please go and check
the definition of instruction 11). So the following operation is performed:

So,
is assigned a value of 39. Due to the definition of instruction
11, the
register is incremented by 1. At the end of this cycle the
registers read as:
- Cycle 5
-
Our instruction is [11] which is 4. We have had a similar instruction
in cycle 3. But this time
is 4 which means that
is assigned the value [4]. From the sequence we get that this value
is 39. So
. By the definition,
is incremented by 2.
Now the registers are:
- Cycle 6
-
The instruction of this cycle is [13], namely 16. This is a comparison
test performed between
and
. If they are equal
is changed to
, if the value of
is greater than the value of
then
is
changed to 1. If it is the third possibility, which is the only one left,
namely the case where the value of
is lesser than the value of
then
is changed to -1. In all cases
is incremented by one.
Following this definition and looking at the contents of the registers
we can conclude that HW-1 will change
to since both
and
have the value 39, hence they are equal. The registers are:
- Cycle 7
-
The instruction is [14] which reads as 10. This is a conditional jump.
If the register
contains a non zero value then the instruction of the
next cycle will be fetched from the sequence position that given at
. In our case the register
indeed contains a . So the jump will not take
place and the
register will simply be incremented by 2. (If the
jump would have taken place then
would be set to 20
and this would be the
position in the sequence from which the instruction for cycle 8
would be fetched)
So the registers are
- Cycle 8
-
The instruction is now [16], that is 2. This will load
with
. In our case this is
and will result in
. For an instruction 2,
will be incremented by 2. At the end of this
cycle we have in the registers
- Cycle 9
-
The instruction is [18] which is 9 an instruction that performs
an unconditional jump.
will be set to
and that is 22.
The registers are
- Cycle 10
-
The instruction is [22] which is 1. This instruction will load
with
. For our case this is 5. Instruction 1 increments
by 2. Now we have the registers as
- Cycle 11
-
We are almost at the end! The instruction in turn is [24], that is 7. An
instruction that performs
![\begin{displaymath}[{\cal R}_1]
\leftarrow{\cal R}_2\end{displaymath}](img75.gif)
and then increment
by one.
Due to this definition a
is carried out. And for the first
time we have changed a value in the sequence. Now the 5th element is no more
99 but 1. This was the claimed action of the HW-1 machine with
this example sequence. After a following incrementation of
the registers are:
- Cycle 12
-
Yes, unbeliveable but true, the machine stops and we all go home! The instruction
for this cycle is [25] which is simply 0. And this means halt.
the final picture of the sequence is:

For sake of completeness we display the registers at the moment of the halt:
Up: Ceng-111 9697 Fall Homework-1
Previous: PROBLEM
Homework Page: Ceng-111 Homework's