Skip to content

Instantly share code, notes, and snippets.

@bryc
Created March 31, 2026 06:25
Show Gist options
  • Select an option

  • Save bryc/42e379fc676494fa722ca404241e74d5 to your computer and use it in GitHub Desktop.

Select an option

Save bryc/42e379fc676494fa722ca404241e74d5 to your computer and use it in GitHub Desktop.
Checksums written in 8-bit Assembly
.cpu 8080
; 8-bit Modulo-255 checksum (aka end-around-carry) - Null terminator version
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
mvi C, $00 ; Initialize checksum value to zero
lxi H, data ; Store the RAM address of our input data, in register HL
csum:
mov A, M ; Get next input byte (Accumulator = RAM at address HL)
cpi 0 ; If Accumulator is zero, enable zero flag
jz done ; If zero flag is set, break out of loop
add C ; Sum with current checksum value (Add stored checksum value to Accumulator)
aci 0 ; Add the carry result (either a 0 or 1 - necessary for Modulo-255 checksum)
mov C, A ; Update checksum with new result (Set checksum register to Accumulator value)
inr L ; Increment RAM address index, to point to next byte
jmp csum ; Return to the start of loop
done:
hlt ; Halt (end) the program execution
data: ; Our input data
db "Hello World, Lorem Ipsum, blah blah!",0
.cpu 8080
; 8-bit Modulo-255 checksum (aka end-around-carry) - Fixed length version
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
mvi C, $00 ; Initialize checksum value to zero
lxi H, data ; Store the RAM address of our input data, in register HL
; Calculate end address (Start addr + len)
mov A, L ; Get data start address
adi 36 ; Add data length to start address
mov E, A ; Store the calculated end address, so we know when to stop
csum:
mov A, M ; Get next input byte (Accumulator = RAM at address HL)
add C ; Sum with current checksum value (Add stored checksum value to Accumulator)
aci 0 ; Add the carry result (either a 0 or 1 - necessary for Modulo-255 checksum)
mov C, A ; Update checksum with new result (Set checksum register to Accumulator value)
inr L ; Increment RAM address index, to point to next byte
; End loop if current address equals the final address
mov A, L ; Get the current RAM address value
cmp E ; Compare with previously stored end address
jz done ; If equal, break out of loop to end program
jmp csum ; Otherwise, repeat the routine again
done:
hlt ; Halt (end) the program execution
data: ; Our input data
db "Hello World, Lorem Ipsum, blah blah!",0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment