Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Latest commit

 

History

History
46 lines (33 loc) · 1.26 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.26 KB

Opcoder

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.

Usage

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.

License

Copyright (c) 2022 Zhong Ruoyu. Licensed under the MIT License.