I have a variable which is byte and change from 0-255
and the result show on LCD.
I want to multiply the variable x 2 , therefore will change from 0-512 (now is word) and to show on Lcd.
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.
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.
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.
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.
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.
But only assuming you're using it immediately, and don't have to store it anywhere - if you've got to store it you may as well use two GPR's as a 16 bit register, which makes the shifting dead simple.
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.
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 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've done plenty of programming on PC's, but we're not talking PC's, and I can't believe any processor would be faster doing an add rather than a simple shift? - it's such a basic instruction, and so easy for a processor to do.
Well the Intel processors are usually pretty crap, so what can you expect?
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.
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.