The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: shaldan on October 31, 2005, 09:49:14 AM

Title: .IF .ELSE
Post by: shaldan on October 31, 2005, 09:49:14 AM
hello ...  can you tell me, what "pure" assembler code produces ?:


.if condition
blablabla statements
.else
another blablabla statements
.endif



Title: Re: .IF .ELSE
Post by: PBrennick on October 31, 2005, 12:30:39 PM
shaldan,


    cmp condition1. eax  ; or similar
    jne  nextcheck

    .... code that goes here is for 'condition is met'
    jmp nextroutine

nextcheck:
    cmp condition2. eax  ; or similar
    jne  nextroutine

    .... code that goes here is for 'condition is met'

nextroutine:



This is untested coe just to show you what a possible layout could be.
Paul
Title: Re: .IF .ELSE
Post by: Mirno on October 31, 2005, 12:43:19 PM
From the list file:

00000000 .code
00000000 start:
    .if eax
00000000  0B C0    *     or eax, eax
00000002  74 04    *     je     @C0001
00000004  0B C0         or  eax, eax
    .else
00000006  EB 02    *     jmp    @C0003
00000008    *@C0001:
00000008  23 C0         and eax, eax
    .endif
0000000A    *@C0003:
end start


The lines with a * are generated, those without are actual lines from the .asm file.

Mirno
Title: Re: .IF .ELSE
Post by: shaldan on October 31, 2005, 01:22:23 PM
thanx ... I thought it could be something like this.

In the NeHe openGl tutorials (MASM source) I found this:


.IF (fullscreen)
                 mov fullscreen, 0
                .ELSE
                 mov fullscreen, 1
                .ENDIF


and I think there are too many statements. I replaced it with:


mov eax,1
xor eax,fullscreen


and it works well.
In comparison with .if else it looks faster and smaller ... am I right or not ? :)
How can a programmer counts cycles ? .. simply handly by knowing how many cycles are needed or is there a more comfortable way ?


Title: Re: .IF .ELSE
Post by: Eugen on October 31, 2005, 01:51:38 PM

Hi shaldan

The simplest way is 'xor fullscreen,1'
Btw, you are not modifying the 'fullscreen' variable in your optimization, only eax :D.

Eugen
Title: Re: .IF .ELSE
Post by: shaldan on October 31, 2005, 02:10:31 PM
hehe ... my fault .. i forgot to past following code, where there is a procedure using the xored eax :)

But xor fullscreen,1 is even better :)) thanks ... (I thought xor must use register as destination)

Title: Re: .IF .ELSE
Post by: diablo2oo2 on October 31, 2005, 04:33:12 PM
Quote from: shaldan on October 31, 2005, 09:49:14 AM
hello ...  can you tell me, what "pure" assembler code produces ?:


.if condition
blablabla statements
.else
another blablabla statements
.endif



you can find this out yourself. just load your compiled programm into a disassembler and see what happens.