1
$\begingroup$

https://en.wikipedia.org/wiki/Processor_register So from the information in this link there are limited Floating point and General Purpose registers in a cpu. My question is how are these registers used. By that I mean let's say I defined some variables in python but I think It's stored in RAM or HDD so does cpu only use those registers when operating on the data fetched from RAM and if so in order to overload cpu's capacity what kind of an algorithm should be followed by such a program ?

$\endgroup$
  • 1
    $\begingroup$ It looks like you may want to read a basic tutorial on an assembly language. By "overload cpu's capacity", do you mean overclocking? $\endgroup$ – Apass.Jack Nov 29 '18 at 4:44
  • $\begingroup$ I think overclocking means increasing cpu’s capacity, what I want to do is how to load all registers at the same time and disable cpu $\endgroup$ – Crazy_39365 Nov 30 '18 at 6:33
  • $\begingroup$ "Disable CPU"? Are you interested in how to disable/damage/fail CPU? $\endgroup$ – Apass.Jack Nov 30 '18 at 6:49
  • $\begingroup$ Yes, I mean I want to test It’s limits.. $\endgroup$ – Crazy_39365 Nov 30 '18 at 10:48
1
$\begingroup$

As a general rule, variables are never stored on the hard disk (there are exceptions but let's not get into that here). The CPU can perform basic operations (arithmetic, comparisons, bit manipulations) in a number of ways, using registers, cache, stack, or general RAM. Registers are fastest but there aren't many of them.

Whether a programming language uses registers for variables depends a bit on what sort of a language it is. For instance, C is compiled to machine code so that, whenever possible, registers are used. If there aren't enough registers available, the C compiler will use something else (usually the stack). Other languages may use the registers differently. For instance, some languages compile to the so-called bytecode, which is a very simple langauge that is then simulated by the CPU. In such cases a single variable operation may correspond to many CPU operations, and variables would typically not be stored in registers.

In general you do not have to worry how registers will be used. Modern language compilers can figure out register usage really well and in fact are typically better at it than humans. There are of course certain guidelines that will make your code faster, but you should not worry about that. If you are not an experienced programmer, you should first worry about writing decent code, study algorithms, and so on. Optimization at the level of CPU comes later.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.