RAM memory allocation and Addressing Modes

In 8051 we can access RAM locations (both bytes and bits) in two ways:-

  • By address: directly designating through the address of a byte or bit (just like we say house number : 232)
  • By name: Mode designation through name of a register like ‘ A’ , ‘R1’ , ‘R2’ (just like we say home of Mr. Donald )

 

REGISTER BANKS

Memory Location: 00- 20 Hex

  • This part of RAM is divided into four register banks.
  • The four register banks are divided into 8 registers R0-R7. 
  • In all the programs we have discussed so far we didn’t mention which register bank we are using when referring to these R0-R7 registers. 
  • The default register bank is zero but we can also choose the other register banks. 
  • The register bank one is not used (generally) as it also serves purpose of stack.
  • This part of RAM can be accessed by name as well as the address.

 

By name: 

Switching to other register banks:-

 

8051 switching to other register banks

 

Now suppose we want to write in the registers of bank 2, then we can set these bits PSW.3 & PSW.4 accordingly to switch to them. 

ORG 0H

SETB PSW.4 ; select bank 2

MOV R1, # 25H ; register 1 of bank2

MOV R2, # 30H ; register 2 of bank 2

END

In this case we are loading values in register bank 2.

 

By address:

{Caution: ‘#’ means a number and without that it is an address}

Below is an example showing the above program (which was earlier written in indirect mode) in direct addressing mode:-

ORG 0H

MOV 10H, # 25H ; register 1 of bank2

MOV 11H, # 30H ; register 2 of bank 2

END

 

RAM Memory Allocation: 

 

8051 RAM Memory Allocation

 

8051 RAM Memory Allocation Registers

BIT ADDRESSABLE RAM

Memory Locations: 20- 30 hex

  • This part of RAM is bit addressable means we can use the bits address for directly using them. 
  • A bit can be set with SETB & cleared with CLR.
  • We can only access this directly by address. There are no special names for this part of RAM.
  • The address of a bit is independent of the byte address.

Below we can see how the bits are numbered:

  

Numbering of bits in Bit Addressable RAM

 

For e.g.:

SETB 5EH ; 5E hex is the address of the bit

; This is direct addressing 

Operations we can perform on a bit are shown below in the table.

 

8051 operations that can be performed on a bit

 

SCRATCH PAD RAM

Memory Address: 30 -7F hex

  • This part of RAM doesn’t have any specific function and is known as general purpose RAM. We can use it in whatever way we like.
  • This can be accessed only by its address and don’t have any special names.
  • Let’s write a program to toggle port1 continuously (after a delay). 

 

        MOV P1, # 55H   ; P1= 55 hex

        MOV 45H, #100 ; load counter with 100 (indirect addressing mode) 

;Caution- ‘#’ means a number & without that it is an address

TOG: CPL P1   ; toggle P1

ACALL DELAY   ; call delay subroutine

DJNZ 45H, TOG  ; repeat 100 times

 

SPECIAL FUNCTION REGISTERS (SFR’s)

Memory Location : 7F- FF hex

  • We have discussed the special registers A, B and PSW. The other will be discussed whenever appropriate.
  • All the ports are also designated as special function registers
  • Some of the SFRs are bit addressable (as shown in figure)
  • Note that I have marked cross at many places in the table and have not mentioned any name for these registers. These registers are reserved for further research and you should not use them.
  • The SFR’s can be accessed through names as well as address.
  • The bit address is independent of the byte address.

Special Function Registers

 

Indirect Addressing Mode: 

Till now we have covered the direct accesing modes i.e.

MOV A, # 20 H       ;by name

MOV E0H, # 20H    ; by address 

 

Pointers in Assembly Language:-

  • When register are used as pointers it is known as Register Indirect Accessing.
  • Only register R0 & R1 can be used as pointers.
  • For using register as a pointer we have to use a sign @ before the registers (R0 & R1).
  • The indirect accessing mode (as pointers) makes data accessing dynamic rather than  static as in case of direct addressing mode (by name & address)

MOV A, @R0 ; move contents of RAM location whose address is stored is held by R0 

                ; into A

MOV @R1, B ; move contents of B into RAM location whose address is held by R1

 

Let us see an example to copy 30hex in RAM memory locations 50H to 55H: 

Case1: Direct Accessing Mode

MOV  A, # 30H ; load A with 30 hex

MOV 50H,  A ; copy contents of A into RAM location 50H

MOV 51H,  A ; copy contents of A into RAM location 51H

MOV 52H,  A ; copy contents of A into RAM location 52H

MOV 53H,  A ; copy contents of A into RAM location 53H

MOV 54H,  A ; copy contents of A into RAM location 54H

MOV 55H,  A ; copy contents of A into RAM location 55H

Case2: Indirect Addressing Mode (without a loop)

MOV         A, # 30H ; load A with 30hex

MOV R0, # 50H ; load the pointer. R0 = 50H

MOV @R0, A ; copy A to RAM location R0 points to

INC R0 ; Increment the pointer R0, now R0= 51H

MOV @R0, A ; copy A to RAM location R0 points to

INC R0 ; Increment the pointer R0, now R0= 52H

MOV @R0, A ; copy A to RAM location R0 points to

INC R0 ; Increment the pointer R0, now R0= 53H

MOV @R0, A ; copy A to RAM location R0 points to

INC R0 ; Increment the pointer R0, now R0= 54H

MOV @R0, A ; copy A to RAM location R0 points to

INC R0 ; Increment the pointer R0, now R0= 55H

MOV @R0, A ; copy A to RAM location R0 points to

 

Case3: Indirect Addressing Mode (with a loop)

MOV A, # 30H ; A= 30hex

MOV R0, # 50H ; load pointer. R0, RAM address

MOV R2, #06H ; load counter, R2= 6

AGAIN:         MOV  @R0, A     ; copy contents of A into RAM location R0 points to

  INC       R0   ; increment pointer R0

  DJNZ, AGAIN   ; loop until counter = zero 

Tags:

Comments

Member since:
15 March 2009
Last activity:
5 years 15 weeks

what is actually meant by Static and dynamic data addressing...