need help on Program counter

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
hello,
A program counter is a register that contains the address of the instruction being executed at the current time. Data ,instruction and address are stored in Rom memory
different instruction cycle
MOV A, Rn 1 byte instruction take one cycle
MOV Rn,A 1 byte instruction take one cycle
Mov A#immediate 2 byte instruction take two cycle
MOV A#immediate 2 byte instruction take two cycle
how does program counter make for 8051

I need basic idea how does program counter make ?
 
Last edited:

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
I have spent many hours to search about program counter. But I did not find useful link that will explain how does PC make
I want to make very small Program counter
what should I know ? I don't understand where to start ? because I cant use up or down counter. I have no Idea ?
 

cmartinez

Joined Jan 17, 2007
8,257
The program counter is an internal register that works through of logic gates, that points to the next next instruction in whatever program is stored in the 8051 (be it flash, eeprom, etc) executable memory. This program can be linear or conditional, and logically single ended or being eternally executed in a closed loop...
The way I understand your question is this: 'I want to know how an actual MCU "thinks" or processes all of the instructions that I programmed in it.' ... is that right?

Are you familiar with any kind of digital logic simulator?
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
The program counter is an internal register that works through of logic gates, that points to the next next instruction in whatever program is stored in the 8051 (be it flash, eeprom, etc) executable memory. This program can be linear or conditional, and logically single ended or being eternally executed in a closed loop...
The way I understand your question is this: 'I want to know how an actual MCU "thinks" or processes all of the instructions that I programmed in it.' ... is that right?

Are you familiar with any kind of digital logic simulator?
I have downloaded 8051 Ide . I now how does up/ down counter make but Program counter is different. I don't understand how does PC make for processor
 

absf

Joined Dec 29, 2010
1,968
The program counter is just a simple register that is made up of binary counters with 'preset' and 'clear' function. We dont use up/down counters, I guess, is because we dont need to decrement by one addresses in a program. Stepping the program counters can be done by simply controlling the clock of the binary counters. But we do have instructions like "INC R1" or "INC A" which are for registers and also direct memories like "INC 0xAABB'.

To modify an address, we can control the clock of the binary counter together with the presets as in JMP or branch instructions. One more thing about the 8051 is that it runs on 12MHz (typical) and each instruction needs roughly 12 clock pulses to execute (single byte instructions). This is about 1 to 3us/instruction on a 12 MHz xtal. Where as a PIC needs 4 clock pulses to achieve 1uS/instruction on a 4 MHz xtal.

Allen
 
Last edited:

cmartinez

Joined Jan 17, 2007
8,257
I have downloaded 8051 Ide . I now how does up/ down counter make but Program counter is different. I don't understand how does PC make for processor
Download Digital Works, and check the examples. The basic, elementary way in which the PC works is through logic gates that later store information in registers... this might take you a while to understand, but it's worth the time you will spend studying it...
 

WBahn

Joined Mar 31, 2012
30,088
hello,
A program counter is a register that contains the address of the instruction being executed at the current time. Data ,instruction and address are stored in Rom memory
different instruction cycle
MOV A, Rn 1 byte instruction take one cycle
MOV Rn,A 1 byte instruction take one cycle
Mov A#immediate 2 byte instruction take two cycle
MOV A#immediate 2 byte instruction take two cycle
how does program counter make for 8051

I need basic idea how does program counter make ?
Ask yourself what things a program counter has to do along with the execution of each instruction. It must do one of two things -- increment to the next instruction or change to a different instruction as a result of a branch/jump. Doesn't that sounds an awful lot like a normal counter than either increments or gets loaded with a new value? There's a reason that it is called a program 'counter'.
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
A program counter is a register that contains the address of the instruction being executed at the current time.program counter incremented just after the instruction has been executed. each byte has its own address,In these situations, the PC incremented by the number of bytes. for Branch or jump instruction. program counter counter move at different address

I need ,preset function so that signal can jump on that address
preset Function ?
 

djsfantasi

Joined Apr 11, 2010
9,163
{omitted} ... for Branch or jump instruction. program counter counter move at different address
I need ,preset function so that signal can jump on that address
preset Function ?
A preset function loads a preset value into the counter. Similar to how we used "load" to transfer register contents (in your other thread). You would present your jump address to the inputs (preset) and load them into the counter, errrr, program counter.
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
A preset function loads a preset value into the counter. Similar to how we used "load" to transfer register contents (in your other thread). You would present your jump address to the inputs (preset) and load them into the counter, errrr, program counter.
there are two part of circuit
1 output of program memory connected with accumulator , register and immediate data
note (there is mistake in program memory I used 8 bit but I can use 4 bit. just ignore )
2. output of program counter connected with Program memory
I want to assemble both circuit. I tried. look this image
upload_2015-1-3_7-22-36.png
I don't understand where to connect input of program counter ? how PC will operate ?
 

