Search code examples
cpu-architectureavrcpu-registersmemory-mapping

What is the benefit of having the registers as a part of memory in AVR microcontrollers?


enter image description here

Larger memories have higher decoding delay; why is the register file a part of the memory then?

Does it only mean that the registers are "mapped" SRAM registers that are stored inside the microprocessor?

If not, what would be the benefit of using registers as they won't be any faster than accessing RAM? Furthermore, what would be the use of them at all? I mean these are just a part of the memory so I don't see the point of having them anymore. Having them would be just as costly as referencing memory.

The picture is taken from Avr Microcontroller And Embedded Systems The: Using Assembly and C by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi


Solution

  • what would be the benefit of using registers as they won't be any faster than accessing RAM?

    accessing General purpose Registers is faster than accessing Ram

    first of all let us define how fast measured in microControllers .... fast mean how many cycle the instruction will take to excute ... LOOk at the avr architecture

    enter image description here

    See the General Purpose Registers GPRs are input for the ALU , and the GPRs are controlled by instruction register (2 byte width) which holds the next instruction from the code memory.

    Let us examine simple instruction ADD Rd , Rr; where Rd,Rr are any two register in GPRs so 0<=r,d<=31 so each of r and d could be rebresented in 5 bit,now open "AVR Instruction Set Manual" page number 32 look at the op-code for this simple add instraction is 000011rdddddrrrr and becuse this op-code is two byte(code memory width) this will fetched , Decoded and excuit in one cycle (under consept of pipline ofcourse) jajajajjj only one cycle seems cool to me

    I mean these are just a part of the memory so I don't see the point of having them anymore. Having them would be just as costly as referencing memory

    You suggest to make the all ram as input for the ALU; this is a very bad idea: a memory address takes 2 bytes.

    If you have 2 operands per instruction as in Add instruction you will need 4 Byte for saving only the operands .. and 1 more byte for the op-code of the operator itself in total 5 byte which is waste of memory!

    And furthermore this architecture could only fetch 2 bytes at a time (instruction register width) so you need to spend more cycles on fetching the code from code memory which is waste of cycles >> more slower system

    Register numbers are only 4 or 5 bits wide, depending on the instruction, allowing 2 per instruction with room to spare in a 16-bit instruction word.

    conclusion GPRs' existence are crucial for saving code memory and program execution time

    Larger memories have higher decoding delay; why is the register file a part of the memory then?

    When cpu deal with GPRs it only access the first 32 position not all the data space

    Final comment

    don't disturb yourself by time diagram for different ram technology because you don't have control on it ,so who has control? the architecture designers , and they put the limit of the maximum crystal frequency you can use with there architecture and everything will be fine .. you only concern about cycles consuming with your application