Program counter

Status
Not open for further replies.

Parth86

Member
how does program counter make for 8051 controller
I know how does program counter work but I don't understand how they make ?
Look the following example
Code:
Machine language  binary language
1 0000                                          ORG 0H
  2 0000       7D25                       MOV R5,#25H
  3 0002       7F34                        MOV R7#34H
  4 0004        7400                        MOV A,#0
  5 0006         2D                             ADD A,R5
  6 0007        2F                             ADD A,R7
  7 0008       2412                        ADD A,#12H
  8 000A       80FE    HERE:      SJMP HERE
9 000C 000C                            END
Code:
PROGRAM MEMORY
Address code
  0000 7D
  0001  25
  0002  7F
  0003  34
  0004  74
  0005  00
  0006  2D
  0007  2F
  0008 24
  0009  12
  000A  80
  000B  FE

· When the 8051 is powered up, the PC (program counter) has 0000 and starts
to fetch the first opcode from location 0000 of the program ROM. In the case
of the above program the first opcode is 7D, which is the code for moving an
operand to R5. Upon executing the opcode, the CPU fetches the value 25 and
places it in R5. Now one instruction is finished. Then the program counter is
incremented to point to 0002 (PC = 0002), which contains opcode 7F, the
opcode for the instruction “MOV R7 , . .”.

· Upon executing the opcode 7F, the value 34H is moved into R7. Then the program counter is incremented to 0004.

· ROM location 0004 has the opcode for the instruction “MOV A, #0″. This
instruction is executed and now PC = 0006. all the above instruc
tions are 2-byte instructions; that is, each one takes two memory locations.

· Now PC = 0006 points to the next instruction, which is “ADD A, R5″. This is
a 1-byte instruction. After the execution of this instruction, PC = 0007.

· The location 0007 has the opcode 2F, which belongs to the instruction “ADD
A,R7″. This also is a 1-byte instruction. Upon execution of this instruction,
PC is incremented to 0008. This process goes on until all the instructions are
fetched and executed.

the program counter points at the next
instruction to be executed

I think input should be reset , clock, opcode ,accumulator, ram memory
what will be input and output for program counter?
 
The 8051 can mix instructions and data and addresses in the same ROM memory.

Time=0, PC=0000, get instruction 7D, MOV R5
Time=1, PC=0001, get address 25, now move R5 into RAM 25

This instruction takes two amounts of time, and two bytes from ROM.
The 8051 has "one clock" and "two clock" instructions.
( there are three clock instructions )
ANL iram addr,#data (53)
DJNZ iram addr,reladdr (D5)

LCALL code addr (12) Is a good example of a 3 byte instruction. Byte 1 is 12, Byte 2 and Byte 3 are the 16 bit address to load into the PC to make the next instruction address.
This instruction takes 3 clocks and is slow. If you can use the short jump that is only two bytes.

If this is a 32 bit ARM then the instructions and address (or data) is in the same 32 bit ROM location. The 32 bit instruction would take only one clock.
 
If possible can we make truth table for program counter. If yes then how can we create table for program counter ?
give me some idea
 
Last edited by a moderator:
1)For single clock instructions: Use a simple truth table.
2)For 2 clock instructions: Set a FF (flip flop) and get ready but don't do anything. Wait for next clock. At second clock, clear FF, get data, do instruction.
3)For 3 clock instructions: Set a FF or counter to 2, with each clock decrease the counter. Get data with each clock. Only advance to next instruction when counter=0.

So we need a loadable-down-counter that we can load with 0 or 1 or 2 depending on how long the instruction is.
>>If counter=0 then this is the end of the instruction.
>>If counter is 1 then there is one more clock to get data.
>>If counter is 2 then there is two more clocks to get data.

In you truth table we must know how many bytes in the instruction and what part of the instruction we are at.
>>If the counter=0 then do the instruction.
>>If the counter<>0 then wait on instruction and go get some data on the next clock and decrease the counter by one.

I am sorry that is not clear.
 

I have done some work
assembly code just for example
Code:
MOV A, # 4A ; load data 4A into A register
MOV R1,# 5E ; load the data 5E into R1
ADD A,R1 ; add the content of R1 into A register
INC R1 ; increase R1 with 1
INC A ; increase A with 1
MOV A,R1 ; move the value of R1 into A register
machine code
Code:
0000 74 4A

0002 79 5E

0004 29

0005 0B

0006 04

0007 E9
binary number
Code:
0000 0000 0000 0000               0111 0100

                                               0100 1010

0000 0000 0000 0010                 01111 001

                                                 0101 1110

0000 0000 0000 0100                  00101001

0000 0000 0000 0101                  00001 001

0000 0000 0000 0110                     00000100

0000 0000 0000 0111                       11101001

Program counter

Code:
0000 0000 0000 0000

0000 0000 0000 0010

0000 0000 0000 0100

0000 0000 0000 0101

0000 0000 0000 0110
this is program counter for 6 line
dose 8051 PC design in this way ?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…