+/**
+ * アセンブラ命令DCの処理
+ * \relates casl2cmd
+ */
+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++) {
+ writedc(cmdl->opd->opdv[i], pass);
+ if(cerr->num > 0) {
+ break;
+ }
+ }
+}
+
+/**
+ * マクロ命令 "IN IBUF,LEN" をアセンブル\n
+ * \code
+ * PUSH 0,GR1
+ * PUSH 0,GR2
+ * LAD GR1,IBUF
+ * LAD GR2,LEN
+ * SVC 1
+ * POP GR2
+ * POP GR1
+ * \endcode
+ * \relates casl2cmd
+ */
+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;
+ }
+ 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 1", pass);
+ assembleline(" POP GR2", pass);
+ assembleline(" POP GR1", pass);
+ FREE(line);
+}
+
+/**
+ * マクロ命令 "OUT OBUF,LEN" をアセンブル\n
+ * \code
+ * PUSH 0,GR1
+ * PUSH 0,GR2
+ * LAD GR1,OBUF
+ * LAD GR2,LEN
+ * SVC 2
+ * LAD GR1,=#A
+ * LAD GR2,=1
+ * SVC 2
+ * POP GR2
+ * POP GR1
+ * \endcode
+ * \relates casl2cmd
+ */
+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;
+ }
+ 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;
+ }
+ }
+ return false;
+}