GNU Info

Info Node: (nasm.info)Section 9.3

(nasm.info)Section 9.3


Next: Chapter 10 Prev: Section 9.2 Up: Chapter 9
Enter node , (file) or (file)node

9.3. Other Mixed-Size Instructions
==================================

   The other way you might want to access data might be using the string
instructions (`LODSx', `STOSx' and so on) or the `XLATB' instruction.
These instructions, since they take no parameters, might seem to have
no easy way to make them perform 32-bit addressing when assembled in a
16-bit segment.

   This is the purpose of NASM's `a16' and `a32' prefixes. If you are
coding `LODSB' in a 16-bit segment but it is supposed to be accessing a
string in a 32-bit segment, you should load the desired address into
`ESI' and then code

             a32     lodsb

   The prefix forces the addressing size to 32 bits, meaning that
`LODSB' loads from `[DS:ESI]' instead of `[DS:SI]'. To access a string
in a 16-bit segment when coding in a 32-bit one, the corresponding `a16'
prefix can be used.

   The `a16' and `a32' prefixes can be applied to any instruction in
NASM's instruction table, but most of them can generate all the useful
forms without them. The prefixes are necessary only for instructions
with implicit addressing: `CMPSx' (*Note Section B.4.27::), `SCASx'
(*Note Section B.4.286::), `LODSx' (*Note Section B.4.141::), `STOSx'
(*Note Section B.4.303::), `MOVSx' (*Note Section B.4.178::), `INSx'
(*Note Section B.4.121::), `OUTSx' (*Note Section B.4.195::), and
`XLATB' (*Note Section B.4.334::). Also, the various push and pop
instructions (`PUSHA' and `POPF' as well as the more usual `PUSH' and
`POP') can accept `a16' or `a32' prefixes to force a particular one of
`SP' or `ESP' to be used as a stack pointer, in case the stack segment
in use is a different size from the code segment.

   `PUSH' and `POP', when applied to segment registers in 32-bit mode,
also have the slightly odd behaviour that they push and pop 4 bytes at
a time, of which the top two are ignored and the bottom two give the
value of the segment register being manipulated. To force the 16-bit
behaviour of segment-register push and pop instructions, you can use the
operand-size prefix `o16':

             o16 push    ss
             o16 push    ds

   This code saves a doubleword of stack space by fitting two segment
registers into the space which would normally be consumed by pushing
one.

   (You can also use the `o32' prefix to force the 32-bit behaviour when
in 16-bit mode, but this seems less useful.)


automatically generated by info2www version 1.2.2.9