School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,000 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,966 people online right now. Registration is fast and FREE... Join Now!




math function in assembly

 

math function in assembly

tomboyraju

24 Sep, 2009 - 01:22 AM
Post #1

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

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 THANKFULL

User is offlineProfile CardPM
+Quote Post


no2pencil

RE: Math Function In Assembly

24 Sep, 2009 - 01:27 AM
Post #2

i R L33t Skiddie, k?
Group Icon

Joined: 10 May, 2007
Posts: 13,489



Thanked: 303 times
Dream Kudos: 2875
Expert In: Goofing Off

My Contributions
As per This page :
QUOTE
DIV source

The divider can be a byte or a word and it is the operator which is given the instruction.

If the divider is 8 bits, the 16 bits AX register is taken as dividend and if the divider is 16 bits the even DX:AX register will be taken as dividend, taking the DX high word and AX as the low.

If the divider was a byte then the quotient will be stored on the AL register and the residue on AH, if it was a word then the quotient is stored on AX and the residue on DX.

User is online!Profile CardPM
+Quote Post

tomboyraju

RE: Math Function In Assembly

24 Sep, 2009 - 01:39 AM
Post #3

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

QUOTE(no2pencil @ 24 Sep, 2009 - 01:27 AM) *

As per This page :
QUOTE
DIV source

The divider can be a byte or a word and it is the operator which is given the instruction.

If the divider is 8 bits, the 16 bits AX register is taken as dividend and if the divider is 16 bits the even DX:AX register will be taken as dividend, taking the DX high word and AX as the low.

If the divider was a byte then the quotient will be stored on the AL register and the residue on AH, if it was a word then the quotient is stored on AX and the residue on DX.


AS I TOLD I AM USING PIC18F SO IN THAT NO DIVISION OPRATION AND IT IS 8 BIT PROCESSOR
User is offlineProfile CardPM
+Quote Post

wildgoose

RE: Math Function In Assembly

24 Sep, 2009 - 03:02 PM
Post #4

D.I.C Regular
Group Icon

Joined: 29 Jun, 2009
Posts: 429



Thanked: 55 times
Dream Kudos: 25
Expert In: Assembly,C,C++

My Contributions
NO NEED TO SCREAM!!!!!

Okay, now that text etiquette is over, despite your broken English let's try this. This looks like the post "CMX Processors", with the same problem and same unclear English, so I'm now guessing at what you're trying to do!

You are working with a PIC18F processor. Dependent upon which individual processor you're trying to use you have limited memory, therefore the goal is to make your code as small as possible to keep memory space low, so you can use the smallest memory based unit so as to keep your costs low dependent upon the minimum requirements of your application. For example if your application can fit on a 18F1220 you don't use the more expensive 18F4550 if you don't have to so as to keep your production costs low.

So...

How is your decimal value getting into the code?
Is it compiled in? If so then make a comment what the value is, and set it as the hex code equivalent! Don't waste processor time or valuable code space just to convert data that's compiled/assembled in.

Is it entered as an ASCII string through a communications port?
Then don't turn it into decimal so you don't have to divide back out into base 10. Import ASCII digits, and store as BCD Binary Coded Decimal. Either one digit per byte or as a digit pair per byte!

"987" 9='9'-'0' 8='8'-'0' 7='7'-'0'

If you are merely converting a decimal value int Hex, remember it is stored in the computer as base 2. Hex is base 16. So shift off 4 bits for the low hex value, and the next four bits as the upper hex value. Repeast for each byte. Then its a simple matter of either using a table lookup Hex value 0...15 "01234.....CDEF" or a level break. If hex is < 10 then hex + '0' else hex + 'A'-10

If you really need to divide by 10 and aren't using a C compiler to do the task for you, then do it simply!

Remember that N * 10
can easily be done as (N << 3) + (N << 1)

A divide by 10 is a tad more complicated but can be done in a similar way.

This post has been edited by wildgoose: 24 Sep, 2009 - 03:31 PM
User is offlineProfile CardPM
+Quote Post

tomboyraju

RE: Math Function In Assembly

24 Sep, 2009 - 06:57 PM
Post #5

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

QUOTE(wildgoose @ 24 Sep, 2009 - 03:02 PM) *

NO NEED TO SCREAM!!!!!

Okay, now that text etiquette is over, despite your broken English let's try this. This looks like the post "CMX Processors", with the same problem and same unclear English, so I'm now guessing at what you're trying to do!

You are working with a PIC18F processor. Dependent upon which individual processor you're trying to use you have limited memory, therefore the goal is to make your code as small as possible to keep memory space low, so you can use the smallest memory based unit so as to keep your costs low dependent upon the minimum requirements of your application. For example if your application can fit on a 18F1220 you don't use the more expensive 18F4550 if you don't have to so as to keep your production costs low.

So...

How is your decimal value getting into the code?
Is it compiled in? If so then make a comment what the value is, and set it as the hex code equivalent! Don't waste processor time or valuable code space just to convert data that's compiled/assembled in.

