I have written a random RISCV32I instruction generator, which generates instructions in hexadecimal format, if needed, binary format as well.
For a short example, I have:
8e900d13
00000013
0b700e13
00000013
00000013
d7400f93
Nothing more. How am I supposed to use RISCV toolchain to compile it into an ELF or something that I can run on a RISCV processor during simulation.
One approach is some text processing to turn this into usable input for a standard toolchain, like GAS (GNU binutils) or clang.
sed 's/^/.word 0x/' foo.hex > foo.swould turn your hex into asm source like.word 0x8e900d13which you could assemble with standard tools. An assembler reads source lines and assembles bytes into the current section of the output file, and doesn't care whether the source line wasli s10, -1815,addi s10, x0, -1815, or.word 0x8e900d13, or the same using.byte.With some additional text around it like
_start:/.global _start, you could have a source file you could usefully assemble + link withgccwith some options.For example, skipping your blank lines (or others that aren't just optional whitespace and alphanumeric characters).
sed -Euses Extended regular expressions so+is one-or-more repeats, unlike the default basic regex.\s*is 0 or more whitespace characters. The initial/pattern/applies the rule only to matching lines, thes/pat/subs/replaces the start of the line (and any initial whitespace) with.word 0xOf course you could just have your instruction generator output asm source like
.word 0x...instead of doing that separately. And pick your favourite text-processing tool for this task;sedis easy for this if you're familiar with old-school Unix tools.Presumably you know what your simulator wants in a linked executable so you can sort that out.
Perhaps
echo -e '_start:\n.global _start' > foo.sand havesedappend (>>instead of>), or write asedcommand that uses anicommand to insert extra text on line0or1or something?