1

I understand that most of the modern CPU's are Turing complete (if given an infinite memory and time).

From the below, I am going to assume that the amount of memory is infinite or as much sufficient and the time is given enough when I say Turing complete.

This means any modern CPU's can simulate what the universal Turing machine can do, and the universal Turing machine can simulate what the modern CPU's do.

How would a Turing machine implement functions such as memory protection, interrupts, protection rings, real timer, etc. that are implemented on the hardware of the modern CPU's?

Or I could ask, how would an old CPU without those hardware functions implement such equivalent features by software? (Since old CPU's are Turing complete)

I am confused because some answers on the Internet says any Turing machines can implement those (seems true to me but how?), while some says implementing a real timer and interrupts is impossible (then modern CPU's do things that a Turing machine can't perform?).

Please consider the processor speed is as fast as it needs, the memory is sufficient, and the time is given enough.

user13397022
  • 107
  • 1
  • 5
  • 1
    Just imagine writing a software emulator for a machine with memory protection. Every time the program being emulated attempts to access memory, you go and look in your protections table to see if the access should be allowed. If yes, you emulate the read or write; if no, you emulate a jump to the exception handler. It does mean that your emulator is many times slower than a real machine, and completely impractical for real life - but time is no object here. – Nate Eldredge Oct 29 '21 at 18:00
  • 1
    As for interrupts and stuff, it's just not in the model of a Turing machine, which assumes its entire input is the contents of the tape. For a real machine, the information about what interrupts arrive, and when, is part of its "input". You could emulate this by feeding the Turing machine a tape containing a list of all interrupts that will occur during its run, and at what time in clock cycles. So every virtual clock cycle, it goes and iterates over the list of interrupts, and handles any that will arrive this cycle. – Nate Eldredge Oct 29 '21 at 18:03
  • Indeed, real-life CPUs usually document the way they handle protection, privileges, interrupts, etc, by giving pseudocode for what the CPU does in each case. So all you have to do is write real code that implements the pseudocode. – Nate Eldredge Oct 29 '21 at 18:05
  • 2
    I’m voting to close this question because it should be asked on [cs.se]. – Peter O. Oct 29 '21 at 21:18
  • I'd recommend memory-mapped I/O: your machine's tape has two special memory cells. If the first of them is set to 1, then the second contains one bit of input. You read it, then clear the first i.e. set it to 0. That way you can get an arbitrary stream of bits from outside the machine, which could encode interrupts and whatever else you desire. You could use two more cells for the opposite direction. To simplify things you could use one or two pairs of cells per device. You'd configure each device's address using jumpers… – MvG Nov 01 '21 at 07:10

0 Answers0