I think this code should help: http://pastebin.com/FaQVAdzt
The main things I've done are this:
1. Push whatever registers you're using before you call routines that mess them up (like a sprite routine, which probably uses nearly all of the registers) and pop them off after.
2. ld a,8 \ ld b,a \ ld a,8 \ ld c,a is entirely unnecessary on multiple levels. First of all, you can simply use ld b,8 \ ld c,8 without using register A. If you're wondering what ld instructions are legal, I've made a Google Doc thing for that (green/yellow means it's allowed, red means it isn't). But even ld b,8 \ ld c,8 can be optimized further. This may take a while to explain...
Let's say you have a 2-digit number (in base 10) and you want both digits to be eight. You could do this: ld FirstDigit,8 \ ld SecondDigit,8 or you could just load 88 into the number in the first place, making both digits equal to eight. You can do the same in assembly, kinda. Think about how you go from two eights to 88, mathematically. You take the number that comes first and multiply it by 10 (because we are dealing with base 10).
So in assembly, since each register (in this case, B and C) each hold a number between 0 and 255, we are sort of dealing with base 256. So we multiply the first number by 256, add in the second one, then load that into BC. So you get ld bc,(8*256)+8. I hope that makes sense...
The main things I've done are this:
1. Push whatever registers you're using before you call routines that mess them up (like a sprite routine, which probably uses nearly all of the registers) and pop them off after.
2. ld a,8 \ ld b,a \ ld a,8 \ ld c,a is entirely unnecessary on multiple levels. First of all, you can simply use ld b,8 \ ld c,8 without using register A. If you're wondering what ld instructions are legal, I've made a Google Doc thing for that (green/yellow means it's allowed, red means it isn't). But even ld b,8 \ ld c,8 can be optimized further. This may take a while to explain...
Let's say you have a 2-digit number (in base 10) and you want both digits to be eight. You could do this: ld FirstDigit,8 \ ld SecondDigit,8 or you could just load 88 into the number in the first place, making both digits equal to eight. You can do the same in assembly, kinda. Think about how you go from two eights to 88, mathematically. You take the number that comes first and multiply it by 10 (because we are dealing with base 10).
So in assembly, since each register (in this case, B and C) each hold a number between 0 and 255, we are sort of dealing with base 256. So we multiply the first number by 256, add in the second one, then load that into BC. So you get ld bc,(8*256)+8. I hope that makes sense...