News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

EFLAGS set with OF by error?

Started by thomas_remkus, March 06, 2008, 03:26:36 AM

Previous topic - Next topic

hutch--

Thomas,

Getting the idea of flags in an x86 processor is getting the concept of what they do in the processors operation. You can reasonably model the concept of flags with a bit of higher level thinking. Create a variable called ZEROFLAG which can have one of two possible settings, 0 or 1.

Now put it into the context of loop code where a variable is being decremented until it reaches zero and you will see how it works.


label:
  var = var - 1
  If var != 0
    goto label


The loop will keep going back to "label" until "var" = 0.

Now its here that assembler is really slick and very efficient. Various instuctions set the zero flag and SUB is one of them. In assembler this simple loop looks like this.


label:
  sub var, 1
  jnz label


Now the same goes for the SIGN flag, its just that you are testing a different condition, if a value in either memory or in a register is above or below zero.

I know the Intel manuals are large and a bit daunting but they really ARE where the action is. Look up the conditional jump instructions to see the major set of tests available and check how and why they use the range of processor flags.


Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on March 09, 2008, 09:52:37 PM
Look up the conditional jump instructions to see the major set of tests available and check how and why they use the range of processor flags.

\Masm32\help\opcodes.hlp is a start. Most important is the distinction between signed and unsigned values, especially when later you move to high level syntax... there are some traps ahead:
.if eax==123  ; works always as you expect it to work
.if eax!=123  ; works always as you expect it to work
.if eax>123    ; may yield surprising results, because -123 is bigger than 123 - for eax
.if eax<-123   ; is never true, because eax is unsigned by default, so eax has values between 0 and +FFFFFFFF
Have fun, and don't despair  :thumbu