#include "casl2.h"
#include "assemble.h"
+/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */
+ASMODE asmode = {false, false, false, false, false};
+
/* 値を格納するポインタ */
WORD ptr;
/* 他のプログラムで参照する入口名 */
char *prog;
-/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */
-ASMODE asmode = {false, false, false, false, false};
-
/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */
/* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */
return 0xFFFF;
}
r = (WORD)(*(str+2) - '0');
- /* 指標レジスタとして用いることはできない */
+ /* GR0は指標レジスタとして用いることができない */
if(is_x == true && r == 0x0) {
setcerr(120, NULL); /* GR0 in operand x */
return 0x0;
}
if(cerrno == 0) {
memory[adr] = word;
- if(pass == SECOND && (&asmode)->asdetail == true) {
+ if(pass == SECOND && asmode.asdetail == true) {
fprintf(stdout, "\t#%04X\t#%04X\n", adr, word);
}
status = true;
for(; ;) {
/* 閉じ「'」がないまま文字列が終了した場合 */
if(*p == '\0') {
- setcerr(123, str); /* illegal string */
+ setcerr(123, str); /* unclosed quote */
break;
}
/* 「'」の場合、次の文字が「'」でない場合は正常終了 */
return status;
}
+void printline(FILE *stream, const char *filename, int lineno, char *line) {
+ fprintf(stream, "%s:%5d:%s", filename, lineno, line);
+}
+
/* 指定された名前のファイルをアセンブル */
/* 2回実行される */
bool assemble(const char *file, PASS pass)
char *line;
FILE *fp;
- if(create_cmdtype_code() == false) {
- return false;
- }
if((fp = fopen(file, "r")) == NULL) {
perror(file);
return false;
}
for(; ;) {
cmdl = malloc(sizeof(CMDLINE));
- line = malloc(LINESIZE+1);
+ line = malloc(LINESIZE + 1);
if((line = fgets(line, LINESIZE, fp)) == NULL) {
break;
}
lineno++;
- if((pass == FIRST && (&asmode)->src == true) ||
- (pass == SECOND && (&asmode)->asdetail == true))
+ if((pass == FIRST && asmode.src == true) ||
+ (pass == SECOND && asmode.asdetail == true))
{
- fprintf(stdout, "%s:%5d:%s", file, lineno, line);
+ printline(stdout, file, lineno, line);
}
if((cmdl = linetok(line)) != NULL) {
if(pass == FIRST && cmdl->label != NULL) {
}
}
if(cerrno > 0) {
- fprintf(stderr, "Assemble error - %d: %s\n %s:%d: %s\n", cerrno, cerrmsg, file, lineno, line);
+ fprintf(stderr, "Assemble error - %d: %s\n", cerrno, cerrmsg);
+ printline(stderr, file, lineno, line);
status = false;
}
fclose(fp);