EASy68K  
It is currently Tue Nov 19, 2019 3:42 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: equation evaluation
PostPosted: Sun Jun 19, 2011 11:38 pm 
Offline

Joined: Sun Jun 19, 2011 1:36 am
Posts: 7
Location: Midwest
How would you use subroutines to evaluate a polynomial expression for a table of numbers? I can make the number table and get how to make a subroutine. The problem I have is that the polynomial is 3x^2+2x+1 or something similar. I know how to square the x, I simply do the following:

MULS D0,D0 ; I multiple the data register D0 by itself. I don't know how to multiply that result by 3 or then add that to a whole other expression 2x. Anyone have any pointers for me?? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2011 2:57 am 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Code:
        MOVE.W  D0,D1   ; save x
        MULS    D0,D0   ; x * x  (note 16-bit x 16-bit to 32-bit operation)
        MULS    #3,D0   ; 3 * (x * x)
        MULS    #2,D1   ; 2 * x
        ADD.L   D1,D0   ; + 2*x
        ADDQ.L  #1,D0   ; + 1


Top
 Profile  
 
 Post subject: thanks
PostPosted: Mon Jun 20, 2011 3:10 am 
Offline

Joined: Sun Jun 19, 2011 1:36 am
Posts: 7
Location: Midwest
that is great! I knew what I needed to do but just not the code for it. thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2011 11:27 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
ElecEngineer73 wrote:
In the code you gave me for the 3X^2+2x+1 I had a question. I have a table with the numbers that will be X. Your first line of code is
MOVE.B D0,D1 wouldn't this move the number value out of D0 into D1?
MULS D0,D0 is your second line but would D0 be empty because of line above?

The MOVE.W D0,D1 copies D0 to D1 (low order 16 bits), it does not destroy D0

If you have a table/array of values for X

Code:
  LEA TableX,A0 ; Array of WORDs
  LEA TableA,A1 ; Array of LONGs
 
  MOVE.W (A0)+,D0 ; Load next X and advance

.. compute formula

  MOVE.L D0,(A1)+ ; Save Answer and advance

.. repeat/loop


Top
 Profile  
 
 Post subject: thanks
PostPosted: Wed Jun 22, 2011 11:46 am 
Offline

Joined: Sun Jun 19, 2011 1:36 am
Posts: 7
Location: Midwest
Thanks. I was able to figure this out thanks to you. I also had to figure out how to pass the parameters through the stack as well for this. thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group