Self-modified code is not guaranteed to run. I explained it in my answer to previous question: How can I write a Self-Modifying code ic C?
]; see also all the answers you got.
This question is different, but essentially this is re-post, as you should have used "Improve question" on the page of your previous question. May be you did not realize that writing self-modified code makes no sense? Well, not you're dealing with the consequences.
It totally depends on operating system; and good operating systems will use the features of CPU to prevent self-modified code. It can be absolutely prevented. What OS do you use trying to run this code? Why do you try to do it? Not really fruitful exercise, I would say. :-)