Z80 Machine Code Question?

embers

Reputable
Dec 27, 2014
103
0
4,710
If any of you reading this know any machine code related to the z80 CPU.

How would you go about comparing a single value to see if it is logic true or false and then acting upon it depending on the result?

Also how would you get the z80 CPU to lets say wait 5 seconds before restarting a program? Like halt for 5 seconds and then reset the program counter to memory location 0?

 
Solution


Hi,

most microarchitectures define false as zero and true as non zero. This is fairly consistent across the board.

As for testing those values, the Z80 and all x86 microprocessors have a status register which is updated after every operation. The bits in the status register provide information about the previous operation. The Z80 status bits are:
Z =...


Hi,

most microarchitectures define false as zero and true as non zero. This is fairly consistent across the board.

As for testing those values, the Z80 and all x86 microprocessors have a status register which is updated after every operation. The bits in the status register provide information about the previous operation. The Z80 status bits are:
Z = Zero
S = Sign (negative)
I = Interrupt
HC = half-carry (gotta love those joined registers)
CY = full carry
P/V = Parity / Overflow
N = 0 for add, 1 for subtraction

All conditional instructions act upon these flags. For example, JP Z jumps to the instruction in the operand if the zero flag is set. JP NZ jumps to the instruction if the zero flag is not set.

To test if a particular value is zero, simply execute an instruction that doesn't change the value and then test the zero bit.
Examples,

Add the value 0 to A and execute either JP Z or JP NZ

Compare A to the value zero and execute either JP Z or JP NZ
 
Solution