2 * Simulator of microcontrollers (mov.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 * source<->dest bug in "mov direct,direct"
30 * get register in "mov @ri,address"
46 * 0x74 2 12 MOV A,#data
47 *____________________________________________________________________________
52 t_uc51::inst_mov_a_Sdata(uchar code)
60 * 0x75 3 24 MOV addr,#data
61 *____________________________________________________________________________
66 t_uc51::inst_mov_addr_Sdata(uchar code)
70 cell= get_direct(fetch());
78 * 0x76-0x77 2 12 MOV @Ri,#data
79 *____________________________________________________________________________
84 t_uc51::inst_mov_Sri_Sdata(uchar code)
88 cell= iram->get_cell(get_reg(code & 0x01)->read());
96 * 0x78-0x7f 2 12 MOV Rn,#data
97 *____________________________________________________________________________
102 t_uc51::inst_mov_rn_Sdata(uchar code)
106 reg= get_reg(code & 0x07);
113 * 0x93 1 24 MOVC A,@A+DPTR
114 *____________________________________________________________________________
119 t_uc51::inst_movc_a_Sa_pc(uchar code)
121 acc->write(mem(MEM_ROM)->read(PC + acc->read()));
128 * 0x85 3 24 MOV addr,addr
129 *____________________________________________________________________________
134 t_uc51::inst_mov_addr_addr(uchar code)
136 class cl_cell *d, *s;
138 /* SD reversed s & d here */
139 s= get_direct(fetch());
140 d= get_direct(fetch());
148 * 0x86-0x87 2 24 MOV addr,@Ri
149 *____________________________________________________________________________
154 t_uc51::inst_mov_addr_Sri(uchar code)
156 class cl_cell *d, *s;
158 d= get_direct(fetch());
159 s= iram->get_cell(get_reg(code & 0x01)->read());
167 * 0x88-0x8f 2 24 MOV addr,Rn
168 *____________________________________________________________________________
173 t_uc51::inst_mov_addr_rn(uchar code)
177 cell= get_direct(fetch());
178 cell->write(get_reg(code & 0x07)->read());
185 * 0x90 3 24 MOV DPTR,#data
186 *____________________________________________________________________________
191 t_uc51::inst_mov_dptr_Sdata(uchar code)
193 sfr->write(DPH, fetch());
194 sfr->write(DPL, fetch());
201 * 0x93 1 24 MOVC A,@A+DPTR
202 *____________________________________________________________________________
207 t_uc51::inst_movc_a_Sa_dptr(uchar code)
209 acc->write(get_mem(MEM_ROM,
210 sfr->read(DPH)*256+sfr->read(DPL) +
218 * 0xa6-0xa7 2 24 MOV @Ri,addr
219 *____________________________________________________________________________
224 t_uc51::inst_mov_Sri_addr(uchar code)
226 class cl_cell *d, *s;
228 d= iram->get_cell(get_reg(code & 0x01)->read());
229 s= get_direct(fetch());
237 * 0xa8-0xaf 2 24 MOV Rn,addr
238 *____________________________________________________________________________
243 t_uc51::inst_mov_rn_addr(uchar code)
245 class cl_cell *reg, *cell;
247 reg = get_reg(code & 0x07);
248 cell= get_direct(fetch());
249 reg->write(cell->read());
256 * 0xc0 2 24 PUSH addr
257 *____________________________________________________________________________
262 t_uc51::inst_push(uchar code)
265 class cl_cell *stck, *cell;
267 cell= get_direct(fetch());
268 sp= sfr->wadd(SP, 1);
269 stck= iram->get_cell(sp);
270 stck->write(cell->read());
277 * 0xc5 2 12 XCH A,addr
278 *____________________________________________________________________________
283 t_uc51::inst_xch_a_addr(uchar code)
288 cell= get_direct(fetch());
290 acc->write(cell->read());
297 * 0xc6-0xc7 1 12 XCH A,@Ri
298 *____________________________________________________________________________
303 t_uc51::inst_xch_a_Sri(uchar code)
308 cell= iram->get_cell(get_reg(code & 0x01)->read());
310 acc->write(cell->read());
317 * 0xc8-0xcf 1 12 XCH A,Rn
318 *____________________________________________________________________________
323 t_uc51::inst_xch_a_rn(uchar code)
328 reg = get_reg(code & 0x07);
330 acc->write(reg->read());
338 *____________________________________________________________________________
343 t_uc51::inst_pop(uchar code)
346 class cl_cell *cell, *stck;
348 cell= get_direct(fetch());
349 stck= iram->get_cell(sfr->get(SP));
350 cell->write(stck->read());
351 sp= sfr->wadd(SP, -1);
358 * 0xd6-0xd7 1 12 XCHD A,@Ri
359 *____________________________________________________________________________
364 t_uc51::inst_xchd_a_Sri(uchar code)
369 cell= iram->get_cell(get_reg(code & 0x01)->read());
370 temp= (d= cell->read()) & 0x0f;
371 cell->write((d & 0xf0) | (acc->read() & 0x0f));
372 acc->write((acc->get() & 0xf0) | temp);
378 * 0xe0 1 24 MOVX A,@DPTR
379 *____________________________________________________________________________
384 t_uc51::inst_movx_a_Sdptr(uchar code)
386 acc->write(read_mem(MEM_XRAM,
387 sfr->read(DPH)*256 + sfr->read(DPL)));
394 * 0xe2-0xe3 1 24 MOVX A,@Ri
395 *____________________________________________________________________________
400 t_uc51::inst_movx_a_Sri(uchar code)
404 d= get_reg(code & 0x01)->read();
405 acc->write(read_mem(MEM_XRAM, sfr->read(P2)*256 + d));
412 * 0xe5 2 12 MOV A,addr
413 *____________________________________________________________________________
418 t_uc51::inst_mov_a_addr(uchar code)
422 cell= get_direct(fetch());
423 acc->write(cell->read());
429 * 0xe6-0xe7 1 12 MOV A,@Ri
430 *____________________________________________________________________________
435 t_uc51::inst_mov_a_Sri(uchar code)
439 cell= iram->get_cell(get_reg(code & 0x01)->read());
440 acc->write(cell->read());
446 * 0xe8-0xef 1 12 MOV A,Rn
447 *____________________________________________________________________________
452 t_uc51::inst_mov_a_rn(uchar code)
454 acc->write(get_reg(code & 0x07)->read());
460 * 0xf0 1 24 MOVX @DPTR,A
461 *____________________________________________________________________________
466 t_uc51::inst_movx_Sdptr_a(uchar code)
468 write_mem(MEM_XRAM, sfr->read(DPH)*256 + sfr->read(DPL), acc->read());
475 * 0xf2-0xf3 1 24 MOVX @Ri,A
476 *____________________________________________________________________________
481 t_uc51::inst_movx_Sri_a(uchar code)
485 d= get_reg(code & 0x01)->read();
486 write_mem(MEM_XRAM, sfr->read(P2)*256 + d, acc->read());
493 * 0xf5 2 12 MOV addr,A
494 *____________________________________________________________________________
499 t_uc51::inst_mov_addr_a(uchar code)
503 cell= get_direct(fetch());
504 cell->write(acc->read());
510 * 0xf6-0xf7 1 12 MOV @Ri,A
511 *____________________________________________________________________________
516 t_uc51::inst_mov_Sri_a(uchar code)
520 cell= iram->get_cell(get_reg(code & 0x01)->read());
521 cell->write(acc->read());
527 * 0xf8-0xff 1 12 MOV Rn,A
528 *____________________________________________________________________________
533 t_uc51::inst_mov_rn_a(uchar code)
537 reg= get_reg(code &0x07);
538 reg->write(acc->read());
543 /* End of s51.src/mov.cc */