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
Results:
Bookmarks