From: j8takagi <j8takagi@nifty.com> Date: Thu, 7 Apr 2011 16:30:10 +0000 (+0900) Subject: アセンブルのソースを整理 X-Git-Tag: v0.1p35 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7add23ad2f39278aaa8f873d4799b77c994bcf0;p=YACASL2.git アセンブルのソースを整理 --- diff --git a/src/assemble.c b/src/assemble.c index fc7aed1..8c1c436 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -59,7 +59,7 @@ void writeRPOP(PASS pass); bool cometcmd(const CMDLINE *cmdl, PASS pass); -bool writememory(WORD word, WORD adr, PASS pass); +void writememory(WORD word, WORD adr, PASS pass); void writestr(const char *str, bool literal, PASS pass); @@ -121,7 +121,6 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass) { int i = 0; ASCMDID cmdid = 0; - bool status = false; ASCMD ascmd[] = { { START, 0, 1, "START" }, { END, 0, 0, "END" }, @@ -156,7 +155,6 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass) setcerr(103, cmdl->opd->opdv[0]); /* label not found */ } } - status = true; break; case END: /* 1åç®ã®ã¢ã»ã³ãã«ã®å ´åã¯ããªãã©ã«é åéå§ã¢ãã¬ã¹ãè¨å® */ @@ -168,33 +166,27 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass) execptr->end = asptr->lptr; } FREE(asptr->prog); - status = true; break; case DS: for(i = 0; i < atoi(cmdl->opd->opdv[0]); i++) { writememory(0x0, (asptr->ptr)++, pass); if(cerr->num > 0) { - return false; + break; } } - status = true; break; case DC: for(i = 0; i < cmdl->opd->opdc; i++) { writeDC(cmdl->opd->opdv[i], pass); if(cerr->num > 0) { - return false; + break; } } - status = true; break; default: return false; } - if(cerr->num > 0) { - status = false; - } - return status; + return (cerr->num == 0) ? true : false; } /** @@ -354,8 +346,7 @@ void writeRPOP(PASS pass) */ bool cometcmd(const CMDLINE *cmdl, PASS pass) { - WORD cmd, adr, r1, r2, x; - bool status = false; + WORD cmd, r_r1, x_r2, adr; /* ãªãã©ã³ããªã */ if(cmdl->opd->opdc == 0) { @@ -363,56 +354,48 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) setcerr(112, cmdl->cmd); /* not command of no operand */ return false; } - if(writememory(cmd, (asptr->ptr)++, pass) == true) { - status = true; - } + writememory(cmd, (asptr->ptr)++, pass); } /* 第1ãªãã©ã³ãã¯æ±ç¨ã¬ã¸ã¹ã¿ */ - else if((r1 = getgr(cmdl->opd->opdv[0], false)) != 0xFFFF) { + else if((r_r1 = getgr(cmdl->opd->opdv[0], false)) != 0xFFFF) { /* ãªãã©ã³ãæ°1 */ if(cmdl->opd->opdc == 1) { if((cmd = getcmdcode(cmdl->cmd, R_)) == 0xFFFF) { setcerr(108, cmdl->cmd); /* not command of operand "r" */ return false; } - cmd |= (r1 << 4); - if(writememory(cmd, (asptr->ptr)++, pass) == true) { - status = true; - } + cmd |= (r_r1 << 4); + writememory(cmd, (asptr->ptr)++, pass); } /* ãªãã©ã³ãæ°2ã第2ãªãã©ã³ãã¯æ±ç¨ã¬ã¸ã¹ã¿ */ - else if(cmdl->opd->opdc == 2 && (r2 = getgr(cmdl->opd->opdv[1], false)) != 0xFFFF) { + else if(cmdl->opd->opdc == 2 && (x_r2 = getgr(cmdl->opd->opdv[1], false)) != 0xFFFF) { if((cmd = getcmdcode(cmdl->cmd, R1_R2)) == 0xFFFF) { setcerr(109, cmdl->cmd); /* not command of operand "r1,r2" */ return false; } - cmd |= ((r1 << 4) | r2); - if(cerr->num == 0 && writememory(cmd, (asptr->ptr)++, pass) == true) { - status = true; - } + cmd |= ((r_r1 << 4) | x_r2); /* 第1ãªãã©ã³ãã第2ãªãã©ã³ãã¨ãã«æ±ç¨ã¬ã¸ã¹ã¿ */ + /* ã¡ã¢ãªã¸ã®æ¸ã込㿠*/ + writememory(cmd, (asptr->ptr)++, pass); } - /* ãªãã©ã³ãæ°2ã¾ãã¯3ã第2ãªãã©ã³ãã¯ã¢ãã¬ã¹ã */ - /* 第3ãªãã©ã³ãã¯ææ¨ã¬ã¸ã¹ã¿ã¨ãã¦ç¨ããæ±ç¨ã¬ã¸ã¹ã¿ */ + /* ãªãã©ã³ãæ°2ã¾ãã¯3 */ else if(cmdl->opd->opdc == 2 || cmdl->opd->opdc == 3) { if((cmd = getcmdcode(cmdl->cmd, R_ADR_X)) == 0xFFFF) { setcerr(110, cmdl->cmd); /* not command of operand "r,adr[,x]" */ return false; } - cmd |= (r1 << 4); - /* ãªãã©ã³ãæ°3 */ - if(cmdl->opd->opdc == 3) { - if((x = getgr(cmdl->opd->opdv[2], true)) == 0xFFFF) { + cmd |= (r_r1 << 4); /* 第1ãªãã©ã³ãã¯æ±ç¨ã¬ã¸ã¹ã¿ */ + /* ãªãã©ã³ãæ°3ã®å ´å */ + if(cmdl->opd->opdc == 3) { /* 第3ãªãã©ã³ãã¯ææ¨ã¬ã¸ã¹ã¿ã¨ãã¦ç¨ããæ±ç¨ã¬ã¸ã¹ã¿ */ + if((x_r2 = getgr(cmdl->opd->opdv[2], true)) == 0xFFFF) { setcerr(125, cmdl->cmd); /* not GR in operand x */ return false; } - cmd |= x; + cmd |= x_r2; } - adr = getadr(asptr->prog, cmdl->opd->opdv[1], pass); + adr = getadr(asptr->prog, cmdl->opd->opdv[1], pass); /* 第2ãªãã©ã³ãã¯ã¢ãã¬ã¹ */ + /* ã¡ã¢ãªã¸ã®æ¸ã込㿠*/ writememory(cmd, (asptr->ptr)++, pass); writememory(adr, (asptr->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } } else { setcerr(113, cmdl->cmd); /* operand too many in COMET II command */ return false; @@ -424,13 +407,13 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) setcerr(111, cmdl->cmd); /* not command of operand "adr[,x]" */ return false; } - /* ãªãã©ã³ãæ°2ã®å ´åã第2ãªãã©ã³ãã¯ææ¨ã¬ã¸ã¹ã¿ã¨ãã¦ç¨ããæ±ç¨ã¬ã¸ã¹ã¿ */ - if(cmdl->opd->opdc == 2) { - x = getgr(cmdl->opd->opdv[1], true); + /* ãªãã©ã³ãæ°2ã®å ´å */ + if(cmdl->opd->opdc == 2) { /* 第2ãªãã©ã³ãã¯ææ¨ã¬ã¸ã¹ã¿ã¨ãã¦ç¨ããæ±ç¨ã¬ã¸ã¹ã¿ */ + x_r2 = getgr(cmdl->opd->opdv[1], true); if(cerr->num > 0) { return false; } - cmd |= x; + cmd |= x_r2; } /* CALLã®å ´åã¯ããã°ã©ã ã®å ¥å£åã表ãã©ãã«ãåå¾ */ /* CALL以å¤ã®å½ä»¤ã®å ´åã¨ãããã°ã©ã ã®å ¥å£åãåå¾ã§ããªãå ´åã¯ã */ @@ -441,34 +424,27 @@ bool cometcmd(const CMDLINE *cmdl, PASS pass) if(cmd != 0x8000 || (pass == SECOND && adr == 0xFFFF)) { adr = getadr(asptr->prog, cmdl->opd->opdv[0], pass); } + /* ã¡ã¢ãªã¸ã®æ¸ã込㿠*/ writememory(cmd, (asptr->ptr)++, pass); writememory(adr, (asptr->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } } - return status; + return (cerr->num == 0) ? true : false; } /** * COMET IIã®ã¡ã¢ãªã«ã¢ãã¬ã¹å¤ãæ¸ãè¾¼ã */ -bool writememory(WORD word, WORD adr, PASS pass) +void writememory(WORD word, WORD adr, PASS pass) { - bool status = false; - - /* COMET IIã¡ã¢ãªãªã¼ãã¼ã®å ´å */ + /* COMET IIã¡ã¢ãªãªã¼ãã¼ã®å ´åãã¨ã©ã¼çºç */ if(adr >= sys->memsize) { setcerr(119, word2n(adr)); /* out of COMET II memory */ + return; } - if(cerr->num == 0) { - (sys->memory)[adr] = word; - if(pass == SECOND && asmode.asdetail == true) { - fprintf(stdout, "\t#%04X\t#%04X\n", adr, word); - } - status = true; + (sys->memory)[adr] = word; + if(pass == SECOND && asmode.asdetail == true) { + fprintf(stdout, "\t#%04X\t#%04X\n", adr, word); } - return status; } /** @@ -590,22 +566,23 @@ WORD getadr(const char *prog, const char *str, PASS pass) /** * 1è¡ãã¢ã»ã³ãã« + * passã1ã®å ´åã¯ã©ãã«ãç»é²ãã2ã®å ´åã¯ã©ãã«ããã¢ãã¬ã¹ãèªã¿è¾¼ã */ bool assembleline(const char *line, PASS pass) { CMDLINE *cmdl; - bool status = true; + bool stat = true; int i; cmdl = linetok(line); - status = (cerr->num == 0) ? true : false; + stat = (cerr->num == 0) ? true : false; if(cmdl != NULL) { - if(status == true) { + if(stat == true) { if(pass == FIRST && cmdl->label != NULL) { - status = addlabel(asptr->prog, cmdl->label, asptr->ptr); + stat = addlabel(asptr->prog, cmdl->label, asptr->ptr); } - if(status == true) { - status = assembletok(cmdl, pass); + if(stat == true) { + stat = assembletok(cmdl, pass); } FREE(cmdl->label); } @@ -618,7 +595,7 @@ bool assembleline(const char *line, PASS pass) FREE(cmdl->cmd); } FREE(cmdl); - return status; + return stat; } /** @@ -634,12 +611,11 @@ void addcerrlist_assemble() /** * æå®ãããååã®ãã¡ã¤ã«ãã¢ã»ã³ãã« - * 1åç®ã§ã¯ã©ãã«ãç»é²ãã2åç®ã§ã¯ã©ãã«ããã¢ãã¬ã¹ãèªã¿è¾¼ã * ã¢ã»ã³ãã«å®äºæã¯trueãã¨ã©ã¼çºçæã¯falseãè¿ã */ bool assemblefile(const char *file, PASS pass) { - int lineno = 0; + int lineno = 1; char *line; FILE *fp; @@ -647,12 +623,8 @@ bool assemblefile(const char *file, PASS pass) perror(file); return false; } - line = malloc_chk(LINESIZE + 1, "assemble.line"); - while(fgets(line, LINESIZE, fp)) { - lineno++; - if((pass == FIRST && asmode.src == true) || - (pass == SECOND && asmode.asdetail == true)) - { + for(line = malloc_chk(LINESIZE + 1, "assemble.line"); fgets(line, LINESIZE, fp); lineno++) { + if((pass == FIRST && asmode.src == true) || (pass == SECOND && asmode.asdetail == true)) { printline(stdout, file, lineno, line); } if(assembleline(line, pass) == false) {