Jump to content
Tuts 4 You



Recommended Posts

K, so i wrote a small masm exe to see how it'll look when its compiled, kinda same..the only major difference was that in the source i did an IF condition.

when i debugged the .exe the .if eax == null.........endif became OR EAX,EAX, i didn't really find anything about that in google for some reason...can anyone explain how that OR works and if i can use it as a replacement for the .if .endif somehow.


Link to comment

read the x86 asm guide :

OR - Logical Inclusive OR


Performs a bitwise inclusive OR operation between the destination (first) and source (second) operands and stores the result in the destination operand location. The source operand can be an immediate, a register, or a memory location; the destination operand can be a register or a memory location. (However, two memory operands cannot be used in one instruction.) Each bit of the result of the OR instruction is 0 if both corresponding bits of the operands are 0; otherwise, each bit is 1.

Link to comment

Example of AND / OR / XOR / NOT:

Instruction		AND	 OR	  XOR   NOT 
Source Bit |0 0 1 1|0 0 1 1|0 0 1 1|0 1|
Destination Bit |0 1 0 1|0 1 0 1|0 1 0 1|X X|
Output Bit |0 0 0 1|0 1 1 1|0 1 1 0|1 0|
Link to comment

I suppose after the OR EAX, EAX there is a JNZ. The OR EAX, EAX is just used to set the Z (Zero) flag if EAX is zero, then the jump skips the piece of code depending on that.

Maybe it helps to think of it like this: Because EAX OR EAX = EAX, EAX does not change. Therefore OR EAX, EAX does about the same thing as CMP EAX, 0.

Even better would be TEST EAX, EAX. If the instruction before the if modifies EAX and sets the Z flag (most instructions like ADD do this) you don't need to set it again.

It may be better to not use macros until you have a firm grasp on pure assembly programming.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...