flat assembler
Message board for the users of flat assembler.

Index > Main > how to load unsigned integer into fpu?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
jack2



Joined: 06 Jul 2008
Posts: 31
jack2
I need to load an unsigned integer into fpu but can't figure out how,
suppose we have an integer = FFFFFFFFFFFFFFFF, what adjustments to the fpu is needed to get the unsigned value?
Post 21 Dec 2008, 16:57
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:54; edited 1 time in total
Post 21 Dec 2008, 18:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

signed/unsigned is not property of value, but of handling type.
cmp: unsigned - check CF, signed - check SF/OF


On FPU it is!
Post 21 Dec 2008, 18:13
View user's profile Send private message Reply with quote
jack2



Joined: 06 Jul 2008
Posts: 31
jack2
I found this snippet on the web
Code:
;esp points to unsigned int64
fild qword ptr [esp]
test byte ptr [esp+7], 80h
jz _ret
fadd dword __pow_2_64
_ret:  ret
__pow_2_64:       db 0, 0, 0x80, 0x5F
    

any better way?
too bad there's no fuild Laughing
Post 21 Dec 2008, 18:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
There is no other way. What you found "on the web" is as good as it gets.
Post 21 Dec 2008, 23:28
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Ah, the decadence - to branch senselessly...
Code:
      push $3FFF + 63
     push -1
     fld tbyte [rsp]    
...or, in 32-bit mode...
Code:
  push $3FFF + 63
     push -1
     push -1
     fld tbyte [esp]    
Very Happy

(need to correct the stack of course)
Post 22 Dec 2008, 00:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Hardly the same thing! You are pushing a fixed value.
Post 22 Dec 2008, 00:52
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Whatever, PUSH works with memory and registers, too - silly.
Post 22 Dec 2008, 00:55
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Not if the value is below 2^63.
Post 22 Dec 2008, 00:56
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Your processor must work differently than mine.
(See Vol.1 8-19, Figure 8-13)
Post 22 Dec 2008, 00:58
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
You need to properly shift the mantissa and adjust the exponent if the number is does not have the high most bit set. Else you get a malformed float.
Post 22 Dec 2008, 01:02
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
If you want to quote Intel manuals then look two pages further in at table 8-3. You get an unnormal for values <2^63
Post 22 Dec 2008, 01:03
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
So, it doesn't work on your processor?
Post 22 Dec 2008, 01:11
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Your code above will work because it is a fixed value (2^64-1). But for the general case it will produce unsupported FPU values for numbers < 2^63.
Post 22 Dec 2008, 01:14
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Yet, it works on your processor.
Post 22 Dec 2008, 01:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
What is it? The general case or the fixed value?
Post 22 Dec 2008, 01:17
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
The general case works.
Post 22 Dec 2008, 01:19
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Okay, it just appears to work.
Post 22 Dec 2008, 01:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Are you sure it works on all CPUs? Have you tested AMD, Intel, Via, Cyrix, Harris, etc.?
Post 22 Dec 2008, 01:21
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Very well, I tested it. CPU: Intel Pentium M.
Code:
include 'win32ax.inc'

start:
        push $3FFF + 63
        push -1
        push -1
        fld tbyte [esp]

        push $3FFF + 63
        push (1 shl 31)-1
        push -1
        fld tbyte [esp]

      fadd st0,st1    ;<---- gives an invalid FPU operation exception (I)

.end start    
Doesn't work for unnormals on my CPU.
Post 22 Dec 2008, 01:32
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.