enter image description here

I don't understand the explanation. Doesn't the assembler have to calculate 3 * 4 + 5 so it takes longer to execute? Also since 3 * 4 +5 has more characters why does it not take more storage?

From problem 2 of:https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-004-computation-structures-spring-2017/c9/c9s3/isa_answers.pdf

  • \$\begingroup\$ Is this homework? \$\endgroup\$ – Justme Sep 15 '20 at 19:16
  • \$\begingroup\$ No it's from ocw.mit.edu/courses/electrical-engineering-and-computer-science/… \$\endgroup\$ – Ray Sep 15 '20 at 19:18
  • 4
    \$\begingroup\$ You are confusing build/compile/assembly stage with executions stage. Build is slightly slower, but you do that only once. Executing is equally fast for both options and you usually do that many times. \$\endgroup\$ – jippie Sep 15 '20 at 19:38

The assembler (compiler) has to calculate the constant at assembly time, so the compilation to binary is marginally slower. A human cannot tell the difference so the compilation time it takes is irrelevant.

The resulting assembly binary will be identical, so they are both equally sized and equally fast programs.

  • \$\begingroup\$ From the point of view of software development, it's good to put the calculation in the source code so it can be checked when modifications are necessary. Even better, define sybolic constants so the expression is more easily understood and a change to a real-world value can be made in one place (the definition of the constant). \$\endgroup\$ – grahamj42 Sep 16 '20 at 8:29

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.