For the record, the pages relevant to protected mode which I am familiar with are
Protected Mode,
Journey To The Protected Land, and
GDT (which the 'Journey' page references). The GDT page has no code examples (though it does describe three data structures necessary for switching to 32-bit p-mode), while the code for the other two is:
"Protected Mode":
Code: Select all
cli ; disable interrupts
lgdt [gdtr] ; load GDT register with start address of Global Descriptor Table
mov eax, cr0
or al, 1 ; set PE (Protection Enable) bit in CR0 (Control Register 0)
mov cr0, eax
; Perform far jump to selector 08h (offset into GDT, pointing at a 32bit PM code segment descriptor)
; to load CS with proper PM32 descriptor)
JMP 08h:PModeMain
and
"Journey To The Protected Land":
Code: Select all
cli
lgdt [gdtr]
; for 386s and later
mov eax, cr0
or eax, 1
mov cr0,eax
; for 286s
smsw ax
or ax,1
lmsw ax
jmp 08h:main
The only real difference is that the former has more extensive commentary, while the latter gives the code for the (almost entirely obsolete) 16-bit protected mode as well as 32-bit protected mode.
I am curious as to which wiki page the OP is referring to, as none of those three use
LEA as can be seen here. In fact, a
search for the keyword "LEA" in the wiki's search tool turns up 21 hits, of which 5 are code examples for unrelated topics, 8 are from a sort of pocket repo in John Burger's private pages, one is a linker dump with the instruction in it, one is a reference to the Doug Lea implementation of
malloc() (a C function used for memory allocation), and the rest are all... well, pages which have my username in them for one reason or another.
Could you please provide a link for us, @starmanz? I suspect we are looking at very different things (as I said, the pages on 64-bit
Long Mode do use
LEA, but you would need to be in 32-bit protected mode first before withing to Long mode).
It might also help if you could post both the code you were trying to assemble, and the error messages you got, because if the assembler - especially a rock-solid standard assembler like Microsoft Macro Assembler - is throwing a fit over a common instruction, something weird is going on.
I suspect that the code you have is for either
NASM,
FASM, or
GAS, none of which take quite the same syntax as
MASM. Most OS-dev code is written with either GNU Assembler (the GNU Binutils assembler, generally used in conjunction with GCC) or NASM (Netwide Assembler, which is pretty much the
de facto standard Intel x86 assembler for anything not involving Visual Studio or GCC) in mind, so a copypasta won't usually work if you are using a different assembler. Flat Assembler (FASM) is pretty common, but it can assemble either MASM or NASM syntax so not as much code targets its own dialect.
Microsoft Macro Assembler is the assembler which Microsoft created in the 1980s as a separate commercial product, but later put under the Visual Studio distribution rules. It can be downloaded
here, but it requires Visual Studio 2005 to run (I am not really sure if it works with later editions, I am just going by what is on the web page).
MASM32 is a specific freeware spin-off of MASM which can be downloaded independently. .Note that the
license for MASM32 specifically forbids using it to developing programs targeting an operating system other than MS-DOS or MS-Windows, or commercial products of any kind not that it really stops anyone, but the more you know.