2010-01-23
進みましたが、バグがいっぱいです
|ytlのアセンブラはRubyにアロケートしたメモリにバイナリを生成してJITで実行できるようになりました。でも、いろいろ試していたらバグがいっぱい出てきて直さないといけないです。特に、間接アドレッシングの当りは全然だめです。こんな感じでプログラムが動きます。いずれにしてもあまりオーバヘッドなくコードが生成できるのでいろいろおもしろそうなことができそうです。
def hello asm = Assembler.new(cs = CodeSpace.new) # registor definition eax = OpEAX.instance esp = OpESP.instance hello = OpImmidiate32.new("Hello World".address) asm.mov(eax, hello) asm.push(eax) rbp = address_of("rb_p") asm.call(rbp) asm.add(esp, OpImmidiate8.new(4)) asm.ret asm.flush cs.call(cs.base_address) end hello
Fib
def fib(n) cs0 = CodeSpace.new cs1 = CodeSpace.new cs2 = CodeSpace.new # registor definition eax = OpEAX.instance ebx = OpEBX.instance esp = OpESP.instance asm = Assembler.new(cs0) ent = cs1.base_address asm.mov(eax, OpImmidiate32.new(n)) asm.call(ent) asm.add(eax, eax) asm.add(eax, OpImmidiate8.new(1)) asm.ret asm.flush asm = Assembler.new(cs1) asm.cmp(eax, OpImmidiate32.new(2)) asm.jl(cs2.base_address) asm.sub(eax, OpImmidiate32.new(1)) asm.push(eax) asm.call(ent) asm.pop(ebx) asm.sub(ebx, OpImmidiate32.new(1)) asm.push(eax) asm.mov(eax, ebx) asm.call(ent) asm.pop(ebx) asm.add(eax, ebx) asm.ret asm.flush asm = Assembler.new(cs2) asm.mov(eax, OpImmidiate32.new(1)) asm.ret asm.flush cs0.call(cs0.base_address) end (1..39).each do |i| p fib(i) end
コメントを書く
トラックバック - http://d.hatena.ne.jp/miura1729/20100123/1264239835
リンク元
- 19 http://www.rubyist.net/~kazu/samidare/
- 11 http://twitter.com/
- 9 http://twitter.com/miura1729
- 8 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4GGLL_ja&q=& エスケープ
- 6 http://www.google.co.jp/search?hl=ja&source=hp&q=ripper+使い方&btnG=Google+検索&lr=&aq=9&oq=ripper
- 4 http://ezsch.ezweb.ne.jp/search/?sr=0101&query=鋳鉄管NS
- 4 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=com.ubuntu:ja:unofficial&q=ruby/tk+アニメーション&btnG=検索&lr=&aq=f&oq=
- 4 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=Bh6&q=yarv2llvm&btnG=検索&lr=&aq=f&oq=
- 4 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=多相インラインキャッシュ&num=50
- 3 http://a.hatena.ne.jp/kilrey/