flat assembler
Message board for the users of flat assembler.

Index > Main > `mov al, 1` vs `or al, 1` which is faster?

Author
Thread Post new topic Reply to topic
tf2_coolguy0000



Joined: 27 Aug 2022
Posts: 1
tf2_coolguy0000 06 Nov 2022, 00:31
`mov al, 1` vs `or al, 1` which is faster?
Post 06 Nov 2022, 00:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2022, 03:03
There is no way to tell. You have to try it in your code to see how it performs.

But a major problem with your question is that they do different things. They are not equivalent instructions.
Post 06 Nov 2022, 03:03
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1619
Location: Toronto, Canada
AsmGuru62 06 Nov 2022, 13:04
They are same if AL=0.
Very Happy
Post 06 Nov 2022, 13:04
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2022, 13:12
AsmGuru62 wrote:
They are same if AL=0.
Very Happy
Only if you don't care about the FLAGS register.

BTW: Having the previous value of AL = 1 also works.
Post 06 Nov 2022, 13:12
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 06 Nov 2022, 14:14
Code:
SALC ; D6 ; if CF=1 and not 64-bit.    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 06 Nov 2022, 14:14
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2493
Furs 06 Nov 2022, 19:35
tf2_coolguy0000 wrote:
`mov al, 1` vs `or al, 1` which is faster?
`mov al, 1` because it renames the register and has no input dependency on its previous value.

It might not always be faster, but it is objectively better, as long as it does the same thing (which I'm assuming you know it does in your specific case, since you're asking). It's also the same amount of bytes to encode: 2.
Post 06 Nov 2022, 19:35
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 06 Nov 2022, 22:39
maybe the "faster" aspect of the question is not only related to the "time needed to execute the instruction", but also, "what amount of circuitry is needed to execute the instruction". means that in an extremely RISC system, the question is relevant cause to mov something, you just point to register, and store immediate value. and for a OR, the CPU should point to register, load the register, OR immediate, store in FLAGS and store in register.

but the time spended to ask this question, you missed a lot of fun in your real life...
Post 06 Nov 2022, 22:39
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 06 Nov 2022, 23:49
Furs wrote:
mov al, 1` because it renames the register and has no input dependency on its previous value.
There is a dependency upon all the other 56 bits of RAX.

Both instructions use previous bits of RAX. Both instructions rename. No difference there. Only one instruction updates the FLAGS. So MOV might be more efficient with power usage. Measure it in your system to see if there is a difference.

If the OP wants a guess, I suspect there will be no measurable difference in execution time in any code or in any CPU. These low level instructions are done in the core of the ALU and are practically identical with regard to how they pass through the execution stages.
Post 06 Nov 2022, 23:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.