Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

CPU / RAM memory registers?

Status
Not open for further replies.

AceOfHearts

New Member
Peace,

Something I have been confused about for a while now from reading a text book.

In an 8051, the CPU has registers R0-R7, am I correct? But RAM also has registers which can be refered to with the labels R0-R7 too...

So if I specify

MOV R0, #1

am I moving #1 into the CPU register, or the RAM register?

Thanks.
 
The only registers are in RAM or the SFR space. There are actually four banks of 8 registers in the first 32 bytes of RAM. The current bank is selected by two bits in the PSW.

Code:
So
     MOV  R0,#1
will move the immediate constant into location 0x00, 0x08, 0x10, or 0x18 of internal RAM depending on the bank select bits in the PSW which is located in the SFR space. WARNING: these are not the same locations as those which are accessed with the MOVX A,@DPTR or MOVX @DPTR,A

Interestingly the Accumulator, B, and the Data Pointer are located in the SFR space.
 
Aha the register banks... ... something I never use :eek:
Except the first bank of coarse.
What's the point having 4 banks?
When you have one bank (8 registers) do to some indirect adressing things isn't that enough? Anyone with a project example using more than 8 registers at the same time to do indirect adressing stuff?

@Papabravo: Why did you bring up the movx instructions? I can't see what they have to do with the register banks :(
 
mcs51mc said:
Aha the register banks... ... something I never use :eek:
Except the first bank of coarse.
What's the point having 4 banks?
When you have one bank (8 registers) do to some indirect adressing things isn't that enough? Anyone with a project example using more than 8 registers at the same time to do indirect adressing stuff?

@Papabravo: Why did you bring up the movx instructions? I can't see what they have to do with the register banks :(
The register banks are useful for fast context switching in interrupt routines. At least that is how I use them. Look at the assembly language output of a compiler some time and you will see that they are used for more than indirect addressing. I brought up the MOVX instructions because, as you well know, there are several places which can be described as address 0.

There is the address 0 in the code space
There is the address 0 in internal RAM
There is the address 0 in external data(xdata) space

This confuses a great many beginners.
 
And the fact that address 0 in the code space can either be internal or external, depending on types of 8051 MCU or how you wire up the EA pin of the MCU .
 
eblc1388 said:
And the fact that address 0 in the code space can either be internal or external, depending on types of 8051 MCU or how you wire up the EA pin of the MCU .
Quite so. An excellent point.
 
Regarding register bands, there is this question always facing beginners:

1. Why does "PUSH R0" not allowed?
Ans: the MCU doesn't know which R0 in these register banks to save to stack.

2. Why does "MOV R0, A" work correctly then?
Ans: the MCU knows exactly which R0 in these register banks to use.

3. Are you kidding me?
Ans: No

4. What is the real answer?
Ans: there isn't available single byte Opcode space to allocate for 8 PUSH and 8 POP instructions for R0-R7. The MCU designer doesn't want to make PUSH or POP a two-byte instruction.
 
There is a workaround for everything :D

Code:
MyISR:
mov  a,R0
push acc
mov  a,R5
push acc


;Do your stuff here


pop  acc
mov  R5,a
pop  acc
mov  R0,a
reti
:D:D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top