###### tags: `assembler` `z80` `cursed`
Cursed Z80 assembler code
==
this was done to show younger people what bad things were sometimes done when coding on older systems. Sometimes to save memory when every byte was important, sometimes just because you *could* and it would still work.
Its demonstrated on an 8-bit Amstrad CPC series emulator simply because I was too lazy to find a decent cross assembler and get the .HEX files into an older Z80 computer, the whole thing is *silly* and bad and I am not a good rĂ´le model (indeed monkeying around with the stack like this is how heckers write stuff like viruses..)
```
; cursed Z80 code;deliberately bad idea,
; I don't encourage anyone doing this in modern era
; TBH equally bad idea in 1980s..
; door mijn schuld, door mijn schuld, door mijn grote schuld
cout equ #bb5a ; emit characters to console
start org #4000
ld hl,msg1
ld de,nxtbit ; next part of code
push de ; push that on the stack
loop ld a,(hl)
or a,a
ret z ; the RET addr will be DE
push hl ; COUT clobbers HL
call cout
pop hl ; so we must preserve it
inc hl ; HL is msg pointer
jr loop
nxtbit ld de,nxtbit2
push de ; return addr on stack
ld hl,msg2
jp loop
nxtbit2 ld de,nxtbit3
push de
ld hl,msg1 ;reuse msg1
jp loop
nxtbit3 ld de,einde
push de
ld hl,msg3
jp loop
einde ret ; end from all this madness
msg1 defb "Crackman on the line, freaking out..",#0d,#0a,0
msg2 defb "Don't do that!",#0a,#0a,#0d,0
msg3 defb "DANGEROUS!",#0a,#0a,#0d,0
```
And it actually assembles and works..

(this is where the text comes from, a bit of an anachronism as the tune is from a few years later in 1992 and I was too distracted by the rave scene to do that much coding (maybe just as well))
{%youtube 9CmbEjZYiVU %}