Krolyxon
Commit 1504706

Branches

Tags

Refs →

bench51README.md

226 lines · 9.7 KB

bench51 — an 8051 assembler, simulator & debugger

A small, Keil µVision-style IDE for the Intel 8051, in two flavours: a TUI that runs in your terminal, and a desktop GUI (bench51-gui) laid out like µVision. Write assembly in the built-in editor, assemble it, inspect the listing and Intel HEX output, then run, pause and single-step the program while watching registers, SFRs, memory, ports, timers, interrupts and the serial port.

Built in Rust with ratatui and egui. It is a learning tool, not a cycle-exact replacement for a vendor simulator.

Debugging serial_hello.asm: source, registers, peripherals, IRAM and the UART console

Editor with the assembled Keil-style listing Stopped at a breakpoint inside the timer 0 ISR, SFR view
Editor + assembled listing Breakpoint inside a timer ISR, SFR view
Assembler errors marked in the gutter and listed in the Errors tab Intel HEX output tab
Assembler errors in the gutter and Errors tab Intel HEX output

Why this exists

I had microcontroller practicals to get through, and the course expects you to use Keil µVision. Keil µVision doesn't run on Linux. Rather than fight with Wine or a Windows VM every lab session, I wrote my own: bench51 does the parts of µVision those practicals actually need (write the code, assemble it, look at the listing and HEX, step through it and watch the registers) right in the terminal.


Features

Usage

cargo install --path .                               # installs the `bench51` binary

cargo run --release -- examples/serial_hello.asm      # open in the TUI
cargo run --release                                   # start with a template
cargo run --release -- firmware.hex                   # disassemble & debug a HEX file

# Headless assembly: writes prog.hex and prog.lst
cargo run --release -- --assemble prog.asm
cargo run --release -- --assemble prog.asm -o out.hex --lst out.lst

--clock <MHz> sets the oscillator frequency used for the elapsed-time display (default 11.0592).

Desktop GUI

bench51-gui is the same assembler and simulator behind a µVision-style window: menus and toolbar, a Project window, the editor with breakpoint gutter, Build Output, and in a debug session the Registers, Disassembly, Memory, Symbols, UART #1, Ports, Timers and Interrupts windows. Every window docks and tabs wherever you drag it; the edit and debug layouts are remembered separately, as in µVision. It follows a monochrome, dot-matrix design (Space Grotesk, Space Mono and Doto, bundled) in a dark and a light theme.

Debug session in the GUI: registers, source with the PC, disassembly, memory and UART #1

Editor and Keil-style build output Stopped at a breakpoint in a timer ISR, light theme
Editor + build output Breakpoint in a timer ISR, light theme
Ports, timers and interrupts windows docked side by side Assembler errors in the gutter and Build Output
Peripheral windows, rearranged Assembler errors
cargo install --path crates/bench51-gui                  # installs `bench51-gui`

cargo run --release -p bench51-gui                        # welcome screen
cargo run --release -p bench51-gui -- examples/*.asm      # open several files
cargo run --release -p bench51-gui -- --theme light firmware.hex

--theme system|dark|light overrides the theme chosen in View → Theme, and --clock <MHz> the Xtal set in Project → Options for Target.

The keys are µVision's, with the TUI's as aliases:

Key Action
F7 build target (also writes .lst and .hex next to a saved file)
Ctrl-F5 / F4 start / stop the debug session
F5 run / stop
F11 / F10 step into / step over
Ctrl-F11 / F12 step out
Ctrl-F10 / F8 run to the cursor line
F9 / Ctrl-Shift-F9 toggle breakpoint / remove all breakpoints
F6 reset the CPU
Ctrl-N / Ctrl-O / Ctrl-S / Ctrl-W new / open / save / close
Ctrl-F find
F1 all shortcuts

Click the gutter to toggle a breakpoint, double-click a byte in Memory to change it, click a pin in Ports to hold it low from outside, and click the bit chips in Registers, Timers and Interrupts to flip SFR bits. Files can be dropped onto the window.

On Linux it runs on Wayland and X11 and uses the XDG desktop portal for file dialogs. To add it to your application launcher:

install -Dm644 crates/bench51-gui/assets/bench51-gui.desktop ~/.local/share/applications/bench51-gui.desktop
install -Dm644 crates/bench51-gui/assets/bench51-gui.svg ~/.local/share/icons/hicolor/scalable/apps/bench51-gui.svg

It also builds for Windows and macOS. On Debian or Ubuntu, first install the packages egui needs: libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev.

Keys

Key Action
F1 help
F2 / Ctrl-S save (assembling a saved file also writes .lst and .hex next to it)
F3 / Ctrl-O open .asm or .hex
Ctrl-G edit in $EDITOR; on save & exit the buffer reloads and reassembles
F4 switch Edit ⇄ Debug
F7 assemble, reset and load
F5 run / pause (assembles first if the source changed)
F11 / F10 / F12 step into / step over / step out
F8 run to cursor
F9 toggle breakpoint on the cursor line
F6 reset
Ctrl-Q quit

Edit mode: Alt-1/2/3 switch between Listing, HEX and Errors; Alt-↑/↓, Alt-PgUp/PgDn scroll them. The editor uses Emacs-style keys (Ctrl-U undo, Ctrl-R redo, Ctrl-Y paste).

Debug mode: Tab cycles focus between Source, Memory, Ports and Serial. Letter shortcuts work too, for terminals that swallow function keys: r run/pause, s step, n step over, o step out, g run to cursor, b breakpoint, x reset, i/f/d/c show IRAM/SFR/XRAM/CODE, p poke memory, +/- speed, . jump to PC, Esc pause / back to editor.

Examples

File Shows
examples/blink.asm port toggling, delay loops, ACALL/RET
examples/timer_irq.asm timer 0 mode 1 interrupt
examples/serial_hello.asm UART setup, string output with MOVC, echo
examples/button_int0.asm edge-triggered INT0, idle mode
examples/bcd_add.asm ADDC and DA A with packed BCD
examples/lookup_movc.asm 7-segment table lookup

Notes and limitations

Development

cargo test --workspace     # assembler, CPU, peripheral, session and example-program tests
cargo clippy --workspace --all-targets

Code layout: