Copyright (C) 2000-2012 |
GNU Info (nasm.info)Section 5.15.1. `BITS': Specifying Target Processor Mode ============================================= The `BITS' directive specifies whether NASM should generate code designed to run on a processor operating in 16-bit mode, or code designed to run on a processor operating in 32-bit mode. The syntax is `BITS 16' or `BITS 32'. In most cases, you should not need to use `BITS' explicitly. The `aout', `coff', `elf' and `win32' object formats, which are designed for use in 32-bit operating systems, all cause NASM to select 32-bit mode by default. The `obj' object format allows you to specify each segment you define as either `USE16' or `USE32', and NASM will set its operating mode accordingly, so the use of the `BITS' directive is once again unnecessary. The most likely reason for using the `BITS' directive is to write 32- bit code in a flat binary file; this is because the `bin' output format defaults to 16-bit mode in anticipation of it being used most frequently to write DOS `.COM' programs, DOS `.SYS' device drivers and boot loader software. You do _not_ need to specify `BITS 32' merely in order to use 32- bit instructions in a 16-bit DOS program; if you do, the assembler will generate incorrect code because it will be writing code targeted at a 32- bit platform, to be run on a 16-bit one. When NASM is in `BITS 16' state, instructions which use 32-bit data are prefixed with an 0x66 byte, and those referring to 32-bit addresses have an 0x67 prefix. In `BITS 32' state, the reverse is true: 32-bit instructions require no prefixes, whereas instructions using 16-bit data need an 0x66 and those working on 16-bit addresses need an 0x67. The `BITS' directive has an exactly equivalent primitive form, `[BITS 16]' and `[BITS 32]'. The user-level form is a macro which has no function other than to call the primitive form. Note that the space is neccessary, `BITS32' will _not_ work!
automatically generated by info2www version 1.2.2.9 |