C
CJ
Hi Friends -
This is a pretty naive question, so be patient. I have been thinking
about the following simple C program:
void main()
{
int a, b, c;
a=1;
b=2;
c=a+b;
printf("%d", c);
}
Let's imagine what the compiler does to this program. Probably it says
"OK, so here we have some variables. We've got an accumulator and some
registers X and Y hanging around. Let's do something like:
LDA 0x1 # put 1 into accumulator
LDX 0x2 # put 2 into register X
ADC X # add register X to accumulator with carry
for example."
So let's fast forward a bit, and our program is executing. But now maybe
we've got A and X set up, but before we get chance to execute the add
instruction, we get interrupted and the kernel passes control to some
other process. In this case, probably all the registers will have to be
pushed onto the stack, then popped back when control returns to our
process.
But haven't we then lost all the benefits of using registers for storage
instead of RAM?
Or to put it another way, why do people worry so much about hitting
cache and optimizing register usage, when this can easily (and probably
will be) wiped out by control passing to another process in the mean
time?
This is a pretty naive question, so be patient. I have been thinking
about the following simple C program:
void main()
{
int a, b, c;
a=1;
b=2;
c=a+b;
printf("%d", c);
}
Let's imagine what the compiler does to this program. Probably it says
"OK, so here we have some variables. We've got an accumulator and some
registers X and Y hanging around. Let's do something like:
LDA 0x1 # put 1 into accumulator
LDX 0x2 # put 2 into register X
ADC X # add register X to accumulator with carry
for example."
So let's fast forward a bit, and our program is executing. But now maybe
we've got A and X set up, but before we get chance to execute the add
instruction, we get interrupted and the kernel passes control to some
other process. In this case, probably all the registers will have to be
pushed onto the stack, then popped back when control returns to our
process.
But haven't we then lost all the benefits of using registers for storage
instead of RAM?
Or to put it another way, why do people worry so much about hitting
cache and optimizing register usage, when this can easily (and probably
will be) wiped out by control passing to another process in the mean
time?