### Author Topic: .if eax  (Read 5169 times)

#### Magnum

• Member
• Posts: 2396
##### .if eax
« on: April 06, 2013, 07:00:20 AM »
I see this a lot and am trying to understand why it's used.

If eax is ORed with itself, it sets any bits that are 1 to 1.
What is the purpose of it ?

Is it the only way to determine success or failure ?

.IF (eax) ; same as OR eax,eax

; 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.

Take care,
Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: .if eax
« Reply #1 on: April 06, 2013, 07:15:51 AM »
many windows API functions return zero or non-zero
OR EAX,EAX sets the zero flag is eax if zero, clears it if not
as a side effect, it always clears the carry flag, as do most logical operations (AND, OR, XOR)
and - the sign flag will be set to the same value as the high bit of the register

as for ".if eax" - if eax is non-zero or true

#### ragdog

• Member
• Posts: 609
##### Re: .if eax
« Reply #2 on: April 06, 2013, 06:10:16 PM »
Hi

.if eax !=0    = cmp eax, 0
.if eax          =  or eax, eax

Or eax,eax is a one byte smaller and faster

this bracket in a if else statment .if (eax) is only cosmetics
for better read a code  ;)

Gel Jochen

#### jj2007

• Member
• Posts: 13648
• Assembly is fun ;-)
##### Re: .if eax
« Reply #3 on: April 06, 2013, 06:32:39 PM »
Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
loop overhead is approx. 189/100 cycles

239     cycles for 100 * 3*Test
240     cycles for 100 * 3*And
240     cycles for 100 * 3*Or
234     cycles for 100 * 3*cmp 0

240     cycles for 100 * 3*Test
240     cycles for 100 * 3*And
239     cycles for 100 * 3*Or
240     cycles for 100 * 3*cmp 0

#### ragdog

• Member
• Posts: 609
##### Re: .if eax
« Reply #4 on: April 06, 2013, 07:05:25 PM »
AMD Athlon(tm) II P360 Dual-Core Processor (SSE3)
++++++14 of 20 tests valid, loop overhead is approx. 239/100 cycles

73      cycles for 100 * 3*Test
73      cycles for 100 * 3*And
73      cycles for 100 * 3*Or
73      cycles for 100 * 3*cmp 0

73      cycles for 100 * 3*Test
73      cycles for 100 * 3*And
73      cycles for 100 * 3*Or
544     cycles for 100 * 3*cmp 0

510     cycles for 100 * 3*Test
675     cycles for 100 * 3*And
566     cycles for 100 * 3*Or
542     cycles for 100 * 3*cmp 0

18      bytes for 3*Test
18      bytes for 3*And
18      bytes for 3*Or
21      bytes for 3*cmp 0

--- ok ---

#### hutch--

• Member
• Posts: 10294
• Mnemonic Driven API Grinder
##### Re: .if eax
« Reply #5 on: April 07, 2013, 12:21:44 AM »
I confess I am highly UNtrusting of abbreviated notation, as a left over from the logic I did many years ago I use the expanded form most of the time.

Code: [Select]
`.if eax == 0  ; do something.else  ; do something else.endif`
hutch at movsd dot com
http://www.masm32.com

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: .if eax
« Reply #6 on: April 07, 2013, 10:31:08 AM »
you could use a similar syntax in old IBM/MS Basic   :P

Code: [Select]
`X=X+YIF X THEN ... ELSE ...`
bitwise operations were one thing i liked about basic