Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Wall_Axe
Manic Miner
Posts: 491
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Wall_Axe »

ohh you mean '9 and 9' in 2 nibbles
this does make outputting numbers to the screen a lot easier
AndyC
Dynamite Dan
Posts: 1386
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Wall_Axe wrote: Thu May 10, 2018 1:58 am ohh you mean '9 and 9' in 2 nibbles
this does make outputting numbers to the screen a lot easier
Yup. BCD is very handy when it comes to numbers you display on screen.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by RMartins »

keith56 wrote: Sun Mar 11, 2018 7:18 am It's quite curious how the different systems use the shadow registers
in my game, I use DI/EI when I use the shadow registers in a normal loop, but two EXX 'es and DI/EI are pretty much the same speed as a PUSH/POP, so there's rarely any cases it's worthwhile.
it seems interrupt handlers on most do not alter them, but the CPC does, I wonder what the 'best' way to use them overall is?
I believe you are not equating all the variables here, and mixing a few concepts.

DI/EI (4T/4T), just controls if maskable interrupts are enabled or not.
Nothing to do with preserving register contents. You can still receive an NMI in the middle of the loop.

NOTE: This is one of the reasons, why assembly tricks using the stack register (SP) and PUSH/POP can be dangerous on machines that have support for NMIs. Any ZX Spectrum can have NMIs being generated, by an external interface, like DivMMC for example.

EX Af, Af' (4T)
EXX (4T)
These are used to SWAP between the register banks, they do not save anything anywhere.

These were designed/created for REAL TIME applications, where time spent inside an interrupt routine is crucial, and must be very low, so these systems, usually, reserve the shadow registers, to be used inside the interrupt routine, to avoid having to backup the registers before using them.
This obviously reduces the number of register you can use in regular programming.

PUSH RR/ POP RR (11T/10T)
These actually, allow you to save the registers on stack, or somewhere else you might move the stack to.
However, to save the registers, and then restore them, you will need a lot of operations:

Code: Select all

PUSH AF
PUSH BC
PUSH DE
PUSH HL

... do the interrupt magic here

POP HL
POP DE
POP BC
POP AF
For the same registers, that you use EX AF, AF and EXX, you will need:
4 * 11T + 4 * 10T = 44 + 40 = 88T

Which is a lot different from 4 + 4 = 8T, for the Swap instructions.

NOTE: I did not include PUSH/POP for IX and IY, to be fair on the comparison.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by RMartins »

Just a correction, for the Swap instructions, we need 4 instructions, not 2:

Code: Select all

EX AF, AF'
EXX

... do the interrupt magic here

EX AF, AF'
EXX
Which is ( 4 + 4 ) + ( 4 + 4 ) = 16T
Still a long way from the 88T for the PUSH/POP solution.
User avatar
g0blinish
Manic Miner
Posts: 281
Joined: Sun Jun 17, 2018 2:54 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by g0blinish »

RMartins wrote: Thu May 24, 2018 6:41 pm Just a correction, for the Swap instructions, we need 4 instructions, not 2:

Code: Select all

EX AF, AF'
EXX

... do the interrupt magic here

EX AF, AF'
EXX
Which is ( 4 + 4 ) + ( 4 + 4 ) = 16T
Still a long way from the 88T for the PUSH/POP solution.
unsafe solution. If you are using music player into interrupt, alt pairs may changed
Post Reply