flat assembler
Message board for the users of flat assembler.

Index > Main > ..

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
pool



Joined: 08 Jan 2007
Posts: 97
Location: Philippines
pool
..


Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total
Post 21 Dec 2012, 16:04
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
It depends on "arg". In general, there is no "if" construction in assembly programming.
Post 21 Dec 2012, 16:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 1 time in total
Post 21 Dec 2012, 16:23
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
if statements usually translate to compare and branch-if-not-condition:
Code:
cmp [arg],0 ; if (arg)
je @f       ; {

@@:         ; }

cmp [arg],0 ; if (!arg)
jne @f      ; {

@@:         ; }    
but this can (and usually will) be optimised in a number of ways.


Last edited by cod3b453 on 21 Dec 2012, 18:59; edited 2 times in total
Post 21 Dec 2012, 18:34
View user's profile Send private message Reply with quote
pool



Joined: 08 Jan 2007
Posts: 97
Location: Philippines
pool
..


Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total
Post 21 Dec 2012, 18:36
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
cod3b453,

You got it completely wrong: if (expression) statement executes statement if expression evaluates to non-zero; therefore proper conditional jump mnemonic is je, so it jumps over when expression evaluates to zero.
Post 21 Dec 2012, 18:50
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Sorry pool/thanks baldr

That's what happens when I copy&paste code on an overtime Friday but as long as you do what I say and not what I do Very Happy I'll fix it now
Post 21 Dec 2012, 18:58
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
pool,

Many C compilers have option to output assembly listing (/Fafilename.asm for Visual C), you may examine it to see how code corresponding to high-level statements is generated. Beware of optimization though.
Post 21 Dec 2012, 20:15
View user's profile Send private message Reply with quote
pool



Joined: 08 Jan 2007
Posts: 97
Location: Philippines
pool
..


Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total
Post 21 Dec 2012, 22:21
View user's profile Send private message Visit poster's website Reply with quote
Bargest



Joined: 09 Feb 2012
Posts: 79
Location: Russia
Bargest
Quote:
Many C compilers have option to output assembly listing

... or you can download any free disassembler and use it to get ASM-code of any construction you want.Smile
For examle, you can write like this:
Code:
_asm nop;
_asm nop;
_asm nop;
_asm nop;
if (arg)
{
    MessageBoxA(0,0,0,0);
}
if (!arg)
{
    MessageBoxW(0,0,0,0);
}
_asm nop;
_asm nop;
_asm nop;
_asm nop;
    

Then disassemlby it and find code between four NOPs.
Also, you should disable optimization, or good compiler can count the value of arg and if it is constant - it will compile code destroying all your IFs:
Code:
push 0
push 0
push 0
push 0
call [MessageBoxA]
    
Post 22 Dec 2012, 19:27
View user's profile Send private message Reply with quote
pool



Joined: 08 Jan 2007
Posts: 97
Location: Philippines
pool
..


Last edited by pool on 17 Mar 2013, 12:18; edited 2 times in total
Post 22 Dec 2012, 23:09
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 3 times in total
Post 22 Dec 2012, 23:17
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
pool,

You're right, those lea edi, [edi] are 7-bytes nops used to align _main to 16-bytes boundary.

----8<----
HaHaAnonymous,

Your comment about setne is partly wrong: instruction sets al to 1 (not 0 as you've said) if ZF==0 (i.e. [var1] is non-zero).
Post 23 Dec 2012, 07:21
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
Weird, maybe it depends on compiler, but Visual Studio
evaluates IF() into zero and one.
I can see that 1 is a non-zero, but a non-zero is wider, it gives
an impression that it can be 3 or -5, but it is actually 1.

I could do this in C (Visual Studio):
Code:
HCURSOR      cursors [2];
...
cursor [0] = LoadCursor (...);
cursor [1] = LoadCursor (...);
...
SetCursor (cursor [(value1 > value2)]);
    

I wonder what other compilers are doing here?
Will that code work with GCC or Watcom or Intel?
Post 23 Dec 2012, 10:42
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
AsmGuru62,

Compilers that adhere to standard (ISO/IEC 9899:2011, AKA C11) yield 0 or 1 as a result of relational/equality operators.
Post 23 Dec 2012, 12:20
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:08; edited 1 time in total
Post 23 Dec 2012, 14:55
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
How did you get Pelles-C to bring that debug window. Every time I put a debug breakpoint and compile with debug symbols it doesn't stop it just runs without breaking on them(break points).

It pisses me off. I just use Visual Studio instead.
Post 23 Dec 2012, 16:13
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
pool wrote:
what is the equivalent of:

if(arg){

}

if(!arg){

}

to assembly?

thanks!!



^^^ This is amateurish code. This code will basically achieve the same thing in the end. The first if statement is enough. Your compiler might optimize it for you though.

Do this:

Code:
if(arg)
{
 ...
}else{
 ...
}
    


Which would translate to (in ASM)

Code:
; The main goal is to test for null.

cmp  [arg], 0  ; if (arg) or if (arg != null) or if(arg > 0) or if(arg != 0)
je      is_null   ; Jump if null or you could jump if not null

no_null:

jmp resume

is_null:


resume:



    
Post 23 Dec 2012, 16:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17662
Location: In your JS exploiting you and your system
revolution
typedef wrote:
pool wrote:
what is the equivalent of:

if(arg){

}

if(!arg){

}

to assembly?

thanks!!
^^^ This is amateurish code. This code will basically achieve the same thing in the end. The first if statement is enough. Your compiler might optimize it for you though.

Do this:
Code:
if(arg)
{
 ...
}else{
 ...
}
    
What about the case where arg changes within the execution of the first if clause?

Or what if arg is a volatile external device status?

Or what if arg is a complex compound statement?

There can be many reasons why your replacement code would not be the same.
Post 23 Dec 2012, 19:56
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
revolution wrote:
typedef wrote:
pool wrote:
what is the equivalent of:

if(arg){

}

if(!arg){

}

to assembly?

thanks!!
^^^ This is amateurish code. This code will basically achieve the same thing in the end. The first if statement is enough. Your compiler might optimize it for you though.

Do this:
Code:
if(arg)
{
 ...
}else{
 ...
}
    
What about the case where arg changes within the execution of the first if clause?

Or what if arg is a volatile external device status?

Or what if arg is a complex compound statement?

There can be many reasons why your replacement code would not be the same.


In this case we're given two expressions with the same goal. Either one of them will lead to the same result. That's what I'm saying. Plus it's a waste of time. Look at this:

Code:

input = getInput()

if(input)  // Test for non-zero value
{
  Debug.Print("Hello");
}


if(!input)
{
  Debug.Print("Good Bye");
}
    


As you can see, the last if statement will be assembled as a different branch of code. That's where ELSE comes in, so that way only the first if statement will be used to evaluate the expression. Wink
Post 23 Dec 2012, 23:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.