summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-05-21 03:16:33 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-05-21 03:16:33 +0000
commit01377d8d7c90659a2db51f0475a2ee73627a6844 (patch)
tree748356edaf820933616551af79fdff4b76731864
parentaa8b6a1ff7e3be77b64f23efb2a914d0e8cafa1a (diff)
downloadnasm-01377d8d7c90659a2db51f0475a2ee73627a6844.tar.gz
Implement new "strict" keyword to inhibit optimization.
-rw-r--r--assemble.c9
-rw-r--r--nasm.h1
-rw-r--r--nasmlib.c2
-rw-r--r--parser.c5
-rw-r--r--test/expimp.asm61
5 files changed, 72 insertions, 6 deletions
diff --git a/assemble.c b/assemble.c
index b8eac2c2..1e8b9b9e 100644
--- a/assemble.c
+++ b/assemble.c
@@ -157,7 +157,8 @@ static int jmp_match (long segment, long offset, int bits,
if (c != 0370 && c != 0371) return 0;
if (ins->oprs[0].opflags & OPFLAG_FORWARD) {
- if (optimizing<0 && c==0370) return 1;
+ if ((optimizing<0 || (ins->oprs[0].type & STRICT))
+ && c==0370) return 1;
else return (pass0==0); /* match a forward reference */
}
isize = calcsize (segment, offset, bits, ins, code);
@@ -552,9 +553,9 @@ static int is_sbyte (insn *ins, int op, int size)
int ret;
ret = !(ins->forw_ref && ins->oprs[op].opflags ) && /* dead in the water on forward reference or External */
- optimizing>=0 &&
-/* !(ins->oprs[op].type & (BITS16|BITS32)) && */
- ins->oprs[op].wrt==NO_SEG && ins->oprs[op].segment==NO_SEG;
+ optimizing>=0 &&
+ !(ins->oprs[op].type & STRICT) &&
+ ins->oprs[op].wrt==NO_SEG && ins->oprs[op].segment==NO_SEG;
v = ins->oprs[op].offset;
if (size==16) v = (signed short)v; /* sign extend if 16 bits */
diff --git a/nasm.h b/nasm.h
index b38e4f8d..fa5142b5 100644
--- a/nasm.h
+++ b/nasm.h
@@ -382,6 +382,7 @@ enum {
#define TO 0x00000100L /* reverse effect in FADD, FSUB &c */
#define COLON 0x00000200L /* operand is followed by a colon */
+#define STRICT 0x00000400L /* do not optimize this operand */
/* type of operand: memory reference, register, etc. */
#define MEMORY 0x00204000L
diff --git a/nasmlib.c b/nasmlib.c
index 8420bf62..c362c20c 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -642,7 +642,7 @@ void saa_fpwrite (struct SAA *s, FILE *fp)
#include "names.c"
static const char *special_names[] = {
"byte", "dword", "far", "long", "near", "nosplit", "qword",
- "short", "to", "tword", "word"
+ "short", "strict", "to", "tword", "word"
};
static const char *prefix_names[] = {
"a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
diff --git a/parser.c b/parser.c
index abfe91f5..88913807 100644
--- a/parser.c
+++ b/parser.c
@@ -34,7 +34,7 @@ static long reg_flags[] = { /* sizes and special flags */
enum { /* special tokens */
S_BYTE, S_DWORD, S_FAR, S_LONG, S_NEAR, S_NOSPLIT, S_QWORD,
- S_SHORT, S_TO, S_TWORD, S_WORD
+ S_SHORT, S_STRICT, S_TO, S_TWORD, S_WORD
};
static int is_comma_next (void);
@@ -404,6 +404,9 @@ insn *parse_line (int pass, char *buffer, insn *result,
case S_TO:
result->oprs[operand].type |= TO;
break;
+ case S_STRICT:
+ result->oprs[operand].type |= STRICT;
+ break;
case S_FAR:
result->oprs[operand].type |= FAR;
break;
diff --git a/test/expimp.asm b/test/expimp.asm
new file mode 100644
index 00000000..90d9aedc
--- /dev/null
+++ b/test/expimp.asm
@@ -0,0 +1,61 @@
+;
+; Test of explicitly and implicitly sized operands
+;
+start:
+ add esi,2 ; Implicit
+ add esi,123456h ; Implicit
+ add esi,byte 2 ; Explicit
+ add esi,dword 2 ; Explicit
+ add esi,dword 123456h ; Explicit
+ add esi,byte 123456h ; Explicit Truncation
+
+ add esi,strict 2 ; Implicit Strict
+ add esi,strict 123456h ; Implicit Strict
+ add esi,strict byte 2 ; Explicit Strict
+ add esi,strict dword 2 ; Explicit Strict
+ add esi,strict dword 123456h ; Explicit Strict
+ add esi,strict byte 123456h ; Explicit Strict Truncation
+;
+; Same thing with branches
+;
+ jmp short start ; Explicit
+ jmp near start ; Explicit
+ jmp word start ; Explicit
+ jmp dword start ; Explicit
+ jmp short forward ; Explicit
+ jmp near forward ; Explicit
+ jmp word forward ; Explicit
+ jmp dword forward ; Explicit
+%ifdef ERROR
+ jmp short faraway ; Explicit (ERROR)
+%endif
+ jmp near faraway ; Explicit
+ jmp word faraway ; Explicit
+ jmp dword faraway ; Explicit
+ jmp start ; Implicit
+ jmp forward ; Implicit
+ jmp faraway ; Implicit
+
+ jmp strict short start ; Explicit Strict
+ jmp strict near start ; Explicit Strict
+ jmp strict word start ; Explicit Strict
+ jmp strict dword start ; Explicit Strict
+ jmp strict short forward ; Explicit Strict
+ jmp strict near forward ; Explicit Strict
+ jmp strict word forward ; Explicit Strict
+ jmp strict dword forward ; Explicit Strict
+%ifdef ERROR
+ jmp strict short faraway ; Explicit (ERROR)
+%endif
+ jmp strict near faraway ; Explicit Strict
+ jmp strict word faraway ; Explicit Strict
+ jmp strict dword faraway ; Explicit Strict
+ jmp strict start ; Implicit Strict
+ jmp strict forward ; Implicit Strict
+ jmp strict faraway ; Implicit Strict
+forward:
+
+ times 256 nop
+faraway:
+
+