Math Function in assembly

Status
Not open for further replies.

Raju C

Member level 2
Joined
Sep 17, 2009
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,558
Can any one help to write a assembly program for the below Formulas..
DEC2HEX(MOD(N,1024)+16384,4)
DEC2HEX(INT(N/1024)+17408,4)

here N is 20bits value ..
 

mov ecx,1024 ;divisor
mov eax,N ;your 20 bit N value
xor edx,edx ;clear edx to give EDX:EAX
div ecx ;divide EDX:EAX by ECX, Quotiet in EAX, remainder in EDX
add edx, 16384 ;Result for 1st equation
add eax, 17408 ;Result for 2nd equation


Do you need a DEC2HEX routine or do you assume that exists?
 

ya thank you but as i am using PIC18F25K20 their is no division operation and it is 8 bit so how to implement this?
 

See multi-byte math routines for PIC here. Use the DIV function with precision 4.

h**p://avtanski.net/projects/math/
 

hey thank you very much i think it helps me .. if any other doubt means i will ask you again ..
 

can you pls tell me how the below code works..

M_DIV: ; Z / X -> Y; remainder -> Z
movlw REG_Y ; passing one value here
call M_CLR ; clearing that resistor
movlw PRECISION*8 ;How it works?
movwf REG_ROT_COUNTER ; passing the multiplied precision value
M_DIV_rot_loop:
btfsc REG_X+PRECISION-1,7; How it works?
goto M_DIV_loop
movlw REG_X
bcf STATUS,C
call M_ROL
decf REG_ROT_COUNTER,f
btfss STATUS,Z
goto M_DIV_rot_loop
bsf STATUS,Z
return
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…