### REGISTER BANK & SWITCHING

Before entering into the topic lets see important terminologies

Bit                                                                               0
Nibble =4bits                                                         0000
Byte=8bits                                                 0000    0000
Word= 2bytes i.e 16bits      0000    0000   0000    0000

There are many registers present in the 8051. We will look each of them in consequent posts. For now let us see most widely used registers of the microcontroller 8051.
They are A(accumulator), B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR(Data pointer) and PC(Program counter). All of them are 8 bit registers except DPTR and PC register, which are of 16bits. Each register will have corresponding address.

Let us look at a simple Programs( we will look indept of all the instructions in further posts,examples shown below are just to have a common idea)

Mov A, #22H     ; moving 22H(hexadecimal type) in register A
Mov R0, #12H   ; moving 12H in register R0
Add A, R0         ; Adding both 22H and 12H and result will be saved in register A

Example2: Adding two decimal numbers 22 and 12

Mov R1, #12     ; moving 12 in register R1
Mov A, #22       ; moving 22(Decimal number) in register A
ADD A, R0         ; Adding both 22 and 12 and result will be saved in register A

Example3: Subtracting two hexadecimal numbers 22H and 12H

Mov R3, #12H   ;Moving 12H into register R3
Mov R0, #22H   ;Moving 22H into register R0
Mov A, R0         ; Now moving the data in the register R0 into the register A i.e now A=22H
SUBB A, R3      ; Subtracting 12H from 22H and result will be saved in register A

Look at the below program it is similar to Example3

Mov R3, #12H   ;Moving 12H into register R3
Mov A, #22H   ;Moving 22H into register A
SUBB A, R3      ; Subtracting 12H from 22H and result will be saved in register A

I think you got a little idea of how we move data into the registers. We will look this topic in depth in further posts.

### REGISTER BANKS IN RAM

Now let us look at the Register banks in the 8051 i.e how registers are arranged in the RAM and their addresses.

There are 128 bytes of RAM in 8051(you can see above) addresses from 00 to 7F(hexadecimal). Divided as follows

• 32 bytes are set aside for Register banks and stack i.e from 00 to 1F. These 32 bytes are divided into 4 banks i.e Register Bank0 , Bank1, Bank2 and Bank3. So, each bank will have 8 bytes(32 div 4). These 8 bytes are divided into registers R0, R1, R2 .... R7. Every bank will have register with the name R0 to R7.

Note that all the banks have the same register names i.e R0 to R7 but their addresses are differ which are indicated in red color.
• Next 16bytes( from 20 to 2F) are set a side for "Bit Addressable" , we will look about them in detail in further posts.
• Next 80bytes are set a side for the scratch pad i.e to do any arithmetic manipulations( simple to call as rough book ;-) )

Now again let us see the above example once

Example3: Subtracting two hexadecimal numbers 22H and 12H

Mov R3, #12H   ;Moving 12H into register R3
Mov R0, #22H   ;Moving 22H into register R0
Mov A, R0         ; Now moving the data in the register R0 into the register A i.e now A=22H
SUBB A, R3      ; Subtracting 12H from 22H and result will be saved in register A

Now say me registers R3 and R0 are belongs to which bank???
When powered the microcontroller as default it is set to the Bank0. So R3 and R0 are belongs to the Bank0.

Now again say me if we want to switch from bank0 to other banks then what should we need to do???
For this purpose we have a special function register called as PSW (Program Status Word) Register.

If we want to switch to any bank then we need to change  the RS1(or psw.4) and RS0(or psw.3) bits of PSW to the corresponding value.
As default RS1 and RS0 will be 0 so  Bank0 is selected.
If we want to switch to Bank1 then RS1 should be 0 and RS0 should be 1
If we want to switch to Bank2 then RS1 should be 1 and RS0 should be 0
If we want to switch to Bank3 then RS1 should be 1 and RS0 should be 1

Note RS1 is nothing but  psw.4 and RS0 is nothing but psw.3.

Important Note: Bank1 is also used as STACK.So in general we dont use Bank1 in our program. See the simple program below to know how to switch to different banks.

Example1 : Move 25H and 30H into the registers R0 and R1 of bank2.
Inorder to select bank2 we need to make RS0=0 and RS1=1 i.e psw.3=0 and psw.4=1

CLR psw.3               ;CLR means clear psw.3 i.e RS0=0
SETB psw.4             ; SETB means setbit psw.4 means RS1=1. now bank2 is selected
MOV R0,#25H        ;move 25H in R0
MOV R1,#30H        ; move 30H in R1

Example2 : Move 10H and 12H into the registers R3 and R4 of bank3.

SETB psw.3             ;Inorder to select bank3 we need to make RS0=1 and RS1=1. Now RS0=1
SETB psw.4             ; SETB means setbit psw.4 means RS1=1. now bank3 have been selected
MOV R3,#10H        ;move 10H in R0
MOV R4,#12H        ; move 12H in R1

Example2 : Move 2H and 12H into the registers R0 of Bank0 and R4 of bank2 respectively.

As default Bank0 will be selected.
MOV R0,#2H    ; we are moving 2 into R0 of bank0
SETB PSW.4     ; It is not necessary to clear the psw.3 because its already zero
; so we set psw.4 to select bank2
MOV R4,#12H  ; moving 12h into r4 of bank2

Now it is clear to us that how we switch from one bank to other bank.

AUTHOR: YOUSTRON SIC

sajid niaz said...

dear i ned 8085 simulator.... can u please send me

YOUSTRON SIC said...

Sajid naiaz you can check this link http://gnusim8085.org/

SUSHANT KUMAR said...

sir is there any simulator for 8051

YOUSTRON SIC said...

Sushant, If you want to check your code one by one along with the register information then prefer 'edsim' simulator , if you want some fancy simulator then prefer 'proteus isis' simulator... I prefer proteus...

This is good news for you. Now, you need not to spend those big bucks for acquiring your
replica rolex watches
replica omega watches,replica Breitling watches UKetc.

Sophie Grace said...

Thanks for sharing a good mythological post related a biblical plumb line for national leadership. webstagram