Search code examples
assemblyreal-mode

What happens when we try to set the register of the currently executing code?


CodeProject has an article:

CS always holds the segment of the currently executing code. You cannot set CS by using, say, mov cs,ax. When you call a function that resides in another segment (FAR call), or when you jump to another segment (FAR jump), CS changes.

So what happens when we try to modify the register directly by using mov cs, ax?


Solution

  • According to the Intel manual, you get an "undefined opcode" exception:

    mov — Move

    { Protected Mode, Real-Address Mode, Virtual-8086 Mode, 64-Bit Mode} Excpetions

    #UD If attempt is made to load the CS register.