[nfbcs] a little brain teaser

Jim Barbour jbar at barcore.com
Wed Jul 20 23:49:45 UTC 2016


Well, using assembler psuedo code, I'd do something like...

     put x into register 1
     put x into register 2
     logical shift register 1 left 3 times
     logical shift register 2 left 1 times
     Add register 2 to register 1

You'd have to detect register overflow, but otherwise this works.

Depending on how you're doing your big O calculations, it's now O(6)
instead of O(10)

Jim

On Wed, Jul 20, 2016 at 06:12:12PM -0500, david hertweck via nfbcs wrote:
> OK this is a CS group have a little CS puzzle / question for anyone.  I work
> down in the micro controller realm and memory and speed is still something
> that a programmer must deal with.
> 
> if one wanted to calculate  y = x*10 such that it took the min time / cpu
> cycles how would you do it.  There is no math co-processor such that * is a
> single operation.
> 
> I have one answer I thought it might be fun / interesting what people could
> come up with.   Will post the best answers.
> 
> have fun.
> 
> 
> 
> _______________________________________________
> nfbcs mailing list
> nfbcs at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> To unsubscribe, change your list options or get your account info for nfbcs:
> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/jbar%40barcore.com
> 




More information about the NFBCS mailing list