Which registers change instruction during fetch and execute period?

Thread Starter

thexy

Joined Dec 13, 2015
130
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:

Thread Starter

thexy

Joined Dec 13, 2015
130
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
 

JohnInTX

Joined Jun 26, 2012
4,113
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.
 

Attachments

Last edited:

Thread Starter

thexy

Joined Dec 13, 2015
130
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.
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.
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?
 

JohnInTX

Joined Jun 26, 2012
4,113
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?
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.
 

Thread Starter

thexy

Joined Dec 13, 2015
130
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.
But in what case PC doesn't change or doesn't have instruction, or literally when I don't need to circle it
 

JohnInTX

Joined Jun 26, 2012
4,113
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.
 

ErnieM

Joined Apr 24, 2011
8,045
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.
 

hp1729

Joined Nov 23, 2015
2,304
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.View attachment 98674


Can someone do it and write detailed explanation?
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.
 

Thread Starter

thexy

Joined Dec 13, 2015
130
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.
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?
 

Thread Starter

thexy

Joined Dec 13, 2015
130
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.
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?
 

hp1729

Joined Nov 23, 2015
2,304
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?
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?
 

Thread Starter

thexy

Joined Dec 13, 2015
130
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?
I have sheets for MC8.
Why affter ADD 81h value is 81h, why it's not 00FFh+81h?
 

ErnieM

Joined Apr 24, 2011
8,045
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
 

Thread Starter

thexy

Joined Dec 13, 2015
130
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
Which flag does it have is writen in sheets or?
And can you tell me that rules for flags?
 

ErnieM

Joined Apr 24, 2011
8,045
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.
 
Top