flat assembler 1.67
Programmer’s Manual
Tomasz Grysztar
2
Contents
1 Introduction 5
1.1 Compiler overview . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1.1 System requirements . . . . . . . . . . . . . . . . . . . 5
1.1.2 Compiler usage . . . . . . . . . . . . . . . . . . . . . . 6
1.1.3 Editor options . . . . . . . . . . . . . . . . . . . . . . . 7
1.1.4 Executing compiler from command line . . . . . . . . . 8
1.1.5 Command line compiler messages . . . . . . . . . . . . 9
1.1.6 Output formats . . . . . . . . . . . . . . . . . . . . . . 10
1.2 Assembly syntax . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.1 Instruction syntax . . . . . . . . . . . . . . . . . . . . 11
1.2.2 Data definitions . . . . . . . . . . . . . . . . . . . . . . 12
1.2.3 Constants and labels . . . . . . . . . . . . . . . . . . . 13
1.2.4 Numerical expressions . . . . . . . . . . . . . . . . . . 15
1.2.5 Jumps and calls . . . . . . . . . . . . . . . . . . . . . . 16
1.2.6 Size settings . . . . . . . . . . . . . . . . . . . . . . . . 16
2 Instruction set 19
2.1 The x86 architecture instructions . . . . . . . . . . . . . . . . 19
2.1.1 Data movement instructions . . . . . . . . . . . . . . . 19
2.1.2 Type conversion instructions . . . . . . . . . . . . . . . 21
2.1.3 Binary arithmetic instructions . . . . . . . . . . . . . . 22
2.1.4 Decimal arithmetic instructions . . . . . . . . . . . . . 24
2.1.5 Logical instructions . . . . . . . . . . . . . . . . . . . . 25
2.1.6 Control transfer instructions . . . . . . . . . . . . . . . 27
2.1.7 I/O instructions . . . . . . . . . . . . . . . . . . . . . . 31
2.1.8 Strings operations . . . . . . . . . . . . . . . . . . . . . 31
2.1.9 Flag control instructions . . . . . . . . . . . . . . . . . 33
2.1.10 Conditional operations . . . . . . . . . . . . . . . . . . 34
2.1.11 Miscellaneous instructions . . . . . . . . . . . . . . . . 35
2.1.12 System instructions . . . . . . . . . . . . . . . . . . . . 36
2.1.13 FPU instructions . . . . . . . . . . . . . . . . . . . . . 38
3
4 CONTENTS
2.1.14 MMX instructions . . . . . . . . . . . . . . . . . . . . 43
2.1.15 SSE instructions . . . . . . . . . . . . . . . . . . . . . 45
2.1.16 SSE2 instructions . . . . . . . . . . . . . . . . . . . . . 50
2.1.17 SSE3 instructions . . . . . . . . . . . . . . . . . . . . . 53
2.1.18 AMD 3DNow! instructions . . . . . . . . . . . . . . . . 54
2.1.19 The x86-64 long mode instructions . . . . . . . . . . . 56
2.2 Control directives . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.2.1 Numerical constants . . . . . . . . . . . . . . . . . . . 59
2.2.2 Conditional assembly . . . . . . . . . . . . . . . . . . . 60
2.2.3 Repeating blocks of instructions . . . . . . . . . . . . . 62
2.2.4 Addressing spaces . . . . . . . . . . . . . . . . . . . . . 63
2.2.5 Other directives . . . . . . . . . . . . . . . . . . . . . . 66
2.2.6 Multiple passes . . . . . . . . . . . . . . . . . . . . . . 67
2.3 Preprocessor directives . . . . . . . . . . . . . . . . . . . . . . 69
2.3.1 Including source files . . . . . . . . . . . . . . . . . . . 69
2.3.2 Symbolic constants . . . . . . . . . . . . . . . . . . . . 70
2.3.3 Macroinstructions . . . . . . . . . . . . . . . . . . . . . 71
2.3.4 Structures . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.3.5 Repeating macroinstructions . . . . . . . . . . . . . . . 80
2.3.6 Conditional preprocessing . . . . . . . . . . . . . . . . 82
2.3.7 Order of processing . . . . . . . . . . . . . . . . . . . . 84
2.4 Formatter directives . . . . . . . . . . . . . . . . . . . . . . . 87
2.4.1 MZ executable . . . . . . . . . . . . . . . . . . . . . . 87
2.4.2 Portable Executable . . . . . . . . . . . . . . . . . . . 87
2.4.3 Common Object File Format . . . . . . . . . . . . . . 89
2.4.4 Executable and Linkable Format . . . . . . . . . . . . 90
3 Windows programming 91
3.1 Basic headers . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.1.1 Structures . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.1.2 Imports . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.1.3 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.1.4 Exports . . . . . . . . . . . . . . . . . . . . . . . . . . 99
3.1.5 Component Object Model . . . . . . . . . . . . . . . . 100
3.1.6 Resources . . . . . . . . . . . . . . . . . . . . . . . . . 101
3.1.7 Text encoding . . . . . . . . . . . . . . . . . . . . . . . 105
3.2 Extended headers . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.2.1 Procedure parameters . . . . . . . . . . . . . . . . . . 105
3.2.2 Structuring the source . . . . . . . . . . . . . . . . . . 107
Chapter 1
Introduction
This chapter contains all the most important information you need to begin
using the flat assembler. If you are experienced assembly language program-
mer, you should read at least this chapter before using this compiler.
1.1 Compiler overview
Flat assembler is a fast assembly language compiler for the x86 architecture
processors, which does multiple passes to optimize the size of generated ma-
chine code. It is self–compilable and versions for different operating systems
are provided. They are designed to be used from the system command line
and they should not differ in behavior.
This document describes also the IDE version designed for the Windows
system, which uses the graphical interface instead of console and has the
integrated editor. But from the view of compilation it has exactly the same
functionality as all the console versions, and so later parts (beginning from
1.2) of this document are common with other releases. The executable of
the IDE version is called fasmw.exe, while fasm.exe is the command line
version.
1.1.1 System requirements
All versions require the x86 architecture 32–bit processor (at least 80386),
although they can produce programs for the x86 architecture 16–bit proces-
sors, too. Windows console version requires any Win32 operating system,
while Windows GUI version requires the Win32 GUI system version 4.0 or
higher, so it should run on all systems compatible with Windows 95.
5