News:

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

floating sign test

Started by korte, March 22, 2009, 12:02:37 PM

Previous topic - Next topic

korte



fsign macro
   fxam
   fstsw ax
   shr ax,1
   shaf
   endm


   fld   valuea
   fsign
   .if CARRY?
       ...
   .endif


its work!

but not nice

how to rewrite macro, using this format

  fld value
  .if FSIGN
     ....
  .endif


   
   

drizz

fsign macro
   fxam
   fstsw ax
   shr ax,1
   shaf
                           exitm<CARRY?>
   endm
The truth cannot be learned ... it can only be recognized.

korte



.if fsign

Error A2148: invalid symbol type in expression

drizz

.if fsign()

you must always use brackets when there is "exitm"
The truth cannot be learned ... it can only be recognized.

korte


GregL

shaf ??

I assume you mean sahf.



GregL

It seems to work OK.  Never seen that one before.  Thanks.

jj2007

Here is a variant accepting a real var argument.

include \masm32\include\masm32rt.inc

FSIGN MACRO rval:REQ
ffree st(7)
fld rval
fxam
fstsw ax
fincstp
shr ax, 1
sahf
exitm <Carry?>
ENDM

.code
r8pos REAL8 1.12345
r8minus REAL8 -1.12345
r8zeroA REAL8 0.0
r8zeroB REAL8 -0.0

start:
.if FSIGN(r8pos)
print "r8pos is negative", 13, 10
.else
print "r8pos is positive", 13, 10
.endif
.if FSIGN(r8minus)
print "r8minus is negative", 13, 10
.else
print "r8minus is positive", 13, 10
.endif
.if FSIGN(r8zeroA)
print "r8zeroA is negative", 13, 10
.else
print "r8zeroA is positive", 13, 10
.endif
.if FSIGN(r8zeroB)
print "r8zeroB is negative", 13, 10
.else
print "r8zeroB is positive", 13, 10
.endif

getkey
exit

end start

drizz

OR something useful  :P
fst real4 ptr [esp-4]
shl dword ptr [esp-4],1
.if carry?
The truth cannot be learned ... it can only be recognized.

korte


GregL

OK, carrying that on ...


r4sign MACRO R4:REQ
    mov eax, R4
    shl eax, 1
    EXITM <CARRY?>
ENDM

r8sign MACRO R8:REQ
    mov edx, OFFSET R8
    mov eax, DWORD PTR [edx+4]
    shl eax, 1
    EXITM <CARRY?>
ENDM

r10sign MACRO R10:REQ
    mov edx, OFFSET R10
    mov eax, DWORD PTR [edx+6]
    shl eax, 1
    EXITM <CARRY?>
ENDM


jj2007

You guys have great ideas, but why not something useful and simple?

FSIGN MACRO rval:REQ
mov eax, OFFSET rval-4+sizeof rval
mov eax, [eax]
shl eax, 1
exitm <Carry?>
ENDM

GregL

Good idea jj.

You could also use bt eax, 31 instead of shl eax, 1.


jj2007

Quote from: Greg on March 22, 2009, 09:17:40 PM
Good idea jj.

You could also use bt eax, 31 instead of shl eax, 1.


Hmmm.... 4 bytes instead of 2?
:bg

EDIT: I just realised I was horribly wasteful with the puter's resources.
This version does the job with 7 bytes:

FSIGN MACRO rval:REQ
mov eax, dword ptr [rval-4+sizeof rval] ; 5 bytes
shl eax, 1 ; 2 bytes
exitm <Carry?>
ENDM

raymond

Just to be picky based on another discussion regarding overwriting a register vs not overwriting it, how about the following (and we really want to know the SIGN, don't we??? thus making the source code a bit more legible)

Code:
FSIGN MACRO rval:REQ
   mov eax, dword ptr [rval-4+sizeof rval]   ; 5 bytes
   test eax, eax            ; 2 bytes
   exitm <Sign?>
ENDM
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com