{ "", NULL }
};
-ASPTR *asptr;
+ASPTR *asptr = NULL;
ASMODE asmode = {false, false, false, false, false};
WORD getadr(const char *prog, const char *str, PASS pass)
{
- WORD adr = 0x0;
+ WORD adr = 0;
if(str[0] == '=') {
adr = getliteral(str, pass);
WORD grword(const char *str, bool is_x)
{
- WORD r;
+ WORD r = 0;
/* "GR[0-7]" 以外の文字列では、0xFFFFを返して終了 */
if(strlen(str) != 3 ||
/* GR0は指標レジスタとして用いることができない */
if(is_x == true && r == 0x0) {
setcerr(120, ""); /* GR0 in operand x */
- return 0x0;
+ return 0;
}
return r;
}
void writememory(WORD word, WORD adr, PASS pass)
{
- char *n;
+ char *n = NULL;
/* メモリオーバーの場合、エラー発生 */
if(adr >= sys->memsize) {
void writestr(const char *str, bool literal, PASS pass)
{
assert(str[0] == '\'');
- int i;
bool lw = false;
/* 「'」の場合、1文字スキップし、次の文字が「'」でなければ正常終了 */
- for(i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
+ for(int i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
/* 「'」が閉じないまま文字列が終了した場合はエラー */
if(!str[i]) {
setcerr(123, str); /* unclosed quote */
void writedc(const char *str, PASS pass)
{
- WORD adr = 0x0;
+ WORD adr = 0;
if(*str == '\'') {
writestr(str, false, pass);
void assemble_ds(const CMDLINE *cmdl, PASS pass)
{
- int i;
if(cmdl->opd->opdc != 1) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 0; i < atoi(cmdl->opd->opdv[0]); i++) {
+ for(int i = 0; i < atoi(cmdl->opd->opdv[0]); i++) {
writememory(0x0, (asptr->ptr)++, pass);
if(cerr->num > 0) {
break;
void assemble_dc(const CMDLINE *cmdl, PASS pass)
{
- int i;
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc >= OPDSIZE) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 0; i < cmdl->opd->opdc; i++) {
+ for(int i = 0; i < cmdl->opd->opdc; i++) {
writedc(cmdl->opd->opdv[i], pass);
if(cerr->num > 0) {
break;
void assemble_in(const CMDLINE *cmdl, PASS pass)
{
char *line = malloc_chk(LINESIZE + 1, "assemble_in.line");
+
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) {
setcerr(106, ""); /* operand count mismatch */
return;
void assemble_out(const CMDLINE *cmdl, PASS pass)
{
char *line = malloc_chk(LINESIZE + 1, "assemble_out.line");
+
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) {
setcerr(106, ""); /* operand count mismatch */
return;
void assemble_rpush(const CMDLINE *cmdl, PASS pass)
{
- int i;
char *line = malloc_chk(LINESIZE + 1, "assemble_rpush.line");
+
if(cmdl->opd->opdc > 0) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 1; i <= GRSIZE-1; i++) {
+ for(int i = 1; i <= GRSIZE-1; i++) {
sprintf(line, " PUSH 0,GR%d", i);
assembleline(line, pass);
}
void assemble_rpop(const CMDLINE *cmdl, PASS pass)
{
- int i;
char *line = malloc_chk(LINESIZE + 1, "assemble_rpop.line");
+
if(cmdl->opd->opdc > 0) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = GRSIZE-1; i >= 1; i--) {
+ for(int i = GRSIZE-1; i >= 1; i--) {
sprintf(line, " POP GR%d", i);
assembleline(line, pass);
}
bool casl2cmd(CMD *cmdtbl, const CMDLINE *cmdl, PASS pass)
{
- int i;
- void (*cmdptr)();
- for(i = 0; cmdtbl[i].name[0]; i++) {
+ void (*cmdptr)() = NULL;
+
+ for(int i = 0; cmdtbl[i].name[0]; i++) {
if(strcmp(cmdl->cmd, cmdtbl[i].name) == 0) {
cmdptr = cmdtbl[i].ptr;
(*cmdptr)(cmdl, pass);
bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass)
{
- WORD cmd, r_r1, x_r2, adr;
+ WORD cmd = 0;
+ WORD r_r1 = 0;
+ WORD x_r2 = 0;
+ WORD adr = 0;
/* オペランドなし */
if(cmdl->opd->opdc == 0) {
bool assembleline(const char *line, PASS pass)
{
- CMDLINE *cmdl;
+ CMDLINE *cmdl = NULL;
bool stat = true;
- int i;
cmdl = linetok(line);
stat = (cerr->num == 0) ? true : false;
}
FREE(cmdl->label);
if(cmdl->opd != NULL) {
- for(i = 0; i < cmdl->opd->opdc; i++) {
+ for(int i = 0; i < cmdl->opd->opdc; i++) {
FREE(cmdl->opd->opdv[i]);
}
}
bool assemblefile(const char *file, PASS pass)
{
int lineno = 1;
- char *line;
- FILE *fp;
+ char *line = NULL;
+ FILE *fp = NULL;
if((fp = fopen(file, "r")) == NULL) {
cerr->num = errno;
void outassemble(const char *file)
{
- FILE *fp;
+ FILE *fp = NULL;
if((fp = fopen(file, "w")) == NULL) {
perror(file);