Drkcore

02042009 perl parrot

parrotでGCD

schemeでレジスタ計算機を書いたら、次はparrotというレジスタ仮想機械、(そしてPerl6へみたいな。)

さて、ダウンロードしてきたソースコードについてたexamples/pir/euclid.pirというのがユークリッドの互除法のサンプルなのでこれを使う。

pirというのはParrot Assembly Language(pasm)よりも抽象度の高い言語らしい。

.sub 'example' :main
        $I1 = 96
        $I2 = 64
        print  "Algorithm E (Euclid's algorithm)\n"
e1:     $I4 = mod $I1, $I2
e2:     unless $I4 goto done
e3:     $I1 = $I2
        $I2 = $I4
        branch e1
done:   print "The greatest common denominator of 96 and 64 is "
        print  $I2
        print  ".\n"
.end

pasmに変換

parrot --output=euclid.pasm euclid.pir 

これで、アセンブリコードが吐き出されたので見てみる。

example:
    set I0, 96
    set I1, 64
    print "Algorithm E (Euclid's algorithm)\n"
e1:
    mod I2, I0, I1
e2:
    unless I2, done
e3:
    set I0, I1
    set I1, I2
    branch e1
done:
    print "The greatest common denominator of 96 and 64 is "
    print I1
    print ".\n"
    end 

ふむふむ。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021