diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-24 17:00:55 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-24 17:04:10 -0400 |
commit | aa3820495e8c2f103f82923240e7936ca78fab84 (patch) | |
tree | fe1441e28054a3e7b7300e2597df9444ac6f018b /usr.bin/oasm/emit.c | |
parent | 24dabe54c845b88ccd4842eb0e7c0fa097a7beaf (diff) |
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 <ian@osmora.org>
Diffstat (limited to 'usr.bin/oasm/emit.c')
-rw-r--r-- | usr.bin/oasm/emit.c | 23 |
1 files changed, 23 insertions, 0 deletions
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; |