From Assembly to C: Evaluating LLMs in Porting Retro Game Logic to UEFI
This article explores the capabilities of Large Language Models (LLMs) in code translation by porting retro game logic from 6502 assembly to C for the UEFI platform. Unlike standard coding benchmarks, this approach tests deep code comprehension, hardware knowledge, and long-context consistency. We detail the technical architecture separating core game logic from the UEFI platform layer, evaluate the LLM's performance, and highlight both its strengths in reconstructing main game flows and its limitations in handling graphic details and multimodal debugging. Finally, we provide a practical methodology for leveraging multimodal LLMs in legacy code migration.
Translating Retro Game Disassembly into a Runnable UEFI Program with LLMs: A Deep Capability Evaluation
1. Why Use “Game Disassembly Translation” to Evaluate LLMs?
When evaluating the coding capabilities of an LLM, the most common practice is to run standardized benchmark tests: algorithm problem pass rates, function completion accuracy, and unit test coverage. While these metrics hold value, they have a clear blind spot—they mostly test “writing code from scratch,” whereas real-world engineering scenarios more often require models to “understand existing code and perform equivalent transformations.”
Translating disassembled code from a retro console (a platform using the 6502 instruction set) function-by-function into C, and running it natively in a UEFI Shell environment, happens to be an exceptionally high-pressure testing scenario:
- Depth of code understanding: Disassembled code has no types, no comments, and uses address labels for naming (e.g.,
sub_E4E8). The model must infer the semantics of each subroutine. - Hardware knowledge reserve: The task requires understanding low-level concepts such as PPU registers, mapper bank switching mechanisms, Sprite OAM write processes, and palette bit encoding.
- Long-context consistency: The disassembly of a fighting game ROM can easily span tens of thousands of lines, with extensive shared state among functions (simulated RAM, mirrored VRAM states). The translation must remain consistent from start to finish.
- Multimodal capabilities: When graphical errors occur in the execution results, screenshots must be fed back to the model to assess its ability to “locate bugs from images.”
There are no shortcuts for this task: a clever “load ROM and emulate directly” solution does not exist, because the goal is logic translation, not hardware emulation. The model must truly understand the game logic and re-express it using a modern language.
2. Task Setup and Technical Approach
2.1 Evaluation Subject and Conditions
The material selected for this evaluation is an early fighting cartridge game utilizing the mapper 91 scheme, with approximately 128KB of program space and 512KB of graphics space. The disassembly is also interspersed with checksum and interference code added by the manufacturer for anti-piracy, further increasing the difficulty of comprehension.
The evaluation is divided into two main tracks:
- Logic translation: Translate the 6502 disassembly into C function by function. Function naming strictly adheres to the assembly labels, ensuring that any generated line of code can be traced back to its original assembly source. Core mechanisms such as PPU register read/writes, bank switching, sprite emission loops, and animation script virtual machines are all translated comparatively.
- Resource extraction: Graphics blocks (CHR), palettes, nametables, and sprite frame data are all parsed and generated into C arrays from the ROM via scripts. They can be regenerated repeatedly without manual transcription, ensuring zero errors at the data level.
2.2 Runtime Architecture
The final product is a native application running under the UEFI Shell, divided into two layers overall:
- Core layer: Mirrors the original machine’s RAM, PPU, and mapper state, carrying the translated game logic. It is platform-agnostic.
- Platform layer: Responsible for only three things: rendering to the screen via the GOP (Graphics Output Protocol) framebuffer, reading keyboard input, and maintaining frame timing. The simulated 256×240 image is scaled by an integer multiple and then Blt to the screen, with no sound.
This “core and platform separation” structure is a reusable methodology: the same set of core translation logic can theoretically be ported to any platform that provides framebuffer and input capabilities.
2.3 “Assembly-Centric” Code Style
An intuitive standard for judging translation quality is whether the generated code retains the bit-manipulation semantics of the original assembly. Take the sprite emission logic as an example: the original routine unpacks each sprite’s (xd, yd, tile) triplet bitwise—the highest bit of xd rolls into the palette accumulator, the lower 7 bits act as the X offset, and after mirroring based on character facing, it is written to the OAM. The translated C code roughly takes this form:
/* Translated from sub_E4E8:* Bit 7 of xd rolls into the palette accumulator, the lower 7 bits are the X offset */c = (xd >> 7) & 1;acc = ((acc << 1) | c) & 0xFF;xdl = xd & 0x7F;X16 = facing ? (base_x - xdl) : (base_x + xdl);
The value of this style lies in auditability: when execution results are wrong, you can compare line-by-line with the assembly to quickly determine whether it is a translation error or a resource extraction error. Conversely, if the model “cleverly” refactors the logic, debugging will become a disaster.
3. Evaluation Results: Highlights and Shortcomings
3.1 Highlights: Main Flow Working in One Go
Impressively, the complete flow of the title screen, character selection, battle loading, and entering combat was successfully run through with relatively few rounds of intervention. Basic actions like punching and moving were also presented normally. This indicates that the model’s overall semantic understanding of 6502 assembly is up to standard, and there are no directional errors in the reconstruction of the state machine’s backbone. Compared to the previous generation of models in the same series, the progress is evident; its multimodal capabilities are also genuinely usable in certain scenarios.
3.2 Shortcomings: Graphic Details and “Image-Based Debugging” Capability
However, looking closely at the execution screen, the problems are equally obvious:
- Character portraits on the VS screen are cut into horizontal bars—a typical tile index or bank switching timing error.
- In-game characters appear as humanoids pieced together from color blocks—there is a deviation in the CHR data addressing of sprite frames or palette bit decoding.
- Crouch animations and AI behavior logic exhibit perceivable differences compared to the original version.
A more critical observation is the fixing process: these bugs were not discovered and fixed autonomously by the model. Instead, it required human intervention to point out the problems round by round, circling abnormal areas on screenshots, before the model could gradually locate the corresponding translation errors. This exposes two capability shortcomings:
- Insufficient precision in understanding visual feedback: The model can recognize that “there is a problem with the image,” but struggles to deduce from an abnormal screen whether it’s a bit-manipulation error, an omitted bank switch, or a lookup table offset error.
- Lack of self-verification awareness: The model tends to claim that the “translation is complete” without proactively building comparative verification methods (such as frame-level screen diffs).
4. Methodology Takeaways: How to Effectively Use Multimodal LLMs for Low-Level Translation
This practice can be distilled into a general human-AI collaboration workflow, applicable to various “legacy code migration” scenarios:
- Step 1: Establish traceable mapping conventions: Function names and variable names should adhere to original labels, and origins should be annotated in comments. It is better to have “ugly” code as long as it is traceable.
- Step 2: Separate data and logic: Use scripts to deterministically generate resources, converging all uncertainty entirely onto the logic translation side.
- Step 3: Isolate platform differences with a layered architecture: Keep the core layer independent of the target platform, facilitating debugging and verification in any environment.
- Step 4: Prepare structured feedback methods: Screenshots + red box annotations + expected behavior descriptions are several times more efficient than purely textual bug descriptions.
- Step 5: Manually gatekeep critical paths: Logic such as animation state machines and interrupt timing, where “one bit off means entirely wrong,” must be manually reviewed.
5. Conclusion
Returning to the original question: Can the current generation of LLMs handle “disassembly-level” code translation? The answer is—the main trunk can, but the details cannot; it can do the work, but it cannot be left unsupervised. It can significantly reduce the startup costs of such projects, compressing weeks of work into days, but final correctness still relies on continuous verification by experienced developers. For developers looking to evaluate intelligent programming tools, it is recommended to skip the benchmarks and directly stress-test using a real project with “hardware semantics, shared state, and visual verification means.” This tells you more than any leaderboard ever could.
