flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
celution 13 Jul 2006, 21:40
I think the tables from the following links should be added to the FASM documentation section - perhaps tacked onto the "Programming Tutorial".
Which flags [ OF, SF, ZF, AF, PF, CF ] are *checked* by which conditional jump instructions? Which flags are *set" by the (cmp, or, xor, etc) logical operand comparison instructions? I am familiar with conditional jumps from VB and started programming with a pre-gui "TI-99 4/A" way back when. None the less, when I saw this code, though I could tell what the condidtional loop did and why, I could not tell what was being referenced (which flags?) to do it. I hope the following will help future ASM newbies with conditional jumps in assembler. I am putting this post in the Main section because the logic applies everywhere. The code snippet below, however, was taken from a tutorial reference on WinAPI. Below is a snippet of code from Iczelion's tutorial #3 which was translated to FASM by "sulaiman" - see original post (My gratitude to both for their contributions.) I've only included the conditional loop bit, as that is where I had to go google-ing for the table references above. The rest I could figure out with the comments Iczelion provided and from knowing VB. I have commented below the code for a newbie, but please check to see that I expained it correctly. If this is helpful, I would be happy to write FASM explanations for the other (MASM) tutorials as I go along. I have to do it, regardless, to "grok" it. <><> Code <><> invoke GetMessage,wMsg,NULL,0,0 or eax,eax je window_message_loop_end <><> End Code <><> >>Line 1 GetMessage returns FALSE (1) to eax register only if WM_QUIT message is received. >>Line 2 The "or" instruction sets C & O flags to (0) everytime regardless of the logical result. The logical result of the "or" instruction, when comparing two operands, is to return (0) when both operands are (0) and to return (1) in all other conditions. When "or" is used to compare something to itself, as in this case, a simplified logic applies. It returns (0) when the operand is (0) and returns (1) otherwise. This logical result is applied to the Z, S, and P flags. As any statement that sets or clears a flag can serve as a test basis for a conditional jump, this allows us to run the test in line #3. >>Line 3 The "je" instruction looks to the Z flag to determine whether or not to jump. As a result of the test in line #2, the Z flag is "set" (1) only if a WM_Quit message has been returned to eax by the "GetMessage" command. "je" jumps only when the Z Flag is "set" (1) and does not jump when Zero Flag (ZF) is "clear" (0). I think of it as "Jump when ZF Equals 1". "je" is functionally identical to "jz" |
|||
![]() |
|
celution 14 Jul 2006, 15:47
I searched for "je" and came up empty; but after looking at Table 2.1, I see now that "j" and "e" are really seperate things combined. This Table makes more sense than listing all the possible combinations.
This is exactly the connection I was looking for. Coming from a HL language, retraining the brain to see the little pieces is the trick. Thanks. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.