1

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

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Tortellini Teusday
  • 1,335
  • 1
  • 12
  • 21
  • 1
    You have this backwards: the register file is small and fast, and register numbers only take a few bits (vs. memory addresses taking many). The strange thing is that registers are also accessible via memory addresses, not that they exist at all! How are you going to encode an instruction like `add [label1], [label2]` into a 16-bit AVR instruction word, with two absolute addresses? – Peter Cordes Oct 14 '20 at 09:37
  • @PeterCordes Thank you so much. This is one point and yes, I agree with what you have said and maybe I emphasized the wrong point. What's peculiar about it is that they are a part of memory. As stated in the book, memory accesses take 2 cycles of work, maybe this would've been reduced to one if there were a small register file inside the microprocessor? – Tortellini Teusday Oct 14 '20 at 15:18
  • @PeterCordes What I've been thinking about is that this could be just mapping and accessing registers through memory interrogation would be translated to directly accessing the register file. – Tortellini Teusday Oct 14 '20 at 15:20
  • 1
    There *is* a small register file inside the microprocessor; that's why ALU instructions like [`add reg,reg` (docs)](https://onlinedocs.microchip.com/pr/GUID-0B644D8F-67E7-49E6-82C9-1B2B9ABE6A0D-en-US-1/index.html) take only 1 cycle to read 2 regs and write 1. AVR chips all have on-chip SRAM; the registers are part of this, or maybe even separate with just address-decoding to select between register file, I/O ports, or "normal" SRAM, or off-chip external memory as shown in @Ibram's answer, based on the actual load or store address. Using load/store insns to access regs is slower than `mov`). – Peter Cordes Oct 14 '20 at 15:22
  • @PeterCordes Thank you so much! – Tortellini Teusday Oct 14 '20 at 15:23

2 Answers2

2

AVR has some instructions with indirect addressing, for example LD (LDD) – Load Indirect From Data Space to Register using Z:

Loads one byte indirect with or without displacement from the data space to a register. [...] The data location is pointed to by the Z (16-bit) Pointer Register in the Register File.

So now you can move from a register by loading its data-space address into Z, allowing indirect or indexed register-to-register moves. Certainly one can think of some usage where such indirect access would save the odd instruction.

kisch
  • 414
  • 2
  • 6
1

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

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ibram Reda
  • 1,882
  • 2
  • 7
  • 18