While writing first post, I was thinking that DT isn't around any more...
And here it is, his solution![]()
Thanks
While writing first post, I was thinking that DT isn't around any more...
And here it is, his solution![]()
Thanks
I found this article
http://www.picbasic.co.uk/forum/cont...153-N-Bit_MATH
That should be enough, to display 64 bit integer.
I tested Darrels example with more numbers and something doesn't work...
Results:Code:include "fp1832l.bas" ;----[Variables]---------------------------------------------------------------- A VAR LONG B VAR LONG A_Float VAR LONG EXT : @A_Float = AARGB2 ; B_Float VAR LONG EXT : @B_Float = BARGB2 ; OutStr VAR BYTE[20] ;----[macro Converts IEEE to Microchip FP format]------------------------------- ASM IEEEtoMCHIP?NN macro Nin, Nout MOVE?BB Nin, Nout MOVE?BB Nin+1, Nout+1 MOVE?BB Nin+2, Nout+2 MOVE?TT Nin+3,7, Nin+2,7 MOVE?BA Nin+3 RLNCF WREG,W MOVE?AB Nout+3 MOVE?TT Nin+2,7, Nout+3,0 endm ENDASM ;----[Test IEEE to Microchip conversion]--------------------------------------- HSEROUT2 ["Value from IEEE calculator: 50" ,13,10] A = $42480000 ; 50 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: -25.62" ,13,10] A = $C1CCF5C3 ; -25.62 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: 23.75" ,13,10] A = $41BE0000 ; 23.75 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: 35.00" ,13,10] A = $420C0000 ; 35.00 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: 24.00" ,13,10] A = $41C00000 ; 24.00 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: 22.00" ,13,10] A = $41B00000 ; 22.00 - IEEE GOSUB ShowConversion HSEROUT2 ["Value from IEEE calculator: 8.875" ,13,10] A = $410E0000 ; 8.875 - IEEE GOSUB ShowConversion STOP ;----[Show conversion via HSEROUT]--------------------------------------------- ShowConversion: HSEROUT2 ["IEEE = ",HEX8 A,13,10] @ IEEEtoMCHIP?NN _A, _B HSEROUT2 ["Mchip= ",HEX8 B,13,10] A_Float = B GOSUB FtoIA HSEROUT2 ["Aint = ",SDEC Aint,13,10] A = Aint A_Float = B ; with 1 decimal place Bint = 10 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/10,".",DEC1 ABS(Aint),13,10] A_Float = B ; with 2 decimal places Bint = 100 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/100,".",DEC2 ABS(Aint),13,10] A_Float = B ; with 3 decimal places Bint = 1000 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/1000,".",DEC3 ABS(Aint),13,10,13,10] RETURN
Code:Value from IEEE calculator: 50 IEEE = 42480000 Mchip= 84480000 Aint = 50 50.0 50.00 50.000 Value from IEEE calculator: -25.62 IEEE = C1CCF5C3 Mchip= 83CCF5C3 Aint = -25 -25.6 -25.62 -25.620 Value from IEEE calculator: 23.75 IEEE = 41BE0000 Mchip= 82BE0000 Aint = -11 -11.8 -11.87 -11.875 Value from IEEE calculator: 35.00 IEEE = 420C0000 Mchip= 840C0000 Aint = 35 35.0 35.00 35.000 Value from IEEE calculator: 24.00 IEEE = 41C00000 Mchip= 82C00000 Aint = -12 -12.0 -12.00 -12.000 Value from IEEE calculator: 22.00 IEEE = 41B00000 Mchip= 82B00000 Aint = -11 -11.0 -11.00 -11.000 Value from IEEE calculator: 8.875 IEEE = 410E0000 Mchip= 820E0000 Aint = 8 8.8 8.87 8.875
As far as I can see, there is some problem with Darrel subroutine.
To get correct number in microchip format I used this code:
Result is: $833E0000Code:aint = 2375 Gosub itofa ' Convert int to float bint = 100 Gosub itofb ' Convert int to float Gosub fpdiv
And I can display correctly with this code:
Output is:Code:A_Float = $833E0000 ; with 1 decimal place Bint = 10 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/10,".",DEC1 ABS(Aint),13,10] A_Float = B ; with 2 decimal places Bint = 100 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/100,".",DEC2 ABS(Aint),13,10] A_Float = B ; with 3 decimal places Bint = 1000 GOSUB ItoFB GOSUB fpmul GOSUB FtoIA HSEROUT2 [" ",SDEC Aint/1000,".",DEC3 ABS(Aint),13,10,13,10]
23.7
23.74
23.749
That is fine...
But when I try to convert $41BE0000 with Darrel's routine result is
IEEE = 41BE0000
Mchip= 82BE0000
I think that I solved this...
From include file FP32.A18:
IeeFormat:Code:; 32 bit floating point representation ; EXPONENT 8 bit biased exponent ; It is important to note that the use of biased exponents produces ; a unique representation of a floating point 0, given by ; EXP = HIGHBYTE = MIDBYTE = LOWBYTE = 0x00, with 0 being ; the only number with EXP = 0. ; HIGHBYTE 8 bit most significant byte of fraction in sign-magnitude representation, ; with SIGN = MSB, implicit MSB = 1 and radix point to the right of MSB ; MIDBYTE 8 bit middle significant byte of sign-magnitude fraction ; LOWBYTE 8 bit least significant byte of sign-magnitude fraction ; EXPONENT HIGHBYTE MIDBYTE LOWBYTE ; xxxxxxxx S.xxxxxxx xxxxxxxx xxxxxxxx ; | ; RADIX ; POINT
http://www.h-schmidt.net/FloatConverter/IEEE754.html
As you can see in IEE format, only 7 bit of exponent is in first byte, so bit 23 should be shifted to first bit of byte3, when shifting to right exponent.
Here is binary for 23.75:
As you can see Darrel's code set sign instead of first bit of exponent.Code:IEE 41BE0000 = 01000001 10111110 00000000 00000000 MCHIP 833E0000 = 10000011 00111110 00000000 00000000 Darel 82BE0000 = 10000010 10111110 00000000 00000000
Here is my code, done in PBP
I'll try to fix Darrel's macro.Code:MyIEEEtoMCHIP: B.BYTE0=A.BYTE0 B.BYTE1=A.BYTE1 B.BYTE2=A.BYTE2 : B.23=A.31 'SIGN B.BYTE3=A.BYTE3<<1 : B.24=A.23 RETURN A-IEEE B-Microchip
I fixed bug in Darrel's macro:
Code:ASM IEEEtoMCHIP?NN macro Nin, Nout MOVE?BB Nin, Nout MOVE?BB Nin+1, Nout+1 MOVE?BB Nin+2, Nout+2 ;MOVE?TT Nin+3,7, Nin+2,7 ;<<<<<<<<here he is setting bit in input byte, not output byte MOVE?TT Nin+3,7, Nout+2,7 ;<<<<<<<<Corrected MOVE?BA Nin+3 RLNCF WREG,W MOVE?AB Nout+3 MOVE?TT Nin+2,7, Nout+3,0 endm ENDASM
Bookmarks