void writestr(const char *str, bool literal, PASS pass)
{
- assert(*str == '\'');
- const char *p = str + 1;
+ assert(str[0] == '\'');
+ int i;
bool lw = false;
- for(; ;) {
- /* 閉じ「'」がないまま文字列が終了した場合 */
- if(!p[0]) {
+ /* 「'」の場合、1文字スキップし、次の文字が「'」でなければ正常終了 */
+ for(i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
+ /* 「'」が閉じないまま文字列が終了した場合はエラー */
+ if(!str[i]) {
setcerr(123, str); /* unclosed quote */
break;
}
- /* 「'」の場合、次の文字が「'」でない場合は正常終了 */
- if(p[0] == '\'') {
- p++;
- if(p[0] != '\'') {
- break;
- }
- } else if(literal == true && lw == true) {
+ if(literal == true && lw == true) {
setcerr(124, str); /* more than one character in literal */
break;
}
/*リテラルの場合はリテラル領域に書込 */
if(literal == true) {
- writememory(p[0], (asptr->lptr)++, pass);
+ writememory(str[i], (asptr->lptr)++, pass);
lw = true;
} else {
- writememory(p[0], (asptr->ptr)++, pass);
+ writememory(str[i], (asptr->ptr)++, pass);
}
- p++;
}
}
if(*str == '\'') {
writestr(str, false, pass);
} else {
- if(*str == '#' || isdigit(*str) || *str == '-') {
+ if(str[0] == '#' || isdigit(str[0]) || str[0] == '-') {
adr = nh2word(str);
} else {
if(pass == SECOND && (adr = getlabel(asptr->prog, str)) == 0xFFFF) {
}
void disassemble_cmd_adr_x(CMDTYPE cmdtype, const char *cmdname, WORD word, WORD adr, WORD pradr)
{
- WORD x;
- char *g;
+ WORD x = 0;
+ char *g = NULL;
int cnt = 0;
cnt += fprintf(stdout, " %-7s ", cmdname);
if(cmdtype == R_ADR_X) {
void disassemble_cmd_r(CMDTYPE cmdtype, const char *cmdname, WORD word, WORD pradr)
{
- char *g, *g1, *g2;
+ char *g = NULL, *g1 = NULL, *g2 = NULL;
int cnt = 0;
cnt += fprintf(stdout, " %-7s ", cmdname);
if(cmdtype == R1_R2) {
fprintf(stdout, "MAIN START\n");
for(word = fgetword(fp); !feof(fp); i++, word = fgetword(fp)) {
- cmdname = getcmdname(cmd = word & 0xFF00);
+ cmd = word & 0xFF00;
+ cmdname = getcmdname(cmd);
cmdtype = getcmdtype(cmd);
if(word == 0){
if(inst == true) { /* プログラム領域の場合 */
disassemble_cmd_r(NONE, "nop", 0, i);
} else { /* データ領域の場合 */
- if((zcnt = zero_data_cnt(fp)) == 1) { /* 1つだけの0はDCとみなす */
+ zcnt = zero_data_cnt(fp);
+ if(zcnt == 1) { /* 1つだけの0はDCとみなす */
disassemble_dc(0, i);
} else { /* 連続する0はDSとみなす */
disassemble_ds(zcnt, i);
void disassemble_memory(WORD start, WORD end)
{
- WORD i, word, cmd;
+ WORD i, cmd;
CMDTYPE cmdtype = 0;
char *cmdname;
bool inst = true;
for(i = start; i <= end; i++) {
- word = sys->memory[i];
- cmdname = getcmdname(cmd = word & 0xFF00);
+ cmd = sys->memory[i] & 0xFF00;
+ cmdname = getcmdname(cmd);
cmdtype = getcmdtype(cmd);
- if(word == 0) {
+ if(sys->memory[i] == 0) {
if(inst == true) { /* プログラム領域の場合 */
disassemble_cmd_r(NONE, "nop", 0, i);
} else { /* データ領域の場合。メモリーでは、DC 0とみなす */
disassemble_dc(0, i);
}
} else if(cmd == 0) {
- disassemble_dc(word, i);
+ disassemble_dc(sys->memory[i], i);
} else {
if(cmdtype == R_ADR_X || cmdtype == ADR_X) {
- disassemble_cmd_adr_x(cmdtype, cmdname, word, sys->memory[i+1], i);
+ disassemble_cmd_adr_x(cmdtype, cmdname, sys->memory[i], sys->memory[i+1], i);
i++;
} else {
- disassemble_cmd_r(cmdtype, cmdname, word, i);
+ disassemble_cmd_r(cmdtype, cmdname, sys->memory[i], i);
}
inst = (cmd != 0x8100) ? true : false;
}
WORD n2word(const char *str)
{
- assert(isdigit(*str) || *str == '-');
+ assert(isdigit(str[0]) || str[0] == '-');
char *check;
int n;
WORD h2word(const char *str)
{
- assert(*str == '#');
+ assert(str[0] == '#');
WORD w = 0x0;
char *check;
enum {
MAXLEN = 5, /* WORD値を10進数で表したときの最大桁数 */
};
- char *p = malloc_chk(MAXLEN + 1, "word2n.p"), *digit = malloc_chk(MAXLEN + 1, "word2n.digit");
+ char *n = malloc_chk(MAXLEN + 1, "word2n.n"), tmp;
int i = 0, j;
do{
- p[i++] = word % 10 + '0';
+ n[i++] = word % 10 + '0';
} while((word /= 10) > 0);
for(j = 0; j < i; j++) {
- digit[j] = p[(i-1)-j];
+ tmp = n[j];
+ n[j] = n[(i-1)-j];
+ n[(i-1)-j] = tmp;
}
- digit[j] = '\0';
- FREE(p);
- return digit;
+ n[j] = '\0';
+ return n;
}
char *word2bit(const WORD word)
void print_dumpword(WORD word, bool logicalmode)
{
- char *bit = word2bit(word);
+ const char *bit = word2bit(word);
if(logicalmode == true) {
fprintf(stdout, "%6d", word);
} else if(word == '\t') {
fprintf(stdout, " = \'\\t\'");
}
- FREE(bit);
}