Does instruction POP in Z80 has an execute cycle?

Discussion in 'Homework Help' started by thexy, Jan 17, 2016.

  1. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    For example
    MOV [HL], A
    Fetch 0000h It goes from memory to instruction reg, value 77h
    Execute In Memory bus it goes from A to MEM

    MOV label, HL
    Fetch 0000h It goes from MEM to IR, value 22h
    Fetch 0001h It goes from MEM to ZR_lo
    Fetch 0002h It goes from MEM to ZR_hi
    Execute ZR It goes from HL_lo MEM
    Execute ZR It goes from HL_hi MEM

    How do I know how much I'll have execute cycles, how do I know if I'm going to have execute at all and where it will start?

    Can someone do for instruction ROR and POP?
    In my case I don't see execute cycle there at all :(
     
  2. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
    Hi,

    See the manual. It will have all instructions and execute times.
    The POP instruction has to take a value from the stack and place it into a register, and also increment the stack pointer. That has to take some time even though it might not be too much time. The stack is just memory addressed by the stack pointer.
     
  3. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    In my manual it's written that for example POP instruction has 1 byte, opcode is F1h, but how from that infos I can know how many fetch and execute cycles I need?
     
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    If I recall right, the duration of a machine cycle (or whatever was the actual name) was mentioned in the data sheet.

    Look if there is a timing diagram precisely for that as well.
     
  5. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
    Hello,

    In the user manual, the pop instructions are given on the pages 117-120 (131-134 in the PDF).

    Bertus
     
    atferrari likes this.
  6. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    So "machine cycles" (3) after all... The rest is to see how a machine cycle relates to Fosc.
     
  7. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
    Hello again,

    Isnt it better to use the T states?

    For example, at 4 MHz each T state is 0.25us, so for an instruction that uses 10 T states it would take 2.5us to execute. At 1MHz it would take 10us to execute.

    The POP instructions vary based on what is being POP'ed. From around 10T and up.

    BTW, thanks to Bertus for posting that pdf manual. It has probably been 20 years now since i last looked at it. The Z80 was my favorite processor back then.
     
  8. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
  9. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    Wow! Wondering if I ever knew that! Most probably, but last programming I did with a Z80 was around 1983, that is 30++ years ago. Moving the Timex Sinclair's stack was kind of an achievement to me...!
     
  10. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    Plus the execute time is affected by possible Z80 memory cycle wait times for every machine cycle or extra waits for an M1 instruction cycle.

    This makes it possible to use very slow memory or to emulate memory/io for the Z80 processor.

    http://forum.allaboutcircuits.com/threads/memio-emulator-for-z80.117003/#post-916798
     
  11. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
    Hi,

    Thanks, that looks interesting. Been a long time now but i guess people are still using these? That's cool.
    If i did not have so much else on the table right now i'd start fooling around with that processor again.
     
  12. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
  13. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
    Hi,

    Wow, that's longer than my last Z80 project.
    Timex Sinclair stack was interesting too, very cool how they did everything with interrupts.
    I have the entire disassembly of the Timex Sinclair's ROM, including all the math routines and notes :)
    It's in a book that was put out in the 80's not sure if it is around anymore though.
    I'll check that site Bertus linked to.
     
  14. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    I agree, it's better to use T States. Machine cycles vary in the number of clock cycles. This is shown clearly in Figure 4 of the PDF posted by bertus.

    And I agree with MrAl. The Z80 was a great improvement on the 8080 series.
     
  15. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490
    Hi,

    I really loved it and starting using that one over the 8080 as soon as i could.
    The 'big' debate at the time was over using a chip like a Z80 over a RISC type chip. I had preferred the larger instruction set even though there was more to learn at first and the assembler was much more complicated (i had to create my own assembler as at the time i had no such thing).
    These days CPU types seem to have started with a RISC, then kept adding instruction sets. So it is kind of funny now, the argument seems to be to use a RISC versus a larger instruction set CPU, or alternately use a CPU with larger instruction set versus a RISC with no end to adding more instructions. Seems like there might not be too much of a difference :)
     
  16. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I don't understand T state.
     
  17. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I don't understand how do I know from that does it have execute or not?
     
  18. sailorjoe

    Member

    Jun 4, 2013
    361
    63
    Thexy, take a look at the manual from bertus. Find the POP instruction on page 117. After the description of the instruction there is a note showing how many M states and how many T states the instruction requires.
    Now look at Figure 4 on page 8. That shows what the M states and T states are for a complete machine instruction.
    Does that help?
     
  19. MrAl

    Well-Known Member

    Jun 17, 2014
    2,433
    490

    Hello,

    Assuming you are not using wait states, you take the oscillator frequency and find the period, then multiply that by the T states for that instruction.
    For example, say we have an instruction that shows 10 T states, and an oscillator frequency of 4 MHz. At 4MHz the period is 1/4000000 which is 0.25us. We multiply that 0.25 times 10 and we get 2.5us. See how easy it is?
    An instruction that shows 20 T states (if there is one) would take 20*0.25=5us to execute.

    Beware the conditional statements, which may have two different T states showing up. In that case, one will be for when the condition is met and one for when it is not met. If it jumps it usually takes more T states, so say we have an instruction that takes 4 T states when it does not jump and 6 T states when it does jump. Here, it would take 0.25*4=1us if it did not jump, and 6*0.25=1.5us if it did jump. This means you have got to figure out when it will jump and when it wont jump in order to figure out the entire code timing. This usually means adding up a lot of times to get the full execute time for a body of code.

    Just for one more example, if the oscillator frequency was 1MHz then each T state is 1us long because that is 1/1000000 in seconds. An instruction that has 10 T states would now take 10*1=10us to execute at this lower oscillator speed.

    The instructions for POP vary with what it is that is being POP'ed, so as sailorjoe said you have to look at the manual for EACH one.
    If you have trouble reading the manual then we might be able to make up a short list for you.
     
  20. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I really don't understand this at all. So confusing.
    manu.JPG tabee.JPG

    first picture is manual of those two instr. Second is my exercise where I need to fill it if it is F/E, which reg and so on. Can someone tell me if this is good?

    I wrote that it has only one cycle of fetch because they have value of 1 byte and there is nothing to execute, I think, not understanding fetch cycle good, so I put that it doesn't have it
     
Loading...