Page 1 of 1

what is 16 bit code program in x86?

Posted: Wed Jan 23, 2013 9:31 pm
by descent
cpu: intel i3
toolchain: gnu toolchain

When I write 16 bit code, I use .code16 in gas, but I still can use 32 bit register like %eax ...
I compare .code16 and .code32 machine code, difference is prefix.
Is 16/32 bit code difference address length?

But in 8086, there is no 32 bit registers to use.

Re: what is 16 bit code program in x86?

Posted: Wed Jan 23, 2013 10:33 pm
by thepowersgang
The x86 is a little confusing in places. Using '.code16' in GAS makes it emit code for 'Real Mode' (aka 16-bit mode), but doesn't restrict it to the 8086's feature set. More modern processors support accessing 32-bit registers using size overrides as you noticed by inspecting the generated code. If you'd experimented more (and were quite observant), you'd probably also see other differences in the generated code, but in most cases the difference is the default operand and adderess size.