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

寵の児 提交于 2020-12-15 19:37:37

问题


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


回答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

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




回答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.



来源:https://stackoverflow.com/questions/64326022/what-is-the-benefit-of-having-the-registers-as-a-part-of-memory-in-avr-microcont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!