Sorting Block Diagram
Sorting Block Diagram
Firstly, in1 comes from the memory and in2 comes from FPGA. We use the inbuilt comparator to
compare both 8 bit numbers. The output z is 1 if in1>in2 else it is 0.When z is 1, ret is in2 otherwise
ret is in1.We basically want one output out of in2 and in1. When ret=1, then a=1 else a is 0. When a
is 1, in1 is returned otherwise in2 is returned. The output from here again goes to memory as
mentioned earlier. The same process is repeated for further basic memory block.
Example
Let us say we have 5 numbers 4, 2, 10, 6, 1. We are supposed to sort these numbers using the
mentioned algorithm.
1. Initially, in1 is empty, i.e. nothing is stored in in1. When 4 comes as input, 4 is stored in the lowest
memory block out of let us say 5 memory blocks.
2. Now, we have 2 as input, we compare it with in1, i.e. 4. In this case, in2, i.e. 2 is smaller.
4>2=>z=1. Since z is 1, ret is now in2. and since a is 0, ret =in2 is only returned. After returning ret to
the memory blocks, ret goes to the next phase and the other value gets stored in the memory block.
In the next phase, since the memory block is empty, 2 is directly stored.
3.In this cycle, we have incoming value 10. Firstly we repeat the above process and check which one
is smaller. Here, since 4<10, the returned value is 4 and 10 gets stored in the memory block. Now we
compare 4 and 2. In this case, 4 gets stored in the memery block and 2 is returned to the next phase.
Since we have an empty block now, we store 2 there.
4.Now we have 6 as input. In the first pass, we have 6 returned to the next phase and 10 remains
stored there. Next we compare 4 and 6 where 4 is returned to the next phase and 6 gets stored
there. In the next phase, 4 and 2 are compared where 2 is the returned value and 4 gets stored.2
again gets stored in the empty block.
5. The last input is 1. 1 is the smallest of these numbers and so, after following the above procedure,
1 is returned in every phase and get stored in the last empty block in the last phase.
This way we have the sorted block as 1, 2, 4, 6, 10.