Skip to content

Instantly share code, notes, and snippets.

@thetrung
Created July 15, 2026 03:51
Show Gist options
  • Select an option

  • Save thetrung/50114b95f2c48be30d804509e56997a9 to your computer and use it in GitHub Desktop.

Select an option

Save thetrung/50114b95f2c48be30d804509e56997a9 to your computer and use it in GitHub Desktop.
Sample Asm code for eZ80
; =========================================================================
; Minimal eZ80 Assembly Boot Code
; Targets: eZ80F91 / General eZ80 Series
; =========================================================================
ASSUME ADL = 1 ; Instruct assembler to output 24-bit ADL opcodes
ORG $000000 ; Power-On Reset Vector
reset_vector:
DI ; Disable interrupts during hardware setup
JP.L init_system ; Long Jump to force 24-bit addressing transition
ORG $000066 ; Non-Maskable Interrupt Vector
nmi_vector:
RETN
; =========================================================================
; Hardware Register Definitions (eZ80F91 Spec)
; =========================================================================
UART0_RBR EQU $C0 ; Receiver Buffer Register
UART0_THR EQU $C0 ; Transmitter Holding Register
UART0_DLL EQU $C0 ; Divisor Latch LSB
UART0_DLM EQU $C1 ; Divisor Latch MSB
UART0_IER EQU $C1 ; Interrupt Enable Register
UART0_FCR EQU $C2 ; FIFO Control Register
UART0_LCR EQU $C3 ; Line Control Register
UART0_LSR EQU $C5 ; Line Status Register
RAM_CTL EQU $B4 ; On-chip SRAM Control Register
SYSTEM_CTL EQU $B6 ; System Control Register
; =========================================================================
; System Initialization
; =========================================================================
init_system:
; 1. Enable On-Chip RAM (Assumes 8KB/16KB internal SRAM)
LD A, $C0 ; Enable internal SRAM, map to top of memory
OUT0 (RAM_CTL), A
; 2. Initialize Stack Pointer
; Using the top of the internal SRAM (e.g., $FFFFFF)
LD SP, $FFFFFF
; 3. Setup UART0 (9600 Baud assuming a 50MHz System Clock)
LD A, $80 ; Enable Divisor Latch Access (DLAB)
OUT0 (UART0_LCR), A
LD A, $45 ; Divisor Latch LSB ($0145 = 325 for 9600 baud)
OUT0 (UART0_DLL), A
LD A, $01 ; Divisor Latch MSB
OUT0 (UART0_DLM), A
LD A, $03 ; Reset DLAB, Set character length to 8 bits, 1 stop, No Parity
OUT0 (UART0_LCR), A
LD A, $00 ; Disable UART interrupts
OUT0 (UART0_IER), A
; 4. Main Application Entry Point
LD HL, msg_boot ; Point to the string
CALL print_string
loop_forever:
JR loop_forever ; Trap CPU here
; =========================================================================
; Helper Functions
; =========================================================================
; Prints a null-terminated string via UART0
print_string:
LD A, (HL)
OR A, A ; Check if byte is null (\0)
RET Z ; If null, return
CALL uart_tx_byte ; Send the byte
INC HL ; Move to next character
JR print_string
; Transmits a single byte in Register A via UART0
uart_tx_byte:
PUSH AF ; Save the character
tx_wait:
IN0 A, (UART0_LSR) ; Read Line Status Register
AND A, $20 ; Check THRE (Transmitter Holding Register Empty) bit
JR Z, tx_wait ; If 0, buffer full; loop until clear
POP AF ; Restore character
OUT0 (UART0_THR), A ; Transmit byte
RET
; =========================================================================
; Data Section
; =========================================================================
msg_boot:
DB "\r\n--- eZ80 System Booted Successfully ---\r\n", 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment