36 byte Snowflake in Assembler
Author: Serato / Finnish Gold
Category: Christmas Challenge
System: ZX Spectrum
Language: Z80 Assembler
Len source code: 1196
Len exe file:
Len code only: 36
Instructions:
Assemble, load, and start with LIST USR 30474
Techniques that save bytes:
- Simple iteration, no subroutines
- Program flow automatically renders the central + (no cost)
- Only draws stars (not spaces) so no character code calculation
- Start address of $7709 is in BC, loaded to HL in 2 bytes
- aligns bitmap bytes at $7700 + col, so L is also column number
- H = %01110111, so an 8-bit rotate sets C to 0 every 4th time
- Modifies the bitmap in place so no need to keep value in register
- branch on carry set is both conditional plot and also rotation loop exit flag
More detail:
This routine draws the pattern from the inside out, by first drawing the stars
that form the + and then right shifting bits out of the bitmap from preceding
bytes one at a time. The first iteration plots the bitmap along the same row and
column as the + so the contents of the pattern byte do not matter. This bit
shifting is done in place turning each byte of the bitmap to 0.