Can LLMs Independently Complete Embedded Native Porting? A 6502-to-C UEFI Experiment

    This article documents an experiment in which 6502 assembly logic was translated function by function into C and run in a UEFI Shell graphics environment. It examines where large language models are useful and where human judgment is still required, covering compliance constraints, result-recording criteria, the five porting stages, common translation errors, visual-understanding limitations, multi-round correction stability, a troubleshooting checklist, and selection recommendations.

    Why This Test Was Run

    Large language models can already produce usable code for general code-generation tasks. Lower-level embedded development has a higher barrier: old instruction sets, complex memory layouts, and register semantics that depend on hardware context. This article records a process of translating 6502 assembly logic function by function into C and running it in a UEFI Shell graphics environment. The goal was to observe the practical boundary of the model in this kind of task, not to produce a releasable product.

    Compliance Boundaries

    This experiment used a ROM image for which the author held legal authorization. Readers who want to repeat similar work should follow these constraints:

    • Use only ROMs that you own, created yourself, or are explicitly permitted to analyze.
    • Do not distribute any copyrighted code or graphics assets.
    • If anti-piracy or integrity-check code is encountered, record its location and stop the analysis. Do not attempt to bypass it.

    For practice only, open-source homebrew games or public NES test ROMs can be used.

    How to Record Evaluation Results

    The original experiment did not fully preserve all parameters, so the data and judgments in this article should be treated as the author’s subjective observations. To reproduce the work, record the following in each round:

    • Model name, version, temperature parameter, and context length.
    • Compiler version and UEFI firmware version.
    • GOP resolution and pixel format.
    • Function partitioning rules, i.e., whether jump instruction boundaries or manual annotation were used.
    • Per-round criteria: whether compilation passed, whether the screen matched the reference, and whether the logic was correct.
    • Number of failures and number of manual interventions.

    Only with a unified set of criteria can comparisons between different models be meaningful.

    The Five Porting Stages

    Stage 1: Disassembly and preprocessing. Disassemble the ROM with standard tools and manually annotate code and data segments. Incorrect boundaries will affect every subsequent step.

    Stage 2: Function-by-function translation. Split the code by function and hand it to the model for translation. The basis for splitting should be stated, along with the proportion of manual annotation versus automatic splitting.

    Stage 3: Runtime adaptation. Map port reads/writes and interrupt requests to the GOP graphics interface and keyboard input interface.

    Stage 4: Graphics data conversion. Decode CHR tiles into pixel data usable by UEFI.

    Stage 5: Integration and correction. Compile, run on real hardware, compare frames against the reference screen, locate errors, and iterate.

    Common Translation Errors

    Using absolute addresses as variables. The 6502 often performs byte-level reads and writes to fixed addresses. In C, incorrect type-width inference can cause truncation or overflow, and the compiler often does not report an error.

    Zero-page addressing. Zero-page instructions omit the high byte of the address, which must be completed from context during translation. Newer models do this reasonably well in common cases, but multi-level indirect addressing still tends to cause errors.

    Implicit flag passing. Comparison results are stored in the status register, and later branches depend on them. C has no corresponding mechanism, so comparisons and branches must be merged into explicit conditions. Incorrect merging leads to faulty decision logic.

    Unrelated code mixed in. Some code is unrelated to game functionality but interwoven with the main logic. Before translation, a human should determine its function and document it. This article does not discuss how to bypass such code.

    Limitations in Visual Understanding

    The author gave runtime screenshots to the model for analysis. The model located code-level issues fairly accurately, but performed weakly on graphics problems such as misaligned color bars, abnormal tile stitching, and background scrolling offsets. Its judgments often pointed toward areas such as texture format, while the actual causes were more often tile-index misalignment or address-calculation overflow. When abnormal areas were marked with boxes on the screenshot and accompanied by text explanations, the judgments became noticeably more accurate. This indicates that the model is still insufficiently reliable for visual tasks that require comparing pixel-position relationships.

    Stability Across Multiple Correction Rounds

    The model responded well to problems explicitly pointed out by the user, but its ability to proactively find hidden defects was limited. The author observed that as correction rounds increased, there were occasional cases where one issue was fixed and another new error was introduced. In one continuous conversation, this phenomenon became more obvious after the fifth round, but the author did not perform systematic statistics on it. The author also mentioned that another closed-source model had better consistency in long contexts but corrected more slowly. Because unified round records were lacking, this comparison can only be used as a reference.

    Troubleshooting Checklist

    After each correction, check the following items:

    • Whether address and data widths are consistent.
    • Whether zero-page addresses have the high byte completed.
    • Whether flags are correctly merged with branch instructions.
    • Whether tile indices and CHR decoding order are consistent.
    • Whether the GOP pixel format matches the decoded output.

    Conclusion and Selection Advice

    In this experiment, the large language model performed well on single-point code generation, syntax restoration, and common pattern matching. It is better suited as an auxiliary tool that helps accelerate translation and suggest modifications. To make a program run completely, engineers are still needed to identify problems, verify results, and decide the direction of changes.

    When selecting a model, three points matter: context length, visual understanding capability, and logical consistency across multiple correction rounds. When planning a project, the workload of multiple rounds of manual verification should be included in the cost, and each result should be recorded with unified criteria so that conclusions can be verified by others.