Heya, I have a reather lengthy program. its running fine, but im wandering if i can tweak it so it is more responsive, so optimising for speed here.
first question (and most important): Does a 'smaller' program (ie bytes) mean it will run faster. or is it dependant on the commands used. or is it dependant on the number of lines?
for example:
(some background on the code. the constants (regctrl, reginputs, regoutputs) are variables in the full program. this segment of the program takes the 'selected input' (0-3 dec), 'selected output' (0-2 dec), 'selected preset' (0-3 dec), and regctrls (3 toggle type buttons, eg %111. %101 etc), and puts them into a 16-bit register for outputing to an led driver.)
CODE 1:
CODE 2:
now, code sample 1 compiles to 49 bytes, but has more lines of code.
code sample 2 compiles to 55 bytes, but is shorter.
which is more efficient?
any other optimisation tips? commands to avoid etc. Hippie, i've read your website regarding this, and implemented it as much as possible
first question (and most important): Does a 'smaller' program (ie bytes) mean it will run faster. or is it dependant on the commands used. or is it dependant on the number of lines?
for example:
(some background on the code. the constants (regctrl, reginputs, regoutputs) are variables in the full program. this segment of the program takes the 'selected input' (0-3 dec), 'selected output' (0-2 dec), 'selected preset' (0-3 dec), and regctrls (3 toggle type buttons, eg %111. %101 etc), and puts them into a 16-bit register for outputing to an led driver.)
CODE 1:
Code:
symbol lamps = w0
symbol temp = w1
symbol temp2 = w2
symbol reginputs = 1
symbol regoutputs = 2
symbol regpreset = 0
symbol regctrl = %010
temp = 1 << reginputs
temp2 = 1 << regoutputs * 2
temp2 = temp2 << 7
temp = temp | temp2
temp2 = 1 << regpreset * 2
temp2 = temp2 << 3
temp = temp | temp2
temp2 = regctrl << 13
temp = temp | temp2
lamps = not temp
Code:
symbol lamps = w0
symbol temp = w1
symbol reginputs = 1
symbol regoutputs = 2
symbol regpreset = 0
symbol regctrl = %010
lamps = $FFFF
clearbit lamps, reginputs
temp = regoutputs + 8
clearbit lamps, temp
temp = regpreset + 4
clearbit lamps, temp
temp = regctrl << 13
temp = not temp
lamps = lamps & temp
code sample 2 compiles to 55 bytes, but is shorter.
which is more efficient?
any other optimisation tips? commands to avoid etc. Hippie, i've read your website regarding this, and implemented it as much as possible