Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
846 views
in Technique[技术] by (71.8m points)

assembly - Is it possible to use 32 bits registers/instructions in real mode?

I'm confused about a simple assembly problem when studying some simple os source code.

In this website: http://wiki.osdev.org/Babystep7 the following code is to switch from real mode to protected mode

mov  eax, cr0
or al,1
mov  cr0, eax

I know how to switch from real mode to protected mode.
But my question is since the program is still in the real mode, how can it use the 32 bit registers or instructions?

Is it possible to use 32 bits registers/instructions in real mode?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When the processor operates in real mode (as it is immediately after booting), it defaults to 16-bit code. However, this does not mean that you are unable to use 32-bit instructions.

There is an "operand size override" prefix (66h) that changes the default mode for a single instruction. When this prefix is used with an instruction executed in 16-bit real mode, it will switch the instruction to 32-bit. Conversely, when this prefix is used with an instruction executed in 32-bit protected mode, it will switch the instruction to 16 bit. (A similar prefix, 67h, works to override address sizes.)

Using this prefix, then, allows you to use 32-bit registers in 16-bit real mode. Your assembler will almost certainly emit this prefix automatically when you try and use 32-bit operands with an instruction when assembling 16-bit code.

Unfortunately, there is no such override prefix for 64-bit instructions, so these cannot be used in real mode. You need to switch into "long mode" to allow these.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...