Opcoder is a utility for converting LEGv8 mnemonics into instructions in hexadecimal format which supports basic syntax error detection. It is modified from Dr K. G. Smitha's OPCoder.
To use it in your JavaScript scripts, see the example below:
import { convertLines } from "./opcoder.js";
const input = `ADD X5, X5, X6 // ADD
LDUR X5, [X2, #0] // LDUR
CBZ X7, #3 // CBZ
B #4 // B
STUR X5, [X2, #2] // STUR`;
console.log(convertLines(input));
To embed this in an HTML page, do this:
<script type="module">
import { convert } from "./opcoder.js";
function convertLines(lines) {
return lines
.split("\n")
.map(line => (line.trim().length !== 0)
? `${convert(line).toUpperCase()} // ${line}`
: line);
}
document.getElementById("input").addEventListener("input", e => {
const lines = document.getElementById("input").value;
document.getElementById("result").value = convertLines(lines).join("\n");
});
</script>
A working example is available here.
Copyright (c) 2022 Zhong Ruoyu. Licensed under the MIT License.