To ask question about running instruction in P-Mode?

Started by leetow2003, April 13, 2011, 02:22:16 PM

Previous topic - Next topic

leetow2003

My codes run well,look:
.386P
cseg    segment   use16     
        assume  cs:cseg
start:
     ;Enter into P-Mode
     mov eax,cr0
     or eax,1
     mov cr0,eax  ;(1)
     ;
     mov ax,10    ;(2)
     mov bx,20
     
     ;Return to R-Mode
     mov eax,cr0
     and eax,0fffffffeh
     mov cr0,eax
         
     mov  ax,4c00h         
     int 21h
cseg  ends
      end  start

After executing instruction:mov cr0,eax,it enters into P-Mode,just now the value
of segment CS is not changed,I suppose it is 2000h,and CPU fetch next instruction
according to CS,and just now the valuse(such as 2000h) is regarded as selector,
so CPU should not fetch the instruction:mov ax,10,but my codes run well,why?

Tedd

The values in segment registers are always selectors. In real mode, they're 'fixed' so they work correctly, but they're still really just selectors.
When you switch to protected-mode, the segment registers still have their old values (valid selectors). So they still work, and code continues to execute from CS - because CS still has the old selector.
Their values won't change until they're explicitly reloaded with new valid protected-mode selectors. For the other segment registers this is simple, but for CS it must be done through executing a far jump (usually just to the next instruction.)
No snowflake in an avalanche feels responsible.