Gas (GNU assembly)

condition flag

  • CF: carry flag. the most recently operation yield carray bit.
  • ZF: zero flag. the most recently operation yield zero.
  • SF: signed flag. the most recently operation yield negative value.
  • OF: overflow flag. the most recently operation cause a two's complement overflow — positive or negative

embedding in C

asm ( code-string [ : output-list [ : input-list [ : overwrite-list ] ] ] );

  • The output-list/input-list will be a list of pairs separated by spaces, and each pair is separated by ","
  • First part of pair will be a string to indicate the type of the operand (= means will assign value to the operand, r means integer register
  • Second part of the pari will be the operand enclosed by parentheses


the example will show that it will status to 0 when overflow happened.

int sum(int x,int y,int *result)
    int status;

    *result = x*y;
        insert the following assembly code:
        setae    %bl            #set low-order byte of register %bx
        movzbl    %bl, status    #zero extend to be status
    asm("setae %%bl;movzbl %%bl,%0"
            : "=r" (result)            //output
            :                    //input
            : "%ebx"                //overwrites
    return status;

For more detail, can see ch 3.15.2 in "computer systems: a programmer's perspective"
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License