Page 1 of 1

ASM question

Posted: Mon Jul 24, 2006 6:46 am
by ComputerPsi
Fellow assembly programmers, have one variable and one register. I need to set the last bit of the variable to the last bit of the register. Not knowing a quick way of doing this, I came up with two codes. Which do you think is more efficient? If you know of something better, please post.

Method1:
mov ah,al
and ah,0x80
and byte [KBFlags],0x7f
or byte [KBFlags],ah


Method2:
test al,0x80
jz .setbit
and byte [KBFlags],0x7f
jz .done
.setbit:
or byte [KBFlags],0x80
.done:

Posted: Mon Jul 24, 2006 6:14 pm
by carbonBased
This would depend on your target platform and the abilities of the processor. However, going strictly on opcode timings, the jump's are the most intensive instruction in those groupings. I'd be inclined to say the first is more efficient.

Of course, I don't believe any sane human could tell the difference anyway, unless you're executing this code a million times in a loop :)

--Jeff