Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I made precisely this .Nigel Goodwin said:Multipling by two is trivial in binary, it's just a logical shift left - as you're going to more than 8 bits you need to make it a 16 bit shift using two bytes, this is why shift instructions shift the bit out to carry - you can then shift it to the next byte.
I use 16f88Hero999 said:I don't know about PICs but on the x86 in virtual mode it's simple in assembly, the add instruction was faster than the logical shift left.
For example to multiply x by 2:
mov ax,[x]
add [x],ax
The above code works in NASM.
Hero999 said:So can't you just apply this example to the micro you're using?
It's exactly the same principle.
blueroomelectronics said:512 Well it's not quite a 16 bit value more like 9 bits. You could probably save a byte and use the carry register which would have the correct bit after a logical shift left.
I take it you haven't done any programming on the PC then.Nigel Goodwin said:Why would you want to use two instructions instead of one?, although for a PIC it will need more than one as it's a 16 bit shift - even so, it's still probably half the instructions of using add.
Hero999 said:I take it you haven't done any programming on the PC then.
Because the x86 can't directly add, subtract or move data in one memory location to another, it has to go via a register. Therefore unless you're using register variables you can't do add [x],[x].
Wait I'm talking total rubbish, you can always do shl [x],1
I blame Bill Gates' crappy operating system rather than the CPU architecture.Nigel Goodwin said:When a decades old Amiga running at 8MHz odd, multi-tasks better than a Pentium IV running at multi-GHz it really shows up the limitations of Intel processors.
Hero999 said:I blame Bill Gates' crappy operating system rather than the CPU architecture.