0

I need to find the exact operation count and i got confused over the below 2

Is a=b+c+d considered as one instruction or 2 instructions?
Similarly is a+=b one instruction or 2?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by tungnk1993
0

Is a=b+c+d considered as one instruction or 2 instructions?

Neither. Barring compiler optimizations, there are three operations going: two additions and an assignment. As far as instructions go, a naive interpretation would be:

mov r1, b
mov r2, c
add
mov r2, d ; Assuming add puts the result in r1
add
mov a, r1

Similarly is a+=b one instruction or 2?

It depends on how the compiler generates machine code for that kind of compound operator. But when working out time complexity, you should be looking at operations in the source language, not the resulting instructions after the source language is compiled. In that case your two example statements are 3 operations and 1 operation, respectively.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.