flat assembler
Message board for the users of flat assembler.
Index
> Main > .. Goto page 1, 2 Next |
Author |
|
pool 21 Dec 2012, 16:04
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
21 Dec 2012, 16:04 |
|
JohnFound 21 Dec 2012, 16:20
It depends on "arg". In general, there is no "if" construction in assembly programming.
|
|||
21 Dec 2012, 16:20 |
|
HaHaAnonymous 21 Dec 2012, 16:23
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 1 time in total |
|||
21 Dec 2012, 16:23 |
|
pool 21 Dec 2012, 18:36
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
21 Dec 2012, 18:36 |
|
baldr 21 Dec 2012, 18:50
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. |
|||
21 Dec 2012, 18:50 |
|
cod3b453 21 Dec 2012, 18:58
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 I'll fix it now |
|||
21 Dec 2012, 18:58 |
|
baldr 21 Dec 2012, 20:15
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. |
|||
21 Dec 2012, 20:15 |
|
pool 21 Dec 2012, 22:21
..
Last edited by pool on 17 Mar 2013, 12:17; edited 1 time in total |
|||
21 Dec 2012, 22:21 |
|
Bargest 22 Dec 2012, 19:27
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] |
|||
22 Dec 2012, 19:27 |
|
pool 22 Dec 2012, 23:09
..
Last edited by pool on 17 Mar 2013, 12:18; edited 2 times in total |
|||
22 Dec 2012, 23:09 |
|
HaHaAnonymous 22 Dec 2012, 23:17
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:09; edited 3 times in total |
|||
22 Dec 2012, 23:17 |
|
baldr 23 Dec 2012, 07:21
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). |
|||
23 Dec 2012, 07:21 |
|
AsmGuru62 23 Dec 2012, 10:42
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? |
|||
23 Dec 2012, 10:42 |
|
baldr 23 Dec 2012, 12:20
AsmGuru62,
Compilers that adhere to standard (ISO/IEC 9899:2011, AKA C11) yield 0 or 1 as a result of relational/equality operators. |
|||
23 Dec 2012, 12:20 |
|
HaHaAnonymous 23 Dec 2012, 14:55
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:08; edited 1 time in total |
|||
23 Dec 2012, 14:55 |
|
typedef 23 Dec 2012, 16:13
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. |
|||
23 Dec 2012, 16:13 |
|
typedef 23 Dec 2012, 16:32
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: |
|||
23 Dec 2012, 16:32 |
|
revolution 23 Dec 2012, 19:56
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. |
|||
23 Dec 2012, 19:56 |
|
typedef 23 Dec 2012, 23:30
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. |
|||
23 Dec 2012, 23:30 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.