as: i386-16bit

1 
1 9.15.14 Writing 16-bit Code
1 ---------------------------
1 
1 While 'as' normally writes only "pure" 32-bit i386 code or 64-bit x86-64
1 code depending on the default configuration, it also supports writing
1 code to run in real mode or in 16-bit protected mode code segments.  To
1 do this, put a '.code16' or '.code16gcc' directive before the assembly
1 language instructions to be run in 16-bit mode.  You can switch 'as' to
1 writing 32-bit code with the '.code32' directive or 64-bit code with the
1 '.code64' directive.
1 
1    '.code16gcc' provides experimental support for generating 16-bit code
1 from gcc, and differs from '.code16' in that 'call', 'ret', 'enter',
1 'leave', 'push', 'pop', 'pusha', 'popa', 'pushf', and 'popf'
1 instructions default to 32-bit size.  This is so that the stack pointer
1 is manipulated in the same way over function calls, allowing access to
1 function parameters at the same stack offsets as in 32-bit mode.
1 '.code16gcc' also automatically adds address size prefixes where
1 necessary to use the 32-bit addressing modes that gcc generates.
1 
1    The code which 'as' generates in 16-bit mode will not necessarily run
1 on a 16-bit pre-80386 processor.  To write code that runs on such a
1 processor, you must refrain from using _any_ 32-bit constructs which
1 require 'as' to output address or operand size prefixes.
1 
1    Note that writing 16-bit code instructions by explicitly specifying a
1 prefix or an instruction mnemonic suffix within a 32-bit code section
1 generates different machine instructions than those generated for a
1 16-bit code segment.  In a 32-bit code section, the following code
1 generates the machine opcode bytes '66 6a 04', which pushes the value
1 '4' onto the stack, decrementing '%esp' by 2.
1 
1              pushw $4
1 
1    The same code in a 16-bit code section would generate the machine
1 opcode bytes '6a 04' (i.e., without the operand size prefix), which is
1 correct since the processor default operand size is assumed to be 16
1 bits in a 16-bit code section.
1