what is 16 bit code program in x86?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
descent
Posts: 10
Joined: Wed Sep 05, 2012 1:25 am
Location: Taiwan

what is 16 bit code program in x86?

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: what is 16 bit code program in x86?

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply