SECTION IV - 8051 PROGRAM COUNTER AND ROM SPACE

SECTION IV - 8051 PROGRAM COUNTER AND ROM SPACE

Let's examine the role of the program counter [PC] register in executing an 8051 program. Also discuss the ROM memory space for 8051 family members.

Program counter in the 8051:

This is another important register in the 8051 PC  [Program counter]. The program counter points to the address of the next instruction to be executed. As the central processing unit [CPU] fetches the opcode from the program ROM, the program counter is incremented to point to the next instruction. The program counter in the 8051 is 16-bits wide. This means that the 8051 can access program addresses 0000 to FFFFH, a total of 64K bytes of code. Entire 64K bytes of on-chip ROM  have not installed in all the members of 8051.

At what address does the CPU wake up upon applying power to it?

In the case of 8051 family, all members, all manufacturers, microcontroller wakes up at memory address 0000 when it is powered up. Powering up mean applying Vcc to the RESET pin. When the 8051 is powered up, the PC [Program counter] has the value 0000 in it. This means that it expects the first opcode to be stored at ROM address 0000H. In the 8051 system, the first opcode must be burned into memory location 0000H of program ROM, as this is the place where program counter looks for the first instruction when it is booted. We achieve this by the ORG statement in the source program.

Fetching and Executing action of Program Counter [PC]:

Lets examine the action of the program counter as fetching and executing a program. First we examine the list file of the sample program taken from the previous section-IIIa and see how the code is placed in the ROM of an 8051 chip. The opcode and operand for each instruction are listed on the left side of the list file.

List File Example and it's Explanation:

1 0000            ORG 0H                   ;Start at origin 0

2 0000   7D25  MOV R5,#24H         ;Load 25H into R5

3 0002   7F34   MOV R7,#34H         ;Load 34H into R7

4 0004   7400   MOV A,#0               ;Load 0 into A

5 0006   2D      ADD A,R5               ;Add contents of R5 to A,A=A+R5

6 0007   2F       ADD A,R7               ;Add contents of R7 to A,A=A+R7

7 0008   2412   ADD A,#12H           ;Add to accumulator value 12H

8 000A   80FE   HERE:SJMP HERE    ;Stay in this loop

9 000C             END                      ;End of asm source file

 

ROM ADDRESS   MACHINE LANGUAGE     ASSEMBLY LANGUAGE
0000                        7D25                                      MOV R5,#25H   
0002                        7F34                                       MOV R7,#34H
0004                        7400                                       MOV A,#0
0006                        2D                                           ADD A,R5
0007                        2F                                            ADD A,R7
0008                        2412                                       ADD A,R7
000A                       80FE                                       HERE:SJMP HERE
  • The opcode and operand are placed in ROM memory locations starting at 0000 after the program is burned into ROM of an 8051 microcontroller.

ROM Contents:

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
  • Above list shows that address 0000 contains 7D which is the opcode for moving a value into register R5. Address 0001 contains the operand [25H] to be moved to R5. Therefore, the instruction "MOV R5,#25H" has a machine code of "7D25". so Finally it is clear that the 7D is the opcode and 25 is the operand.
  • In the same way, the machine code "7F34" is located in memory locations 0002 and 0003 and represents the opcode and operand for the instruction "MOV R7,#34H".
  • Machine code "7400" is located in memory locations 0004 and 0005 and represents the opcode and the operand for the instruction "MOV A,#0".
  • The memory location 0006 has the opcode of 2D which is the opcode for the instruction "ADD A,R5". Memory location 0007 has the content 2F, which is opcode for the "ADD A,R7" instruction
  • The opcode for instruction "ADD A,#12H" is located at address 0008 and the operand 12H as address 0009. The memory location 000A has the opcode for the "SJMP" instruction and its target address is located in location 000B.

Byte by Byte Program Executing:

When we apply the power to thw 8051, the action of PC [Program counter] is explain in further detail.

  • When the 8051 is powered up, the program counter [PC] has 0000 and starts to fetch the first opcode from location 0000 of the program ROM. In 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. One instruction is finished. The program counter [PC] is incremented to point to 0002 [PC = 0002], which contains opcode 7F, the opcode for the instruction "MOV R7,#34H".
  • After executing the opcode 7F, the value 34H is moved into R7. The program counter is incremented to 0004.
  • 0004 ROM location has the opcode for instruction "MOV A,#0". This instruction is executed and now PC=0006. All the above instructions are 2-byte instructions, i.e. each takes two memory locations.
  • Then the program counter [PC] PC=0006 points to the next instruction which is "ADD A,R5". This is a 1-byte instruction. After the execution of this instruction, program counter PC=0007.
  • 0007 location has the opcode 2F which belongs to the instruction "ADD A,R7", which is also a 1-byte instruction. After executing of this instruction, program counter is incremented to 0008. This process goes on until all the instructions are fetched and executed.

Read Only Memory [ROM] Structure map in 8051 Microcontrollers Family:

Some family members have 4K bytes of on-chip ROM e.g, 8751, AT8951. Some family members gave 8K bytes of ROM. Dallas semiconductors DS5000-32 has 32K bytes of on-chip ROM. Dallas semiconductor also has an 8051 with 64K bytes of on-chip ROM. The point is that no member of 8051 family can access more than 64K bytes of opcode since the program counter in the 8052 is a 16-bit register [0000 to FFFF address range]. Although the first location of program ROM inside the 8051 has the address of 0000, the last location can be different depending on the size of ROM on the chip. The 4K bytes ROM memory has memory address of 0000 to 0FFFH. So the first location of on-chip ROM of this 8051 has an address of 0000 and the last location has the address of 0FFFH.

More From Iamtechnical.com

Advertisement: