I have a 4 byte float (real32) I'm trying to read from a file. I tried
the following code:
fileio.getf( inputHandle );
ffst( r32 );
stdout.put( ( type real32 r32 ), nl );
I got: "HLA Exception (5): Conversion error". I know the code's dying
on the first instruction: fileio.getf(inputHandle). Any ideas why?
---John
|
|
0
|
|
|
|
Reply
|
jchludzinski (50)
|
6/8/2007 6:31:19 PM |
|
On Jun 8, 2:31 pm, "jchludzin...@gmail.com" <spamt...@crayne.org>
wrote:
> I have a 4 byte float (real32) I'm trying to read from a file. I tried
> the following code:
>
> fileio.getf( inputHandle );
> ffst( r32 );
> stdout.put( ( type real32 r32 ), nl );
>
> I got: "HLA Exception (5): Conversion error". I know the code's dying
> on the first instruction: fileio.getf(inputHandle). Any ideas why?
>
Is a real80 not good enough for ya?
program float;
#include("stdlib.hhf")
var
vF :real80;
vS :real80;
hFile :dword;
static
ts :dword := 36;
tn :dword := 10;
fy :dword := 50;
begin float;
finit();
fild( ts );
fild( tn );
fdiv();
fild( fy );
fadd();
fstp( vF );
stdout.put( vF, nl );
fileio.open( "temp.dat", fileio.w );
mov( eax, hFile );
fileio.putr80( hFile, vF );
fileio.close( hFile );
fileio.open( "temp.dat", fileio.r );
mov( eax, hFile );
fileio.getr80( hFile, vS );
fileio.close( hFile );
stdout.put( vS, nl );
end float;
Nathan.
|
|
0
|
|
|
|
Reply
|
nbaker2328
|
6/8/2007 9:31:49 PM
|
|
First, thanks for the time and effort to respond.
The (binary) file I have has 4-byte floats in its header and I'd like
to read them directly onto the floating-point stack. I can use
fileio.read(...) and place the value into a general-purpose register
but I'd prefer to place it on the fp-stack directly.
---John
On Jun 8, 5:31 pm, nbaker2328 <spamt...@crayne.org> wrote:
> On Jun 8, 2:31 pm, "jchludzin...@gmail.com" <spamt...@crayne.org>
> wrote:
>
> > I have a 4 byte float (real32) I'm trying to read from a file. I tried
> > the following code:
>
> > fileio.getf( inputHandle );
> > ffst( r32 );
> > stdout.put( ( type real32 r32 ), nl );
>
> > I got: "HLA Exception (5): Conversion error". I know the code's dying
> > on the first instruction: fileio.getf(inputHandle). Any ideas why?
>
> Is a real80 not good enough for ya?
>
> program float;
> #include("stdlib.hhf")
>
> var
> vF :real80;
> vS :real80;
> hFile :dword;
>
> static
> ts :dword := 36;
> tn :dword := 10;
> fy :dword := 50;
>
> begin float;
>
> finit();
> fild( ts );
> fild( tn );
> fdiv();
> fild( fy );
> fadd();
> fstp( vF );
>
> stdout.put( vF, nl );
>
> fileio.open( "temp.dat", fileio.w );
> mov( eax, hFile );
> fileio.putr80( hFile, vF );
> fileio.close( hFile );
>
> fileio.open( "temp.dat", fileio.r );
> mov( eax, hFile );
> fileio.getr80( hFile, vS );
> fileio.close( hFile );
>
> stdout.put( vS, nl );
>
> end float;
>
> Nathan.
|
|
0
|
|
|
|
Reply
|
john
|
6/11/2007 3:35:39 PM
|
|
On Jun 8, 11:31 am, "jchludzin...@gmail.com" <spamt...@crayne.org>
wrote:
> I have a 4 byte float (real32) I'm trying to read from a file. I tried
> the following code:
>
> fileio.getf( inputHandle );
> ffst( r32 );
> stdout.put( ( type real32 r32 ), nl );
>
> I got: "HLA Exception (5): Conversion error". I know the code's dying
> on the first instruction: fileio.getf(inputHandle). Any ideas why?
>
> ---John
fileio.getf reads ASCII data (like "1.2345") and converts it to a
floating-point value (which it leaves on the stack). If you are
reading 4-byte binary data from the "inputHandle" file, there is no
question you'll most likely get a conversion error. The binary bits
that make up the IEEE floating-point format rarely match any ASCII
sequence that would be a valid floating-point representation.
If you're reading binary FP data, you need to use the fileio.read
function and tell it to read 4 bytes directly from your file into the
Real32 variable.
E.g.,
fileio.read( fileHandle, r32, 4 );
hLater,
Randy Hyde
|
|
0
|
|
|
|
Reply
|
rhyde
|
6/11/2007 6:57:21 PM
|
|
Is there an HLA instruction that will allow me to place 32-bit or 64-
bit or 80-bit floating point values (in binary) directly onto the (top
of the) fp-stack?
---John
On Jun 11, 2:57 pm, "r...@cs.ucr.edu" <spamt...@crayne.org> wrote:
> On Jun 8, 11:31 am, "jchludzin...@gmail.com" <spamt...@crayne.org>
> wrote:
>
> > I have a 4 byte float (real32) I'm trying to read from a file. I tried
> > the following code:
>
> > fileio.getf( inputHandle );
> > ffst( r32 );
> > stdout.put( ( type real32 r32 ), nl );
>
> > I got: "HLA Exception (5): Conversion error". I know the code's dying
> > on the first instruction: fileio.getf(inputHandle). Any ideas why?
>
> > ---John
>
> fileio.getf reads ASCII data (like "1.2345") and converts it to a
> floating-point value (which it leaves on the stack). If you are
> reading 4-byte binary data from the "inputHandle" file, there is no
> question you'll most likely get a conversion error. The binary bits
> that make up the IEEE floating-point format rarely match any ASCII
> sequence that would be a valid floating-point representation.
>
> If you're reading binary FP data, you need to use the fileio.read
> function and tell it to read 4 bytes directly from your file into the
> Real32 variable.
> E.g.,
>
> fileio.read( fileHandle, r32, 4 );
>
> hLater,
> Randy Hyde
|
|
0
|
|
|
|
Reply
|
john
|
6/12/2007 7:11:12 PM
|
|
On Jun 12, 12:11 pm, john.chludzinski <spamt...@crayne.org> wrote:
> Is there an HLA instruction that will allow me to place 32-bit or 64-
> bit or 80-bit floating point values (in binary) directly onto the (top
> of the) fp-stack?
>
> ---John
fld( r32 );
fld( r64 );
fld( r80 );
hLater,
Randy Hyde
|
|
0
|
|
|
|
Reply
|
rhyde
|
6/13/2007 12:18:53 AM
|
|
rhyde@cs.ucr.edu wrote:
> On Jun 12, 12:11 pm, john.chludzinski <spamt...@crayne.org> wrote:
>
>>Is there an HLA instruction that will allow me to place 32-bit or 64-
>>bit or 80-bit floating point values (in binary) directly onto the (top
>>of the) fp-stack?
>>
>>---John
>
>
> fld( r32 );
> fld( r64 );
> fld( r80 );
> hLater,
> Randy Hyde
If I understand John's question, he wants to read this FP value from a
file - binary IEEE data, not ascii - using the FP stack as a "buffer". I
don't think this is possible. However, what he might be able to do is
"create" an "HLA instruction" as a macro (or subroutine) that would use
the CPU stack as a "buffer", "fileio.read" into that, "fld" (a real
"instruction") from the stack, then "clean up" the stack. In Nasmese,
something like:
; for extended precision - 80 bit fp
sub esp, 16 ; we only need 10... better alignment this way
; read 10 bytes from file
; (Linux)
mov eax, 3 ; write
mov ebx, 0 ; stdin
mov ecx, esp ; buffer
mov edx, 10 ; length
int 80h ; do it
fld tword [esp]
add esp, 16
.... only HLA would say it differently... if your "r32/64/80" were "local
variables" on the stack, it would do the same thing... (not clear where
these are defined, in your example - doesn't make much difference)
John's been trying to get an answer to this for a while - he started out
assuming that fileio.getf read binary data, and you guys were assuming
his file had ascii data. If his question is "can I read from a file
straight onto the FPU stack?", I think the simple answer is "no". (nor
could you write the top of FPU stack directly to a file...)
If I misunderstand the question... try *again*, John!
Best,
Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
6/13/2007 2:25:24 AM
|
|
Frank Kotler wrote:
> ; read 10 bytes from file
> ; (Linux)
> mov eax, 3 ; write
That would be "; read", of course. Sorry.
Best,
Frank
|
|
0
|
|
|
|
Reply
|
Frank
|
6/13/2007 4:58:40 AM
|
|
You are correct in that I'm trying to find a way to directly place fp-
values onto the fp-stack from a file where they are stored in binary
as 32-bit values. Must they first be stored in some memory location
(i.e., a "valiable") and then fld(32-bit-variable) onto the fp-stack?
---John
On Jun 12, 10:25 pm, Frank Kotler <spamt...@crayne.org> wrote:
> r...@cs.ucr.edu wrote:
> > On Jun 12, 12:11 pm, john.chludzinski <spamt...@crayne.org> wrote:
>
> >>Is there an HLA instruction that will allow me to place 32-bit or 64-
> >>bit or 80-bit floating point values (in binary) directly onto the (top
> >>of the) fp-stack?
>
> >>---John
>
> > fld( r32 );
> > fld( r64 );
> > fld( r80 );
> > hLater,
> > Randy Hyde
>
> If I understand John's question, he wants to read this FP value from a
> file - binary IEEE data, not ascii - using the FP stack as a "buffer". I
> don't think this is possible. However, what he might be able to do is
> "create" an "HLA instruction" as a macro (or subroutine) that would use
> the CPU stack as a "buffer", "fileio.read" into that, "fld" (a real
> "instruction") from the stack, then "clean up" the stack. In Nasmese,
> something like:
>
> ; for extended precision - 80 bit fp
> sub esp, 16 ; we only need 10... better alignment this way
>
> ; read 10 bytes from file
> ; (Linux)
> mov eax, 3 ; write
> mov ebx, 0 ; stdin
> mov ecx, esp ; buffer
> mov edx, 10 ; length
> int 80h ; do it
>
> fld tword [esp]
>
> add esp, 16
>
> ... only HLA would say it differently... if your "r32/64/80" were "local
> variables" on the stack, it would do the same thing... (not clear where
> these are defined, in your example - doesn't make much difference)
>
> John's been trying to get an answer to this for a while - he started out
> assuming that fileio.getf read binary data, and you guys were assuming
> his file had ascii data. If his question is "can I read from a file
> straight onto the FPU stack?", I think the simple answer is "no". (nor
> could you write the top of FPU stack directly to a file...)
>
> If I misunderstand the question... try *again*, John!
>
> Best,
> Frank
|
|
0
|
|
|
|
Reply
|
jchludzinski
|
6/18/2007 10:01:54 PM
|
|
"jchludzinski@gmail.com" <spamtrap@crayne.org> wrote:
>
>You are correct in that I'm trying to find a way to directly place fp-
>values onto the fp-stack from a file where they are stored in binary
>as 32-bit values. Must they first be stored in some memory location
>(i.e., a "valiable") and then fld(32-bit-variable) onto the fp-stack?
I would think this was painfully obvious. File handling is done by the
operating system. Operating system file services load sectors from some
storage device (disk, net, etc) into a buffer in memory. It's ALWAYS going
to start out in memory.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
6/19/2007 4:46:13 AM
|
|
I'm aware of the buffering done during a file read BUT I am speaking
from the viewpoint of the coder. Do I have to explicitly store the fp-
value (from the binary file) in a memory location, then explicitly
store the value (from the memory location) onto fp-stack? Understand?
---John
On Jun 19, 12:46 am, Tim Roberts <spamt...@crayne.org> wrote:
> "jchludzin...@gmail.com" <spamt...@crayne.org> wrote:
>
> >You are correct in that I'm trying to find a way to directly place fp-
> >values onto the fp-stack from a file where they are stored in binary
> >as 32-bit values. Must they first be stored in some memory location
> >(i.e., a "valiable") and then fld(32-bit-variable) onto the fp-stack?
>
> I would think this was painfully obvious. File handling is done by the
> operating system. Operating system file services load sectors from some
> storage device (disk, net, etc) into a buffer in memory. It's ALWAYS going
> to start out in memory.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
jchludzinski
|
6/19/2007 9:29:11 PM
|
|
jchludzinski@gmail.com <spamtrap@crayne.org> wrote in part:
> I'm aware of the buffering done during a file read BUT I
> am speaking from the viewpoint of the coder. Do I have to
> explicitly store the fp- value (from the binary file) in
> a memory location, then explicitly store the value (from
> the memory location) onto fp-stack? Understand? ---John
Please don't top-post. It obscures context.
You should be more than aware of the buffering during a file
read: You have to explicity program a memory destination
for the file [portion] you want.
Memory is memory -- you don't need to do any "read, save, read"
unless the binary file needs reformatting:
[syscalls to read datafile into memory starting at array:]
FLD QWORD PTR array[esi*8]
FLD QWORD PTR array[edi*8]
FMUL
-- Robert
|
|
0
|
|
|
|
Reply
|
Robert
|
6/20/2007 1:12:52 PM
|
|
"jchludzinski@gmail.com" <spamtrap@crayne.org> wrote:
>
>I'm aware of the buffering done during a file read BUT I am speaking
>from the viewpoint of the coder. Do I have to explicitly store the fp-
>value (from the binary file) in a memory location, then explicitly
>store the value (from the memory location) onto fp-stack? Understand?
I guess I don't. You call a file read routine somehow. When that read
read routine returns, your floating point values in memory. At that point,
it's strictly up to you to fld it onto the floating point stack.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
6/21/2007 6:17:14 AM
|
|
|
12 Replies
138 Views
(page loaded in 0.173 seconds)
Similiar Articles:7/22/2012 10:28:55 AM
|