Is it entered as an ASCII string through a communications port?
Then don't turn it into decimal so you don't have to divide back out into base 10. Import ASCII digits, and store as BCD Binary Coded Decimal. Either one digit per byte or as a digit pair per byte!

"987" 9='9'-'0' 8='8'-'0' 7='7'-'0'

If you are merely converting a decimal value int Hex, remember it is stored in the computer as base 2. Hex is base 16. So shift off 4 bits for the low hex value, and the next four bits as the upper hex value. Repeast for each byte. Then its a simple matter of either using a table lookup Hex value 0...15 "01234.....CDEF" or a level break. If hex is < 10 then hex + '0' else hex + 'A'-10

If you really need to divide by 10 and aren't using a C compiler to do the task for you, then do it simply!

Remember that N * 10
can easily be done as (N << 3) + (N << 1)

A divide by 10 is a tad more complicated but can be done in a similar way.


ya thanks but ..will you pls be more clear with some example so that i can get easily..

User is offlineProfile CardPM
+Quote Post

wildgoose

RE: Math Function In Assembly

24 Sep, 2009 - 07:07 PM
Post #6

D.I.C Regular
Group Icon

Joined: 29 Jun, 2009
Posts: 429



Thanked: 55 times
Dream Kudos: 25
Expert In: Assembly,C,C++

My Contributions
Sorry, not allowed. The rules of this website is for you to properly post your best attempt with formated code, then we can review your code and see what we can see and if we can help.


User is offlineProfile CardPM
+Quote Post

tomboyraju

RE: Math Function In Assembly

24 Sep, 2009 - 07:34 PM
Post #7

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

QUOTE(wildgoose @ 24 Sep, 2009 - 07:07 PM) *

Sorry, not allowed. The rules of this website is for you to properly post your best attempt with formated code, then we can review your code and see what we can see and if we can help.

CODE
  
LFSR 1,0X10
NVALUE: MOVWF INDF1
      
;; UNTILL THE REMINDER IS LESS THAN DIVIDEND CALCULATE THE VALUE

            SUBLW D'1024'
            CPFSLT D'1024'
            BRA $-4

            ADDLW D'16384'
            MOVWF SSP1BUF
            CLRF INDF1
            INCF FSR1L  

            BRA NVALUE


directly 1024 we cant pass bcz as it is 8 bit processor in hex it is 400h so i have to pass two times but how to do this loop for substraction and comparision .

This post has been edited by tomboyraju: 24 Sep, 2009 - 07:35 PM
User is offlineProfile CardPM
+Quote Post

tomboyraju

RE: Math Function In Assembly

25 Sep, 2009 - 12:41 AM
Post #8

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

QUOTE(tomboyraju @ 24 Sep, 2009 - 06:57 PM) *

QUOTE(wildgoose @ 24 Sep, 2009 - 03:02 PM) *

NO NEED TO SCREAM!!!!!

Okay, now that text etiquette is over, despite your broken English let's try this. This looks like the post "CMX Processors", with the same problem and same unclear English, so I'm now guessing at what you're trying to do!

You are working with a PIC18F processor. Dependent upon which individual processor you're trying to use you have limited memory, therefore the goal is to make your code as small as possible to keep memory space low, so you can use the smallest memory based unit so as to keep your costs low dependent upon the minimum requirements of your application. For example if your application can fit on a 18F1220 you don't use the more expensive 18F4550 if you don't have to so as to keep your production costs low.

So...

How is your decimal value getting into the code?
Is it compiled in? If so then make a comment what the value is, and set it as the hex code equivalent! Don't waste processor time or valuable code space just to convert data that's compiled/assembled in.

Is it entered as an ASCII string through a communications port?
Then don't turn it into decimal so you don't have to divide back out into base 10. Import ASCII digits, and store as BCD Binary Coded Decimal. Either one digit per byte or as a digit pair per byte!

"987" 9='9'-'0' 8='8'-'0' 7='7'-'0'

If you are merely converting a decimal value int Hex, remember it is stored in the computer as base 2. Hex is base 16. So shift off 4 bits for the low hex value, and the next four bits as the upper hex value. Repeast for each byte. Then its a simple matter of either using a table lookup Hex value 0...15 "01234.....CDEF" or a level break. If hex is < 10 then hex + '0' else hex + 'A'-10

If you really need to divide by 10 and aren't using a C compiler to do the task for you, then do it simply!

Remember that N * 10
can easily be done as (N << 3) + (N << 1)

A divide by 10 is a tad more complicated but can be done in a similar way.


ya thanks but ..will you pls be more clear with some example so that i can get easily..


Is this multiplication hint what you had given is work for all integers?bcz i am getting different answer so

User is offlineProfile CardPM
+Quote Post

tomboyraju

RE: Math Function In Assembly

8 Oct, 2009 - 10:29 PM
Post #9

New D.I.C Head
*

Joined: 13 Sep, 2009
Posts: 18

how to do the bit padding?pls reply
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:21AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month