home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * m_cpu.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include "mnemonics.h"
- #include "error.h"
- #include "option.h"
- #include "put.h"
- #include "input.h"
- #include "global.h"
- #include "expr.h"
- #include "area.h"
- #include "get.h"
- #include "m_cpu.h"
-
-
-
- /** DATA dst=lhs<op>rhs **/
-
- static void dstlhsrhs(unsigned int ir)
- {
- unsigned int op;
- op = getCpuReg();
- ir |= DST_OP(op);
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after dst.");
- op = getCpuReg();
- ir |= LHS_OP(op);
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after lhs.");
- ir = getRhs(FALSE,ir);
- putIns(ir);
- }
-
- static void dstrhs(unsigned int ir)
- {
- unsigned int op;
- op = getCpuReg();
- ir |= DST_OP(op);
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after dst.");
- ir = getRhs(FALSE,ir);
- putIns(ir);
- }
-
- void m_adc(unsigned int cc)
- {
- dstlhsrhs(cc|M_ADC);
- }
-
- void m_add(unsigned int cc)
- {
- dstlhsrhs(cc|M_ADD);
- }
-
- void m_and(unsigned int cc)
- {
- dstlhsrhs(cc|M_AND);
- }
-
- void m_bic(unsigned int cc)
- {
- dstlhsrhs(cc|M_BIC);
- }
-
-
- void m_eor(unsigned int cc)
- {
- dstlhsrhs(cc|M_EOR);
- }
-
- void m_mov(unsigned int cc)
- {
- dstrhs(cc|M_MOV);
- }
-
- void m_mvn(unsigned int cc)
- {
- dstrhs(cc|M_MVN);
- }
-
- void m_orr(unsigned int cc)
- {
- dstlhsrhs(cc|M_ORR);
- }
-
- void m_rsb(unsigned int cc)
- {
- dstlhsrhs(cc|M_RSB);
- }
-
- void m_rsc(unsigned int cc)
- {
- dstlhsrhs(cc|M_RSC);
- }
-
- void m_sbc(unsigned int cc)
- {
- dstlhsrhs(cc|M_SBC);
- }
-
- void m_sub(unsigned int cc)
- {
- dstlhsrhs(cc|M_SUB);
- }
-
- /** DATA test **/
-
- static void lhsrhs(unsigned int ir)
- {
- unsigned int op;
- op = getCpuReg();
- ir |= LHS_OP(op);
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after lhs.");
- ir = getRhs(FALSE,ir);
- putIns(ir);
- }
-
- void m_cmn(unsigned int cc)
- {
- lhsrhs(cc|M_CMN);
- }
-
- void m_cmp(unsigned int cc)
- {
- lhsrhs(cc|M_CMP);
- }
-
- void m_teq(unsigned int cc)
- {
- lhsrhs(cc|M_TEQ);
- }
-
- void m_tst(unsigned int cc)
- {
- lhsrhs(cc|M_TST);
- }
-
- /** DATA 1a **/
-
- extern int pedantic;
-
- static void onlyregs(BOOL acc, unsigned int ir)
- {
- WORD dst,rhs,lhs;
- dst = getCpuReg();
- ir |= DST_MUL(dst);
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after dst.");
- lhs = getCpuReg();
- skipblanks();
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after lhs.");
- rhs = getCpuReg();
- if(dst == lhs) {
- if(dst == rhs)
- error(ErrorError,TRUE,"Destination and left operand are the same register %d.",dst);
- else {
- if(pedantic)
- error(ErrorInfo,TRUE,"Changing order of operands in %s.",acc?"mla":"mul");
- { int t = lhs; lhs = rhs; rhs = t; }
- }
- }
- ir |= LHS_MUL(lhs);
- ir |= RHS_MUL(rhs);
- skipblanks();
- if(acc) {
- if(inputLook() == ',') {inputSkip(); skipblanks();}
- else error(ErrorError,TRUE,"Inserting a comma after rhs.");
- ir |= ACC_MUL(getCpuReg());
- skipblanks();
- }
- putIns(ir);
- }
-
- void m_mla(unsigned int cc)
- {
- onlyregs(TRUE,cc|M_MLA);
- }
-
- void m_mul(unsigned int cc)
- {
- onlyregs(FALSE,cc|M_MUL);
- }
-