2 * Simulator of microcontrollers (jmp.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 /* Bugs fixed by Sandeep Dutta:
29 * relative<->absolute jump in "jmp @a+dptr"
41 #include "interruptcl.h"
45 * 0x[02468ace]1 2 24 AJMP addr
46 *____________________________________________________________________________
51 t_uc51::inst_ajmp_addr(uchar code)
55 h= (code >> 5) & 0x07;
58 PC= (PC & 0xf800) | (h*256 + l);
64 * 0x10 3 12 JBC bit,addr
65 *____________________________________________________________________________
70 t_uc51::inst_jbc_bit_addr(uchar code)
79 if ((mem= bit2mem(bitaddr, &a, &m)) == 0)
81 t_mem d= mem->read(a, HW_PORT);
82 mem->write(a, d & ~m);
84 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
92 *____________________________________________________________________________
97 t_uc51::inst_ljmp(uchar code)
99 PC= fetch()*256 + fetch();
106 * 0x[13579bdf]1 2 24 ACALL addr
107 *____________________________________________________________________________
112 t_uc51::inst_acall_addr(uchar code)
118 h= (code >> 5) & 0x07;
120 sp= sfr->wadd(SP, 1);
122 stck= iram->get_cell(sp);
123 stck->write(PC & 0xff); // push low byte
126 sp= sfr->wadd(SP, 1);
128 stck= iram->get_cell(sp);
129 stck->write((PC >> 8) & 0xff); // push high byte
130 PC= (PC & 0xf800) | (h*256 + l);
136 * 0x12 3 24 LCALL addr
137 *____________________________________________________________________________
142 t_uc51::inst_lcall(uchar code, uint addr)
153 sp= sfr->wadd(SP, 1);
155 stck= iram->get_cell(sp);
156 stck->write(PC & 0xff); // push low byte
160 sp= sfr->wadd(SP, 1);
162 stck= iram->get_cell(sp);
163 stck->write((PC >> 8) & 0xff); // push high byte
173 * 0x20 3 24 JB bit,addr
174 *____________________________________________________________________________
179 t_uc51::inst_jb_bit_addr(uchar code)
181 uchar bitaddr, jaddr;
186 if ((mem= bit2mem(bitaddr= fetch(), &a, &m)) == 0)
190 if (mem->read(a) & m)
191 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
198 *____________________________________________________________________________
203 t_uc51::inst_ret(uchar code)
210 stck= iram->get_cell(sp);
212 sp= sfr->wadd(SP, -1);
215 stck= iram->get_cell(sp);
217 sp= sfr->wadd(SP, -1);
224 * 0x30 3 24 JNB bit,addr
225 *____________________________________________________________________________
230 t_uc51::inst_jnb_bit_addr(uchar code)
232 uchar bitaddr, jaddr;
237 if ((mem= bit2mem(bitaddr= fetch(), &a, &m)) == 0)
241 if (!(mem->read(a) & m))
242 PC= (PC + (signed char)jaddr) & (get_mem_size(MEM_ROM)-1);
249 *____________________________________________________________________________
254 t_uc51::inst_reti(uchar code)
261 stck= iram->get_cell(sp);
263 sp= sfr->wadd(SP, -1);
266 stck= iram->get_cell(sp);
268 sp= sfr->wadd(SP, -1);
271 interrupt->was_reti= DD_TRUE;
272 class it_level *il= (class it_level *)(it_levels->top());
276 il= (class it_level *)(it_levels->pop());
285 *____________________________________________________________________________
290 t_uc51::inst_jc_addr(uchar code)
297 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
304 *____________________________________________________________________________
309 t_uc51::inst_jnc_addr(uchar code)
316 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
323 *____________________________________________________________________________
328 t_uc51::inst_jz_addr(uchar code)
335 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
342 *____________________________________________________________________________
347 t_uc51::inst_jnz_addr(uchar code)
354 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
360 * 0x73 1 24 JMP @A+DPTR
361 *____________________________________________________________________________
366 t_uc51::inst_jmp_Sa_dptr(uchar code)
368 PC= (sfr->read(DPH)*256 + sfr->read(DPL) + acc->read()) &
376 * 0x80 2 24 SJMP addr
377 *____________________________________________________________________________
382 t_uc51::inst_sjmp(uchar code)
384 signed char target= fetch();
386 PC= (PC + target) & (EROM_SIZE -1);
393 * 0xb4 3 24 CJNE A,#data,addr
394 *____________________________________________________________________________
399 t_uc51::inst_cjne_a_Sdata_addr(uchar code)
401 uchar data, jaddr, ac;
406 SFR_SET_C((ac= acc->read()) < data);
408 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
414 * 0xb5 3 24 CJNE A,addr,addr
415 *____________________________________________________________________________
420 t_uc51::inst_cjne_a_addr_addr(uchar code)
426 cell= get_direct(a= fetch());
430 SFR_SET_C(acc->get() < data);
431 if (acc->read() != data)
432 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
438 * 0xb6-0xb7 3 24 CJNE @Ri,#data,addr
439 *____________________________________________________________________________
444 t_uc51::inst_cjne_Sri_Sdata_addr(uchar code)
449 cell= iram->get_cell(get_reg(code & 0x01)->read());
454 SFR_SET_C((d= cell->read()) < data);
456 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
462 * 0xb8-0xbf 3 24 CJNE Rn,#data,addr
463 *____________________________________________________________________________
468 t_uc51::inst_cjne_rn_Sdata_addr(uchar code)
473 reg = get_reg(code & 0x07);
478 SFR_SET_C((r= reg->read()) < data);
480 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
486 * 0xd5 3 24 DJNZ addr,addr
487 *____________________________________________________________________________
492 t_uc51::inst_djnz_addr_addr(uchar code)
497 cell = get_direct(fetch());
500 t_mem d= cell->read(HW_PORT);//cell->wadd(-1);
503 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
509 * 0xd8-0xdf 2 24 DJNZ Rn,addr
510 *____________________________________________________________________________
515 t_uc51::inst_djnz_rn_addr(uchar code)
520 reg = get_reg(code & 0x07);
523 t_mem r= reg->wadd(-1);
525 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
530 /* End of s51.src/jmp.cc */