News:

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

Jump simplification

Started by Ian_B, February 13, 2006, 01:40:25 AM

Previous topic - Next topic

Ian_B

I am wondering if I can simplify this jumptest:

        test    eax, eax
        js      @F
        jz      @F
        ...


The table of jumpcodes in the MASM documentation is confusing because it seems there is no way to test simply for the sign flag, it's all "SF = OF" or "SF != OF", which doesn't seem appropriate here because with a TEST instruction there should surely be no carry or overflow set, it's a simple bit-test.

Any suggestions, or is this really the simplest way to test for a positive, non-zero number using TEST?

IanB

hutch--

Ian,

I think a cmp / jg 0 is a better proposition that a test and 2 Jxx instructions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

EduardoS

To make things easier,
After a test instruction the OF and CF are reseted, SF is set equal to the higest bit, the ZF is set if zero and the PF is set according with parity.
In a positive non-zero number the ZF and SF is reseted (ZF=SF=OF=0),

The jg use these condition.

Ian_B

Thankyou both. So in my example with TEST, because the carry/overflow flag is explicitly reset according to Eduardo, I should be able to do a JNG instead of JS/JZ.

hutch--

What about this, it tests OK.


    test eax, eax
    jg lbl1

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

Ratch

Ian_B,

     You might want to look at this link below.  It's not quite the same question you had, but it's somewhat in the same category.   Ratch

http://www.masmforum.com/simple/index.php?topic=2764.0

Ian_B

@Hutch, thanks, but it's the opposite jump I need, JNG. In my original example I'm jumping away (to error) if the number is NOT positive or non-zero, sorry if I wasn't clear in my text.

@Ratch, interesting. I almost never use .IF constructs in my code, though, it's part of my general antipathy to macros.  :'(  I am only doing simple compares though, and they are rarely signed unless I have an error value of -1 as a possible output from a function... which is how my example code came about, because 0 is also an unusable value in this case.

For newbie reference, most of the coding jump mistakes I have made so far have been using JB (jump if below, or on carry/borrow) after using a subtraction to test for a negative result, when the original number being subtracted from was ALREADY negative. In these cases it should of course be JS, jump if signed, as there will be no carry/borrow flag set if the number was already negative. This is a really easy mistake to make and is difficult to debug unless you are really following what values you are getting.

IanB