40バイトサインジェネレータ
x86 の機械語40バイトで、コサインテーブルを生成する方法。
元ネタがどこにあったか分からなくなったので貼り付けておこう。
--(sin.txt)------------------------------------------------------- ここに、ACE BBSの広告の中のサインテーブルジェネレータに関しての 説明があります. 使用される方法は再帰的なサインsythesisです.nが1周期の値の数であ る場合、前の2つとcos(2a/N)の値だけで、すべてのサインの値を計算す ることができます. Here's some explanation about the sinus table generator in the ACE BBS advert. The method used is a recursive sinus sythesis. It's possible to compute all sinus values with only the two previous ones and the value of cos(2a/N) , where n is the number of values for one period. It's as follow: Sin(K)=2.Cos(2a/N).Sin(K-1)-Sin(K-2) or Cos(K)=2.Cos(2a/N).Cos(K-1)-Cos(K-2) cosテーブルのはじめの二つの値が1とcos(2a/n)で、この二つの値で 続く全ての値を計算できるので、後者を使った方が最も簡単です. The last one is easiest to use , because the two first values of the cos table are 1 & cos(2a/n) and with this two values you are able to build all the following... Some simple code: the cos table has 1024 values & ranges from -2^24 to 2^24 build_table: lea DI,cos_table mov CX,1022 mov EBX,cos_table[4] mov EAX,EBX @@calc: imul EBX shrd EAX,EDX,23 sub EAX,[DI-8] stosd loop @@caslc cos_table dd 16777216 ; 2^24 dd 16776900 ; 2 ^24*cos(2a/1024) dd 1022 dup (?) Enjoy KarL/NoooN ---(sin.txt)------------------------------------------------------
テラスゴスwwwwww