ASM question

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

ASM question

Post 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:
Anything is possible if you put your mind to it.
ComputerPsi
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Post 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
Post Reply