Add "alignr" standard macro (using resb)
[platform/upstream/nasm.git] / standard.mac
1 ; Standard macro set for NASM -*- nasm -*-
2
3 ; Macros to make NASM ignore some TASM directives before the first include
4 ; directive.
5
6     %idefine IDEAL
7     %idefine JUMPS
8     %idefine P386
9     %idefine P486
10     %idefine P586
11     %idefine END
12
13 ; This is a magic token which indicates the end of the TASM macros
14 *END*TASM*MACROS*
15
16 ; Note that although some user-level forms of directives are defined
17 ; here, not all of them are: the user-level form of a format-specific
18 ; directive should be defined in the module for that directive.
19
20 ; These three need to be defined, though the actual definitions will
21 ; be constantly updated during preprocessing.
22 %define __FILE__
23 %define __LINE__
24 %define __BITS__
25
26 %define __SECT__                ; it ought to be defined, even if as nothing
27
28 %imacro section 1+.nolist
29 %define __SECT__ [section %1]
30           __SECT__
31 %endmacro
32 %imacro segment 1+.nolist
33 %define __SECT__ [segment %1]
34           __SECT__
35 %endmacro
36
37 %imacro absolute 1+.nolist
38 %define __SECT__ [absolute %1]
39           __SECT__
40 %endmacro
41
42 %imacro struc 1.nolist
43 %push
44 %define %$strucname %1
45 [absolute 0]
46 %$strucname:                    ; allow definition of `.member' to work sanely
47 %endmacro 
48 %imacro endstruc 0.nolist
49 %{$strucname}_size:
50 %pop
51 __SECT__
52 %endmacro
53
54 %imacro istruc 1.nolist
55 %push
56 %define %$strucname %1
57 %$strucstart:
58 %endmacro
59 %imacro at 1-2+.nolist
60           times %1-($-%$strucstart) db 0
61           %2
62 %endmacro
63 %imacro iend 0.nolist
64           times %{$strucname}_size-($-%$strucstart) db 0
65 %pop
66 %endmacro
67
68 %imacro align 1-2+.nolist nop
69           times ($$-$) % (%1) %2
70 %endmacro
71 %imacro alignb 1-2+.nolist resb 1
72           times ($$-$) % (%1) %2
73 %endmacro
74 %imacro alignr 1-2+.nolist
75           %ifempty %2
76                 resb ($$-$) % (%1)
77           %else
78                 times ($$-$) % (%1) %2
79           %endif
80 %endmacro
81
82 %imacro extern 1-*.nolist
83 %rep %0
84 [extern %1]
85 %rotate 1
86 %endrep
87 %endmacro
88
89 %imacro bits 1+.nolist
90 [bits %1]
91 %endmacro
92
93 %imacro use16 0.nolist
94 [bits 16]
95 %endmacro
96 %imacro use32 0.nolist
97 [bits 32]
98 %endmacro
99 %imacro use64 0.nolist
100 [bits 64]
101 %endmacro
102
103 %imacro global 1-*.nolist
104 %rep %0
105 [global %1]
106 %rotate 1
107 %endrep
108 %endmacro
109
110 %imacro common 1-*.nolist
111 %rep %0
112 [common %1]
113 %rotate 1
114 %endrep
115 %endmacro
116
117 %imacro cpu 1+.nolist
118 [cpu %1]
119 %endmacro
120
121 %define __FLOAT_DAZ__ nodaz
122 %define __FLOAT_ROUND__ near
123 ; __FLOAT__ contains the whole floating-point configuration so it can
124 ; be saved and restored
125 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
126 %imacro float 1-*.nolist
127 %rep %0
128 [float %1]
129 %ifidni %1,daz
130 %define __FLOAT_DAZ__ daz
131 %elifidni %1,nodaz
132 %define __FLOAT_DAZ__ nodaz
133 %elifidni %1,near
134 %define __FLOAT_ROUND__ near
135 %elifidni %1,up
136 %define __FLOAT_ROUND__ up
137 %elifidni %1,down
138 %define __FLOAT_ROUND__ down
139 %elifidni %1,zero
140 %define __FLOAT_ROUND__ zero
141 %elifidni %1,default
142 %define __FLOAT_DAZ__ nodaz
143 %define __FLOAT_ROUND__ near
144 %endif
145 %rotate 1
146 %endrep
147 %endmacro
148
149 %imacro default 1+.nolist
150 [default %1]
151 %endmacro
152
153 %imacro incbin 1-2+.nolist 0
154 %push
155 %pathsearch %$dep %1
156 %depend %$dep
157         %? %$dep,%2
158 %pop
159 %endmacro