Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

floating point calculation in Assembly language

Status
Not open for further replies.

Suresh R

Member level 1
Joined
Nov 16, 2006
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,535
Hi,
iam interested to know whether i could do floating point calculations in AT89S52 microcontroller.
If yes, could any one give me some example on how it could be done using Assembly language programming?

for eg: how could i do the following using Assembly language programming??
3.43 + 5.98

kindly assist me.

Suresh.
 

PaulHolland

Advanced Member level 2
Joined
Jan 15, 2003
Messages
664
Helped
95
Reputation
190
Reaction score
34
Trophy points
1,308
Location
Holland
Activity points
4,841
Hi, One very simple trick is to scale all your numbers with a constant so that you only get integer numbers. You can do all your callculations scaled and the result will be scaled also but still usable. This way you maybe have to do 16 bit ir 32 bith math but ist much faster and more simple than floating point or fixed point.

So in your example: Scale all by 100. the result is also scaled by 100. Keep in mind dat multiply will scale by 10000 and not 100 since 100 * 100 = 10000

3.42 + 5.98 = 9.41 (normal)
343 + 598 = 941 (scaled by 100)
 

    Suresh R

    Points: 2
    Helpful Answer Positive Rating

Suresh R

Member level 1
Joined
Nov 16, 2006
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,535
Hi,
Thank you.
I applied your method in the "MUL" and "ADD" instructions of 8051 which i use.
Iam getting the result but its in hexadecimal form. Can i know how it could be converted to decimal form or BCD form?
Because need to give that to the seven segment display.
I couldnt find a suitable method to convert Hexadecimal to decimal or BCD. i though of doing this conversion to fetch its equivalent seven segment values using a lookup table.

Here is the example to describe:

16.6 * 16.6 = 275.56
I do the above like this:
166 * 166 = 27556 (decimal) = 6BA4(Hexadecimal)

Here i could not find a suitable method for using the 6BA4 (Hexadecimal) to display 275.56 in the seven segment display.
can i get some light on this issue?

Suresh.
 

PaulHolland

Advanced Member level 2
Joined
Jan 15, 2003
Messages
664
Helped
95
Reputation
190
Reaction score
34
Trophy points
1,308
Location
Holland
Activity points
4,841
That is not so difficult and you can find lots and lots of examples on internet for the 8051...
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Copy right Notice;;;;;;;;;;;;;;;;
;;This program is for personal use only.You may change/modify it regarding ur requirements. 
;;This program has been tested and verfied, but in case of any queries, feel free to 
;;email(mail_to_salman@yahoo.com) me.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;This routine is for 16 bit Hex to BCD conversion;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;Accepts a 16 bit binary number in R1,R2 and returns 5 digit BCD in R7,R6,R5,R4,R3( 
upto 64K )
 
 
Hex2BCD:
        MOV R1,#0fFH        ;  MSByte
        MOV R2,#0FFH       ;  LSByte
 
        MOV R3,#00D
        MOV R4,#00D
        MOV R5,#00D
        MOV R6,#00D
        MOV R7,#00D
 
MOV B,#10D
        MOV A,R2
        DIV AB
        MOV   R3,B              ;   
        MOV   B,#10             ; R7,R6,R5,R4,R3
        DIV   AB
        MOV   R4,B
        MOV   R5,A
        CJNE R1,#0H,HIGH_BYTE   ; CHECK FOR HIGH BYTE
        SJMP ENDD
 
HIGH_BYTE:
MOV   A,#6
        ADD   A,R3
MOV   B,#10
DIV   AB
        MOV   R3,B
ADD   A,#5
        ADD   A,R4
MOV   B,#10
DIV   AB
        MOV   R4,B
ADD   A,#2
        ADD   A,R5
MOV   B,#10
DIV   AB
        MOV   R5,B
        CJNE R6,#00D,ADD_IT
        SJMP CONTINUE
ADD_IT:
        ADD A,R6
CONTINUE:
        MOV R6,A
        DJNZ R1,HIGH_BYTE
        MOV B, #10D
        MOV A,R6
        DIV AB
        MOV R6,B
        MOV R7,A
ENDD:   SJMP $

More code on: https://www.8052.com/codelib.phtml
 

    Suresh R

    Points: 2
    Helpful Answer Positive Rating

Suresh R

Member level 1
Joined
Nov 16, 2006
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,535
Thank you. I think i can do that.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top