Stack Pointer Data Pointer and Program Counter in 8051 Microcontroller

Microcontroller 8051 has many registers mainly classified into General purpose and Special Function registers. SP, PC and DPTR are the special function registers used in 8051 microcontrollers which work as memory pointer.

Let’s see the function of Stack Pointer Data Pointer and Program counter in 8051 Microcontroller one by one.

The Stack Pointer (SP) in 8051

  • The stack is a section of internal RAM used by the CPU to store information temporarily. This information could be data or an address.
  • The CPU needs this storage area since there are only limited number of registers. The register to access the stack is called Stack Pointer.
  • The stack pointer (SP) is an 8-bit register within the SFR area, with the address 81H and it can point an address location between 00h to FFh.
  • Stack pointer is used to hold the address of Top of the Stack. The address held in the SP is the location in internal RAM where the last byte of data was stored by a stack operation.
  • This register can hold one 8-bit address at a time, which is actually the memory location at top of the stack.
  • The stack pointer is initialized to the value 07H when the 8051 microcontroller is reset.

The Program Counter (PC) in 8051

  • The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to execute is found in memory.
  • When the 8051 is initialized PC always starts at 0000h and is incremented each time an instruction is executed.
  • It is important to note that PC isn’t always incremented by one. Since some instructions require 2 or 3 bytes the PC will be incremented by 2 or 3 in these cases.
  • The Program Counter is special in that there is no way to directly modify its value. That means, you can’t do something like PC=2000h. On the other hand, if you execute instruction LJMP 2000h you have effectively accomplished the same thing.

The Data Pointer (DPTR) in 8051

  • The Data Pointer (DPTR) is the 8051s only user-accessible 16-bit (2-byte) register.
  • The Accumulator, “R” registers, and “B” register are all 1-byte values.
  • DPTR, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8051 to access external memory.
  • When the 8051 accesses external memory it will access external memory at the address indicated by DPTR.
  • While DPTR is most often used to point to data in external memory, many programmers often take advantage of the fact that it is the only true 16-bit register available. It is often used to store 2-byte values which have nothing to do with memory locations.

Recent posts

1 thought on “Stack Pointer Data Pointer and Program Counter in 8051 Microcontroller”

  1. Oh my goodness! a tremendous article dude. Thanks Nevertheless I am experiencing concern with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting an identical rss downside? Anybody who is aware of kindly respond. Thnkx

Leave a Comment

Your email address will not be published. Required fields are marked *