I can't figure out what is wrong. It should be very straight forward, but I keep getting ## as my output.



program tut2;

#include( "stdlib.hhf" )

var
inputVar:real32;
begin tut2;


stdout.put("Enter number:",nl);

stdin.getf(); //get a real number and leave it in ST0
fsqrt; //take sqrt of ST0
fstp (inputVar); //pop and store

stdout.putr32(inputVar,2,2);


end tut2;
Posted on 2004-12-06 06:52:34 by polyfractal
The width element of putr32 is too small. If the result can't fit in width, HLA places # chars to fill the insufficient width.
Posted on 2004-12-06 22:04:25 by Kain
Wow. Thanks. Something so simple. :D
Posted on 2004-12-07 06:20:39 by polyfractal
More questions.



while ( eax <= limit) do

mov(eax,i); //move eax to the temp counter variable
fstp(st0); //clear out previous
fild(i); //push our temp iterator variable onto FPU stack
fild(original); //push original

stdout.put("Iterator: ", i, nl);
repeat
fprem1(); //Take partial remainder
fstsw (ax); //Get condition code bits into AX
and (1,ah); //if AX is set to one
until (@z); //Repeat until C2 is clear
fistp (final); //Pop and convert into final

stdout.put("Remainder: ", final, nl);

mov (i,eax); //move temp variable back to eax
inc(eax); //increment counter
endwhile;


I'm not entirely convinced my Modulous code is functioning correctly. If the number divides evenly, remainder (var:int32 final) returns 0. But if it doesn divide evenly, I get some odd number that is not the remainder (sometimes positive, sometimes negative). In this case, I dont really care, but would like to know why it is doing that.

Thanks.
Posted on 2004-12-08 07:01:04 by polyfractal
Google is great 8)

FPREM1
This instruction is a modification of the FPREM instruction to compute the remainder as specified in the IEEE Std 754. According to that Standard, the magnitude of the remainder must be less than or equal to half of the modulus ST(1). The sign of the remainder can thus be different than the sign of the original value in ST(0).

For example, using integers, 11 modulo7 with the FPREM instruction would be +4. With the FPREM1 instruction, 4 being more than half the modulus 7, the resulting remainder would be -3. (10 modulo7 would be +3 with either instruction.)
Posted on 2004-12-08 18:37:53 by arlequin
Ahh, thanks. My book didnt explain that. It just said "Use FPREM1 instead of FPREM".

Is there any advantage to using one or the other?
Posted on 2004-12-08 21:04:50 by polyfractal
FPREM is backward compatible with older processors... pretty much useless with HLA since it's 32bits assembly.
Posted on 2004-12-08 21:47:47 by Kain