Attachments

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
Did you check post #14 on your thread "ROM Memory"?

Allen
Hi Allen,
I looked that design
upload_2015-1-3_8-56-11.png
we have circuit that execute three instruction and program counter that hold current instruction address
MOV A#5
mov R1,A
Mov A,R1

actually I don't understand how that program counter will work ?
 

absf

Joined Dec 29, 2010
1,968
we have circuit that execute three instru
ction and program counter that hold current instruction address

MOV A#5
mov R1,A
Mov A,R1

actually I don't understand how that program counter will work ?
Imagine about executing the instruction "LJMP 1234H".

In the 27256 eprom, let's assume the instruction is stored at address 0100H-0102H like this
Code:
Address (Hex)      data (Hex)      instruction      remarks
----------------------------------------------------------------------
0100               02              LJMP 1234H
0101               34                               lower 8 bit of address
0102               12                               upper 8 bit of address
From the above, can you guess how are the inputs of the P.C. are connected to? Also look at the data sheet of 8051 and see the block diagram of the core architecture and see how the P.C. is connected.

Allen
 
Last edited:

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
Think of executing the instruction "LJMP 1234H".

In the 27256 eprom, the instruction is stored at address 0100H-0102H like this
Code:
Address (Hex)      data (Hex)      instruction      remarks
----------------------------------------------------------------------
0100               20              LJMP 1234H
0101               34                               lower 8 bit of address
0102               12                               upper 8 bit of address
From the above, can you guess how are the inputs of the P.C. are connected to? Also look at the data sheet of 8051 and see the block diagram of the core architecture and see how the P.C. is connected.

Allen
what are the low address mux and high address mux. why we use multiplexer with program counter
 

absf

Joined Dec 29, 2010
1,968
Simply because your address is 16-bit and your data is 8-bit. So you need to load a 16 bit address from 8 bit data bus in 2 clock cycles.

Allen
 

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
Simply because your address is 16-bit and your data is 8-bit. So you need to load a 16 bit address from 8 bit data bus in 2 clock cycles.

Allen
I know address is 16-bit and data is 8-bit. I now what is multiplexer and its truth table. I don't understand why we use multiplexer with program counter ?
 

absf

Joined Dec 29, 2010
1,968
It is just terminology.
If you want to call it selector or tri-state buffers or anything you want, it's fine.

In my work, it is normally called a data selector and the symbol looks like this -

data selector.PNG
Allen
 
Last edited:

absf

Joined Dec 29, 2010
1,968
I know address is 16-bit and data is 8-bit. I now what is multiplexer and its truth table. I don't understand why we use multiplexer with program counter ?
I am not sure if I understand your question correctly. Are you saying that a mux is not needed in the program counter design?

Allen
 
Last edited:

Thread Starter

abhimanyu143

Joined Aug 25, 2014
211
I am not sure if I understand your question correctly. Are you saying that a mux is not needed in the program counter design?

Allen
data bus is 8 bit and address bus is 16 bit. you have divided address bus into two part low address bus and high address bus
I think it will easy to understand me if I connect program counter with my circuit.
assume we have circuit that can be load or store data ,

I made circuit in my other thread Rom memory that can execute some load and store instruction
actually I want to add program counter with that circuit
I want to see that how does program counter deal with following code
Code:
MOV A,#2H
MOV A,#4H
Acall delay :
MOV A,#5H
Acall delay 
MOv R1#4
MOV R1,A
 

absf

Joined Dec 29, 2010
1,968
Even "ACALL" instruction has an address of 11 bits. You still need to break the address down to 3 + 8 bits and load them in 2 steps. Besides, ACALL involve stack pointer register and return address when returning from the called subroutine, which I think would be tough for you to implement. Why not wait till you have a full understanding on how its mechanism works?

There is the SJMP instruction but it uses offset to calculate the jump address and I have no idea how to implement it. May be the ALU is needed there.

I think it will easy to understand me if I connect program counter with my circuit.
assume we have circuit that can be load or store data ,
Can you say this in simpler English? I dont understand what you mean...

Allen
 
Last edited:
Top