I have this assembly code (on Linux):
.globl _start
_start:
cli
xorw %ax,%ax # Set %ax to zero
movw %ax,%ds
movw %ax,%es
movw %ax,%ss
I first add .code16
at the top to generate a 16-bit code and then replace that with .code32
to generate a 32-bit code.
I compile these with these two commands:
gcc -m32 -nostdinc -c file.s
ld -m elf_i386 -o file.exe file.o
And, then I examine with
objdump -d file.exe
For the first case (.code16
) I get this output:
08048054 <_start>:
8048054: fa cli
8048055: 31 c0 xor %eax,%eax
8048057: 8e d8 mov %eax,%ds
8048059: 8e c0 mov %eax,%es
804805b: 8e d0 mov %eax,%ss
For the second case (.code32
) I get this output:
08048054 <_start>:
8048054: fa cli
8048055: 66 31 c0 xor %ax,%ax
8048058: 8e d8 mov %eax,%ds
804805a: 8e c0 mov %eax,%es
804805c: 8e d0 mov %eax,%ss
I understand the 66
operand prefix part. What confuses me is the assembly mnemonics printed. Shouldn't xor %eax, %eax
be printed for the .code32
case as well? Or, should it be printing xor %ax, %ax
for .code16
case? Can somebody please clarify?