From ea521725a7739ec568eb6961edabf71d8169ef9e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 22 Jul 2025 02:34:25 -0400 Subject: oasm: Introduce encoding for MUL instruction Signed-off-by: Ian Moffett --- usr.bin/oasm/emit.c | 5 +++++ usr.bin/oasm/lex.c | 3 +++ usr.bin/oasm/parse.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c index 80adba9..83dbe46 100644 --- a/usr.bin/oasm/emit.c +++ b/usr.bin/oasm/emit.c @@ -190,6 +190,10 @@ emit_encode_arith(struct emit_state *state, struct oasm_token *tok) inst_str = "sub"; opcode = OSMX64_SUB; break; + case TT_MUL: + inst_str = "mul"; + opcode = OSMX64_MUL; + break; } /* @@ -329,6 +333,7 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit) break; case TT_ADD: case TT_SUB: + case TT_MUL: curtok = emit_encode_arith(emit, curtok); break; case TT_HLT: diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c index b3af2b1..7b78d54 100644 --- a/usr.bin/oasm/lex.c +++ b/usr.bin/oasm/lex.c @@ -42,6 +42,7 @@ static char putback = '\0'; #define S_IMN_MOV "mov" #define S_IMN_ADD "add" #define S_IMN_SUB "sub" +#define S_IMN_MUL "mul" #define S_IMN_DIV "div" #define S_IMN_INC "inc" #define S_IMN_DEC "dec" @@ -182,6 +183,8 @@ token_arith(char *p) return TT_DIV; } else if (strcmp(p, S_IMN_HLT) == 0) { return TT_HLT; + } else if (strcmp(p, S_IMN_MUL) == 0) { + return TT_MUL; } return TT_UNKNOWN; diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c index c688e2e..2b5eb14 100644 --- a/usr.bin/oasm/parse.c +++ b/usr.bin/oasm/parse.c @@ -110,6 +110,7 @@ parse_reg(struct oasm_state *state, struct oasm_token *tok) case TT_INC: case TT_ADD: case TT_SUB: + case TT_MUL: state->last = tok->type; break; default: @@ -146,6 +147,10 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok) state->last = tok->type; emit_osmx64(&emit_state, tok); break; + case TT_MUL: + state->last = tok->type; + emit_osmx64(&emit_state, tok); + break; case TT_MOV: state->last = tok->type; emit_osmx64(&emit_state, tok); -- cgit v1.2.3