Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/12/02 08:59
Read: times


 
#24312 - RE: floating point optimization
Where are you getting this value from, the one you have to display upto 8 digits precision? If I guess properly, you will doing some calculations...specifically some division operation (else you won't get a floating point value!!).

In that just keep dividing after the decimal point in a loop until you get the required precision.

suppose you have: (assuming all 8-bit values)

mov a,dividend
mov b,divisor
div ab ;quotient in a, remainder in b

;So now a= Q1 (Quotient 1)and b = R1 (remainder)
;The actual value can be represented as:
;result = Q1 + R1/divisor
;R1 always > divisor

mov r1,ADDR
;address in RAM where u want 8-digit result stored
loop for n = 0 to 8:
{
mov a,b
mov b,#0ah
mul ab
mov b, divisor
div ab
mov @r1,a
;store the nth digit of result at ADDR+n
inc r1
}

You will find that the 8 bytes after ADDR will contain the required 8 numbers after the decimal point in BCD format. You can then display it in the usual fashion (adding #30h etc etc).

I'd give the same in C if I could, but I have no experience in embedded C... :)) If you count the time for each loop and multiply it by 8, you will find it shouldn't take too long (around 20 cycles * 8 loops ?) However the above pseudo-code is for 8-bit values of dividend and divisor. If you have 16-bit values, it will be more complicated.

It is possible to optimize it though by using only 1 byte operations wherever possible (for example, the ranges of your dividend and divisor wil be such that the remainder is always only 1 byte long)....

kundi

List of 33 messages in thread
TopicAuthorDate
floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: thanks            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: Erik confused!!!!            01/01/70 00:00      
RE: C51 optimizing c cross compiler            01/01/70 00:00      
RE: C51 optimizing c cross compiler            01/01/70 00:00      
RE: C51 optimizing c cross compiler            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: floating point optimization/Kunal            01/01/70 00:00      
RE: floating point optimization/Kunal            01/01/70 00:00      
RE: floating point optimization/Kunal            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      
RE: Higher speed devices ?            01/01/70 00:00      
RE: C51 optimizing c cross compiler            01/01/70 00:00      
RE: C51 optimizing c cross compiler            01/01/70 00:00      
RE: floating point optimization            01/01/70 00:00      

Back to Subject List