Say what? An if statement requires at a minimum a branch instruction and an
instruction for each of the assignments, plus an unconditional jump after
one of the assignments, four instructions, i.e.
BRANCH on <boolean> to <true clause>
STORE <variable> value 0
JUMP to <end of true clause>
true clause:
STORE <variable> value 2
end of true clause:
A multiply will by one instruction if the multiply instruction can do its
own memory storing, two if it can't:
MULTIPLY <boolean> by 2 into <register or <variable>>
#and, if MULTIPLY does not do memory storage:
STORE <variable> from <register>
In addition, execution speed is slowed by a branch instruction due to
today's pipelined RISC chips. There are advantages to the MULTIPLY over the
IF, *especially* if this code will be run (looped, most likely) over and
over. This is a hand optimization, not something the compiler can do. Do we
want efficient coding techniques available, or do we simply want to count
on unlimited computing power?
<UNNECESSARY AND FRUSTRATED FLAME>
Take a class on it and try again!
</UNNECESSARY AND FRUSTRATED FLAME>
} == John ==
--Greg