From: j8takagi Date: Thu, 6 Jan 2011 12:21:25 +0000 (+0900) Subject: マクロの内部処理を変更 X-Git-Tag: v0.1p15 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4866d13fcff241efb18d16b33fb007c5beed21de;p=YACASL2.git マクロの内部処理を変更 --- diff --git a/src/assemble.c b/src/assemble.c index 563431c..c86334f 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -49,13 +49,13 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass); bool macrocmd(const CMDLINE *cmdl, PASS pass); -bool writeIN(const char *ibuf, const char *len, PASS pass); +void writeIN(const char *ibuf, const char *len, PASS pass); -bool writeOUT(const char *obuf, const char *len, PASS pass); +void writeOUT(const char *obuf, const char *len, PASS pass); -bool writeRPUSH(PASS pass); +void writeRPUSH(PASS pass); -bool writeRPOP(PASS pass); +void writeRPOP(PASS pass); bool cometcmd(const CMDLINE *cmdl, PASS pass); @@ -65,7 +65,9 @@ void writestr(const char *str, bool literal, PASS pass); void writeDC(const char *str, PASS pass); -bool assembleline(const CMDLINE *cmdl, PASS pass); +bool assembletok(const CMDLINE *cmdl, PASS pass); + +bool assembleline(const char *line, PASS pass); void printline(FILE *stream, const char *filename, int lineno, char *line); @@ -155,14 +157,15 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass) status = true; break; case END: - /* リテラル領域の設定 */ + /* 1回目のアセンブルの場合は、リテラル領域開始番地を設定 */ if(pass == FIRST) { asprop->lptr = asprop->ptr; } - /* 実行終了番地と次のプログラムの実行開始番地を設定 */ + /* 2回目のアセンブルの場合は、リテラル領域終了番地を実行終了番地として設定 */ else if(pass == SECOND) { prog->end = asprop->lptr; } + /* プログラム名のクリア */ asprop->prog = NULL; status = true; break; @@ -202,8 +205,7 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass) { int i = 0; MACROCMDID cmdid; - bool status = false; - MACROCMD macrocmd[] = { + MACROCMD macrocmd[] = { { IN, 2, 2, "IN" }, { OUT, 2, 2, "OUT" }, { RPUSH, 0, 0, "RPUSH" }, @@ -226,21 +228,20 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass) switch(cmdid) { case IN: - status = writeIN(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass); - break; + writeIN(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass); + return true; case OUT: - status = writeOUT(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass); - break; + writeOUT(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass); + return true; case RPUSH: - status = writeRPUSH(pass); - break; + writeRPUSH(pass); + return true; case RPOP: - status = writeRPOP(pass); - break; + writeRPOP(pass); + return true; default: return false; } - return status; } /** @@ -253,33 +254,21 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass) * POP GR2 * POP GR1 */ -bool writeIN(const char *ibuf, const char *len, PASS pass) +void writeIN(const char *ibuf, const char *len, PASS pass) { - bool status = false; - - /* PUSH 0,GR1 */ - writememory(0x7001, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* PUSH 0,GR2 */ - writememory(0x7002, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* LAD GR1,IBUF */ - writememory(0x1210, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, ibuf, pass), (asprop->ptr)++, pass); - /* LAD GR2,LEN */ - writememory(0x1220, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, len, pass), (asprop->ptr)++, pass); - /* SVC 1 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0001, (asprop->ptr)++, pass); - /* POP GR2 */ - writememory(0x7120, (asprop->ptr)++, pass); - /* POP GR1 */ - writememory(0x7110, (asprop->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } - return status; + char *line = malloc_chk(LINESIZE+1, "writeIN.line"); + + assembleline(" PUSH 0,GR1", pass); + assembleline(" PUSH 0,GR2", pass); + sprintf(line, " LAD GR1,%s", ibuf); + assembleline(line, pass); + sprintf(line, " LAD GR2,%s", len); + assembleline(line, pass); + assembleline(" SVC 1", pass); + assembleline(" POP GR2", pass); + assembleline(" POP GR1", pass); + + free_chk(line, "writeIN.line"); } /** @@ -290,57 +279,28 @@ bool writeIN(const char *ibuf, const char *len, PASS pass) * LAD GR2,LEN * SVC 2 * LAD GR1,=#A - * LAD GR2,1 + * LAD GR2,=1 * SVC 2 * POP GR2 * POP GR1 */ -bool writeOUT(const char *obuf, const char *len, PASS pass) +void writeOUT(const char *obuf, const char *len, PASS pass) { - bool status = false; - - /* PUSH 0,GR1 */ - writememory(0x7001, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* PUSH 0,GR2 */ - writememory(0x7002, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* LAD GR1,OBUF */ - writememory(0x1210, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, obuf, pass), (asprop->ptr)++, pass); - /* LAD GR2,OLEN */ - writememory(0x1220, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, len, pass), (asprop->ptr)++, pass); - /* SVC 2 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0002, (asprop->ptr)++, pass); - /* LAD GR1,=#A */ - writememory(0x1210, (asprop->ptr)++, pass); - if(pass == FIRST) { - (asprop->ptr)++; - } else { - writememory(asprop->lptr, (asprop->ptr)++, pass); /* リテラルのアドレスを書込 */ - } - writememory(0xA, (asprop->lptr)++, pass); - /* LAD GR2,=1 */ - writememory(0x1220, (asprop->ptr)++, pass); - if(pass == FIRST) { - (asprop->ptr)++; - } else { - writememory(asprop->lptr, (asprop->ptr)++, pass); /* リテラルのアドレスを書込 */ - } - writememory(0x1, (asprop->lptr)++, pass); - /* SVC 2 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0002, (asprop->ptr)++, pass); - /* POP GR2 */ - writememory(0x7120, (asprop->ptr)++, pass); - /* POP GR1 */ - writememory(0x7110, (asprop->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } - return status; + char *line = malloc_chk(LINESIZE+1, "writeOUT.line"); + + assembleline(" PUSH 0,GR1", pass); + assembleline(" PUSH 0,GR2", pass); + sprintf(line, " LAD GR1,%s", obuf); + assembleline(line, pass); + sprintf(line, " LAD GR2,%s", len); + assembleline(line, pass); + assembleline(" SVC 2", pass); + assembleline(" LAD GR1,=#A", pass); + assembleline(" LAD GR2,=1", pass); + assembleline(" SVC 2", pass); + assembleline(" POP GR2", pass); + assembleline(" POP GR1", pass); + free_chk(line, "writeOUT.line"); } /** マクロ命令「RPUSH」をメモリに書き込む @@ -352,19 +312,16 @@ bool writeOUT(const char *obuf, const char *len, PASS pass) * PUSH 0,GR6 * PUSH 0,GR7 */ -bool writeRPUSH(PASS pass) +void writeRPUSH(PASS pass) { int i; - bool status = false; + char *line = malloc_chk(LINESIZE+1, "writeRPUSH.line"); - for(i = 1; i <= 7; i++) { - writememory(0x7000 + i, (asprop->ptr)++, pass); /* PUSH GRn */ - writememory(0x0, (asprop->ptr)++, pass); - } - if(cerr->num == 0) { - status = true; + for(i = 1; i <= GRSIZE-1; i++) { + sprintf(line, " PUSH 0,GR%d", i); + assembleline(line, pass); } - return status; + free_chk(line, "writeRPUSH.line"); } /** @@ -378,22 +335,21 @@ bool writeRPUSH(PASS pass) * POP GR2 * POP GR1 */ -bool writeRPOP(PASS pass) +void writeRPOP(PASS pass) { int i; - bool status = false; - for(i = 7; i >= 1; i--) { - writememory((0x7100 + (i << 4)), (asprop->ptr)++, pass); /* POP GRn */ - } - if(cerr->num == 0) { - status = true; + char *line = malloc_chk(LINESIZE+1, "writeRPOP.line"); + + for(i = GRSIZE-1; i >= 1; i--) { + sprintf(line, " POP GR%d", i); + assembleline(line, pass); } - return status; + free_chk(line, "writeRPOP.line"); } /** * 機械語命令をメモリに書込 - * 書込に成功した場合はtrue、それ以外の場合はfalseを返す + * 書込に、成功した場合はtrue、失敗した場合はfalse、を返す */ bool cometcmd(const CMDLINE *cmdl, PASS pass) { @@ -434,7 +390,7 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) status = true; } } - /* オペランド数2〜3。第2オペランドはアドレス、 */ + /* オペランド数2または3。第2オペランドはアドレス、 */ /* 第3オペランドは指標レジスタとして用いる汎用レジスタ */ else if(cmdl->opd->opdc == 2 || cmdl->opd->opdc == 3) { if((cmd = getcmdcode(cmdl->cmd, R_ADR_X_)) == 0xFFFF && @@ -463,7 +419,7 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) return false; } } - /* オペランド数1〜2。第1オペランドはアドレス */ + /* オペランド数1または2。第1オペランドはアドレス */ else if(cmdl->opd->opdc == 1 || cmdl->opd->opdc == 2) { if((cmd = getcmdcode(cmdl->cmd, ADR_X)) == 0xFFFF) { setcerr(111, cmdl->cmd); /* not command of operand "adr[,x]" */ @@ -571,7 +527,7 @@ void writeDC(const char *str, PASS pass) /** * 1行をアセンブル */ -bool assembleline(const CMDLINE *cmdl, PASS pass) +bool assembletok(const CMDLINE *cmdl, PASS pass) { bool status = false; /* 命令がない場合 */ @@ -632,6 +588,27 @@ WORD getadr(const char *prog, const char *str, PASS pass) return adr; } + +/** + * 1行をアセンブル + */ +bool assembleline(const char *line, PASS pass) +{ + CMDLINE *cmdl; + + if((cmdl = linetok(line)) != NULL) { + if(pass == FIRST && cmdl->label != NULL) { + if(addlabel(asprop->prog, cmdl->label, asprop->ptr) == false) { + return false; + } + } + if(assembletok(cmdl, pass) == false) { + return false; + } + } + return true; +} + /** * 指定された名前のファイルをアセンブル * 2回実行される @@ -661,15 +638,8 @@ bool assemble(const char *file, PASS pass) { printline(stdout, file, lineno, line); } - if((cmdl = linetok(line)) != NULL) { - if(pass == FIRST && cmdl->label != NULL) { - if(addlabel(asprop->prog, cmdl->label, asprop->ptr) == false) { - break; - } - } - if(assembleline(cmdl, pass) == false) { - break; - } + if(assembleline(line, pass) == false) { + break; } if(cerr->num > 0) { break; diff --git a/src/exec.c b/src/exec.c index e19b415..340ec52 100644 --- a/src/exec.c +++ b/src/exec.c @@ -5,11 +5,16 @@ #include "exec.h" #include "cerr.h" -/* 実行エラーの定義 */ +/** + * アセンブルファイル読み込みエラーの定義 + */ static CERR cerr_loadassemble[] = { { 201, "Loading - full of COMET II memory" }, }; +/** + * 実行エラーの定義 + */ static CERR cerr_exec[] = { { 202, "SVC input - out of Input memory" }, { 203, "SVC output - out of COMET II memory" }, @@ -409,7 +414,7 @@ bool exec() } } free_chk(errpr, "errpr"); - /* 主オペランドが1〜4の場合、第2ビットを無視 */ + /* 主オペランドが1から4の場合、第2ビットを無視 */ if(op >= 0x1000 && op <= 0x4FFF) { op &= 0xFB00; } @@ -530,6 +535,7 @@ bool exec() default: break; } + /* クロック周波数の設定 */ do { clock_end = clock(); } while(clock_end - clock_begin < CLOCKS_PER_SEC / sys->clocks); diff --git a/test/system/casl2/Makefile b/test/system/casl2/Makefile index 6be7c11..21aec37 100644 --- a/test/system/casl2/Makefile +++ b/test/system/casl2/Makefile @@ -42,7 +42,7 @@ $(GROUP_LOG_FILE): $(TEST_LOG_FILES) @$(call group_log,$^,$@) $(TEST_LOG_FILES): - @$(MAKE) $(MAKECMDGOALS) -sC $(dir $@) NODISP=1 + @$(MAKE) $(MAKECMDGOALS) -C $(dir $@) NODISP=1 $(GROUP_TIME_FILE): $(TEST_TIME_FILES) @$(call group_log,$^,$@) diff --git a/test/system/casl2/cmd_OUT_out/0.txt b/test/system/casl2/cmd_OUT_out/0.txt index 38ba728..89e9f01 100644 --- a/test/system/casl2/cmd_OUT_out/0.txt +++ b/test/system/casl2/cmd_OUT_out/0.txt @@ -31,12 +31,12 @@ Assemble ../../../../as/cmd/OUT/out.casl (1) #0007 #004D #0008 #F000 #0009 #0002 + #00B0 #000A #000A #1210 #000B #00B0 - #00B0 #000A + #00B1 #0001 #000C #1220 #000D #00B1 - #00B1 #0001 #000E #F000 #000F #0002 #0010 #7120 @@ -52,12 +52,12 @@ Assemble ../../../../as/cmd/OUT/out.casl (1) #0019 #006E #001A #F000 #001B #0002 + #00B2 #000A #001C #1210 #001D #00B2 - #00B2 #000A + #00B3 #0001 #001E #1220 #001F #00B3 - #00B3 #0001 #0020 #F000 #0021 #0002 #0022 #7120 @@ -73,12 +73,12 @@ Assemble ../../../../as/cmd/OUT/out.casl (1) #002B #008F #002C #F000 #002D #0002 + #00B4 #000A #002E #1210 #002F #00B4 - #00B4 #000A + #00B5 #0001 #0030 #1220 #0031 #00B5 - #00B5 #0001 #0032 #F000 #0033 #0002 #0034 #7120 @@ -94,12 +94,12 @@ Assemble ../../../../as/cmd/OUT/out.casl (1) #003D #00AF #003E #F000 #003F #0002 + #00B6 #000A #0040 #1210 #0041 #00B6 - #00B6 #000A + #00B7 #0001 #0042 #1220 #0043 #00B7 - #00B7 #0001 #0044 #F000 #0045 #0002 #0046 #7120 diff --git a/test/system/casl2/hello/0.txt b/test/system/casl2/hello/0.txt index 372dce5..59baef2 100644 --- a/test/system/casl2/hello/0.txt +++ b/test/system/casl2/hello/0.txt @@ -31,12 +31,12 @@ Assemble ../../../../as/hello.casl (1) #0007 #0020 #0008 #F000 #0009 #0002 + #0021 #000A #000A #1210 #000B #0021 - #0021 #000A + #0022 #0001 #000C #1220 #000D #0022 - #0022 #0001 #000E #F000 #000F #0002 #0010 #7120