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"
43 * 0x[02468ace]1 2 24 AJMP addr
44 *____________________________________________________________________________
49 t_uc51::inst_ajmp_addr(uchar code)
53 h= (code >> 5) & 0x07;
56 PC= (PC & 0xf800) | (h*256 + l);
62 * 0x10 3 12 JBC bit,addr
63 *____________________________________________________________________________
68 t_uc51::inst_jbc_bit_addr(uchar code)
70 uchar bitaddr, *addr, jaddr;
74 addr = get_bit(bitaddr, &event_at.ri, &event_at.rs);
75 if (*addr & BIT_MASK(bitaddr))
77 (*addr)&= ~BIT_MASK(bitaddr);
78 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
86 *____________________________________________________________________________
91 t_uc51::inst_ljmp(uchar code)
93 PC= fetch()*256 + fetch();
100 * 0x[13579bdf]1 2 24 ACALL addr
101 *____________________________________________________________________________
106 t_uc51::inst_acall_addr(uchar code)
108 uchar h, l, *sp, *aof_SP;
111 h= (code >> 5) & 0x07;
113 aof_SP= &((sfr->umem8)[SP]);
114 //MEM(MEM_SFR)[SP]++;
116 proc_write_sp(*aof_SP);
117 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
120 (*sp)= PC & 0xff; // push low byte
123 //MEM(MEM_SFR)[SP]++;
125 proc_write_sp(*aof_SP);
126 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
129 (*sp)= (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)
144 uchar h= 0, l= 0, *sp, *aof_SP;
152 aof_SP= &((sfr->umem8)[SP]);
153 //MEM(MEM_SFR)[SP]++;
155 proc_write_sp(*aof_SP);
156 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
159 (*sp)= PC & 0xff; // push low byte
163 //MEM(MEM_SFR)[SP]++;
165 proc_write_sp(*aof_SP);
166 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
169 (*sp)= (PC >> 8) & 0xff; // push high byte
179 * 0x20 3 24 JB bit,addr
180 *____________________________________________________________________________
185 t_uc51::inst_jb_bit_addr(uchar code)
187 uchar *addr, bitaddr, jaddr;
189 addr= get_bit(bitaddr= fetch(), &event_at.ri, &event_at.rs);
192 if (read(addr) & BIT_MASK(bitaddr))
193 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
200 *____________________________________________________________________________
205 t_uc51::inst_ret(uchar code)
207 uchar h, l, *sp, *aof_SP;
210 aof_SP= &((sfr->umem8)[SP]);
211 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
215 //MEM(MEM_SFR)[SP]--;
217 proc_write_sp(*aof_SP);
220 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
224 //MEM(MEM_SFR)[SP]--;
226 proc_write_sp(*aof_SP);
233 * 0x30 3 24 JNB bit,addr
234 *____________________________________________________________________________
239 t_uc51::inst_jnb_bit_addr(uchar code)
241 uchar *addr, bitaddr, jaddr;
243 addr= get_bit(bitaddr= fetch(), &event_at.ri, &event_at.rs);
246 if (!(read(addr) & BIT_MASK(bitaddr)))
247 PC= (PC + (signed char)jaddr) & (get_mem_size(MEM_ROM)-1);
254 *____________________________________________________________________________
259 t_uc51::inst_reti(uchar code)
261 uchar h, l, *sp, *aof_SP;
264 aof_SP= &((sfr->umem8)[SP]);
265 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
269 //MEM(MEM_SFR)[SP]--;
271 proc_write_sp(*aof_SP);
274 sp= get_indirect(*aof_SP/*sfr->get(SP)*/, &res);
278 //MEM(MEM_SFR)[SP]--;
280 proc_write_sp(*aof_SP);
284 class it_level *il= (class it_level *)(it_levels->top());
288 il= (class it_level *)(it_levels->pop());
297 *____________________________________________________________________________
302 t_uc51::inst_jc_addr(uchar code)
309 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
317 *____________________________________________________________________________
322 t_uc51::inst_jnc_addr(uchar code)
329 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
337 *____________________________________________________________________________
342 t_uc51::inst_jz_addr(uchar code)
349 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
356 *____________________________________________________________________________
361 t_uc51::inst_jnz_addr(uchar code)
368 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
374 * 0x73 1 24 JMP @A+DPTR
375 *____________________________________________________________________________
380 t_uc51::inst_jmp_$a_dptr(uchar code)
382 PC= (sfr->get(DPH)*256 + sfr->get(DPL) +
383 read_mem(MEM_SFR, ACC)) &
390 * 0x80 2 24 SJMP addr
391 *____________________________________________________________________________
396 t_uc51::inst_sjmp(uchar code)
398 signed char target= fetch();
399 PC= (PC + target) & (EROM_SIZE -1);
406 * 0xb4 3 24 CJNE A,#data,addr
407 *____________________________________________________________________________
412 t_uc51::inst_cjne_a_$data_addr(uchar code)
419 SET_C(sfr->get(ACC) < data);
420 if (read_mem(MEM_SFR, event_at.rs= ACC) != data)
421 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
427 * 0xb5 3 24 CJNE A,addr,addr
428 *____________________________________________________________________________
433 t_uc51::inst_cjne_a_addr_addr(uchar code)
435 uchar data, *addr, jaddr;
437 addr = get_direct(fetch(), &event_at.ri, &event_at.rs);
441 SET_C(sfr->get(ACC) < data);
442 if (sfr->get(event_at.rs= ACC) != data)
443 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
449 * 0xb6-0xb7 3 24 CJNE @Ri,#data,addr
450 *____________________________________________________________________________
455 t_uc51::inst_cjne_$ri_$data_addr(uchar code)
457 uchar *addr, data, jaddr;
460 addr = get_indirect(event_at.ri= *(get_reg(code & 0x01)), &res);
466 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
472 * 0xb8-0xbf 3 24 CJNE Rn,#data,addr
473 *____________________________________________________________________________
478 t_uc51::inst_cjne_rn_$data_addr(uchar code)
480 uchar *reg, data, jaddr;
482 reg = get_reg(code & 0x07, &event_at.ri);
488 PC= (PC + (signed char)jaddr) & (EROM_SIZE - 1);
494 * 0xd5 3 24 DJNZ addr,addr
495 *____________________________________________________________________________
500 t_uc51::inst_djnz_addr_addr(uchar code)
504 addr = get_direct(fetch(), &event_at.wi, &event_at.ws);
508 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
514 * 0xd8-0xdf 2 24 DJNZ Rn,addr
515 *____________________________________________________________________________
520 t_uc51::inst_djnz_rn_addr(uchar code)
524 reg = get_reg(code & 0x07, &event_at.wi);
528 PC= (PC + (signed char)jaddr) & (EROM_SIZE-1);
533 /* End of s51.src/jmp.cc */