1YASM_ARCH(7)             Yasm Supported Architectures             YASM_ARCH(7)
2
3
4

NAME

6       yasm_arch - Yasm Supported Target Architectures
7

SYNOPSIS

9       yasm -a arch [-m machine] ...
10

DESCRIPTION

12       The standard Yasm distribution includes a number of modules for
13       different target architectures. Each target architecture can support
14       one or more machine architectures.
15
16       The architecture and machine are selected on the yasm(1) command line
17       by use of the -a arch and -m machine command line options,
18       respectively.
19
20       The machine architecture may also automatically be selected by certain
21       object formats. For example, the “elf32” object format selects the
22       “x86” machine architecture by default, while the “elf64” object format
23       selects the “amd64” machine architecture by default.
24

X86 ARCHITECTURE

26       The “x86” architecture supports the IA-32 instruction set and
27       derivatives and the AMD64 instruction set. It consists of two machines:
28       “x86” (for the IA-32 and derivatives) and “amd64” (for the AMD64 and
29       derivatives). The default machine for the “x86” architecture is the
30       “x86” machine.
31
32   BITS Setting
33       The x86 architecture BITS setting specifies to Yasm the processor mode
34       in which the generated code is intended to execute. x86 processors can
35       run in three different major execution modes: 16-bit, 32-bit, and on
36       AMD64-supporting processors, 64-bit. As the x86 instruction set
37       contains portions whose function is execution-mode dependent (such as
38       operand-size and address-size override prefixes), Yasm cannot assemble
39       x86 instructions correctly unless it is told by the user in what
40       processor mode the code will execute.
41
42       The BITS setting can be changed in a variety of ways. When using the
43       NASM-compatible parser, the BITS setting can be changed directly via
44       the use of the BITS xx assembler directive. The default BITS setting is
45       determined by the object format in use.
46
47   BITS 64 Extensions
48       The AMD64 architecture is a new 64-bit architecture developed by AMD,
49       based on the 32-bit x86 architecture. It extends the original x86
50       architecture by doubling the number of general purpose and SIMD
51       registers, extending the arithmetic operations and address space to 64
52       bits, as well as other features.
53
54       Recently, Intel has introduced an essentially identical version of
55       AMD64 called EM64T.
56
57       When an AMD64-supporting processor is executing in 64-bit mode, a
58       number of additional extensions are available, including extra general
59       purpose registers, extra SSE2 registers, and RIP-relative addressing.
60
61       Yasm extends the base NASM syntax to support AMD64 as follows. To
62       enable assembly of instructions for the 64-bit mode of AMD64
63       processors, use the directive BITS 64. As with NASM's BITS directive,
64       this does not change the format of the output object file to 64 bits;
65       it only changes the assembler mode to assume that the instructions
66       being assembled will be run in 64-bit mode. To specify an AMD64 object
67       file, use -m amd64 on the Yasm command line, or explicitly target a
68       64-bit object format such as -f win64 or -f elf64.
69
70       Register Changes
71              The additional 64-bit general purpose registers are named
72              r8-r15. There are also 8-bit (rXb), 16-bit (rXw), and 32-bit
73              (rXd) subregisters that map to the least significant 8, 16, or
74              32 bits of the 64-bit register. The original 8 general purpose
75              registers have also been extended to 64-bits: eax, edx, ecx,
76              ebx, esi, edi, esp, and ebp have new 64-bit versions called rax,
77              rdx, rcx, rbx, rsi, rdi, rsp, and rbp respectively. The old
78              32-bit registers map to the least significant bits of the new
79              64-bit registers.
80
81              New 8-bit registers are also available that map to the 8 least
82              significant bits of rsi, rdi, rsp, and rbp. These are called
83              sil, dil, spl, and bpl respectively. Unfortunately, due to the
84              way instructions are encoded, these new 8-bit registers are
85              encoded the same as the old 8-bit registers ah, dh, ch, and bh.
86              The processor tells which is being used by the presence of the
87              new REX prefix that is used to specify the other extended
88              registers. This means it is illegal to mix the use of ah, dh,
89              ch, and bh with an instruction that requires the REX prefix for
90              other reasons. For instance:
91
92                  add ah, [r10]
93
94              (NASM syntax) is not a legal instruction because the use of r10
95              requires a REX prefix, making it impossible to use ah.
96
97              In 64-bit mode, an additional 8 SSE2 registers are also
98              available. These are named xmm8-xmm15.
99
100       64 Bit Instructions
101              By default, most operations in 64-bit mode remain 32-bit;
102              operations that are 64-bit usually require a REX prefix (one bit
103              in the REX prefix determines whether an operation is 64-bit or
104              32-bit). Thus, essentially all 32-bit instructions have a 64-bit
105              version, and the 64-bit versions of instructions can use
106              extended registers “for free” (as the REX prefix is already
107              present). Examples in NASM syntax:
108
109                  mov eax, 1  ; 32-bit instruction
110
111                  mov rcx, 1  ; 64-bit instruction
112
113              Instructions that modify the stack (push, pop, call, ret, enter,
114              and leave) are implicitly 64-bit. Their 32-bit counterparts are
115              not available, but their 16-bit counterparts are. Examples in
116              NASM syntax:
117
118                  push eax  ; illegal instruction
119
120                  push rbx  ; 1-byte instruction
121
122                  push r11  ; 2-byte instruction with REX prefix
123
124       Implicit Zero Extension
125              Results of 32-bit operations are implicitly zero-extended to the
126              upper 32 bits of the corresponding 64-bit register. 16 and 8 bit
127              operations, on the other hand, do not affect upper bits of the
128              register (just as in 32-bit and 16-bit modes). This can be used
129              to generate smaller code in some instances. Examples in NASM
130              syntax:
131
132                  mov ecx, 1  ; 1 byte shorter than mov rcx, 1
133
134                  and edx, 3  ; equivalent to and rdx, 3
135
136       Immediates
137              For most instructions in 64-bit mode, immediate values remain 32
138              bits; their value is sign-extended into the upper 32 bits of the
139              target register prior to being used. The exception is the mov
140              instruction, which can take a 64-bit immediate when the
141              destination is a 64-bit register. Examples in NASM syntax:
142
143                  add rax, 1           ; optimized down to signed 8-bit
144
145                  add rax, dword 1     ; force size to 32-bit
146
147                  add rax, 0xffffffff  ; sign-extended 32-bit
148
149                  add rax, -1          ; same as above
150
151                  add rax, 0xffffffffffffffff ; truncated to 32-bit (warning)
152
153                  mov eax, 1           ; 5 byte
154
155                  mov rax, 1           ; 5 byte (optimized to signed 32-bit)
156
157                  mov rax, qword 1     ; 10 byte (forced 64-bit)
158
159                  mov rbx, 0x1234567890abcdef ; 10 byte
160
161                  mov rcx, 0xffffffff  ; 10 byte (does not fit in signed 32-bit)
162
163                  mov ecx, -1          ; 5 byte, equivalent to above
164
165                  mov rcx, sym         ; 5 byte, 32-bit size default for symbols
166
167                  mov rcx, qword sym   ; 10 byte, override default size
168
169              The handling of mov reg64, unsized immediate is different
170              between YASM and NASM 2.x; YASM follows the above behavior,
171              while NASM 2.x does the following:
172
173                  add rax, 0xffffffff  ; sign-extended 32-bit immediate
174
175                  add rax, -1          ; same as above
176
177                  add rax, 0xffffffffffffffff ; truncated 32-bit (warning)
178
179                  add rax, sym         ; sign-extended 32-bit immediate
180
181                  mov eax, 1           ; 5 byte (32-bit immediate)
182
183                  mov rax, 1           ; 10 byte (64-bit immediate)
184
185                  mov rbx, 0x1234567890abcdef ; 10 byte instruction
186
187                  mov rcx, 0xffffffff  ; 10 byte instruction
188
189                  mov ecx, -1          ; 5 byte, equivalent to above
190
191                  mov ecx, sym         ; 5 byte (32-bit immediate)
192
193                  mov rcx, sym         ; 10 byte instruction
194
195                  mov rcx, qword sym   ; 10 byte (64-bit immediate)
196
197       Displacements
198              Just like immediates, displacements, for the most part, remain
199              32 bits and are sign extended prior to use. Again, the exception
200              is one restricted form of the mov instruction: between the
201              al/ax/eax/rax register and a 64-bit absolute address (no
202              registers allowed in the effective address). In NASM syntax, use
203              of the 64-bit absolute form requires [qword]. Examples in NASM
204              syntax:
205
206                  mov eax, [1]    ; 32 bit, with sign extension
207
208                  mov al, [rax-1] ; 32 bit, with sign extension
209
210                  mov al, [qword 0x1122334455667788] ; 64-bit absolute
211
212                  mov al, [0x1122334455667788] ; truncated to 32-bit (warning)
213
214       RIP Relative Addressing
215              In 64-bit mode, a new form of effective addressing is available
216              to make it easier to write position-independent code. Any memory
217              reference may be made RIP relative (RIP is the instruction
218              pointer register, which contains the address of the location
219              immediately following the current instruction).
220
221              In NASM syntax, there are two ways to specify RIP-relative
222              addressing:
223
224                  mov dword [rip+10], 1
225
226              stores the value 1 ten bytes after the end of the instruction.
227              10 can also be a symbolic constant, and will be treated the same
228              way. On the other hand,
229
230                  mov dword [symb wrt rip], 1
231
232              stores the value 1 into the address of symbol symb. This is
233              distinctly different than the behavior of:
234
235                  mov dword [symb+rip], 1
236
237              which takes the address of the end of the instruction, adds the
238              address of symb to it, then stores the value 1 there. If symb is
239              a variable, this will not store the value 1 into the symb
240              variable!
241
242              Yasm also supports the following syntax for RIP-relative
243              addressing:
244
245                  mov [rel sym], rax  ; RIP-relative
246
247                  mov [abs sym], rax  ; not RIP-relative
248
249              The behavior of:
250
251                  mov [sym], rax
252
253              Depends on a mode set by the DEFAULT directive, as follows. The
254              default mode is always "abs", and in "rel" mode, use of
255              registers, an fs or gs segment override, or an explicit "abs"
256              override will result in a non-RIP-relative effective address.
257
258                  default rel
259
260                  mov [sym], rbx      ; RIP-relative
261
262                  mov [abs sym], rbx  ; not RIP-relative (explicit override)
263
264                  mov [rbx+1], rbx    ; not RIP-relative (register use)
265
266                  mov [fs:sym], rbx   ; not RIP-relative (fs or gs use)
267
268                  mov [ds:sym], rbx   ; RIP-relative (segment, but not fs or gs)
269
270                  mov [rel sym], rbx  ; RIP-relative (redundant override)
271
272                  default abs
273
274                  mov [sym], rbx      ; not RIP-relative
275
276                  mov [abs sym], rbx  ; not RIP-relative
277
278                  mov [rbx+1], rbx    ; not RIP-relative
279
280                  mov [fs:sym], rbx   ; not RIP-relative
281
282                  mov [ds:sym], rbx   ; not RIP-relative
283
284                  mov [rel sym], rbx  ; RIP-relative (explicit override)
285
286       Memory references
287              Usually the size of a memory reference can be deduced by which
288              registers you're moving--for example, "mov [rax],ecx" is a
289              32-bit move, because ecx is 32 bits. YASM currently gives the
290              non-obvious "invalid combination of opcode and operands" error
291              if it can't figure out how much memory you're moving. The fix in
292              this case is to add a memory size specifier: qword, dword, word,
293              or byte.
294
295              Here's a 64-bit memory move, which sets 8 bytes starting at rax:
296
297                  mov qword [rax], 1
298
299              Here's a 32-bit memory move, which sets 4 bytes:
300
301                  mov dword [rax], 1
302
303              Here's a 16-bit memory move, which sets 2 bytes:
304
305                  mov word [rax], 1
306
307              Here's an 8-bit memory move, which sets 1 byte:
308
309                  mov byte [rax], 1
310

LC3B ARCHITECTURE

312       The “lc3b” architecture supports the LC-3b ISA as used in the ECE 312
313       (now ECE 411) course at the University of Illinois, Urbana-Champaign,
314       as well as other university courses. See
315       http://courses.ece.uiuc.edu/ece411/ for more details and example code.
316       The “lc3b” architecture consists of only one machine: “lc3b”.
317

SEE ALSO

319       yasm(1)
320

BUGS

322       When using the “x86” architecture, it is overly easy to generate AMD64
323       code (using the BITS 64 directive) and generate a 32-bit object file
324       (by failing to specify -m amd64 on the command line or selecting a
325       64-bit object format). Similarly, specifying -m amd64 does not default
326       the BITS setting to 64. An easy way to avoid this is by directly
327       specifying a 64-bit object format such as -f elf64.
328

AUTHOR

330       Peter Johnson <peter@tortall.net>
331           Author.
332
334       Copyright © 2004, 2005, 2006, 2007 Peter Johnson
335
336
337
338
339Yasm                             October 2006                     YASM_ARCH(7)
Impressum