シミュレーション

シミュレータが完成

2007年6月24日

シミュレータが、(おそらく)完成した。最後に残っていた、複合命令まわりのコードを仕上げた。いくつかの複合命令を実行してみたが、うまく動いている様子。

主な変更点を、抜粋しておく。

memory.cpp
// The Basic Sub Routines
class BSR : public MEMORY {
public:
    unsigned short ip;
    void inc(){
        ip++;
    }
    unsigned char read(){
        setSegment(ip>>8);
        setAddr(ip&0xff);
        return ((MEMORY*)this)->read();
    }
    void reset(unsigned char command){
        switch (command){
        case 0xc0: ip=0x00; return; // mov a1,XXh
        case 0xc1: ip=0x05; return; // mov a2,XXh
        case 0xc2: ip=0x0a; return; // mov b1,XXh
        case 0xc3: ip=0x0f; return; // mov b2,XXh
        case 0xc4: ip=0x14; return; // call x
        case 0xc5: ip=0x17; return; // ret far
        case 0xc6: ip=0x1a; return; // call x:[b2]
        case 0xc7: ip=0x21; return; // jmp x:[b2]
        case 0xc8: ip=0x28; return; // jmp ip+x
        case 0xc9: ip=0x35; return; // jmp ip-x
        case 0xca: ip=0x42; return; // ret far+1
        case 0xcb: ip=0x50; return; // call ip+x
        case 0xcc: ip=0x53; return; // call ip-x
        case 0xcd: ip=0x60; return; // not a1
        case 0xce: ip=0x66; return; // and a1,a2
        case 0xcf: ip=0x70; return; // or a1,a2
        case 0xd0: ip=0x7a; return; // rtr a1
        case 0xd1: ip=0x89; return; // rtl a2
        case 0xd2: ip=0x98; return; // shr a1
        case 0xd3: ip=0xa0; return; // shl a2
        case 0xd4: ip=0xa8; return; // exc a1,a2
        case 0xd5: ip=0xad; return; // exc a1,x
        case 0xd6: ip=0xb2; return; // exc a2,x
        case 0xd7:

        case 0xff:
        default:
            ip=0;
        }
    }
};

