Continue to Site

# 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

movwf   Hund

movwf   Ones

movf    NumH,w

andlw   0X0F

movwf   Tens

swapf   NumL,w

andlw   0X0F

rlf     Tens,f

rlf     Ones,f

comf    Ones,f

rlf     Ones,f

movf    NumL,w

andlw   0X0F

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:

decf    Tens,f

btfss   3,0

goto   Lb1

Lb2:

decf    Hund,f

btfss   3,0

goto   Lb2

Lb3:

decf    Thou,f

btfss   3,0

goto   Lb3

Lb4:

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.

Replies
6
Views
2K
Replies
11
Views
4K
Replies
12
Views
2K
Replies
14
Views
2K
Replies
9
Views
2K