2 * Simulator of microcontrollers (jmp_inst.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
36 *____________________________________________________________________________
40 cl_avr::ijmp(t_mem code)
44 z= ram->get(ZH)*256 + ram->get(ZL);
45 PC= ((PC & ~0xffff) | z) % rom->size;
51 cl_avr::eijmp(t_mem code)
58 cl_avr::icall(t_mem code)
65 cl_avr::eicall(t_mem code)
72 cl_avr::ret(t_mem code)
79 cl_avr::reti(t_mem code)
89 *____________________________________________________________________________
93 cl_avr::rjmp_k(t_mem code)
95 long k= code & 0xfff, pc;
109 cl_avr::rcall_k(t_mem code)
116 * Compare Skip if Equal
117 * CPSE Rd,Rr 0<=d<=31, 0<=r<=31
118 * 0001 00rd dddd rrrr
119 *____________________________________________________________________________
123 cl_avr::cpse_Rd_Rr(t_mem code)
128 r= ((code&0x200)>>5)|(code&0xf);
129 if (ram->read(r) == ram->read(d))
131 t_mem next_code= rom->get(PC);
133 struct dis_entry *dt= dis_tbl();
134 while ((next_code & dt[i].mask) != dt[i].code &&
137 if (dt[i].mnemonic != NULL)
139 PC= (PC + dt[i].length) % get_mem_size(MEM_ROM);
152 * 1001 010k kkkk 110k
153 * kkkk kkkk kkkk kkkk
154 *____________________________________________________________________________
158 cl_avr::jmp_k(t_mem code)
162 k= ((code&0x1f0)>>3)|(code&1);
172 * Long Call to a Subroutine
173 * CALL k 0<=k<=64k/4M
174 * 1001 010k kkkk 111k
175 * kkkk kkkk kkkk kkkk
176 *____________________________________________________________________________
180 cl_avr::call_k(t_mem code)
184 k= (((code&0x1f0)>>3)|(code&1))*0x10000;
193 * Branch if Bit in SREG is Set
194 * BRBS s,k 0<=s<=7, -64<=k<=+63
195 * 1111 00kk kkkk ksss
196 *____________________________________________________________________________
200 cl_avr::brbs_s_k(t_mem code)
206 t_mem sreg= ram->get(SREG);
212 PC= (PC+k) % get_mem_size(MEM_ROM);
220 * Branch if Bit in SREG is Cleared
221 * BRBC s,k 0<=s<=7, -64<=k<=+63
222 * 1111 01kk kkkk ksss
223 *____________________________________________________________________________
227 cl_avr::brbc_s_k(t_mem code)
233 t_mem sreg= ram->get(SREG);
239 PC= (PC+k) % get_mem_size(MEM_ROM);
247 * Skip if Bit in Register is Cleared
248 * SBRC Rr,b 0<=r<=31, 0<=b<=7
249 * 1111 110r rrrr Xbbb
250 *____________________________________________________________________________
254 cl_avr::sbrc_Rr_b(t_mem code)
256 t_addr r= (code&0x1f0)>>4;
259 if (!(ram->read(r) & mask))
261 t_mem next_code= rom->get(PC);
263 struct dis_entry *dt= dis_tbl();
264 while ((next_code & dt[i].mask) != dt[i].code &&
267 if (dt[i].mnemonic != NULL)
269 PC= (PC + dt[i].length) % get_mem_size(MEM_ROM);
280 * Skip if Bit in Register is Set
281 * SBRS Rr,b 0<=r<=31, 0<=b<=7
282 * 1111 111r rrrr Xbbb
283 *____________________________________________________________________________
287 cl_avr::sbrs_Rr_b(t_mem code)
289 t_addr r= (code&0x1f0)>>4;
292 if (ram->read(r) & mask)
294 t_mem next_code= rom->get(PC);
296 struct dis_entry *dt= dis_tbl();
297 while ((next_code & dt[i].mask) != dt[i].code &&
300 if (dt[i].mnemonic != NULL)
302 PC= (PC + dt[i].length) % get_mem_size(MEM_ROM);
313 * Skip if Bit in I/O Register is Clear
314 * SBIC P,b 0<=P<=31 0<=b<=7
315 * 1001 1001 pppp pbbb
316 *____________________________________________________________________________
320 cl_avr::sbic_P_b(t_mem code)
324 addr= ((code&0xf8)>>3)+0x20;
326 if (0 == (mask & ram->read(addr)))
329 int size= inst_length(code);
342 * Skip if Bit in I/O Register is Set
343 * SBIS P,b 0<=P<=31 0<=b<=7
344 * 1001 1011 pppp pbbb
345 *____________________________________________________________________________
349 cl_avr::sbis_P_b(t_mem code)
353 addr= ((code&0xf8)>>3)+0x20;
355 if (mask & ram->read(addr))
358 int size= inst_length(code);
370 /* End of avr.src/jump_inst.cc */