void setBSR(BSR* bsr){
    int i;
    unsigned char data[256];
    char* asmdata[]={
    // mov al,XXh
        "push x",       //00
        "mov x,[ip++]",
        "mov a1,x",
        "pop x",
        "nop",
    // mov a2,XXh
        "push x",       //05
        "mov x,[ip++]",
        "mov a2,x",
        "pop x",
        "nop",
    // mov b1,XXh
        "push x",       //0a
        "mov x,[ip++]",
        "mov b1,x",
        "pop x",
        "nop",
    // mov b2,XXh
        "push x",       //0f
        "mov x,[ip++]",
        "mov b2,x",
        "pop x",
        "nop",
    // call x
        "push ip",      //14
        "mov ip,x",
        "nop",
    // ret far
        "pop ip",       //17 
        "pop cs",
        "nop",
    // call x:[b2]
        "mov [b2-3],x",  //1a
        "mov x,[b2]",
        "mov [b2-2],x",
        "push cs",
        "push ip",
        "mov x,[b2-1]",
        "jmp x:[b2]",
    // jmp x:[b2]
        "mov cs,x",        //21
        "mov x,[b2]",
        "mov ip,x",
        "nop",
        "nop",
        "nop",
        "nop",
    // jmp ip+x
        "push a1",      //28
        "mov [b2],x",
        "mov x,ip",
        "mov a1,x",
        "add a1,[b2]",
        "mov ip,x",
        "pop a1",
        "if nc",
        "nop",
        "mov x,cs",
        "inc x",
        "mov cs,x",
        "nop",
    // jmp ip-x
        "push a1",      //35
        "mov [b2],x",
        "mov x,ip",
        "mov a1,x",
        "sub a1,[b2]",
        "mov ip,x",
        "pop a1",
        "if nc",
        "nop",
        "mov x,cs",
        "dec x",
        "mov cs,x",
        "nop",
    // ret far+1
        "pop cs",        //42
        "pop ip",
        "mov [b2],x",
        "mov x,ip",
        "inc x",
        "mov ip,x",
        "mov x,[b2]",
        "if nz",
        "nop",
        "mov x,cs",
        "inc x",
        "mov cs,x",
        "mov x,[b2]",
        "nop",
    // call ip+x
        "push cs",        //50
        "push ip",
        "jmp ip+x",
    // call ip-x
        "push cs",        //53
        "push ip",
        "jmp ip-x",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
        "nop",
    // not a1
        "push a2",        //60
        "sub a1,a1",
        "mov a2,x",
        "nor a1,a2",
        "pop a2",
        "nop",
    // and a1,a2
        "push a1",        //66
        "push a2",
        "nand a1,a2",
        "mov a1,x",
        "sub a1,a1",
        "mov a2,x",
        "nor a1,a2",
        "pop a2",
        "pop a1",
        "nop",
    // or a1,a2
        "push a1",        //70
        "push a2",
        "nor a1,a2",
        "mov a1,x",
        "sub a1,a1",
        "mov a2,x",
        "nor a1,a2",
        "pop a2",
        "pop a1",
        "nop",
    // rtr a1
        "push x",        //7a
        "push a2",
        "mov xh,0h",
        "mov xl,0h",
        "if c",
        "mov xh,8h",
        "mov a2,x",
        "shr a1",
        "push f",
        "add a1,a2",
        "mov a1,x",
        "pop f",
        "pop a2",
        "pop x",
        "nop",
    // rtl a2
        "push x",        //89
        "push a1",
        "mov xh,0h",
        "mov xl,0h",
        "mov a1,x",
        "if c",
        "inc a1",
        "shl a2",
        "push f",
        "add a1,a2",
        "mov a2,x",
        "pop f",
        "pop a2",
        "pop x",
        "nop",
    // shr a1
        "push a2",        //98
        "push a1",
        "pop a2",
        "shr a2",
        "push a2",
        "pop a1",
        "pop a2",
        "nop",
    // shl a2
        "push a1",        //a0
        "push a2",
        "pop a1",
        "shl a1",
        "push a1",
        "pop a2",
        "pop a1",
        "nop",
    // exc a1,a2
        "push a1",        //a8
        "push a2",
        "pop a1",
        "pop a2",
        "nop",
    // exc a1,x        
        "push a1",        //ad
        "push x",
        "pop a1",
        "pop x",
        "nop",
    // exc a2,x        
        "push a1",        //b2
        "push x",
        "pop a1",
        "pop x",
        "nop",
        "nop",
        "nop",
        "nop",


        ""};
    for (i=0;asmdata[i][0]!=0;i++) data[i]=(unsigned char)assemble(asmdata[i]);
    bsr->setSegment(0);
    for (i=0;i<256;i++) {
        bsr->setAddr((unsigned char)i);
        bsr->write(data[i]);
    }
    bsr->setRom(0,255);
}
複合命令を記述した部分。まだスペースは4分の1ほどしか使用していないので、後でいろいろ追加するだろう。

main.cpp
/* Timing chart

   clock1 clock2 clock2'
    0  1   0  1   0  1
    |      |      |
    +--+   |      +--+ event 1
       |   |         |
    +--+   +--+      | event 2
    |         |      |
    +--+      |   +--+ event 3
       |      |   |
    +--+   +--+   |    event 4
    |      |      |

*/
/* Flags
    f register:
      [7] [6] [5] [4] [3] [2] [1] [0]
       |                       |   |
       |                       |   +-- Zero flag (z)
       |                       +------ Carry flag (c)
       +------------------------------ Basic Sub Routine flag
*/
void _main (){
    int ret;
    unsigned char org_cs,org_ip;
    unsigned short org_bsrip;
    ip.reset();
    f.reset();

    while(1){
        // Event 1
        // Prepare environment for reading command
        // Decrement b2 register for PUSH
        memory.setSegment(cs.getValue());
        memory.setAddr(ip.getValue());
        if ((command & 0xf0)==0x10 && !(command & 0x08)) {
            b2.dec( 0 );
        }
        if (ifBSR() && command==0x4d) ip.inc( 0 );
        
        // Event 2
        // Read command from memory
        if (ifBSR()) command=bsr.read();
        else command=memory.read();

        // Event 3
        // Prepare environment for command
        // increment ip
        // Increment b2 register for POP
        if ((command & 0xf0)==0x10 && (command & 0x08)) {
            b2.inc( 0 );
        }
        org_cs=cs.value;
        org_ip=ip.value;
        org_bsrip=bsr.ip;
        if (ifBSR()) {
            if ((command & 0xc0)!=0xc0) bsr.inc();
        } else ip.inc( 0 );

        // Event 4
        ret=mnemonic();

        debug(org_ip,org_cs,org_bsrip);
        if (ret) return;
    }
}
複合命令を追加したことにより、_main() 関数が書き換わっている。ここは、各種イベントのタイミングを決定する、センシティブな部分だ。

