Assembly code for 68HC11 to calculate sin(x)

左心房为你撑大大i 提交于 2019-12-11 02:48:59

问题


What would be the assembly code for 68HC11 to calculate value of sine using either Taylor series or a lookup table?

Display value will be only in integer. How would a lookup table work in this case? How can it be implemented using Taylor series?


回答1:


I haven't done any 68HC11 programming in a long time, so I won't be able to give you exact instructions, but you want to do more-or-less the following:

  1. Define a table in memory that has 256 (or however many) values for Sin(x), over one quadrant, in the range [0-Pi/2].
  2. Convert your input to the range [0-Pi/2], keeping track of which quadrant it was originally in. For Q2, you want the value (Pi/2-x), for example.
  3. Look up the adjusted value in the table, negating the result if the original angle was in the 3rd or 4th quadrants.

Specifics would of course depend on input and output ranges, but generally speaking, you'll use indexed addressing mode, with the index register pointing into the table, or alternatively, extended addressing, with the offset set by modifying the opcode.




回答2:


If you are looking for a floating point solution, you'll need to implement floating point operations first. That part will be non-trivial on a 68HC11 which has no support for even 32 bit operations. After that, calculating sin is easy but very slow. ;-)

Use a lookup table.




回答3:


Don't use Taylor series.

Google found this.



来源:https://stackoverflow.com/questions/1959335/assembly-code-for-68hc11-to-calculate-sinx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!