??? 05/04/08 12:52 Read: times |
#154366 - Floating Point Routine Listed Responding to: ???'s previous message |
Hello Friends:
Thanks to Jerson who responded earlier. I am able to get the floating point routine to work. I however, find the results to not be accurate or most times incorrect. For example, dividing 148,000/12,700. The result should equal 11.6535. The function returns the following: Float Result = 3a74e9 Integer Result = 00000b :What happend to the .6535 ? Examining the Float Result, I viewed a DECIMAL to ASCII chart. It reveals the following: "3a" = 58 ;"74"= 116; e = "14"; 9 = "9" If I manipulate the order, this "could" mean: "11658149" or "11.658149" Then if I included a decimal.It looks "almost" correct. (I'm guessing here...) In my test code below, I can check the results of each function call to verify it returns correctly, by sending the results to the Serial Port for observation. All the calls to int2float and float2int are correct. The results from the fpdiv32, not so correct. Has anyone "successfully" used this routine? A little note about my project: My P89C668 is connected to a readout encoder. This encoder outputs a 24 bit binary code. If I divide this count by 12,700, I get a value in "inches". I now want to display this "value in inches" to an LCD display. My guess is I needed this floating point routine first. Next I will need a routine to convert the "float to ascii" for sending to the LCD. Is my solution correct? Or am I going about this incorrectly? Thanks in advance! CMD1: mov Aarg,#9CH ;Denominator mov Aarg+1,#31H mov Aarg+2,#00H acall int2float ;Debugging - Let's check result from above int2float() - ; MOV ANSWER,Aarg+2 ;MSB MOV ANSWER+1,Aarg+1 MOV ANSWER+2,Aarg+0 ;LSB MOV ANSWER+3,Aexp ; ;Send value to Serial Display[1] ; MOV R0,#ANSWER LCALL PRNT_4H LCALL CRLF ; acall copy_ab ; mov Aarg,#20H ;Numerator mov Aarg+1,#42H mov Aarg+2,#02H acall int2float ; ;Debugging - Let's check result from above int2float() - ; MOV ANSWER,Aarg+2 ;MSB MOV ANSWER+1,Aarg+1 MOV ANSWER+2,Aarg+0 ;LSB MOV ANSWER+3,Aexp ; ;Send value to Serial Display[2] ; MOV R0,#ANSWER LCALL PRNT_4H LCALL CRLF ; ;Sanity Check - Let's convert Integer to Float to if it returns ;our orignally value of 0x3E8, before we multiply. ; ;lcall float2int ;Debugging - Checking float2Int() - Expecting 0x3E8 ; ;MOV ANSWER,Aarg+2 ;MSB ;MOV ANSWER+1,Aarg+1 ;MOV ANSWER+2,Aarg+0 ;LSB ; ;Send value to Serial Display[3] ; ;MOV R0,#ANSWER ;LCALL PRNT_6H ;LCALL CRLF ; ; ;Floating point multiplication ;Input - Aarg,Aexp ; - Barg,Bexp ; ;Let's see if the Inputs (Aarg,Aexp ; Barg,Bexp) are correct. ; ;MOV ANSWER,Aarg+2 ;MSB ;MOV ANSWER+1,Aarg+1 ;MOV ANSWER+2,Aarg+0 ;LSB ;MOV ANSWER+3,Aexp ;MOV ANSWER+4,Barg+2 ;MOV ANSWER+5,Barg+1 ;MOV ANSWER+6,Barg+0 ;MOV ANSWER+7,Bexp ;Send value to Serial Display[4] ; ;MOV R0,#ANSWER ;LCALL PRNT_8H ;LCALL CRLF ; acall fpdiv32 ; ;Lets check the FLOAT result of the fpmul32() BEFORE we convert the result to Integer. ; MOV ANSWER,Aarg+2 ;MSB MOV ANSWER+1,Aarg+1 MOV ANSWER+2,Aarg+0 ;LSB ; ;Send value to Serial Display[5] ; MOV R0,#ANSWER LCALL PRNT_3H LCALL CRLF ; ; acall float2int ; ;Debugging - Let's check result from multiplication - Result is INTEGER- ; MOV ANSWER,Aarg+2 ;MSB MOV ANSWER+1,Aarg+1 MOV ANSWER+2,Aarg+0 ;LSB ; ;Send value to Serial Display[6] ; MOV R0,#ANSWER LCALL PRNT_3H LCALL CRLF ; RET |
Topic | Author | Date |
Floating Point Routine Listed | 01/01/70 00:00 | |
Contact Jerson | 01/01/70 00:00 | |
Floating Point Routine Listed | 01/01/70 00:00 | |
Replied to personal email | 01/01/70 00:00 | |
Floating Point Routine Listed | 01/01/70 00:00 | |
You\'re almost there | 01/01/70 00:00 | |
Floating Point Routine Listed | 01/01/70 00:00 | |
No - I COUNTRY | 01/01/70 00:00 | |
Floating Point Routine Listed![]() | 01/01/70 00:00 |