LoginSignup
0
0

More than 1 year has passed since last update.

インタープリタを作る その16

Posted at

概要

インタープリタを作ってみた。
avrインタープリター書いてみた。
インとアウトを取り付ける。

方針

アウトは、レジスタ31を監視する。
インは、内部表現に、合わせる。

インの実装

レジスタの内部表現が
[false, false, false, false, false, false, false, false]
なので、変換する関数を書いた。


function hen(x) {   
    var a, b, c, d, e, f, g, h;
    x = x.charCodeAt(0);
    if ((x & 0x01) > 0)
    {
        a = true;
    }
    else
    {
        a = false;
    }
    if ((x & 0x02) > 0)
    {
        b = true;
    }
    else
    {
        b = false;
    }
    if ((x & 0x04) > 0)
    {
        c = true;
    }
    else
    {
        c = false;
    }
    if ((x & 0x08) > 0)
    {
        d = true;
    }
    else
    {
        d = false;
    }
    if ((x & 0x10) > 0)
    {
        e = true;
    }
    else
    {
        e = false;
    }
    if ((x & 0x20) > 0)
    {

        f = true;
    }
    else
    {
        f = false;
    }
    if ((x & 0x40) > 0)
    {
        g = true;
    }
    else
    {
        g = false;
    }
    if ((x & 0x80) > 0)
    {
        h = true;
    }
    else
    {
        h = false;
    }
    K = [a, b, c, d, e, f, g, h];
    return K;
}

アウトの実装

レジスタ31の変換関数、書いた。

function kan(K) {
    var x = 0;
    if (K[0]) x += 0x01;
    if (K[1]) x += 0x02;
    if (K[2]) x += 0x04;
    if (K[3]) x += 0x08;
    if (K[4]) x += 0x10;
    if (K[5]) x += 0x20;
    if (K[6]) x += 0x40;
    if (K[7]) x += 0x80;
  return String.fromCharCode(x);
}   

投入したソース

avr.ldi(31, 'H')
avr.ldi(31, 'e')
avr.ldi(31, 'l')
avr.ldi(31, 'l')
avr.ldi(31, 'o')
avr.ldi(31, ' ')
avr.ldi(31, 'w')
avr.ldi(31, 'o')
avr.ldi(31, 'r')
avr.ldi(31, 'l')
avr.ldi(31, 'd')
avr.ldi(31, '!')

結果

Hello world!

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0