# Running an algorithm for fixed amount of time on RAM model machine

Suppose there is a deterministic algorithm of size $$O(1)$$ that operates on an input of size $$N$$ on a RAM model machine. I want to run the algorithm for $$O(\sqrt{N})$$ time, pause the algorithm, print "Hello", and then resume its execution, run it again for $$O(\sqrt{N})$$ time and repeat this cycle until the algorithm execution terminates. If the algorithm takes time $$T$$, then there would be $$O(T/\sqrt{N})$$ print statements.

It is obvious that an algorithm can be paused/resumed in constant time by storing/loading the content of all registers of the CPU in the memory. However, how is it possible to measure elapsed time in the RAM model and stop the algorithm after $$O(\sqrt{N})$$ steps? Does the RAM model support such an operation (a Turing machine definitely does)? Any reference or a simple argument is welcome!

One approach is to implement an interpreter for the RAM model, and then instrument the interpreter with a counter that keeps track of the number of instructions executed. I suspect it should be possible to build an interpreter that incurs at most a $$O(1)$$-factor slowdown, but I haven't checked the details (the instruction set is so primitive that the programming is ugly) -- you should be able to check whether the obvious approach works.