Author Topic: Fast SGN and ABS Inline Function  (Read 3171 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 964
    • it-berater
Fast SGN and ABS Inline Function
« on: December 19, 2009, 02:12:06 PM »
This is of more use. You just want to know if that number is negative.
Here is FastSGN. Just needed is yesterday.

Code: [Select]
' P2 will be set to 1 in case SIGN of P1 is negative
MACRO SGN_LNG(P1,P2)
MACROTEMP POX
! MOV P2,0
! BT P1,31
! JNC POX
! MOV P2,1
POX:
END MACRO

ABS will normally be compiled from Powerbasic using Floating Point Mnemonics.
If you have a LONG value and just want to cut the Sign, you can use this few lines.

Code: [Select]
MACRO ABS_LNG(P1)
MACROTEMP POS
! BT P1,31
! JNC POS
! NEG P1
POS:
END MACRO
« Last Edit: December 20, 2009, 08:17:54 AM by Theo Gottwald »

Offline Steve Hutchesson

  • Moderator
  • Jr. Member
  • *****
  • Posts: 83
    • The MASM Forum
Re: Fast SGN and ABS Inline Function
« Reply #1 on: December 20, 2009, 10:55:07 AM »
 ;D

Works fine.