1
\$\begingroup\$

So as we know both of the program counter and DPTR are 16bits in 8051 and hence both of them are capable of reaching 216 possible locations, which is sufficient for both RAM and ROM, then why DPTR is introduced while the program counter can points through all the possible location of RAM? is DPTR specially designed to point only the ROM space? is program counter is for pointing data from RAM and DPTR is for pointing data from ROM?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ How would you move or copy a block of memory throughout the full external memory address space without the DPTR? \$\endgroup\$
    – jonk
    Commented Jul 8, 2021 at 17:00
  • \$\begingroup\$ That makes sense. \$\endgroup\$
    – Sayan
    Commented Jul 8, 2021 at 17:05

2 Answers 2

1
\$\begingroup\$

is DPTR specially designed to point only the ROM space?

That's correct. From the 8051 Wikipedia article:

"In addition to code, it is possible to store read-only data such as lookup tables in program memory, retrieved by the MOVC A,@A+DPTR or MOVC A,@A+PC instructions. The address is computed as the sum of the 8-bit accumulator and a 16-bit register (PC or DPTR)."

The PC is pointing to the current instruction, so a PC-relative address would be useful for a nearby lookup table. On the other hand, the DPTR can be set independently to point to an arbitrary location in ROM, not necessarily near the program counter, so you can address locations not within [PC, PC + 256).

is program counter is for pointing data from RAM and DPTR is for pointing data from ROM?

No. The program counter points to an address in ROM containing instructions to be executed, just like DPTR. RAM is addressed either with direct addressing, or an indirect address using either R0 or R1. Edit: not 100% correct, see Dave Tweed's answer which mentions a way DPTR can be used to address external RAM

\$\endgroup\$
4
  • \$\begingroup\$ could you please elaborate then why we use RAM if the instructions are burned into the ROM? we could have easily see the burned instruction in ROM and follow them, why the involvement of RAM? \$\endgroup\$
    – Sayan
    Commented Jul 8, 2021 at 17:07
  • 1
    \$\begingroup\$ @Sayan Many older 8051 systems included internal ROM that was pre-set by the factory for customers (at a price.) This ROM could be disabled using a single pin to do so, though. Meanwhile, when using an external memory system many designs included both ROM and RAM in the external system. Mixtures are quite easy to implement. (Of course, you have to accept and implement write operations for RAM.) RAM is useful for data. For example, if you collect ADC data and store it in RAM prior to analysis. \$\endgroup\$
    – jonk
    Commented Jul 8, 2021 at 17:12
  • 2
    \$\begingroup\$ @Sayan We use RAM to store variables that are not known ahead of time, but needed for the purpose of your program, much like the use of RAM in almost any microcontroller system. For example, an 8051-based digital thermometer might need to use RAM to store the raw reading from a digital temperature sensor, and ROM to store a lookup table and/or the factors for converting between the raw reading and celsius/fahrenheit. \$\endgroup\$
    – nanofarad
    Commented Jul 8, 2021 at 17:14
  • \$\begingroup\$ excellent answers, thanks both of you. \$\endgroup\$
    – Sayan
    Commented Jul 8, 2021 at 17:36
3
\$\begingroup\$

is DPTR specially designed to point only the ROM space?

No, it isn't. It can be used to access ROM space using the movc instruction, or it can be used to access RAM space using the movx instruction.

On the other hand, the PC can only be used to access ROM space.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.