der Mouse wrote:
digit = value
% 10;
value /= 10;
whereas if you were writing it in ASM, both results would be
available to you in the same operation
Not necessarily; not all machines have a divide instruction that
produces both quotient and reminader. (Indeed, some don't have a
divide instruction at all - or are those the ones you were thinking
of?)
*Exactly*! If you have to do the divide yourself (i.e. in ASM),
you end up with both results for free. If, OTOH, you write in
a HLL *on this same class of machine*, the compiler writes code
to do the divide (typically, just calls a "helper" function),
discards the remainder and then goes to work on the modulus
operation... :-(
(point being, compilers aren't all created equally as
processors aren't -- the differences in efficiency of
compiled code vs. ASM can vary tremendously depending on what
you are working on)
On those that do have a divide that produces both quo
& rem, a good
compiler will notice that you have both a/b and a%b in close proximity
and collapse them. (Not all compilers are "good", of course.)