Skip to content

Commit fa43d8e

Browse files
author
H. Peter Anvin
committed
asm: new --bits option to set the processor mode on the command line
This is really just a shorthand for the --before option, but it is really convenient for quickly writing multimode tests. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent 2c63ab0 commit fa43d8e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

asm/nasm.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ enum text_options {
912912
OPT_NO_LINE,
913913
OPT_DEBUG,
914914
OPT_INFO,
915-
OPT_REPRODUCIBLE
915+
OPT_REPRODUCIBLE,
916+
OPT_BITS
916917
};
917918
enum need_arg {
918919
ARG_NO,
@@ -947,6 +948,7 @@ static const struct textargs textopts[] = {
947948
{"verbose", OPT_INFO , ARG_MAYBE, 0},
948949
{"debug", OPT_DEBUG, ARG_MAYBE, 0},
949950
{"reproducible", OPT_REPRODUCIBLE, ARG_NO, 0},
951+
{"bits", OPT_BITS, ARG_YES, 0},
950952
{NULL, OPT_BOGUS, ARG_NO, 0}
951953
};
952954

@@ -1301,6 +1303,10 @@ static bool process_arg(char *p, char *q, int pass)
13011303
if (pass == 2)
13021304
pp_pre_command("%pragma", param);
13031305
break;
1306+
case OPT_BITS:
1307+
if (pass == 2)
1308+
pp_pre_command("BITS", param);
1309+
break;
13041310
case OPT_BEFORE:
13051311
if (pass == 2)
13061312
pp_pre_command(NULL, param);
@@ -2469,6 +2475,7 @@ static void help(FILE *out, const char *what)
24692475
fputs(
24702476
" --pragma str pre-executes a specific %pragma\n"
24712477
" --before str add line (usually a preprocessor statement) before the input\n"
2478+
" --bits nn set bits to nn (equivalent to --before \"BITS nn\")\n"
24722479
" --no-line ignore %line directives in input\n"
24732480
" --prefix str prepend the given string to the names of all extern,\n"
24742481
" common and global symbols (also --gprefix)\n"

doc/changes.src

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ It is the production version of NASM since 2025.
3333

3434
\b A new \c{%selbits()} preprocessor function. See \k{f_selbits}.
3535

36+
\b A new \c{--bits} option as convenience shorthand for \c{--before
37+
"BITS ..."}. See \k{opt-bits}.
38+
3639

3740
\S{cl-3.00} Version 3.00
3841

doc/running.src

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,26 @@ is equivalent to the example in \k{opt-pfix}. See \k{pragma}.
556556

557557
\S{opt-before} The \i\c{--before} Option
558558

559-
A preprocess statement can be accepted with this option. The example
560-
shown in \k{opt-pragma} is the same as running this:
559+
Insert a statement (usually, but not necessarily) a preprocess
560+
statement before the input file. The example shown in \k{opt-pragma}
561+
is the same as running this:
561562

562563
\c nasm -f macho --before "%pragma macho gprefix _"
563564

564565

566+
\S{opt-bits} The \i\c{--bits} Option
567+
568+
Set the processor mode by inserting a \c{BITS} directive (kee
569+
\k{bits}) before the input file. The following two statements are
570+
exactly equivalent:
571+
572+
\c nasm -f bin --bits 16 file.asm
573+
\c nasm -f bin --before "BITS 16" file.asm
574+
575+
The \c{--bits} option was introduced in NASM 3.01; the \c{--before}
576+
form can be used for compatibility with older versions of NASM.
577+
578+
565579
\S{opt-limit} The \i\c{--limit-X} Option
566580

567581
This option allows user to setup various maximum values after which

0 commit comments

Comments
 (0)