I have learned that Turing Machine is good to use because it has the "same power" as out computers.
Also,my lecture said that every C code can be executed by some Turing Machine.
I believe that is the key for leaning this subject, but i didn't found any proof for that.
What is the algorithm to translate a C code to some Turing machine which execute it and gives the same output for as the c code will give for some input?
An algorithm that converts (arbitrary) C code into a turing table would be quite difficult to write, and I think that it would not be very instructive. I would rather suggest to consider the following:
a = b + c;
. The CPU can only do "simple things" such as arithmetic, access memory, and jumps to different locations in the program. The last bit is used to implement loops and if-then-else constructs: "If some condition is true, jump to this location and execute the code there, otherwise, jump to another location".#@||||#|||||#
(#
are blank parts of the tape, @
is the head), To add the numbers, our machine just needs to remove the inner #
, replace it by |
and remove one |
from either start or end of the tape to get #@|||||||||#
. With the turing instruction table, you are able to make decisions depending on the current state of the tape: If we are in state A and see a |, do this (write a symbol, move head, change state), else, do something else.So my suggestion is that you don't try to get from C to a turing machine, but to imagine/look up/ask what a real world CPU has to do to execute a certain C statement, and then figure out that a Turing machine can do the same thing.
Yet another approach: A real world computer that executes compiled C programs consists of
A Turing machine consists of
I hope this helps.