register.cpp
class REGISTER_B : public REGISTER{
private:
    REGISTER* segment;
    char isB1;
    unsigned char bsrStack[8];
    unsigned char bsrSP;
public:
    REGISTER_B(REGISTER* seg, char isB1v){
        segment=seg;
        isB1=isB1v;
    }
    void inc(char flag=1){
        if (isB1<0 && ifBSR()) {
            bsrSP=(bsrSP+1)&7;
        } else {
            value++;
            if (value==0) segment->inc(flag);
        }
    }
    void dec(char flag=1){
        if (isB1<0 && ifBSR()) {
            bsrSP=(bsrSP-1)&7;
        } else {
            value--;
            if (value==0) segment->dec(flag);
        }
    }
    void write(unsigned char data, unsigned char add=0){
        if (isB1<0 && ifBSR() && (command & 0xf0)==0x10) { // push statement in BSR
            bsrStack[bsrSP]=data;
            return;
        }
        memory.setSegment(segment->getValue());
        memory.setAddr(value+isB1*(add & 3));
        memory.write(data);
    }
    unsigned char read(unsigned char add=0, char debug=0){
        if (isB1<0 && ifBSR() && (command & 0xf0)==0x10 && !debug) { // pop statement in BSR
            return bsrStack[bsrSP];
        }
        memory.setSegment(segment->getValue());
        memory.setAddr(value+isB1*(add & 3));
        return memory.read();
    }
};
b2 レジスタを少し変更し、複合命令を実行中はpush/popに専用のスタック領域を用いるようにした。これにより、複合命令を実行しても[b2]の内容が保存される。このスタック領域は、8バイトほど用意しておけば十分だろう。

次はいよいよ、シミュレータを用いて円周率を計算する。これが出来れば、コンピューターとしては最低限の機能を備えていることになるから、いよいよ設計図の作成にとりかかることになる。

<%media(20070625-simulator.zip|simulator.zip)%>

コメント

coach purses (2018年10月16日 16:09:38)

http://www.nike-huaraches.us.com/ huaraches
http://www.jordans11shoes.us.com/ jordan 11
http://www.adidasnmdrunnerr1.us.com/ yeezy boost 350
http://www.mcm--bags.us.com/ mcm wallet
http://www.valentino--shoes.us.com/ valentino
http://www.katespadepurses.us.com/ kate spade
http://www.polo-ralph-lauren.org.uk/ ralph lauren polo shirts
http://www.ray--ban.us.com/ ray ban eyeglasses
http://www.ralphlauren--polo.us.com/ ralph lauren dresses
http://www.adidasyeezy-350.us.com/ yeezy shoes
http://www.nikeairmax-97.us.com/ air max 97 silver bullet
http://www.nikelebron15.us.com/ lebron shoes
http://www.kd10-shoes.us.com/ nike kd
http://www.barbourjackets.co.uk/ barbour jacket
http://www.air-max-95.us.com/ air max 95
http://www.monclerjacketwomens.us.com/ moncler
http://www.pandorajewelryscharms.us.com/ pandora jewelry
http://www.nike-airmax-2018.us.com/ air max 2018
http://www.adidasoriginalsultraboost.us.com/ ultra boost uncaged
http://www.oakley--sunglassess.us.com/ oakley sunglasses
http://www.salomon--shoes.us.com/ Salomon Boots
http://www.christianlouboutinredbottoms.us.com/ red bottom shoes
http://www.mbts.us.com/ mbt mens shoes
http://www.jordanretro11-shoes.us.com/ jordan 11
http://www.adidasnmds.co.uk/ nmd
http://www.airmax90shoes.us.com/ nike air max
http://www.northfacejacketoutlets.us.com/ womens north face jacket
http://www.nikeair-max90.co.uk/ nike air max 90
http://www.chromehearts-jewelry.us.com/ chrome hearts bracelet
http://www.coachbags-outlet.us.com/ coach wallet
http://www.salomonspeedcross3.us.com/ salomon speedcross 3
http://www.nike-airmax270.us.com/ air max
http://www.pandora-jewelrybracelet.us.com/ pandora bracelet
http://www.pandora--jewelrys.us.com/ pandora
http://www.adidas-superstarshoes.us.com/ adidas superstar shoes
http://www.katespadebags.us.com/ kate spade outlet
http://www.montblancs.us.com/ mont blanc pens
http://www.mulberrys.org.uk/ mulberry purse
http://www.ugg--slippers.us.com/ uggs for women
http://www.burberry-bags.us.com/ burberry scarf
http://www.airjordan11spacejam.us.com/ jordan retro 11
http://www.uggsformen.us.com/ uggs for women
http://www.longchampbackpack.us.com/ longchamp
http://www.pandora-jewelrysale.us.com/ pandora jewelry
http://www.adidas-yeezyboost350.us.com/ yeezy boost 350
http://www.katespade--outlet.us.com/ kate spade outlet
http://www.swarovskisjewelry.us.com/ swarovski pen
http://www.coach--bags.us.com/ coach outlet
http://www.nike--shoes.co.uk/ nike air max 270
http://www.hermesbirkin-handbags.us.com/ Hermes Handbags
http://www.kyrie-4.us.com/ kyire 3
http://www.adidas--shoes.co.uk/ adidas outlet
http://www.ray--bansunglassess.us.com/ ray ban glasses
http://www.uggs--boots.us.com/ uggs on sale
http://www.longchampbag.us.com/ longchamp bag
http://www.ed-hardys.us.com/ ed hardy clothing
http://www.balenciagas-sneakers.us.com/ balenciaga trainers
http://www.lacosteshirts.us.com/ lacoste outlet
http://www.pandoraearrings.us.com/ pandora jewelry
http://www.asicss.us.com/ asics outlet
http://www.skechers--shoes.us.com/ skechers women
http://www.mcms.us.com/ mcm backpack
http://www.monclerjacketmens.us.com/ moncler jacket womens
http://www.goyardbackpack.us.com/ goyard backpack
http://www.adidasoriginalsnmd.us.com/ adidas originals nmd
http://www.swarovskis.us.com/ swarovski bracelet
http://www.salvatore-ferragamo.us.com/ salvatore
http://www.stephen-curry-shoes.us.com/ stephen curry shoes
http://www.airmax95.co.uk/ nike air max 95
http://www.asics--shoes.us.com/ asics womens shoes
http://www.ultra--boost.us.com/ adidas ultra boost uncaged
http://www.oakley--glasses.us.com/ oakley glasses
http://www.northface-jacket.us.com/ womens north face jacket
http://www.lebron15-shoes.us.com/ lebron james shoes
http://www.pumarihannafenty.us.com/ puma rihanna
http://www.fitflops-sale.us.com/ fitflop
http://www.adidas-ultraboost.us.com/ ultra boost
http://www.true--religion.us.com/ true religion jeans for women
http://www.fitflop--sandals.us.com/ fitflops uk
http://www.chromeheartsjewelrys.us.com/ chrome hearts t shirt
http://www.pandora--rings.us.com/ Pandora Rings
http://www.air-max-270.us.com/ nike air max 270
http://www.james-hardenshoes.us.com/ james harden
http://www.nikeairmax97.co.uk/ nike air max 90
http://www.nikeair-max.co.uk/ nike air max
http://www.truereligion--jeans.us.com/ true religion jeans
http://www.skechersuk.co.uk/ skechers
http://www.yeezyboost350v2.co.uk/ adidas yeezy
http://www.burberry--scarf.us.com/ burberry handbags
http://www.supreme--clothing.us.com/ supreme clothing
http://www.burberrys.org.uk/ burberry backpack
http://www.fitflopsshoes.us.com/ fitflop
http://www.pandorajewelryrings.us.com/ pandora earrings
http://www.goyardbag.us.com/ goyard backpack
http://www.nikeairmax270.org.uk/ nike air max 95
http://www.air-max-90.us.com/ air max 90
http://www.eccoshoesoutlets.us.com/ ecco sandals
http://www.bvlgaris.us.com/ bvlgari wallet
http://www.curry4-shoes.us.com/ under armour stephen curry
http://www.monclerjacket.org.uk/ moncler coat
http://www.new--balance.us.com/ new balance running shoes women
http://www.birkenstocksandalssale.us.com/ birkenstock sale
http://www.rayban-glasses.us.com/ ray ban
http://www.salomon-boots.us.com/ salomon boots
http://www.vapormaxs.us.com/ nike vapormax
http://www.michaelkors-handbagss.us.com/ michael kors
http://www.pandorauk.us.com/ pandora rings
http://www.ferragamoshoess.us.com/ salvatore
http://www.yeezyboost350shoes.us.com/ yeezy boost 350 v2
http://www.barbours.org.uk/ barbour wax jacket
http://www.louboutinredbottoms.us.com/ red bottoms
http://www.jimmychooheels.us.com/ jimmy choo trainers
http://www.supremeshirt.us.com/ supreme clothing
http://www.nikeairvapormaxflyknit.us.com/ nike air max 90
http://www.pandoras-jewelrys.us.com/ pandora
http://www.prada--handbags.us.com/ prada shoes
http://www.cartier-bracelet.us.com/ cartier
http://www.airmax270.co.uk/ air max 270
http://www.nikeairmax-90.us.com/ nike air max 90
http://www.kyrie-irving-shoes.us.com/ kyrie 4
http://www.jordan--11.us.com/ jordan retro 11
http://www.salomonshoes.co.uk/ salomon
http://www.ralphlaurenspoloshirts.us.com/ ralph lauren outlet
http://www.celines.us.com/ celine,celine bag
http://www.rayban--glasses.us.com/ ray ban sunglasses
http://www.balenciaga--shoes.us.com/ balenciaga shoes
http://www.airmax-2018.us.com/ air max 2018
http://www.adidas-yeezy-shoes.us.com/ Yeezy
http://www.fitflop--shoes.us.com/ fitflop
http://www.uggs-forwomen.us.com/ uggs on sale
http://www.birkenstock--sandals.us.com/ birkenstock
http://www.nikekdshoes.us.com/ nike kd
http://www.hermes--belt.us.com/ hermes belt
http://www.jordan11spacejams.us.com/ space jam 11
http://www.mulberry-handbags.us.com/ mulberry
http://www.redbottoms-louboutin.us.com/ christian louboutin
http://www.moncler--jacket.us.com/ moncler
http://www.nike--vapormax.us.com/ nike vapor max
http://www.air-max-97.us.com/ air max 97 womens
http://www.huaraches.us.com/ nike huarache
http://www.under-armour-shoes.us.com/ under armour
http://www.yeezyboost350--v2.us.com/ yeezy boost 350
http://www.kevin-durant-shoes.us.com/ nike kd
http://www.chrome--hearts.us.com/ chrome hearts necklace
http://www.skecherss.us.com/ skechers shoes
http://www.adidasnmd-womens.us.com/ adidas originals nmd
http://www.michael-kors-bags.us.com/ michael kors purse
http://www.redbottom--shoes.us.com/ red bottom shoes
http://www.monclers.uk/ moncler jacket mens
http://www.pandoras-uk.co.uk/ pandora jewelry
http://www.prada--bags.us.com/ prada
http://www.jordan11.co.uk/ jordan 11
http://www.polo-ralphlauren-outlet.us.com/ ralph lauren polo shirts
http://www.adidasyeezys.org.uk/ yeezy shoes
http://www.nikeairmax-95.us.com/ air max 95 mens
http://www.pandorasjewelry.co.uk/ pandora charm
http://www.pandora-charmsjewelry.us.com/ pandora jewelry
http://www.moncler-coat.us.com/ moncler
あって

skechers shoes (2019年1月13日 20:18:29)

http://www.moncler-uk.co.uk/ moncler jacket mens
http://www.chaussurelouboutinpascher.fr/ louboutin
http://www.pandora-jewelrys.ca/ pandora rings
http://www.chaussure-adidas.fr/ chaussure adidas
http://www.jordan--shoes.us.com/ jordan 11
http://www.birkenstock-sandals.ca/ birkenstock
http://www.curry-5shoes.us/ curry 4
http://www.christianlouboutins.ca/ red bottom shoes
http://www.yeezy.in.net/ yeezy boost 350
私が忙しくなり

コメント送信