1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * parser.c source line parser for the Netwide Assembler
55 extern int in_abs_seg
; /* ABSOLUTE segment flag */
56 extern int32_t abs_seg
; /* ABSOLUTE segment */
57 extern int32_t abs_offset
; /* ABSOLUTE segment offset */
59 static int is_comma_next(void);
62 static struct tokenval tokval
;
64 static struct ofmt
*outfmt
; /* Structure of addresses of output routines */
65 static struct location
*location
; /* Pointer to current line's segment,offset */
67 void parser_global_info(struct ofmt
*output
, struct location
* locp
)
73 static int prefix_slot(enum prefixes prefix
)
103 error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
108 static void process_size_override(insn
* result
, int operand
)
110 if (tasm_compatible_mode
) {
111 switch ((int)tokval
.t_integer
) {
112 /* For TASM compatibility a size override inside the
113 * brackets changes the size of the operand, not the
114 * address type of the operand as it does in standard
115 * NASM syntax. Hence:
117 * mov eax,[DWORD val]
119 * is valid syntax in TASM compatibility mode. Note that
120 * you lose the ability to override the default address
121 * type for the instruction, but we never use anything
122 * but 32-bit flat model addressing in our code.
125 result
->oprs
[operand
].type
|= BITS8
;
128 result
->oprs
[operand
].type
|= BITS16
;
132 result
->oprs
[operand
].type
|= BITS32
;
135 result
->oprs
[operand
].type
|= BITS64
;
138 result
->oprs
[operand
].type
|= BITS80
;
141 result
->oprs
[operand
].type
|= BITS128
;
145 "invalid operand size specification");
149 /* Standard NASM compatible syntax */
150 switch ((int)tokval
.t_integer
) {
152 result
->oprs
[operand
].eaflags
|= EAF_TIMESTWO
;
155 result
->oprs
[operand
].eaflags
|= EAF_REL
;
158 result
->oprs
[operand
].eaflags
|= EAF_ABS
;
161 result
->oprs
[operand
].disp_size
= 8;
162 result
->oprs
[operand
].eaflags
|= EAF_BYTEOFFS
;
167 if (result
->prefixes
[PPS_ASIZE
] &&
168 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
170 "conflicting address size specifications");
172 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
175 result
->oprs
[operand
].disp_size
= 16;
176 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
180 result
->oprs
[operand
].disp_size
= 32;
181 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
184 result
->oprs
[operand
].disp_size
= 64;
185 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
188 error(ERR_NONFATAL
, "invalid size specification in"
189 " effective address");
195 insn
*parse_line(int pass
, char *buffer
, insn
* result
,
196 efunc errfunc
, evalfunc evaluate
, ldfunc ldef
)
200 struct eval_hints hints
;
203 bool insn_is_label
= false;
208 result
->forw_ref
= false;
212 stdscan_bufptr
= buffer
;
213 i
= stdscan(NULL
, &tokval
);
215 result
->label
= NULL
; /* Assume no label */
216 result
->eops
= NULL
; /* must do this, whatever happens */
217 result
->operands
= 0; /* must initialize this */
219 if (i
== 0) { /* blank line - ignore */
220 result
->opcode
= -1; /* and no instruction either */
223 if (i
!= TOKEN_ID
&& i
!= TOKEN_INSN
&& i
!= TOKEN_PREFIX
&&
224 (i
!= TOKEN_REG
|| (REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
]))) {
225 error(ERR_NONFATAL
, "label or instruction expected"
226 " at start of line");
231 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
232 /* there's a label here */
234 result
->label
= tokval
.t_charptr
;
235 i
= stdscan(NULL
, &tokval
);
236 if (i
== ':') { /* skip over the optional colon */
237 i
= stdscan(NULL
, &tokval
);
239 error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
240 "label alone on a line without a colon might be in error");
242 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
244 * FIXME: location->segment could be NO_SEG, in which case
245 * it is possible we should be passing 'abs_seg'. Look into this.
246 * Work out whether that is *really* what we should be doing.
247 * Generally fix things. I think this is right as it is, but
248 * am still not certain.
250 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
251 location
->offset
, NULL
, true, false, outfmt
, errfunc
);
256 result
->opcode
= -1; /* this line contains just a label */
260 for (j
= 0; j
< MAXPREFIX
; j
++)
261 result
->prefixes
[j
] = P_none
;
264 while (i
== TOKEN_PREFIX
||
265 (i
== TOKEN_REG
&& !(REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
])))
270 * Handle special case: the TIMES prefix.
272 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
275 i
= stdscan(NULL
, &tokval
);
277 evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, error
, NULL
);
279 if (!value
) { /* but, error in evaluator */
280 result
->opcode
= -1; /* unrecoverable parse error: */
281 return result
; /* ignore this instruction */
283 if (!is_simple(value
)) {
285 "non-constant argument supplied to TIMES");
288 result
->times
= value
->value
;
289 if (value
->value
< 0 && pass0
== 2) {
290 error(ERR_NONFATAL
, "TIMES value %d is negative",
296 int slot
= prefix_slot(tokval
.t_integer
);
297 if (result
->prefixes
[slot
]) {
298 if (result
->prefixes
[slot
] == tokval
.t_integer
)
300 "instruction has redundant prefixes");
303 "instruction has conflicting prefixes");
305 result
->prefixes
[slot
] = tokval
.t_integer
;
306 i
= stdscan(NULL
, &tokval
);
310 if (i
!= TOKEN_INSN
) {
314 for (j
= 0; j
< MAXPREFIX
; j
++)
315 if ((pfx
= result
->prefixes
[j
]) != P_none
)
318 if (i
== 0 && pfx
!= P_none
) {
320 * Instruction prefixes are present, but no actual
321 * instruction. This is allowed: at this point we
322 * invent a notional instruction of RESB 0.
324 result
->opcode
= I_RESB
;
325 result
->operands
= 1;
326 result
->oprs
[0].type
= IMMEDIATE
;
327 result
->oprs
[0].offset
= 0L;
328 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
331 error(ERR_NONFATAL
, "parser: instruction expected");
337 result
->opcode
= tokval
.t_integer
;
338 result
->condition
= tokval
.t_inttwo
;
341 * INCBIN cannot be satisfied with incorrectly
342 * evaluated operands, since the correct values _must_ be known
343 * on the first pass. Hence, even in pass one, we set the
344 * `critical' flag on calling evaluate(), so that it will bomb
345 * out on undefined symbols.
347 if (result
->opcode
== I_INCBIN
) {
348 critical
= (pass0
< 2 ? 1 : 2);
351 critical
= (pass
== 2 ? 2 : 0);
353 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
354 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
355 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
356 result
->opcode
== I_DY
|| result
->opcode
== I_INCBIN
) {
357 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
361 result
->eops_float
= false;
364 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
367 i
= stdscan(NULL
, &tokval
);
370 else if (first
&& i
== ':') {
371 insn_is_label
= true;
376 eop
= *tail
= nasm_malloc(sizeof(extop
));
379 eop
->type
= EOT_NOTHING
;
383 /* is_comma_next() here is to distinguish this from
384 a string used as part of an expression... */
385 if (i
== TOKEN_STR
&& is_comma_next()) {
386 eop
->type
= EOT_DB_STRING
;
387 eop
->stringval
= tokval
.t_charptr
;
388 eop
->stringlen
= tokval
.t_inttwo
;
389 i
= stdscan(NULL
, &tokval
); /* eat the comma */
390 } else if (i
== TOKEN_STRFUNC
) {
392 const char *funcname
= tokval
.t_charptr
;
393 enum strfunc func
= tokval
.t_integer
;
394 i
= stdscan(NULL
, &tokval
);
397 i
= stdscan(NULL
, &tokval
);
399 if (i
!= TOKEN_STR
) {
401 "%s must be followed by a string constant",
403 eop
->type
= EOT_NOTHING
;
405 eop
->type
= EOT_DB_STRING_FREE
;
407 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
408 &eop
->stringval
, func
);
409 if (eop
->stringlen
== (size_t)-1) {
410 error(ERR_NONFATAL
, "invalid string for transform");
411 eop
->type
= EOT_NOTHING
;
414 if (parens
&& i
&& i
!= ')') {
415 i
= stdscan(NULL
, &tokval
);
417 error(ERR_NONFATAL
, "unterminated %s function",
422 i
= stdscan(NULL
, &tokval
);
423 } else if (i
== '-' || i
== '+') {
424 char *save
= stdscan_bufptr
;
426 sign
= (i
== '-') ? -1 : 1;
427 i
= stdscan(NULL
, &tokval
);
428 if (i
!= TOKEN_FLOAT
) {
429 stdscan_bufptr
= save
;
430 i
= tokval
.t_type
= token
;
435 } else if (i
== TOKEN_FLOAT
) {
437 eop
->type
= EOT_DB_STRING
;
438 result
->eops_float
= true;
439 switch (result
->opcode
) {
459 error(ERR_NONFATAL
, "floating-point constant"
460 " encountered in DY instruction");
464 error(ERR_NONFATAL
, "floating-point constant"
465 " encountered in unknown instruction");
467 * fix suggested by Pedro Gimeno... original line
469 * eop->type = EOT_NOTHING;
474 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
477 eop
->stringval
= (char *)eop
+ sizeof(extop
);
478 if (!eop
->stringlen
||
479 !float_const(tokval
.t_charptr
, sign
,
480 (uint8_t *)eop
->stringval
,
481 eop
->stringlen
, error
))
482 eop
->type
= EOT_NOTHING
;
483 i
= stdscan(NULL
, &tokval
); /* eat the comma */
485 /* anything else, assume it is an expression */
489 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
490 critical
, error
, NULL
);
492 if (!value
) { /* error in evaluator */
493 result
->opcode
= -1; /* unrecoverable parse error: */
494 return result
; /* ignore this instruction */
496 if (is_unknown(value
)) {
497 eop
->type
= EOT_DB_NUMBER
;
498 eop
->offset
= 0; /* doesn't matter what we put */
499 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
500 } else if (is_reloc(value
)) {
501 eop
->type
= EOT_DB_NUMBER
;
502 eop
->offset
= reloc_value(value
);
503 eop
->segment
= reloc_seg(value
);
504 eop
->wrt
= reloc_wrt(value
);
507 "operand %d: expression is not simple"
508 " or relocatable", oper_num
);
513 * We're about to call stdscan(), which will eat the
514 * comma that we're currently sitting on between
515 * arguments. However, we'd better check first that it
518 if (i
== 0) /* also could be EOL */
521 error(ERR_NONFATAL
, "comma expected after operand %d",
523 result
->opcode
= -1; /* unrecoverable parse error: */
524 return result
; /* ignore this instruction */
528 if (result
->opcode
== I_INCBIN
) {
530 * Correct syntax for INCBIN is that there should be
531 * one string operand, followed by one or two numeric
534 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
535 error(ERR_NONFATAL
, "`incbin' expects a file name");
536 else if (result
->eops
->next
&&
537 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
538 error(ERR_NONFATAL
, "`incbin': second parameter is",
540 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
541 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
542 error(ERR_NONFATAL
, "`incbin': third parameter is",
544 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
545 result
->eops
->next
->next
->next
)
547 "`incbin': more than three parameters");
551 * If we reach here, one of the above errors happened.
552 * Throw the instruction away.
556 } else /* DB ... */ if (oper_num
== 0)
557 error(ERR_WARNING
| ERR_PASS1
,
558 "no operand for data declaration");
560 result
->operands
= oper_num
;
565 /* right. Now we begin to parse the operands. There may be up to four
566 * of these, separated by commas, and terminated by a zero token. */
568 for (operand
= 0; operand
< MAX_OPERANDS
; operand
++) {
569 expr
*value
; /* used most of the time */
570 int mref
; /* is this going to be a memory ref? */
571 int bracket
; /* is it a [] mref, or a & mref? */
574 result
->oprs
[operand
].disp_size
= 0; /* have to zero this whatever */
575 result
->oprs
[operand
].eaflags
= 0; /* and this */
576 result
->oprs
[operand
].opflags
= 0;
578 i
= stdscan(NULL
, &tokval
);
580 break; /* end of operands: get out of here */
581 else if (first
&& i
== ':') {
582 insn_is_label
= true;
586 result
->oprs
[operand
].type
= 0; /* so far, no override */
587 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
588 switch ((int)tokval
.t_integer
) {
590 if (!setsize
) /* we want to use only the first */
591 result
->oprs
[operand
].type
|= BITS8
;
596 result
->oprs
[operand
].type
|= BITS16
;
602 result
->oprs
[operand
].type
|= BITS32
;
607 result
->oprs
[operand
].type
|= BITS64
;
612 result
->oprs
[operand
].type
|= BITS80
;
617 result
->oprs
[operand
].type
|= BITS128
;
622 result
->oprs
[operand
].type
|= BITS256
;
626 result
->oprs
[operand
].type
|= TO
;
629 result
->oprs
[operand
].type
|= STRICT
;
632 result
->oprs
[operand
].type
|= FAR
;
635 result
->oprs
[operand
].type
|= NEAR
;
638 result
->oprs
[operand
].type
|= SHORT
;
641 error(ERR_NONFATAL
, "invalid operand size specification");
643 i
= stdscan(NULL
, &tokval
);
646 if (i
== '[' || i
== '&') { /* memory reference */
648 bracket
= (i
== '[');
649 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
650 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
651 process_size_override(result
, operand
);
652 i
= stdscan(NULL
, &tokval
);
654 } else { /* immediate operand, or register */
656 bracket
= false; /* placate optimisers */
659 if ((result
->oprs
[operand
].type
& FAR
) && !mref
&&
660 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
661 error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
664 value
= evaluate(stdscan
, NULL
, &tokval
,
665 &result
->oprs
[operand
].opflags
,
666 critical
, error
, &hints
);
668 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
669 result
->forw_ref
= true;
671 if (!value
) { /* error in evaluator */
672 result
->opcode
= -1; /* unrecoverable parse error: */
673 return result
; /* ignore this instruction */
675 if (i
== ':' && mref
) { /* it was seg:offset */
677 * Process the segment override.
679 if (value
[1].type
!= 0 || value
->value
!= 1 ||
680 REG_SREG
& ~nasm_reg_flags
[value
->type
])
681 error(ERR_NONFATAL
, "invalid segment override");
682 else if (result
->prefixes
[PPS_SEG
])
684 "instruction has conflicting segment overrides");
686 result
->prefixes
[PPS_SEG
] = value
->type
;
687 if (!(REG_FSGS
& ~nasm_reg_flags
[value
->type
]))
688 result
->oprs
[operand
].eaflags
|= EAF_FSGS
;
691 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
692 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
693 process_size_override(result
, operand
);
694 i
= stdscan(NULL
, &tokval
);
696 value
= evaluate(stdscan
, NULL
, &tokval
,
697 &result
->oprs
[operand
].opflags
,
698 critical
, error
, &hints
);
700 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
701 result
->forw_ref
= true;
703 /* and get the offset */
704 if (!value
) { /* but, error in evaluator */
705 result
->opcode
= -1; /* unrecoverable parse error: */
706 return result
; /* ignore this instruction */
711 if (mref
&& bracket
) { /* find ] at the end */
713 error(ERR_NONFATAL
, "parser: expecting ]");
715 } else { /* we got the required ] */
716 i
= stdscan(NULL
, &tokval
);
717 if (i
!= 0 && i
!= ',') {
718 error(ERR_NONFATAL
, "comma or end of line expected");
722 } else { /* immediate operand */
723 if (i
!= 0 && i
!= ',' && i
!= ':') {
724 error(ERR_NONFATAL
, "comma, colon or end of line expected");
726 } else if (i
== ':') {
727 result
->oprs
[operand
].type
|= COLON
;
731 do { /* error recovery */
732 i
= stdscan(NULL
, &tokval
);
733 } while (i
!= 0 && i
!= ',');
736 /* now convert the exprs returned from evaluate() into operand
739 if (mref
) { /* it's a memory reference */
741 int b
, i
, s
; /* basereg, indexreg, scale */
742 int64_t o
; /* offset */
744 b
= i
= -1, o
= s
= 0;
745 result
->oprs
[operand
].hintbase
= hints
.base
;
746 result
->oprs
[operand
].hinttype
= hints
.type
;
748 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
749 if (e
->value
== 1) /* in fact it can be basereg */
751 else /* no, it has to be indexreg */
752 i
= e
->type
, s
= e
->value
;
755 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
756 if (b
!= -1) /* If the first was the base, ... */
757 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
759 else if (e
->value
!= 1) { /* If both want to be index */
761 "beroset-p-592-invalid effective address");
768 if (e
->type
!= 0) { /* is there an offset? */
769 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
771 "beroset-p-603-invalid effective address");
775 if (e
->type
== EXPR_UNKNOWN
) {
776 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
777 o
= 0; /* doesn't matter what */
778 result
->oprs
[operand
].wrt
= NO_SEG
; /* nor this */
779 result
->oprs
[operand
].segment
= NO_SEG
; /* or this */
781 e
++; /* go to the end of the line */
783 if (e
->type
== EXPR_SIMPLE
) {
787 if (e
->type
== EXPR_WRT
) {
788 result
->oprs
[operand
].wrt
= e
->value
;
791 result
->oprs
[operand
].wrt
= NO_SEG
;
793 * Look for a segment base type.
795 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
797 "beroset-p-630-invalid effective address");
801 while (e
->type
&& e
->value
== 0)
803 if (e
->type
&& e
->value
!= 1) {
805 "beroset-p-637-invalid effective address");
810 result
->oprs
[operand
].segment
=
811 e
->type
- EXPR_SEGBASE
;
814 result
->oprs
[operand
].segment
= NO_SEG
;
815 while (e
->type
&& e
->value
== 0)
819 "beroset-p-650-invalid effective address");
827 result
->oprs
[operand
].wrt
= NO_SEG
;
828 result
->oprs
[operand
].segment
= NO_SEG
;
831 if (e
->type
!= 0) { /* there'd better be nothing left! */
833 "beroset-p-663-invalid effective address");
838 /* It is memory, but it can match any r/m operand */
839 result
->oprs
[operand
].type
|= MEMORY_ANY
;
841 if (b
== -1 && (i
== -1 || s
== 0)) {
842 int is_rel
= globalbits
== 64 &&
843 !(result
->oprs
[operand
].eaflags
& EAF_ABS
) &&
845 !(result
->oprs
[operand
].eaflags
& EAF_FSGS
)) ||
846 (result
->oprs
[operand
].eaflags
& EAF_REL
));
848 result
->oprs
[operand
].type
|= is_rel
? IP_REL
: MEM_OFFS
;
850 result
->oprs
[operand
].basereg
= b
;
851 result
->oprs
[operand
].indexreg
= i
;
852 result
->oprs
[operand
].scale
= s
;
853 result
->oprs
[operand
].offset
= o
;
854 } else { /* it's not a memory reference */
855 if (is_just_unknown(value
)) { /* it's immediate but unknown */
856 result
->oprs
[operand
].type
|= IMMEDIATE
;
857 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
858 result
->oprs
[operand
].offset
= 0; /* don't care */
859 result
->oprs
[operand
].segment
= NO_SEG
; /* don't care again */
860 result
->oprs
[operand
].wrt
= NO_SEG
; /* still don't care */
862 if(optimizing
>= 0 && !(result
->oprs
[operand
].type
& STRICT
))
865 result
->oprs
[operand
].type
|= SBYTE16
| SBYTE32
| SBYTE64
;
867 } else if (is_reloc(value
)) { /* it's immediate */
868 result
->oprs
[operand
].type
|= IMMEDIATE
;
869 result
->oprs
[operand
].offset
= reloc_value(value
);
870 result
->oprs
[operand
].segment
= reloc_seg(value
);
871 result
->oprs
[operand
].wrt
= reloc_wrt(value
);
872 if (is_simple(value
)) {
873 if (reloc_value(value
) == 1)
874 result
->oprs
[operand
].type
|= UNITY
;
875 if (optimizing
>= 0 &&
876 !(result
->oprs
[operand
].type
& STRICT
)) {
877 int64_t v64
= reloc_value(value
);
878 int32_t v32
= (int32_t)v64
;
879 int16_t v16
= (int16_t)v32
;
881 if (v64
>= -128 && v64
<= 127)
882 result
->oprs
[operand
].type
|= SBYTE64
;
883 if (v32
>= -128 && v32
<= 127)
884 result
->oprs
[operand
].type
|= SBYTE32
;
885 if (v16
>= -128 && v16
<= 127)
886 result
->oprs
[operand
].type
|= SBYTE16
;
889 } else { /* it's a register */
892 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
893 error(ERR_NONFATAL
, "invalid operand type");
899 * check that its only 1 register, not an expression...
901 for (i
= 1; value
[i
].type
; i
++)
902 if (value
[i
].value
) {
903 error(ERR_NONFATAL
, "invalid operand type");
908 /* clear overrides, except TO which applies to FPU regs */
909 if (result
->oprs
[operand
].type
& ~TO
) {
911 * we want to produce a warning iff the specified size
912 * is different from the register size
914 rs
= result
->oprs
[operand
].type
& SIZE_MASK
;
918 result
->oprs
[operand
].type
&= TO
;
919 result
->oprs
[operand
].type
|= REGISTER
;
920 result
->oprs
[operand
].type
|= nasm_reg_flags
[value
->type
];
921 result
->oprs
[operand
].basereg
= value
->type
;
923 if (rs
&& (result
->oprs
[operand
].type
& SIZE_MASK
) != rs
)
924 error(ERR_WARNING
| ERR_PASS1
,
925 "register size specification ignored");
930 result
->operands
= operand
; /* set operand count */
932 /* clear remaining operands */
933 while (operand
< MAX_OPERANDS
)
934 result
->oprs
[operand
++].type
= 0;
937 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
939 switch (result
->opcode
) {
941 result
->opcode
= I_RESB
;
942 result
->oprs
[0].offset
*= 2;
945 result
->opcode
= I_RESB
;
946 result
->oprs
[0].offset
*= 4;
949 result
->opcode
= I_RESB
;
950 result
->oprs
[0].offset
*= 8;
953 result
->opcode
= I_RESB
;
954 result
->oprs
[0].offset
*= 10;
957 result
->opcode
= I_RESB
;
958 result
->oprs
[0].offset
*= 16;
961 result
->opcode
= I_RESB
;
962 result
->oprs
[0].offset
*= 32;
971 static int is_comma_next(void)
978 i
= stdscan(NULL
, &tv
);
980 return (i
== ',' || i
== ';' || !i
);
983 void cleanup_insn(insn
* i
)
987 while ((e
= i
->eops
)) {
989 if (e
->type
== EOT_DB_STRING_FREE
)
990 nasm_free(e
->stringval
);