Which registers change instruction during fetch and execute period?

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

  1. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Mod note: this is essentially the same question you posted in Homework Help. Please do not open multiple threads with the same question. I have moved the thread here so that the discussion may continue in one place.

    I have part of program in MC8-Assembler (The CPU of the MC8 is formed by the 8bit processor Zilog Z80 of the Training Board) What value is going to have flag after execution and what value is being found in register? Values before execution are given in first collum. mddm.PNG


    Can someone do it and write detailed explanation?
     
    Last edited by a moderator: Jan 15, 2016
  2. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Hello guys. Here is talk about Assembler MC8 (list of instrucion I'm going to put if someone wants to help me). I need to circle all registers that following following instruction change during fetch and execute period?

    Capture.JPG
     
  3. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    Have you tried looking at the documentation for the processor?
     
  4. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Yup, but I'm not able to do example.
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    The Z80's reference manual was posted here
    http://forum.allaboutcircuits.com/threads/add-comand.119382/page-3#post-948182
    and the next post in case you missed it.

    How the registers and flags work in general begins on page 63. Then just go down and look at the detailed description for each instruction you list and you will be set. Note that some of the MC8 mnemonics (instruction names) have been changed from their Z80 equivalents. The cross-reference is here.
    http://forum.allaboutcircuits.com/threads/add-comand.119382/page-3#post-948174

    For example, ROR in MC8 is RRCA in Z80. RRCA is described on page 207 of the Z80 manual. I have attached it for reference.

    The description and diagram says what RRCA does - it shifts Register A right 1 bit and the LSBit shifted out gets put back into the MSBit (that's why its a 'rotate' and not a 'shift'. The description also tells how many bytes long (1) the instruction is and how many machine cycles it takes. This information with that in the other thread that covered what happens on the bus in each cycle tells you exactly what the chip will do on its bus when it executes RRCA. It also tells you what the PC (Program Counter) will do.

    Condition Bits Affected describes how RRCA affects the internal flags.

    So: The answer to the RRCA is that it affects A, it does not affect HL, it increments the PC by one and (if ZR is the flags register) tells you what will happen to the flags. H and N are reset, C is value of the LSbit before the rotate.

    This is a good exercise. Many of us *older guys* had to master the internals of the processor to do any coding at all. It is tedious but just keep digging into the reference materials and you'll get the hang of it.

    Good luck.
     
    Last edited: Jan 14, 2016
  6. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Thank you for helping me. But it's still not clear to me. It also tells you what the PC (Program Counter) will do. Can you explain me this?
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    Sure, since RRCA is only one instruction, the PC only has to increment by 1 to fetch the next instruction. If you have an instruction that takes 3 bytes, the PC will be incremented by 3 and so on.
     
  8. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    But in what case PC doesn't change or doesn't have instruction, or literally when I don't need to circle it
     
  9. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    The PC will change with every instruction. Its function is to address the program memory and fetch (read) instructions from memory for the processor to execute. The instructions are stored in successive memory locations and it is the PC's job to get them in sequence so it changes on each instruction executed. The exception to sequential order is when it JUMPS (GOTO, CALLs etc) to another location. In that case, the JUMP instruction contains a new address value for the PC. The PC is set to that value and execution resumes from that address.
     
  10. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
    How much does this job pay?
     
    thumb2 likes this.
  11. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Me no have $ haha
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Find the set of instruction for the Z80. This will explain these and all other operations the processor can perform.

    I suggest either Google for this search, or your class text book.
     
    thumb2 likes this.
  13. hp1729

    Well-Known Member

    Nov 23, 2015
    1,944
    219
    What part of the instructions do you not understand?
    MOV HL 00FFh moves the data 00FF (hex) into the register pair HL.
    DEC HL decrements the value in register pair HL
    ADD 81h Adds 81 (hex) to the Accumulator (A register). Results in A.
    CP A ... is that complement A? Make 1's to 0's and 0's to 1's. Results in A
    SUB 02h subtracts 02 (hex) from the Accumulator. Results in A.

    Download a data sheet for the Z80 that explains the registers and instruction set.
    Would one in English be useful to you? Microprocessors are tough enough in your native language. In another language it is tougher.

    Why do the instructions seem backwards? MOV HL, 00FFh means move to HL data in the next two bytes. If you look at the instruction set in binary it looks like 00 100 001 (or some such thing, I'm going from memory here). "00" says this is a move to a register pair instruction. "100" selects the destination to be HL. "001" selects the source to be a 16 bit value made from the next two bytes.
    All instructions have that "operation code / destination / source" format. Depending on your native language, in English it seems anti-intuitive.
     
  14. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I'm not studying on my native language all, but I prefer to study on english.

    So I'm looking to my paper with instructions.

    MOV HL, 00FH MOV HL-00 100 001 and 00FH is 0000 0000 1111 So can you explain me on this example how to find flag and what registers are and I'll try on others?
     
  15. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I have tried something on my own
    So is this correct
    ROR - A, PC
    MOV A, [HL] A, PC
    MOV label, A PC
    ADD 08H PC I
    NC HL HL
    PC JP label I don't know

    Does byte and flags tell me something about which register I'm going to have?
     
  16. hp1729

    Well-Known Member

    Nov 23, 2015
    1,944
    219
    00FFh =000 0000 1111 1111
    In your table the value of HL after executing the MOV HL 00FF will be 00FFh.
    After executing the DEC HL instruction HL is 00FEh.
    After executing the ADD 81h the Accumulator should be 81h
    After executing the CP A instruction A equals 0111 1110 or 7Eh
    After executing the SUB 02h instruction the Accumulator would equal 7Ch
    Have you found a Z80 data sheet?
     
  17. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    I have sheets for MC8.
    Why affter ADD 81h value is 81h, why it's not 00FFh+81h?
     
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Because the add operation adds 81h to the accumulator, and the initial condition had the zero flag set, and that flag tells you the accumulator is empty or zero to start.

    So when you add 81h to 0h you get 81h
     
  19. thexy

    Thread Starter Member

    Dec 13, 2015
    126
    0
    Which flag does it have is writen in sheets or?
    And can you tell me that rules for flags?
     
  20. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The rules are in the data sheets or manual for the device you are looking at. Have you been able to locate one? If so, best you post a link to it so we can guide you where to look.

    If not, google is your friend. Find one you like and post us the link.
     
Loading...