- int i = 0;
- MACROCMDID cmdid;
- bool status = false;
- MACROCMD macrocmd[] = {
- { IN, 2, 2, "IN" },
- { OUT, 2, 2, "OUT" },
- { RPUSH, 0, 0, "RPUSH" },
- { RPOP, 0, 0, "RPOP" },
- { 0, 0, 0, NULL }
- };
-
- do {
- if(strcmp(cmdl->cmd, macrocmd[i].cmd) == 0) {
- if(cmdl->opd->opdc < macrocmd[i].opdc_min ||
- cmdl->opd->opdc > macrocmd[i].opdc_max)
- {
- setcerr(106, NULL); /* operand count mismatch */
- return false;
- }
- cmdid = macrocmd[i].cmdid;
- break;
+ char *line = malloc_chk(LINESIZE + 1, "assemble_out.line");
+ if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) {
+ setcerr(106, ""); /* operand count mismatch */
+ return;
+ }
+ assembleline(" PUSH 0,GR1", pass);
+ assembleline(" PUSH 0,GR2", pass);
+ sprintf(line, " LAD GR1,%s", cmdl->opd->opdv[0]);
+ assembleline(line, pass);
+ sprintf(line, " LAD GR2,%s", cmdl->opd->opdv[1]);
+ 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(line);
+}
+
+/**
+ * マクロ命令 "RPUSH" をメモリに書き込む
+ * \code
+ * PUSH 0,GR1
+ * PUSH 0,GR2
+ * PUSH 0,GR3
+ * PUSH 0,GR4
+ * PUSH 0,GR5
+ * PUSH 0,GR6
+ * PUSH 0,GR7
+ * \endcode
+ * \relates casl2cmd
+ */
+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++) {
+ sprintf(line, " PUSH 0,GR%d", i);
+ assembleline(line, pass);
+ }
+ FREE(line);
+}
+
+/**
+ * マクロ命令 "RPOP" をメモリに書き込む\n
+ * \code
+ * POP GR7
+ * POP GR6
+ * POP GR5
+ * POP GR4
+ * POP GR3
+ * POP GR3
+ * POP GR2
+ * POP GR1
+ * \endcode
+ * \relates casl2cmd
+ */
+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--) {
+ sprintf(line, " POP GR%d", i);
+ assembleline(line, pass);
+ }
+ FREE(line);
+}
+
+/**
+ * アセンブラ言語CASL IIの命令を処理\n
+ * 命令が表で定義されている場合はtrue、それ以外の場合はfalseを返す\n
+ * エラー発生時は、cerrを設定\n
+ * 関数へのポインタで呼び出す関数は、Class Reference 参照
+ * \class casl2cmd
+ */
+bool casl2cmd(CMD *cmdtbl, const CMDLINE *cmdl, PASS pass)
+{
+ int i;
+ void (*cmdptr)();
+ for(i = 0; *(cmdtbl[i].name) != '\0'; i++) {
+ if(strcmp(cmdl->cmd, cmdtbl[i].name) == 0) {
+ cmdptr = cmdtbl[i].ptr;
+ (*cmdptr)(cmdl, pass);
+ return true;