Migrating Disassembly to Native Execution: Evaluating LLM Coding Skills on Low-Level Code

    This article describes a test that asks large language models to convert disassembled code from an early home console game into a modern C program that runs in a firmware boot environment. It explains why this kind of migration is a demanding benchmark, the steps needed to recover high-level logic from assembly, and the rendering, animation, and AI defects that remained after several rounds of generation and testing. It also proposes criteria for judging a model on first-run success, feature recovery, defect localization, change stability, and the human effort required.

    1. Why Use Disassembly Migration to Test LLMs

    Judging a large language model’s programming ability should not rely only on whether it can produce a few routine business functions. Complex engineering tasks require a model to handle incomplete context, existing code, implicit state, hardware constraints, data formats, and runtime errors at the same time.

    Migrating a game program for an older platform from disassembled code to modern C is therefore a representative stress test. It examines the following abilities:

    1. Assembly semantics: The model must understand how registers, the stack, jumps, flags, and memory mapping relate to each other.
    2. Cross-language restructuring: Simply translating instructions one by one is not enough. The model must recover function boundaries, variable meanings, and control flow.
    3. Data structure inference: Information such as character state, animation frames, collision areas, and input state rarely exists as a clear structure.
    4. Graphics implementation: The model must turn tiles, palettes, sprites, and background logic from the original program into a drawing process that the target environment can run.
    5. Debugging and verification: Code that compiles does not guarantee correct behavior. It must pass extensive runtime testing and defect diagnosis.

    The value of this task is that it is close to real software archaeology, legacy system migration, and low-level program restructuring. It goes well beyond ordinary code completion.

    2. Test Task and Runtime Environment

    The goal of this test is not to re-emulate the original hardware. Instead, it extracts the game logic and converts it into a standalone program that runs in a firmware boot environment. The program displays its output through a generic graphics output interface and receives control signals through basic input mechanics.

    The program being migrated is a fighting game from an early home console. Its codebase is not especially large, but it has several clear difficulties:

    • It uses a specific memory mapping scheme.
    • Program code and graphics data are stored in different regions.
    • Tiles and palettes follow a layout specific to the early platform.
    • It contains many routines related to storage media verification and address switching.
    • Some functions have no clear names, and their parameters and return values must be inferred from call relationships.
    • Animation, collision, and AI logic are tightly interwoven, so reading one function alone rarely yields a complete picture.

    To reduce variables, the test focuses on the game flow and core interactions. These include the title screen, character selection, the battle screen, character drawing, basic attacks, simple AI, and scene transitions.

    This test does not require the model to reproduce every timing detail of the original hardware. It checks whether the model can recover a high-level program from low-level implementation that runs, can be explained, and can be maintained.

    3. Recovering High-Level Logic from Disassembly: Where the Difficulties Lie

    The biggest difference between disassembly and source code is that information has been lost. Original variable names, types, comments, module boundaries, and design intent usually do not exist. The model does not see something like this:

    1. player->velocity_x += acceleration;

    Instead, it sees a series of instructions that read, write, shift, and conditionally jump on memory addresses.

    A reliable conversion usually involves the following steps.

    1. Build a Memory Access Table

    First, record where each memory address is read and written, and judge what state it might represent. For example:

    • An address that is repeatedly added to or subtracted from may be a coordinate or a velocity.
    • An address that changes only after input detection may be an input state.
    • An address that increments at fixed intervals and is used as an image index may be an animation counter.
    • An area accessed by several character routines may be global game state.

    This step cannot rely on a single function. It requires cross-checking against call relationships and observed runtime behavior.

    2. Recover Control Flow

    Jumps in assembly often serve several purposes at once, such as loops, conditional checks, state machine transitions, and exception handling. Translating them directly into nested goto statements may preserve local behavior, but it makes later maintenance very difficult.

    A better approach is to identify the state machine. For example, the original flow can be abstracted as:

    1. typedef enum {
    2. STATE_TITLE,
    3. STATE_SELECT,
    4. STATE_FIGHT,
    5. STATE_RESULT
    6. } GameState;

    Entry points and jumps can then be mapped to state transitions instead of mechanically preserving every jump structure. This makes debugging easier and reduces errors caused by address calculations.

    3. Separate Game Data from Platform Data

    Some of the original code exists only to support hardware mapping, storage media switching, or verification. After migration to the new runtime environment, this code may not need to be kept.

    If a model cannot distinguish game logic from platform adaptation code, it may translate unrelated verification routines as well. This creates a large amount of wasted work and can even cause errors, because the target environment has no matching hardware.

    4. Actual Results and Main Defects

    After several rounds of generation, compilation, and manual correction, the program could complete the basic flow. It could enter the title screen, select a character, load the battle scene, and start interacting. Characters could move and perform some attacks. This shows that the model recovered part of the game’s state machine and input handling logic.

    However, there is still a clear gap between “it runs” and “the migration is correct.”

    1. Sprite Slicing Errors

    On the character selection screen, some portraits showed horizontal banding. Common causes include:

    • Errors in tile index calculation;
    • Confusion between image width and height units;
    • Incorrect inference of the sprite block arrangement order;
    • Inconsistent row and column address offsets;
    • Palette indexes that do not correctly match the graphics data.

    These problems are easy for a human to spot, but the model often does not detect them on its own. It may judge the code structure to be reasonable and assume the drawing logic is correct as long as the code compiles.

    2. Characters Rendered as Blocks of Color

    In battle, characters sometimes appeared only as rough humanoid blocks of color, with outlines and details clearly missing. The model understood the overall goal of “draw a character,” but it did not fully recover the original rules for assembling tiles.

    Early platforms usually did not store a complete bitmap directly. Instead, they built characters from many small tiles, using flip flags, palettes, and coordinate offsets. If any one of these steps is misunderstood, the final image shows gaps, misalignment, or abnormal colors.

    3. Incomplete Animation State

    Characters could throw punches, but transitions between animation frames were unstable. Some moves ended early, some stayed on the wrong frame, and in some cases the attack state and the standing state were active at the same time.

    This is usually not a problem in a single function. It happens because the following states are not synchronized:

    • The current action;
    • The animation frame number;
    • Frame duration;
    • Horizontal and vertical velocity;
    • Whether switching actions is allowed;
    • Whether the attack hitbox has already triggered.

    If the model translates only the drawing functions and does not build a complete character state structure, animation behavior will be hard to stabilize.

    4. Incomplete AI Behavior

    The opponent could perform a small number of actions, but its behavior still fell short of the original. It might not track the player, fail to block, attack at the wrong time, or choose from a very limited set of actions.

    AI in early games is usually not complicated, but it depends on several discrete states and timers. If the model misses one conditional branch, the program may still run, but its behavior will drift noticeably from the original.

    5. Why Multimodal Recognition Is Still Unreliable

    In this kind of engineering work, screenshot recognition is important. Developers often provide the model with screenshots of errors, marked regions, and expected results, and ask it to determine whether the cause is coordinates, tiles, or palettes.

    Practice shows that the model can identify obvious overall problems, such as “the character is sliced into strips” or “the image is largely misaligned.” However, its precision in pinpointing causes is unstable:

    • It cannot reliably tell whether an error comes from the tile index or the drawing coordinates;
    • It often mistakes color problems for asset problems;
    • It does not rank several similar errors accurately by priority;
    • After seeing a fixed screenshot, it may overlook local defects that remain.

    Screenshots therefore cannot replace runtime logs and structured diagnostics. A more reliable approach is to provide the following together:

    • The coordinates of the erroneous region;
    • The current character state;
    • Tile indexes;
    • Palette indexes;
    • The order of drawing calls;
    • Before-and-after comparison screenshots.

    Image evidence shows where the problem is. Logs and variable values explain why it happens.

    6. The Role of Human Feedback in the Debugging Loop

    This kind of task is difficult to complete with a single prompt. A more effective method is a cycle of generate, run, observe, locate, and modify.

    Step 1: Limit the Scope of Each Change

    Do not ask the model to rewrite the entire project at once. Split the problems into separate modules, such as image layout, input handling, action switching, and collision detection, and adjust only one category per round.

    This has two benefits. It makes it easier to confirm whether a fix works, and it reduces the risk of the model changing other code that was already correct.

    Step 2: Keep the Symptoms Reproducible

    Every test should record a fixed sequence of operations, for example:

    1. Start the program;
    2. Enter character selection;
    3. Select a specific character;
    4. Enter battle;
    5. Perform one movement;
    6. Perform one attack;
    7. Capture the key screens.

    Only when the test steps are fixed can the differences between versions be compared meaningfully.

    Step 3: Describe Errors Precisely

    “The screen looks wrong” gives the model very little to work with. A better description states what can be observed:

    • The character’s right shoulder is shifted left by about one tile width;
    • The lower body in the third animation frame is drawn on the previous row;
    • After the opponent enters the attack state, it does not return to the idle state;
    • On the character selection screen, the portrait is split horizontally into several strips.

    The closer a description is to observable facts, the easier it is for the model to map the problem to specific code.

    Step 4: Give the Model Constraints

    Be explicit about what the model should do:

    • Do not modify input modules that have already been verified as correct;
    • Keep the existing data layout;
    • Change only the tile arrangement function;
    • Add debug output instead of deleting abnormal branches;
    • Explain the reason for each change and its likely scope of impact.

    These constraints noticeably reduce the chance that fixing one problem introduces two new ones.

    7. How to Build a More Objective Evaluation Standard for LLM Programming

    Judging a model only by its final screenshot can overstate or understate its ability. It is better to assess five dimensions together:

    1. First-Run Success Rate

    Whether the code the model generates first can compile and start shows its basic engineering organization skill.

    2. Feature Recovery Rate

    Measure how far each module has been recovered, including the title screen, input, state transitions, drawing, collision, and AI. Do not stop at whether the program starts.

    3. Defect Localization Ability

    Whether the model can quickly identify the source of an error from logs, screenshots, and reproduction steps is the key difference between simple code generation and real debugging ability.

    4. Change Stability

    A strong model should not only propose fixes. It should also avoid breaking existing functions. Regression results after each change are very important.

    5. Human Intervention Cost

    If the model needs a developer to point out every detail, mark every region, and supply many intermediate conclusions, its ability to work independently should be assessed with caution.

    8. Conclusion: Running Is Only the Starting Point; Understanding Is the Core

    Migrating disassembled programs to a modern runtime environment reveals the real limits of LLMs in complex software engineering. Models are generally good at quickly building frameworks, filling in common code, and completing local conversions. However, they still need experienced developers for low-level semantic recovery, graphics data inference, implicit state management, and cross-module debugging.

    This kind of task suits a human-AI collaborative approach. The model handles code reading, initial conversion, boilerplate generation, and candidate fixes. Humans verify assumptions, design tests, set priorities, and maintain the overall architecture.

    When evaluating a model, the question should not only be “Can it write code?” It should also ask three things:

    • Does it truly understand how the original program behaves?
    • Can it locate problems based on evidence instead of guessing from experience?
    • Can it keep the system stable through repeated changes?

    Only when a model closes this loop reliably across all three areas can it be considered capable of handling complex low-level migration work.