Skip to content

Instantly share code, notes, and snippets.

@Sarverott
Last active March 16, 2023 19:53
Show Gist options
  • Save Sarverott/b9cbd99a80e4e2f9ca6ded05606123d2 to your computer and use it in GitHub Desktop.
Save Sarverott/b9cbd99a80e4e2f9ca6ded05606123d2 to your computer and use it in GitHub Desktop.
code in assembler for Intel 8080, that is self-replicatory virus example. Written for fun for 80's old school microprocessor unit. Tested on http://asm80.com/ and https://github.com/eliben/js-8080-sim emulators
;asmWorm - self-replication code in assembler for Intel 8080
;Sett Sarverott @ 2022
lxi h, 0000h ;start read
lxi d, 002fh ;stop read/start write
mvi c, 2fh ;length
mvi a, 00h ;index
replicator:
;copy this code to space after this code
mov b, m ;b=*read_pointer
xchg
mov m, b ;*write_pointer=b
xchg
inx h ;read_pointer++
inx d ;write_pointer++
inr a ;index++
cmp c ;flags=index-length
jnz replicator ;if(flags!=0) goto replicator label
;constants update
mov b, h
mov c, l
inx h
mov m, c
inx h
mov m, b
;lxi h in line 3 - read start
inx h
inx h
mov m, e
inx h
mov m, d
;lxi h in line 4 - write start
lxi d, 000eh
dad d
;get line 19 in compiled ram - jnz replicator (label in complied code is constant memory addres)
mov d, b
mov e, c
lxi d, 000ah
xchg
dad b
;get line 7 label address
xchg
mov m, e
inx h
mov m, d
;jnz in line 19 updated with new address of label in line 5 for copy
;after that execute new code written after last command of current code
;effect - after execution of code independent and fully operational copy starts on end of current code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment