__OFSUB__宏

生成(x-y)的溢出標誌

定義如下:

// overflow flag of subtraction (x-y)
template<class T, class U> int8 __OFSUB__(T x, U y)
{
  if ( sizeof(T) < sizeof(U) )
  {
    U x2 = x;
    int8 sx = __SETS__(x2);
    return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y));
  }
  else
  {
    T y2 = y;
    int8 sx = __SETS__(x);
    return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2));
  }
}

中間使用的__SETS__如下:

// sign flag
template<class T> int8 __SETS__(T x)
{
  if ( sizeof(T) == 1 )
    return int8(x) < 0;
  if ( sizeof(T) == 2 )
    return int16(x) < 0;
  if ( sizeof(T) == 4 )
    return int32(x) < 0;
  return int64(x) < 0;
}

使用到的結構如下

typedef          char    int8;
typedef   signed char    sint8;
typedef unsigned char    uint8;
typedef          short   int16;
typedef   signed short   sint16;
typedef unsigned short   uint16;
typedef          int     int32;
typedef   signed int     sint32;
typedef unsigned int     uint32;
typedef __int64          int64;
typedef __int64          sint64;
typedef unsigned __int64 uint64;

參考鏈接:https://stackoom.com/question/1ZDLT/IDA-PRO%E5%B0%86C-%E4%BB%A3%E7%A0%81%E8%BD%AC%E6%8D%A2%E4%B8%BAC%E4%BB%A3%E7%A0%81-OFSUB-%E5%AE%8F

發佈了168 篇原創文章 · 獲贊 17 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章