2 * Simulator of microcontrollers (inst.cc)
4 * Copyright (C) 1999,2002 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7 * Other contributors include:
8 * Karl Bongers karl@turbobit.com,
13 /* This file is part of microcontroller simulator: ucsim.
15 UCSIM is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 UCSIM is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with UCSIM; see the file COPYING. If not, write to the Free
27 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
39 cl_xa::get_reg(int word_flag, unsigned int index)
41 //if (index < 3) { /* banked */
43 // return get_word_direct(0x400+index);
45 // return mem_direct[0x400+index];
46 //} else { /* non-banked */
48 return get_word_direct(0x400+index);
50 return mem_direct[0x400+index];
55 cl_xa::inst_NOP(uint code, int operands)
60 #define RI_F0 ((code >> 4) & 0xf)
61 #define RI_70 ((code >> 4) & 0x7)
62 #define RI_0F (code & 0xf)
63 #define RI_07 (code & 0x7)
66 cl_xa::inst_ADD(uint code, int operands)
72 #include "inst_gen.cc"
78 cl_xa::inst_ADDC(uint code, int operands)
84 #include "inst_gen.cc"
90 cl_xa::inst_SUB(uint code, int operands)
96 #include "inst_gen.cc"
101 cl_xa::inst_SUBB(uint code, int operands)
107 #include "inst_gen.cc"
112 cl_xa::inst_CMP(uint code, int operands)
118 #include "inst_gen.cc"
122 cl_xa::inst_AND(uint code, int operands)
128 #include "inst_gen.cc"
132 cl_xa::inst_OR(uint code, int operands)
138 #include "inst_gen.cc"
142 cl_xa::inst_XOR(uint code, int operands)
148 #include "inst_gen.cc"
152 cl_xa::inst_ADDS(uint code, int operands)
157 cl_xa::inst_NEG(uint code, int operands)
162 cl_xa::inst_SEXT(uint code, int operands)
167 cl_xa::inst_MUL(uint code, int operands)
172 cl_xa::inst_DIV(uint code, int operands)
177 cl_xa::inst_DA(uint code, int operands)
182 cl_xa::inst_ASL(uint code, int operands)
187 cl_xa::inst_ASR(uint code, int operands)
192 cl_xa::inst_LEA(uint code, int operands)
197 cl_xa::inst_CPL(uint code, int operands)
202 cl_xa::inst_LSR(uint code, int operands)
207 cl_xa::inst_NORM(uint code, int operands)
212 cl_xa::inst_RL(uint code, int operands)
217 cl_xa::inst_RLC(uint code, int operands)
222 cl_xa::inst_RR(uint code, int operands)
227 cl_xa::inst_RRC(uint code, int operands)
232 cl_xa::inst_MOVS(uint code, int operands)
237 cl_xa::inst_MOVC(uint code, int operands)
242 short srcreg = reg2(RI_07);
243 if (code & 0x0800) { /* word op */
256 if (operands == REG_IREGINC) {
257 set_reg2(RI_07, srcreg+1);
266 cl_xa::inst_MOVX(uint code, int operands)
271 cl_xa::inst_PUSH(uint code, int operands)
277 unsigned short direct_addr = ((operands & 0x7) << 8) | fetch();
281 if (code & 0x0800) { /* word op */
282 store2( sp, get_word_direct(direct_addr));
284 store2( sp, get_byte_direct(direct_addr));
291 unsigned char rlist = fetch();
292 rlist = rlist; //shutup compiler
299 cl_xa::inst_POP(uint code, int operands)
305 unsigned short direct_addr = ((operands & 0x7) << 8) | fetch();
308 if (code & 0x0800) { /* word op */
309 set_word_direct(direct_addr, get2(sp) );
311 set_byte_direct(direct_addr, get2(sp) & 0xff );
319 unsigned char rlist = fetch();
320 rlist = rlist; //shutup compiler
326 cl_xa::inst_XCH(uint code, int operands)
331 cl_xa::inst_SETB(uint code, int operands)
333 unsigned short bitAddr = (code&0x03 << 8) + fetch();
339 cl_xa::inst_CLR(uint code, int operands)
341 unsigned short bitAddr = (code&0x03 << 8) + fetch();
347 cl_xa::inst_MOV(uint code, int operands)
353 #include "inst_gen.cc"
357 cl_xa::inst_ANL(uint code, int operands)
362 cl_xa::inst_ORL(uint code, int operands)
367 cl_xa::inst_BEQ(uint code, int operands)
369 short jmpAddr = fetch1()*2;
370 if (get_psw() & BIT_Z) {
371 PC=(PC+jmpAddr)&0xfffffffe;
376 cl_xa::inst_BR(uint code, int operands)
378 short jmpAddr = fetch1()*2;
379 PC=(PC+jmpAddr)&0xfffffffe;
383 cl_xa::inst_JMP(uint code, int operands)
385 unsigned int jmpaddr;
394 PC = (PC + jmpaddr) & 0xfffffffe;
399 PC |= (reg2(RI_07) & 0xfffe); /* word aligned */
401 /* fixme 2 more... */
406 cl_xa::inst_CALL(uint code, int operands)
408 unsigned int jmpaddr;
418 store2(sp+2, 0); /* segment(not sure about ordering...) */
420 PC = (PC + jmpaddr) & 0xfffffffe;
428 store2(sp+2, 0); /* segment(not sure about ordering...) */
429 jmpaddr = reg2(RI_07);
431 PC = (PC + jmpaddr) & 0xfffffffe;
434 /* fixme 2 more... */
439 cl_xa::inst_RET(uint code, int operands)
441 unsigned int retaddr;
445 //retaddr |= get2(sp+2) << 16);
450 cl_xa::inst_Bcc(uint code, int operands)
455 cl_xa::inst_JB(uint code, int operands)
457 short saddr = (fetch1() * 2);
458 if (get_psw() & BIT_Z) {
464 cl_xa::inst_JNB(uint code, int operands)
469 cl_xa::inst_CJNE(uint code, int operands)
472 case REG_DIRECT_REL8:
475 if (code & 0x800) { // word op
477 int src = get_word_direct( ((code & 0x7)<<4) | fetch1());
478 int addr = (fetch1() * 2);
479 int dst = reg2(RI_F0);
482 flags &= ~BIT_ALL; /* clear these bits */
484 if (result == 0) flags |= BIT_Z;
485 if (result > 0xffff) flags |= BIT_C;
486 if (dst < src) flags |= BIT_N;
492 int src = get_byte_direct( ((code & 0x7)<<4) | fetch1());
493 int addr = (fetch1() * 2);
494 int dst = reg1(RI_F0);
497 flags &= ~BIT_ALL; /* clear these bits */
499 if (result == 0) flags |= BIT_Z;
500 if (result > 0xff) flags |= BIT_C;
501 if (dst < src) flags |= BIT_N;
511 int daddr = ((code & 0x7) << 8) | fetch();
512 int addr = fetch() * 2;
514 if (code & 0x800) { // word op
515 unsigned short tmp = get_word_direct(daddr)-1;
516 set_word_direct(daddr, tmp);
520 unsigned char tmp = get_word_direct(daddr)-1;
521 set_byte_direct(daddr, tmp);
531 cl_xa::inst_DJNZ(uint code, int operands)
536 int addr = (fetch1() * 2);
537 if (code & 0x800) { // word op
538 unsigned short tmp = mov2(0, reg2(RI_F0)-1);
539 set_reg2(RI_F0, tmp);
543 unsigned char tmp = mov1(0, reg1(RI_F0)-1);
544 set_reg1(RI_F0, tmp);
553 int daddr = ((code & 0x7) << 8) | fetch();
554 int addr = fetch() * 2;
556 if (code & 0x800) { // word op
557 unsigned short tmp = get_word_direct(daddr)-1;
558 set_word_direct(daddr, tmp);
562 unsigned char tmp = get_word_direct(daddr)-1;
563 set_byte_direct(daddr, tmp);
574 cl_xa::inst_JZ(uint code, int operands)
576 /* reg1(8) = R4.b, is ACC for MCS51 compatiblility */
577 short saddr = (fetch1() * 2);
584 cl_xa::inst_JNZ(uint code, int operands)
586 short saddr = (fetch1() * 2);
587 /* reg1(8) = R4.b, is ACC for MCS51 compatiblility */
589 PC = (PC + saddr) & 0xfffffe;
594 cl_xa::inst_BKPT(uint code, int operands)
599 cl_xa::inst_TRAP(uint code, int operands)
604 cl_xa::inst_RESET(uint code, int operands)
610 /* End of xa.src/inst.cc */