summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-27 23:25:08 -0400
committerIan Moffett <ian@osmora.org>2025-07-28 03:31:14 -0400
commit0d5a742b653870e742b3565389743bbccb39851d (patch)
treed90ec73163012779d7834697e21ff07788bb970c /usr.bin
parent7859e0ff5fbc94ec0b36168ac81e94482274b5c6 (diff)
oasm: Introduce XOR mnemonic
Implement mnemonic for the XOR instruction: -- xor x4, #1 ! x4 = x4 ^ 1 -- Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/oasm/emit.c5
-rw-r--r--usr.bin/oasm/include/oasm/lex.h1
-rw-r--r--usr.bin/oasm/lex.c3
-rw-r--r--usr.bin/oasm/parse.c7
4 files changed, 16 insertions, 0 deletions
diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c
index ebbd824..63f716a 100644
--- a/usr.bin/oasm/emit.c
+++ b/usr.bin/oasm/emit.c
@@ -398,6 +398,10 @@ emit_encode_bitw(struct emit_state *state, struct oasm_token *tok)
opcode = OSMX64_OR;
inst_str = "or";
break;
+ case TT_XOR:
+ opcode = OSMX64_XOR;
+ inst_str = "xor";
+ break;
}
/* Next token should be a register */
@@ -527,6 +531,7 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit)
break;
case TT_AND:
case TT_OR:
+ case TT_XOR:
curtok = emit_encode_bitw(emit, curtok);
break;
case TT_BR:
diff --git a/usr.bin/oasm/include/oasm/lex.h b/usr.bin/oasm/include/oasm/lex.h
index c542c72..4c81bc4 100644
--- a/usr.bin/oasm/include/oasm/lex.h
+++ b/usr.bin/oasm/include/oasm/lex.h
@@ -105,6 +105,7 @@ typedef enum {
TT_MROQ, /* 'mroq' */
TT_AND, /* 'and' */
TT_OR, /* 'or' */
+ TT_XOR, /* 'xor' */
/* Register ops */
TT_MOV, /* 'mov' */
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c
index 4c402be..ce97400 100644
--- a/usr.bin/oasm/lex.c
+++ b/usr.bin/oasm/lex.c
@@ -56,6 +56,7 @@ static char putback = '\0';
#define S_IMN_MROQ "mroq"
#define S_IMN_AND "and"
#define S_IMN_OR "or"
+#define S_IMN_XOR "xor"
/* Instruction length */
#define OSMX64_INST_LEN 4
@@ -212,6 +213,8 @@ token_arith(char *p)
return TT_HLT;
} else if (strcmp(p, S_IMN_MUL) == 0) {
return TT_MUL;
+ } else if (strcmp(p, S_IMN_XOR) == 0) {
+ return TT_XOR;
}
return TT_UNKNOWN;
diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c
index b4bb7be..ce5a446 100644
--- a/usr.bin/oasm/parse.c
+++ b/usr.bin/oasm/parse.c
@@ -60,6 +60,7 @@ static const char *tokstr[] = {
[ TT_MROQ ] = "mroq",
[ TT_AND ] = "and",
[ TT_OR ] = "or",
+ [ TT_XOR ] = "xor",
/* X<n> registers */
[ TT_X0 ] = "x0",
@@ -126,6 +127,8 @@ parse_reg(struct oasm_state *state, struct oasm_token *tok)
case TT_DIV:
case TT_BR:
case TT_AND:
+ case TT_OR:
+ case TT_XOR:
state->last = tok->type;
break;
default:
@@ -176,6 +179,10 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok)
state->last = tok->type;
emit_osmx64(&emit_state, tok);
break;
+ case TT_XOR:
+ state->last = tok->type;
+ emit_osmx64(&emit_state, tok);
+ break;
case TT_HLT:
state->last = tok->type;
emit_osmx64(&emit_state, tok);