LLM Coding in Practice: From Code Generation to Firmware Bug Fixes
Evaluating large language models as coding assistants requires more than measuring how fast they generate code. This article uses the example of a graphics game running in a firmware environment to explain why a complete engineering loop—code review, debugging with logs, display mode switching, and fallback diagnosis—matters more than code generation itself. It covers how to define "done" before handing tasks to a model, how to review interface contracts and pointer ownership, how to build fault boundaries with staged logging, and how to run two development rounds with different goals. It also provides a practical framework for objectively measuring AI-assisted coding results and building efficient human-AI collaboration workflows.
1. Judge LLM Coding by Whether It Closes the Delivery Loop
When discussing the coding ability of large language models, the easiest things to observe are code generation speed, the number of files produced, and module organization. These are useful references, but they are not enough to determine whether a program actually works.
An engineering task involves at least five stages: understanding requirements, organizing code, completing the build, verifying runtime behavior, and fixing defects. A model that generates neatly structured source code has only completed part of the job. In firmware, embedded systems, and other low-level environments, the gap between “code that compiles” and “code that runs correctly” is often considerable.
The original practice material offers a typical scenario: a graphics-based mini game with reasonably complete module separation, but without reliable build and run results. An AI coding tool was then used to review the code, add debug output, and adjust the graphics initialization flow, gradually narrowing down issues such as unexpected program exit and a blank screen.
The point of this kind of exercise is not to prove that one model beats another, but to surface a more general question:
Can an LLM turn “code that looks reasonable” into “a program proven to run”?
So when evaluating AI coding tools, the focus should shift from one-shot generation performance to the complete engineering loop.
2. Why Firmware Graphics Programs Are Good Tests of Engineering Ability
Ordinary applications benefit from mature windowing systems, input frameworks, and debugging facilities. Graphics programs in firmware environments must handle far more low-level details directly, such as locating graphics protocols, selecting display modes, accessing the framebuffer, polling input events, and cleaning up resources.
Even a simple block game may involve all of the following:
- Whether the target binary format matches the execution environment;
- Whether build configuration includes the required protocol declarations and dependencies;
- Whether the graphics interface is successfully acquired;
- Whether the current display mode supports the intended drawing method;
- Whether the framebuffer address, pixel format, and scanline pitch are correct;
- Whether the main loop terminates unexpectedly;
- Whether input reads block game updates;
- Whether error paths leak resources or keep dereferencing invalid pointers.
These problems generally cannot be solved by tweaking the game algorithm. A program may have complete collision detection, scoring rules, and a modular structure, yet fail to display anything because of a single error in the initialization phase.
That said, a low-level graphics task only reflects how a model performs in that particular scenario. It cannot be generalized into an overall verdict across all coding tasks. Business API development, data processing, concurrent programs, and low-level programs all place different demands on the model.
3. Define “Done” Before Handing the Task to the Model
When AI coding tasks fail, the cause is not always weak generation ability. Often, the requirement lacks a verifiable boundary.
“Write a game that runs” is far too vague. A more effective task description should specify the execution environment, deliverables, how to operate the program, and acceptance criteria. For example:
- The program builds reproducibly following fixed steps.
- When launched, it shows a test screen and the basic game area.
- The user can move, rotate, pause, and quit.
- When the input device briefly produces no events, the main loop still keeps running.
- If graphics initialization fails, the program prints an error message and exits safely.
- On exit, the program releases the temporary resources it owns.
For low-level projects, it also helps to distinguish two development strategies up front:
Building from scratch mainly tests requirement understanding, architecture design, and code generation.
Taking over and fixing emphasizes reading existing code, identifying wrong assumptions, controlling the scope of changes, and regression testing.
The effort involved in each cannot be judged by file count alone. Taking over and fixing may save time writing code, but it may also be harder because of hidden defects and unclear design intent.
4. Code Review Should Check Interface Contracts, Not Just Structure
When taking over an existing project, a sensible first step is code review. But the review should not stop at style suggestions like “add more comments” or “refactor into smaller modules.”
A more valuable review follows the program’s execution path:
Entry function → environment checks → protocol acquisition → mode setup → graphics initialization → input initialization → main loop → cleanup and exit
At each stage, answer three questions:
- What are the conditions for the call to succeed?
- How is failure handled?
- For how long is successfully returned data valid?
1. Cross-check declarations, calls, and build dependencies
Low-level interfaces typically have explicit calling conventions, parameter types, and return statuses. If declarations are mismatched, parameter widths are wrong, or required dependencies are missing from the build, code can look locally reasonable yet fail at build time or runtime.
When reviewing, prioritize checking interface declarations and build configuration before rewriting business logic.
2. Clarify pointer origin and ownership
For every important pointer, record:
- Who created or returned it;
- Whether the caller is responsible for freeing it;
- Whether it depends on another object remaining alive;
- Whether it remains valid after an environment state change;
- Whether other references exist after it is freed.
A common mistake is treating a pointer returned by an interface as permanently valid data. Another is asserting, after seeing a runtime anomaly, that some specific call freed some specific memory.
A more rigorous approach is to confirm the lifecycle against interface contracts, error paths, and runtime logs—rather than turning speculation into conclusions.
3. Distinguish code defects from environment defects
A build failure may come from the source code, or from the target architecture, missing dependencies, or build configuration. A runtime failure may come from the code, or from an execution environment that does not provide the required interface.
If these two categories get mixed up, the model tends to keep modifying unrelated code, which only widens the troubleshooting scope.
5. Program Exits After Startup: Use Logs to Establish Fault Boundaries
A program that prints a startup message and immediately exits is a classic symptom in low-level debugging. What matters most here is not guessing the cause, but finding “the last step confirmed to have succeeded.”
Before graphics output can be trusted, use an independent debug output channel to log progress. The log should include at least:
- The current execution stage;
- Return statuses of key calls;
- Whether important objects are null;
- The current mode number and display dimensions;
- The framebuffer address and available capacity;
- The reason the main loop exited.
Logs should not just emit a stream of “starting,” “continuing,” “done.” They must answer: which call failed, which branch was taken after the failure, and which preconditions were not met.
For example, initialization can be split into multiple checkpoints:
Stage 1: Confirm the entry point executedStage 2: Locate the graphics interfaceStage 3: Enumerate candidate modesStage 4: Set the target modeStage 5: Read the currently effective graphics infoStage 6: Draw a solid-color test screenStage 7: Enter the input and update loop
If the log stops at stage 4, focus on the mode-setting call and its return value—not on collision detection or scoring logic.
Every change should also state its assumption. For example: “The current drawing uses information saved before the mode switch, which may not match the actual mode.” Then verify by re-reading the current state. If nothing changes, keep the evidence and keep investigating—don’t treat the assumption as a confirmed root cause.
6. After a Mode Switch, Re-establish Graphics State
One important principle in graphics initialization: the candidate mode information you queried is not the same as the currently active mode state.
Candidate modes help the program choose resolution and display settings. After switching modes, the rendering module should initialize based on the currently effective state—never assume the previously cached information still applies.
A reliable flow usually looks like this:
- Query available modes.
- Select a mode that meets the requirements.
- Call the mode-setting interface.
- Check whether the call succeeded.
- Read the currently effective mode information.
- Initialize the drawing logic based on the actual dimensions, pixel format, and scanline pitch.
Here it is important to distinguish “stale state” from “invalid memory.” After a mode switch, old information may no longer represent the current display state; however, whether a query result was freed and when it became invalid must be judged against the interface contract and the actual code—you cannot blanketly claim that “switching modes inevitably produces dangling pointers.”
Framebuffer addressing is not just screen width
When accessing the framebuffer directly, pixel addresses are usually computed from the actual scanline pitch:
pixel offset = y × pixels stored per row + x
The number of pixels stored per row does not necessarily equal the visible width. Ignoring end-of-row padding can cause diagonal misalignment, torn-looking image arrangement, or out-of-bounds access.
Additionally, before drawing, confirm the pixel format. Never assume every environment uses the same color channel order, and never assume all modes support the same direct-write method.
7. Program Keeps Running, but No Graphics Appear
“No picture” is a result, not a single cause.
It may mean the graphics protocol was not correctly acquired, the mode switch failed, the framebuffer address is invalid, drawing went out of bounds, or the program never even reached the rendering stage.
One possibility is an incorrectly configured protocol identifier. In low-level environments, similarly named identifiers may serve different purposes—interface lookup, event notification, or something else—and they cannot be swapped based on name similarity alone.
When troubleshooting, check:
- Whether the identifier matches the target interface;
- Whether the returned object matches the expected interface layout;
- Whether the lookup call succeeded;
- Whether the execution environment provides that interface;
- Whether subsequent mode reads and drawing calls succeed.
Next, draw a minimal test screen first—for example, a solid-color background plus one fixed rectangle. Only after the minimal graphics check passes should you bring back text, checkerboards, moving blocks, and animation.
This effectively isolates the problem: if even a solid background can’t be displayed, game rules are usually not the priority.
8. Two Development Rounds Should Have Different Goals
Splitting work into “make it run” and “then refine” is reasonable, but each round needs its own acceptance criteria.
Round 1: Build the minimal runnable pipeline
This round only addresses the critical path:
- Build artifacts are produced;
- The program starts;
- The graphics interface initializes;
- Simple graphics display;
- Input can be read;
- The main loop keeps running;
- The exit path is explainable.
Minimize the number of modules changed simultaneously. If you rewrite the entry point, rendering, input, and game logic all at once, the program may recover, but you will have no idea which change actually fixed it.
Round 2: Improve correctness and maintainability
Once the minimal pipeline works, check:
- Whether block movement and rotation stay within bounds;
- Whether collision with walls and settled blocks behaves consistently;
- Whether the board updates correctly after clearing lines;
- Whether game speed is affected by machine execution speed;
- Whether rapid key presses and pause/resume behave as expected;
- Whether exit and error paths release resources;
- Whether logs can distinguish normal exit from abnormal failure.
Visual polish belongs to this phase, but it must not replace functional verification. A prettier interface does not mean a more stable program.
9. How to Objectively Evaluate AI Coding Results
Time spent on different tasks cannot directly rank model capability. Task complexity, existing code quality, environment preparation, and human intervention all affect the outcome.
A more sensible approach is to fix the task conditions and record multiple dimensions:
| Dimension | Evidence to observe |
|---|---|
| Build reliability | Can the project be rebuilt following fixed steps? |
| Runtime correctness | Does it pass explicit acceptance cases? |
| Diagnosis ability | Does it use logs to narrow down faults? |
| Change quality | Are modifications targeted at root causes? |
| Regression awareness | Are related features checked after fixes? |
| Human cost | How much environment and debug info must humans supply? |
| Explanation quality | Does it separate facts, assumptions, and unverified items? |
Subjective impressions can be included, but they should be converted into recordable process observations. For example, rather than saying “the model really understands low-level development,” record whether it proactively checks return values, whether it spots state-caching issues, and whether it proposes a minimal reproduction.
A single success is case evidence, not proof of stable capability. Only repeated runs, testing under abnormal conditions, and complete change records make a conclusion trustworthy.
10. Building an Efficient Human-AI Collaboration Workflow
For complex engineering tasks, it helps to require the model to deliver four items per round:
- Confirmed facts: logs, build results, and reproducible symptoms.
- Current hypotheses: possible root causes and the evidence behind them.
- Minimal change: the scope to be adjusted in this round.
- Verification steps: how to judge whether the change works and how to check for regressions.
At the same time, keep a working version and complete test steps on hand so you don’t lose your baseline after a chain of edits. For low-level code, manually double-check pointer lifecycles, boundary calculations, interface declarations, and failure paths.
If a task involves writing to real firmware or modifying persistent configuration, validate it in an isolated test environment first, and clearly separate dangerous operations from ordinary build-and-run activity. A mini game running in testing does not mean its code can enter a real device’s critical boot path without review.
Ultimately, the value of LLM-assisted programming is not “writing all the code in one shot for the developer.” It lies in helping teams read code, form hypotheses, make localized changes, and verify results faster. The real highlight worth watching is whether it can consistently maintain this chain of evidence: bounded requirements, justified changes, logged faults, and reproducible results. Only then can AI coding move from a demonstration-style generation process into reliable engineering practice.
