flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
pool
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
![]() |
|
JohnFound
It depends on "arg". In general, there is no "if" construction in assembly programming.
|
|||
![]() |
|
HaHaAnonymous
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 1 time in total |
|||
![]() |
|
pool
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
![]() |
|
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. |
|||
![]() |
|
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 ![]() |
|||
![]() |
|
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. |
|||
![]() |
|
pool
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
![]() |
|
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. ![]() 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] |
|||
![]() |
|
pool
..
Last edited by pool on 17 Mar 2013, 12:18; edited 2 times in total |
|||
![]() |
|
HaHaAnonymous
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 3 times in total |
|||
![]() |
|
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). |
|||
![]() |
|
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? |
|||
![]() |
|
baldr
AsmGuru62,
Compilers that adhere to standard (ISO/IEC 9899:2011, AKA C11) yield 0 or 1 as a result of relational/equality operators. |
|||
![]() |
|
HaHaAnonymous
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:08; edited 1 time in total |
|||
![]() |
|
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. |
|||
![]() |
|
typedef
pool wrote: what is the equivalent of: ^^^ 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: |
|||
![]() |
|
revolution
typedef wrote:
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. |
|||
![]() |
|
typedef
revolution wrote:
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. ![]() |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.