From aa3820495e8c2f103f82923240e7936ca78fab84 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 24 Jul 2025 17:00:55 -0400 Subject: oasm: Introduce encoding for the NOP instruction The NOP (no operation) instruction simply tells the processor to do nothing. This can be useful for various things such as padding, timing, etc. -- nop nop nop ... -- Signed-off-by: Ian Moffett --- usr.bin/oasm/emit.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'usr.bin/oasm/emit.c') diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c index 3261522..139cf47 100644 --- a/usr.bin/oasm/emit.c +++ b/usr.bin/oasm/emit.c @@ -357,6 +357,26 @@ emit_encode_mro(struct emit_state *state, struct oasm_token *tok) return TAILQ_NEXT(tok, link); } +/* + * Encode a NOP instruction + * + * 'nop' - no operands + * + * Returns the next token on success, + * otherwise NULL. + */ +static struct oasm_token * +emit_encode_nop(struct emit_state *state, struct oasm_token *tok) +{ + inst_t curinst; + + curinst.opcode = OSMX64_NOP; + curinst.rd = 0; + curinst.unused = 0; + emit_bytes(state, &curinst, sizeof(curinst)); + return TAILQ_NEXT(tok, link); +} + int emit_osmx64(struct emit_state *state, struct oasm_token *tp) { @@ -428,6 +448,9 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit) curtok = TAILQ_FIRST(&emit->ir); while (curtok != NULL) { switch (curtok->type) { + case TT_NOP: + curtok = emit_encode_nop(emit, curtok); + break; case TT_MOV: curtok = emit_encode_mov(emit, curtok); break; -- cgit v1.2.3