Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Math function in assembly

Status
Not open for further replies.

Raju C

New Member
can any one help me to write code for this ..

DEC2HEX(MOD(N,1024)+16384,4)
DEC2HEX(INT(N/1024)+17408,4)

FOR MOD FUNCTION I CAN WRITE BUT HOW TO WRITE FOR DECIMAL TO HEX I DONT KNOW .I AM USING PIC 18F AND I HAVE TO PUT THIS FORMULA IN LOOP BCZ HERE N VALUE I AM CHANGING FREQUENTLY..IF YOU GVE ANY HINT ATLEAST I WILL BE VERY THANK FULL
 
Nigels has some code that show you how it dose DEC to hex you can find it here
Here the part that converts
Code:
;This routine downloaded from http://www.piclist.com

Convert:                        ; Takes number in NumH:NumL

                                ; Returns decimal in

                                ; TenK:Thou:Hund:Tens:Ones

        swapf   NumH, w

	iorlw	B'11110000'

        movwf   Thou

        addwf   Thou,f

        addlw   0XE2

        movwf   Hund

        addlw   0X32

        movwf   Ones



        movf    NumH,w

        andlw   0X0F

        addwf   Hund,f

        addwf   Hund,f

        addwf   Ones,f

        addlw   0XE9

        movwf   Tens

        addwf   Tens,f

        addwf   Tens,f



        swapf   NumL,w

        andlw   0X0F

        addwf   Tens,f

        addwf   Ones,f



        rlf     Tens,f

        rlf     Ones,f

        comf    Ones,f

        rlf     Ones,f



        movf    NumL,w

        andlw   0X0F

        addwf   Ones,f

        rlf     Thou,f



        movlw   0X07

        movwf   TenK



                    ; At this point, the original number is

                    ; equal to

                    ; TenK*10000+Thou*1000+Hund*100+Tens*10+Ones

                    ; if those entities are regarded as two's

                    ; complement binary.  To be precise, all of

                    ; them are negative except TenK.  Now the number

                    ; needs to be normalized, but this can all be

                    ; done with simple byte arithmetic.



        movlw   0X0A                             ; Ten

Lb1:

        addwf   Ones,f

        decf    Tens,f

        btfss   3,0

        goto   Lb1

Lb2:

        addwf   Tens,f

        decf    Hund,f

        btfss   3,0

        goto   Lb2

Lb3:

        addwf   Hund,f

        decf    Thou,f

        btfss   3,0

        goto   Lb3

Lb4:

        addwf   Thou,f

        decf    TenK,f

        btfss   3,0

        goto   Lb4



        retlw	0x00
then use a table for the hex letters maybe nigel will tell you more
 
Last edited:
thank you sir .. But as i am bit new to this so i am not getting exactly so.. will you pls explain me just by giving one example to LB1 loop i will do further ..
 
thank you sir.. but as i am new to this so not getting exactly so will you pls explain Lb1 loop with one example further i do ..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top