0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

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>
This commit is contained in:
H. Peter Anvin
2025-10-07 09:56:20 -07:00
parent 2c63ab038c
commit fa43d8e01d
3 changed files with 27 additions and 3 deletions

View File

@@ -912,7 +912,8 @@ enum text_options {
OPT_NO_LINE,
OPT_DEBUG,
OPT_INFO,
OPT_REPRODUCIBLE
OPT_REPRODUCIBLE,
OPT_BITS
};
enum need_arg {
ARG_NO,
@@ -947,6 +948,7 @@ static const struct textargs textopts[] = {
{"verbose", OPT_INFO , ARG_MAYBE, 0},
{"debug", OPT_DEBUG, ARG_MAYBE, 0},
{"reproducible", OPT_REPRODUCIBLE, ARG_NO, 0},
{"bits", OPT_BITS, ARG_YES, 0},
{NULL, OPT_BOGUS, ARG_NO, 0}
};
@@ -1301,6 +1303,10 @@ static bool process_arg(char *p, char *q, int pass)
if (pass == 2)
pp_pre_command("%pragma", param);
break;
case OPT_BITS:
if (pass == 2)
pp_pre_command("BITS", param);
break;
case OPT_BEFORE:
if (pass == 2)
pp_pre_command(NULL, param);
@@ -2469,6 +2475,7 @@ static void help(FILE *out, const char *what)
fputs(
" --pragma str pre-executes a specific %pragma\n"
" --before str add line (usually a preprocessor statement) before the input\n"
" --bits nn set bits to nn (equivalent to --before \"BITS nn\")\n"
" --no-line ignore %line directives in input\n"
" --prefix str prepend the given string to the names of all extern,\n"
" common and global symbols (also --gprefix)\n"

View File

@@ -33,6 +33,9 @@ It is the production version of NASM since 2025.
\b A new \c{%selbits()} preprocessor function. See \k{f_selbits}.
\b A new \c{--bits} option as convenience shorthand for \c{--before
"BITS ..."}. See \k{opt-bits}.
\S{cl-3.00} Version 3.00

View File

@@ -556,12 +556,26 @@ is equivalent to the example in \k{opt-pfix}. See \k{pragma}.
\S{opt-before} The \i\c{--before} Option
A preprocess statement can be accepted with this option. The example
shown in \k{opt-pragma} is the same as running this:
Insert a statement (usually, but not necessarily) a preprocess
statement before the input file. The example shown in \k{opt-pragma}
is the same as running this:
\c nasm -f macho --before "%pragma macho gprefix _"
\S{opt-bits} The \i\c{--bits} Option
Set the processor mode by inserting a \c{BITS} directive (kee
\k{bits}) before the input file. The following two statements are
exactly equivalent:
\c nasm -f bin --bits 16 file.asm
\c nasm -f bin --before "BITS 16" file.asm
The \c{--bits} option was introduced in NASM 3.01; the \c{--before}
form can be used for compatibility with older versions of NASM.
\S{opt-limit} The \i\c{--limit-X} Option
This option allows user to setup various maximum values after which