Is it possible to use EAX
,EBX
,... in x86_32 virtual 8086 or real mode?
I know, that these registers have the size of 32 bits (and, that of course their non-Extended parts are 16 bits wide), however it is not explained in class, that in which modes they can be used, only that FS
and GS
are allowed only in protected mode.
Yes. The operand-size and address-size machine-code prefixes work in all modes including pure real mode, on 386-compatible CPUs. In 16-bit mode, the default operand-size and address-size are 16-bit. Those prefixes flip to the other size.
Of course a 286 or earlier wouldn't know what to do with 66
or 67
prefixes so they're often avoided in 16-bit code intended to be portable to older CPUs. (Including any non-Intel CPU that's 186 but not 386 compatible).
But if you only care about running on 386-compatible CPUs, yes you can use 32-bit operand-size and address-size, with registers like EAX. Including addressing modes like [EAX + ECX*2]
. Use that when it saves instructions and/or code-size. (Note that the segment size limit is still set at 64k in Real Mode, so 32-bit addressing modes can't exceed that unless you switch to protected mode and change it, then return to real mode. That's call "unreal mode")
Also, FS and GS can be freely used in any mode (again on 386-compabible CPUs only). In machine code, they have their own prefixes like ss:
or es:
overrides, and for mov to/from segment registers they also have register numbers.
This is all documented in Intel's manuals; encodings for segment prefixes, and of register operands for 8, 16, and 32 operand size.
https://en.wikipedia.org/wiki/X86-64#Operating_modes has a nice table of which operand-sizes (and address-sizes) are supported in which mode.