[nfbcs] a little brain teaser
david hertweck
david.hertweck at sbcglobal.net
Thu Jul 21 01:38:47 UTC 2016
yes this gets you there and has the same number of operations I think.
-----Original Message-----
From: Doug Lee via nfbcs
Sent: Wednesday, July 20, 2016 8:26 PM
To: Jim Barbour via nfbcs
Cc: Doug Lee
Subject: Re: [nfbcs] a little brain teaser
That's nearly what I thought up on reading the original message, but mine
was this:
Load R1 with x
Shift R1 left once
Load R2 with R1
Shift R1 left two more times
Add R2 into R1
Store R1 in y
On Wed, Jul 20, 2016 at 04:49:45PM -0700, NFBCS mailing list wrote:
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
>
_______________________________________________
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/dgl%40dlee.org
--
Doug Lee dgl at dlee.org http://www.dlee.org
SSB BART Group doug.lee at ssbbartgroup.com
http://www.ssbbartgroup.com
"Nearly all men can stand adversity, but if you want to test a man's
character, give him power." -Abraham Lincoln
_______________________________________________
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/david.hertweck%40sbcglobal.net
More information about the NFBCS
mailing list