-1

I'm studying computer architecture and I was thinking about what assembly instruction corresponds to this simple assignment :


int main () {

 int local_test = 10;

}

Considering that the STORE instruction store something from a register to RAM and that the LOAD instruction load something from RAM into a register what is the assembly instruction used for local_test ?

  • I know that it could depend on the CPU, so feel free to give a specific example for a specific machine
Kode1000
  • 111
  • 3
  • 1
    [let gcc show you](https://godbolt.org/z/sTfKr9cTo). That particular link is for x64, but godbolt also has ARM compilers, choose what you want in the dropdown. – yano Sep 23 '22 at 16:51
  • What architecture are you programming for? – fuz Sep 23 '22 at 17:25
  • Your code doesn't have an *assignment*. It has an *initialization*. :) – Adrian Mole Sep 23 '22 at 17:27
  • what happened when you tried it. Note as written it is dead code so depending on optimization will simply get removed entirely. – old_timer Sep 23 '22 at 18:31

1 Answers1

1

Firstly, there isn't any assignment in the code you have shown. = in a declaration indicates an initializer.

Second, since you don't do anything with the value that produces program output, any decent compiler will eliminate it, and no output at all will be produced.

However, suppose you instead of not using the value you used it as the return value of your function. In that case, on most architectures RAM will never be used because function return values are in registers. On ARM, the output would simply be movs r0, 10 to put the value in the return register.

Alternatively suppose you added a line to copy the value to an external variable. The output would still be the same on many architectures, just whatever is necessary to get an immediate value into a register. After that there would be a store instruction to write to the external variable, but that would equate to a later line of code not the one you have asked about.

Tom V
  • 4,827
  • 2
  • 5
  • 22