1. 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.
    Dismiss Notice

Rom address and rom location

Discussion in '8051/8951' started by jidan, Oct 30, 2013.

  1. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    Rom and ram both memory are used in micro controller
    Rom address- the address where data stored
    Ram location - the location where data stored
    both things are confuse me does anyone can explain
     
  2. CroneA

    CroneA New Member

    Joined:
    Oct 23, 2013
    Messages:
    19
    Likes:
    0
    ROM stands for Read Only Memory
    RAM stands for Random Access Memory
    They are both memory, but will have different speeds, among other things. The exact details for a microcontroller's memory is in it's datasheet. Be sure to read the datasheet for the microcontroller that you are using!
     
  3. CroneA

    CroneA New Member

    Joined:
    Oct 23, 2013
    Messages:
    19
    Likes:
    0
    I forgot to say that the general rule is that ROM is intended for data that doesn't need to change, and will be there each time the power is on. And RAM is where the data can be changed freely, but disappears when the power goes off.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK

    Try to think of it more like... ROM is "Code space" and "RAM" is Data space" In the 8051 chips they both start at address 0x000 just confuse you even more.... Any Data stored in ROM are constants ie.. cannot be changed.

    This should read... the address where code stored...
     
  6. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    in
    In assembly language we write code that stored in ram and rom
    Ok when we write code in assembly language code store in rom memory and program counter increase step . what is the work of ram memory
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Only on the larger chips.... And really only when using an operating system... I wouldn't use RAM on the smaller chips unless I had a decent File system to get it into memory...

    Are you talking about the PC in general?
     
  8. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal

    Hi Ian,

    how come both ROM and RAM (you're talking on the externals or internals?) start at the same address?

    it doesnt make sense.
     
  9. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
  10. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Hi NS.
    Thank you very much.

    I read on the Harvard Architecture in Wiki,

    however, I didn't managed to understand the following.

    Both RAM and ROM store data, right? (the ROM may store const variables, and RAM stores the Stack and Dynamic memory).
    So the CPU will read data from both during the program execution.

    so when the CPU wants to read some data from address 0x0005 from the ROM, how does he "tell" the address and data buses to read it from the ROM and not from the RAM? (or the other way around)
     
  11. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    The set of instructions which address program memory (ROM) is different from the set of instructions which address data memory (RAM).
     
    • Like Like x 1
  12. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    oh, i see, thanks!!

    I indeed read that to read from data memory (RAM), you use MOVX.

    it wasn't specified there (in wiki link that NS shared) what is the instruction for ROM
     
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Not exactly... movx is move memory external... This is ram is off chip...
     
  14. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    It makes perfect sense. ROM and RAM are not contiguous space. Rather, they are spaces that are physically separate from each other. It's all in HOW we access the memory space and which instructions we use that determines whether we are accessing the internal ROM, internal RAM, external RAM, and the SFR space.

    On both 8051 and 8052, directly addressing addresses in the range of 0x80-0xFF always accesses the SFR space. On the 8052, we also have on chip RAM that resides in the 0x80-0xFF range, but we use indirect addressing to access this space.

    Example, if we execute -

    Code (text):

                        mov               0x90, #0x55                              ;load value 0x55 to P1 register
     
    This writes the value 0x55 to the P1 SFR. However, if we execute -

    Code (text):

                        mov                R0,#0x90                                 ;load RAM address to R0
                        mov                @R0,#0x55                              ;store value 0x55 to RAM address in R0
     
    This writes the value 0x55 to address 0x90 in internal RAM space as we have indirectly addressed RAM location 0x90 using the R0 register as an address pointer.

    Another little trick that you only use if you really know what you're doing is to use the stack pointer along with the push and pop instructions to read/write the memory space from 0x80-0xFF. This works because the stack indirectly addresses the RAM space. On most 8052 applications, I actually dedicate the 0x80-0xFF RAM space to the stack by moving the stack pointer to address 0x7F in my initialization code.

    The program counter ONLY accesses internal ROM as this is where the code is stored. We can also read data in code memory by using the MOVC instruction.

    *EDIT* - The program counter accesses internal ROM if and ONLY if the !EA pin is tied high. If an instruction in the code calls for an access to program ROM past the internal ROM's address range, it will attempt to access that location on external ROM. However, if the !EA pin is tied low, the program counter will ONLY access external ROM (EA stands for External Access. This pin governs whether the 8051/8052 will execute code from internal or external ROM).

    When reading external RAM, we use the MOVX instruction.

    Through the use of different instructions and addressing methods to access the different memory spaces, this allows each separate memory space to use the same address ranges.

    To summarize -

    MOVX is dedicated to external RAM space only
    MOV is dedicated to internal RAM space and SFR space only
    MOVC is dedicated to internal and external program ROM only
    The program counter is dedicated to internal/external ROM space only
     
    Last edited: Jan 12, 2014
    • Like Like x 2
    • Informative Informative x 1
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,022
    Likes:
    317
    Location:
    Brisbane Australia
    Note that in Jon's example,
    Code (text):

                        mov               0x90, #0x55                              ;load value 0x55 to P1 register
     
    the value 0x55 is stored in ROM as part of the instruction.

    On a pic chip the similar instruction movlw 0x55 also stores the value in ROM.

    Mike.
     
    • Like Like x 1
  16. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Jon

    WOW, thank you so much for this great explanation! :)

    You explained it so well and it really helped me out understand it!

    thank you!

    Mike, Ian
    Thank you guys for your comments and help as always :)

     
  17. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Hi friends.

    I'd appreciate your comments on this matter.

    I read about memory shadowing - in which contect of ROM is copied into RAM - in order to read the content faster.

    I'm trying to understand the 2 following matters:

    1. what type of content is copied from ROM to RAM?
    i.e. Program instructions (as x = a + b;) or is it just about const variables, constants, and values of initialized global variables?

    2. how can you tell how much of the ROM and which part of it is copied into RAM?

    Thank you very much.
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    I use shadowing in a different context.. Shadowing ram can mean a lot of things... A framebuffer for example when working with graphical screens...

    The old PC's used to have a BIOS and some PC's used to shadow this by placing the BIOS in ram so the basic IO was quicker... On large processing equipment programs ARE loaded into ram..

    On your humble 8051 derivative you have "code space" ROM.... This is referred to as firmware. On a small micro you would never need to shadow the code... But on a pentiumIII you have relocatable memory and code is run from ram anyway...
     
    • Like Like x 2
  19. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Hi Ian
    Thank you very much.

    What about copying ROM's content to RAM, in uCs in general - i.e. if it's not done in 8051 (are you sure?) then in other processors as ARM (i'm talking on Embedded, not Computers).

    I'm looking to understand these two basics matters:

    1. what type of content is copied from ROM to RAM?

    2. how can you tell how much of the ROM and which part of it is copied into RAM?
     
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Didn't say that.... You need to see if the architecture will support it... Apparently you can do it but you'll need to map your code to external memory.. The micro will see it as external ROM if you know what I mean.

    If you look at the PC ( Program counter ) on small micro's it can only be pointed to the code space allocated and not RAM so it cannot be done in this case... However some small micro's allow external Eprom's, if you exchange it for SRAM, you would need a way to load it at boot time and there would be no facility to write to the device...

    I know that ARM and the PIC32 can run code from RAM.... But ask yourself a question... The whole point of micro's is that you are running firmware, so why bother trying.
     

Share This Page