Some of those decisions are left up to the compiler as to how to evaluate an expression. You know the result and how it must get there from a mathematical and a C standpoint, though.
This is how LCC broke down your line of code into assembly without optimizations:
Code:
; 7 g = a/2 + b*4/a - abc/3;
.line 7
movl -8(%ebp),%edi
movl %edi,%eax
movl $2,%ecx
cdq
idivl %ecx
movl %eax,-20(%ebp)
movl -12(%ebp),%esi
movl %esi,%eax
sall $2,%eax
movl %edi,%ecx
cdq
idivl %ecx
movl -20(%ebp),%edi
addl %eax,%edi
movl -16(%ebp),%eax
movl $3,%ecx
cdq
idivl %ecx
subl %eax,%edi
movl %edi,-4(%ebp)
- It loads a first, divides it by 2, and stores the result in a temp variable.
- It loads b into memory, fast multiplies by 4, divides by a, stores the result into the temp variable, and then adds the two temp values together.
- It moves the last variable, abc, divides by 3, subtracts it from the result of the addition of the previous two temp values, and finally sets G to the value.
This is all without optimizations, and it's rather a silly way to write it into assembly, but it works, and it's easy enough to explain.