I have been reading about Program Counter of 8085. This material here states that the function of the program counter is to point to the memory address from which the next byte is to be fetched. When a byte (machine code) is being fetched, the program counter is incremented by one to point to the next memory location. My question is how does it handle the condition if instruction size varies. Suppose the current instruction is of 3 bytes then PC should point to current address+3. How does PC knows the size of the current instruction? I am new to 8085, any help would be appreciated. Thanks
Asked
Active
Viewed 1,491 times
0
-
Are you sure it doesn't have only instructions of the same size, as is the case in RISC architectures? Edit : nevermind, it has 3 categories of instructions based on size. – Aaron Nov 06 '15 at 10:48
-
@Aaron: no, 8080 (and followers) are typical CICS machines. To the OP: the first byte needs to be inspected/decoded to determine the number of "extra" bytes that need to be read. In practice (say 386 etc) newer cics machines actually read the instruction stream in larger chunks (say 4 bytes) and decode it afterwards. – joop Nov 06 '15 at 10:50
-
@joop How does that determination of extra bytes takes place was primarily my question. – Ravi Nov 06 '15 at 10:57
-
1It is part of the instruction decoding. Often the "addressig mode" is coded by a distinct set of bits in the first instruction byte; you can see the 1-vs-2-vs-3-etc byte instructions as strips or bands in the 16*16 instruction map. – joop Nov 06 '15 at 11:05
1 Answers
2
The material you reference doesn't really say anything about that issue specifically - all it says is that the PC is incremented when a byte is fetched, which is correct (it doesn't say that there couldn't be multiple bytes to an instruction).
In general, a CPU will increment the program counter to point to the next instruction.
More precisely, during the instruction decoding phase, the CPU will read as many bytes as are needed for the instruction and increment the PC accordingly.

500 - Internal Server Error
- 28,327
- 8
- 59
- 66
-
But 8085 has 1-3 bytes of instruction size. How does PC know which address to point depending upon the instruction? – Ravi Nov 06 '15 at 10:55
-
The PC doesn't know, but the CPU does - see my updated answer. – 500 - Internal Server Error Nov 06 '15 at 10:57
-
1The CPU has built-in tables (or the equivalent) that tells it when it sees the first byte of an instruction whether another byte is needed for encoding it, and so on. – 500 - Internal Server Error Nov 06 '15 at 10:58
-
Thanks! Understood now. CPU does the calculation and informs PC and PC increments accordingly. – Ravi Nov 06 '15 at 11:00