Protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
spiner900
Member
Member
Posts: 26
Joined: Mon Mar 09, 2009 10:47 am

Protected mode

Post by spiner900 »

Hey, I have only one question. When we try to set the first bit of CR0, many web site do
MOV EAX, CR0. But EAX is a 32 bit register and in rMode we works with 16 bit register. Why this is a good instruction ?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Protected mode

Post by AJ »

Hi,

When you 'MOV EAX, CR0' in real mode, your assembler automatically adds a 32 bit prefix to extend the operation size. There are many circumstances where it's useful to work with the full 32 bit registers even in real mode.

Cheers,
Adam
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Protected mode

Post by skyking »

Because in real mode you can work with 32-bits registers as well as you in protected mode can work with 16-bits registers. The operand size prefix is used to use the size that is not default.
spiner900
Member
Member
Posts: 26
Joined: Mon Mar 09, 2009 10:47 am

Re: Protected mode

Post by spiner900 »

Ok, but rMode is also in 32 bit ??
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Protected mode

Post by AJ »

Hi,

In real mode, the default operand size (registers and stack operations) and addressing mode is 16 bit. You are stuck with the 16 bit addressing mode in pure Real Mode, but the default operand size can be overridden.

Cheers,
Adam
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected mode

Post by Combuster »

AJ wrote:You are stuck with the 16 bit addressing mode in pure Real Mode, but the default operand size can be overridden.
Not entirely true, you can use 32-bit addressing in pure real mode - you just have to be aware of the real mode access limit preventing you from using an effective address over 64k. As with 32 bit code, the assembler will add the necessary prefixes if you use [EAX+4*EBX] in real mode to make it work (just make sure that eax+4*ebx < 65536 when that gets executed).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply