acl4のプログラムのページ0004

(1) アセンブラとは?

(2) p0004a.c [36行] : 即興で作ったアセンブラ

#define a_Version 1
#include <acl4.c>

void myPut(Preprocessor_Put0 *w, VecChr *lin) // 実はt0013b.cで作ったやつと同じ.
{
    if (Preprocessor_isDirective(lin->p, lin->p + lin->n) != 0)
        fprintf(stderr, "[err] %.*s", (int) lin->n, lin->p);
    else
        VecChr_puts(w->dst, lin->p, lin->p + lin->n);
}

int main(int argc, const char **argv)
{
    if (argc < 2) return 1;
    Preprocessor pp[1]; Preprocessor_ini(pp);                            // プリプロセッサの初期化.
    pp->put = (void *) myPut;                                            // 出力関数の変更.
    Preprocessor_SourceFiles_addFile(pp->sfs, argv[1], strlen(argv[1])); // 入力ファイルを指定.
    Preprocessor_SourceFiles_addFile(pp->sfs, "a4vm-asm-p0004a.h", 17);  // 最初にこれをインクロードさせる.
    VecChr vc[1]; VecChr_ini(vc); pp->put0->dst = vc;                    // 出力先のオブジェクトを指定.
    Preprocessor_main(pp); Preprocessor_din(pp);                         // プリプロセッサ処理. およびメモリ開放.

    Token0 t0[1]; Token0_ini1(t0);
    t0->s = vc->p; t0->s1 = vc->p + vc->n;
    Preprocessor_Eval ev[1]; ev->err = 0;
    for (;;) {
        intptr_t i = Preprocessor_eval(ev, t0, 0x7fff);
        if (ev->err != 0) break;
        printf("%02x ", i);
        Token1_get(t0);
        if (t0->c != ',') break;
    }
    putchar('\n');
    VecChr_din(vc);
    a_malloc_debugList(_arg);
    return 0;
}

(3) 実行結果

>p0004a p0004a0.txt
01 00 20 00 00 00 02 00 00 00 00 12 00 04 00 01 00 00 00 06 00 7f 00 00 00 00 00 00 00 13 0a 00 00 00 11 00 00 00 00

(99) 更新履歴


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS