Question

It seems that the following is a common method given in many tutorials on switching a processor from 16-bit to 32-bit:

    mov     eax, cr0            ; set bit 0 in CR0-go to pmode
    or      eax, 1
    mov     cr0, eax

Why wouldn't I simply do the following:

    or      cr0, 1

Is there something I'm missing? Possibly the only thing I can think of is that I cannot perform an operation like this on the cr0 register.

Was it helpful?

Solution

The or operator doesn't have an op-code in which it can access the CR0 register. (It's not possible to perform this operation on the CR0 register.)

That's why the mov is there: there exists an op-code which can access the CR0 register.

OTHER TIPS

or is a comparison operator where it actually takes two values and creates a solution. The solution is stored in eax after the or operation is completed. Or can not be used a a storage register as it is a specialized operation and is ruled by scope and that is why it is good practice to take its results and immediately store the new value right after the process completes.

Elaborating on what was said about using or with operands, it has no capacity for storage it merely performs an operation on data that id already present. Think of or like a button on a calculator where it has one operation like add, subtract, multiply or divide. The code is the calculator that manages the memory buffers; etc. and utilizes the services of an operator/operation on data within its memory stores and when finished gets the return results for further operations or finished output to the user.

The question here is a logical one as well as the code being well thought out and concise -- nice stuff.

Try this and force 1 to cr0 in 1 command:

MOV cr0, 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top