PDA

View Full Version : Floating Point Display Problem (serial string out)



Cash Olsen
- 20th December 2007, 02:03
While using the 4FUNC32.BAS routine I discovered that it did not display negative numbers correctly. The 4FUNCTN .BAS program does not seem to have the same problems.

The errors consist of two catigories: 1) incomplete initialization and 2) improper truncation from 24 bit to 16 bit value.

The floating point sign is tested (aargb0.7) and the minus sign is printed if the number is negative.

IF aargb0.7 THEN ' Check the floating point sign bit
HSEROUT ["-"]
ASM
bsf PCLATH, 3
; Gosub fpsub
call FPS32 ; AARG = AARG - BARG
bcf PCLATH, 3
ENDASM
ELSE
ASM
bsf PCLATH, 3
; Gosub fpadd
call FPA32 ; AARG = AARG + BARG
bcf PCLATH, 3
ENDASM
ENDIF


When the routine:

call INT3224 ; 32-bit float to 24-bit int

is executed the floating point number is converted to a 24 bit integer, even though only the least significant 16 bits are used in the variable - ahold - the variable will only be valid if the sign is accounted for, in effect the absolute value of the variable calculated.


IF (AARGB0.7) THEN
ahold = (ahold ^ $FFFF ) + 1
ENDIF


The routine FLO2432 converts a 24 bit integer to a 32 bit floating point value, but the variable - aint - is a 16 bit word.

AARGB0 = 0
ASM
bsf PCLATH, 3
; GOSUB itofa ' Convert integer back to float
call FLO2432 ; 24-bit int to 32-bit float
bcf PCLATH, 3
ENDASM

The assembly language is because I loaded the floating point routines in the second page of memory, ie. ORG $800