summaryrefslogtreecommitdiffstats
path: root/ue4/mycpu/instructions.h
diff options
context:
space:
mode:
Diffstat (limited to 'ue4/mycpu/instructions.h')
-rw-r--r--ue4/mycpu/instructions.h157
1 files changed, 83 insertions, 74 deletions
diff --git a/ue4/mycpu/instructions.h b/ue4/mycpu/instructions.h
index 3f2fd51..fd547aa 100644
--- a/ue4/mycpu/instructions.h
+++ b/ue4/mycpu/instructions.h
@@ -19,9 +19,9 @@
19 * Syntax: inc R1 19 * Syntax: inc R1
20 * (R1++) 20 * (R1++)
21 */ 21 */
22template<class T=CDat<int>, int width=0> 22template <class T>
23class CInstructionInc 23class CInstructionInc
24 : public CInstruction<T> 24 : public CInstruction<T>
25{ 25{
26 typedef CInstruction<T> super; 26 typedef CInstruction<T> super;
27 27
@@ -45,22 +45,21 @@ class CInstructionInc
45 45
46/*----------------------------------------------------------------------------*/ 46/*----------------------------------------------------------------------------*/
47 47
48template<class T=CDat<int>, int width=0> 48template <class T>
49void CInstructionInc<T>::compile(std::list<std::string>& params) 49void CInstructionInc<T>::compile(std::list<std::string>& params)
50{ 50{
51 if (params.size() != 1) 51 if (params.size() != 1)
52 throw std::runtime_error("Invalid paramater count - must be 1"); 52 throw CInstructionError("Invalid paramater count - must be 1");
53 m_regidx1 = super::parseRegister(params.front()); 53 m_regidx1 = super::parseRegister(params.front());
54 params.pop_front(); 54 params.pop_front();
55} 55}
56 56
57/*----------------------------------------------------------------------------*/ 57/*----------------------------------------------------------------------------*/
58 58
59template<class T=CDat<int>, int width=0> 59template <class T>
60void CInstructionInc<T>::execute(CCPU<T> *cpu) 60void CInstructionInc<T>::execute(CCPU<T> *cpu)
61{ 61{
62 assert(cpu != NULL); 62 assert(cpu != NULL);
63 assert(cpu->getRegisters() != NULL);
64 super::checkRegister(cpu, m_regidx1); 63 super::checkRegister(cpu, m_regidx1);
65 cpu->getRegisters()[ m_regidx1 ]++; 64 cpu->getRegisters()[ m_regidx1 ]++;
66} 65}
@@ -74,7 +73,7 @@ void CInstructionInc<T>::execute(CCPU<T> *cpu)
74 * Syntax: dec R1 73 * Syntax: dec R1
75 * (R1--) 74 * (R1--)
76 */ 75 */
77template<class T=CDat<int>, int width=0> 76template <class T>
78class CInstructionDec 77class CInstructionDec
79 : public CInstruction<T> 78 : public CInstruction<T>
80{ 79{
@@ -100,22 +99,21 @@ class CInstructionDec
100 99
101/*----------------------------------------------------------------------------*/ 100/*----------------------------------------------------------------------------*/
102 101
103template<class T=CDat<int>, int width=0> 102template <class T>
104void CInstructionDec<T>::compile(std::list<std::string>& params) 103void CInstructionDec<T>::compile(std::list<std::string>& params)
105{ 104{
106 if (params.size() != 1) 105 if (params.size() != 1)
107 throw std::runtime_error("Invalid paramater count - must be 1"); 106 throw CInstructionError("Invalid paramater count - must be 1");
108 m_regidx1 = super::parseRegister(params.front()); 107 m_regidx1 = super::parseRegister(params.front());
109 params.pop_front(); 108 params.pop_front();
110} 109}
111 110
112/*----------------------------------------------------------------------------*/ 111/*----------------------------------------------------------------------------*/
113 112
114template<class T=CDat<int>, int width=0> 113template <class T>
115void CInstructionDec<T>::execute(CCPU<T> *cpu) 114void CInstructionDec<T>::execute(CCPU<T> *cpu)
116{ 115{
117 assert(cpu != NULL); 116 assert(cpu != NULL);
118 assert(cpu->getRegisters() != NULL);
119 super::checkRegister(cpu, m_regidx1); 117 super::checkRegister(cpu, m_regidx1);
120 cpu->getRegisters()[ m_regidx1 ]--; 118 cpu->getRegisters()[ m_regidx1 ]--;
121} 119}
@@ -129,7 +127,7 @@ void CInstructionDec<T>::execute(CCPU<T> *cpu)
129 * Syntax: add R1, R2, R3 127 * Syntax: add R1, R2, R3
130 * (R1 = R2 + R3) 128 * (R1 = R2 + R3)
131 */ 129 */
132template<class T=CDat<int>, int width=0> 130template <class T>
133class CInstructionAdd 131class CInstructionAdd
134 : public CInstruction<T> 132 : public CInstruction<T>
135{ 133{
@@ -159,11 +157,11 @@ class CInstructionAdd
159 157
160/*----------------------------------------------------------------------------*/ 158/*----------------------------------------------------------------------------*/
161 159
162template<class T=CDat<int>, int width=0> 160template <class T>
163void CInstructionAdd<T>::compile(std::list<std::string>& params) 161void CInstructionAdd<T>::compile(std::list<std::string>& params)
164{ 162{
165 if (params.size() != 3) 163 if (params.size() != 3)
166 throw std::runtime_error("Invalid paramater count - must be 3"); 164 throw CInstructionError("Invalid paramater count - must be 3");
167 m_regidx1 = super::parseRegister(params.front()); 165 m_regidx1 = super::parseRegister(params.front());
168 params.pop_front(); 166 params.pop_front();
169 m_regidx2 = super::parseRegister(params.front()); 167 m_regidx2 = super::parseRegister(params.front());
@@ -174,11 +172,10 @@ void CInstructionAdd<T>::compile(std::list<std::string>& params)
174 172
175/*----------------------------------------------------------------------------*/ 173/*----------------------------------------------------------------------------*/
176 174
177template<class T=CDat<int>, int width=0> 175template <class T>
178void CInstructionAdd<T>::execute(CCPU<T> *cpu) 176void CInstructionAdd<T>::execute(CCPU<T> *cpu)
179{ 177{
180 assert(cpu != NULL); 178 assert(cpu != NULL);
181 assert(cpu->getRegisters() != NULL);
182 super::checkRegister(cpu, m_regidx1); 179 super::checkRegister(cpu, m_regidx1);
183 super::checkRegister(cpu, m_regidx2); 180 super::checkRegister(cpu, m_regidx2);
184 super::checkRegister(cpu, m_regidx3); 181 super::checkRegister(cpu, m_regidx3);
@@ -195,7 +192,7 @@ void CInstructionAdd<T>::execute(CCPU<T> *cpu)
195 * Syntax: sub R1, R2, R3 192 * Syntax: sub R1, R2, R3
196 * (R1 = R2 - R3) 193 * (R1 = R2 - R3)
197 */ 194 */
198template<class T=CDat<int>, int width=0> 195template <class T>
199class CInstructionSub 196class CInstructionSub
200 : public CInstruction<T> 197 : public CInstruction<T>
201{ 198{
@@ -225,11 +222,11 @@ class CInstructionSub
225 222
226/*----------------------------------------------------------------------------*/ 223/*----------------------------------------------------------------------------*/
227 224
228template<class T=CDat<int>, int width=0> 225template <class T>
229void CInstructionSub<T>::compile(std::list<std::string>& params) 226void CInstructionSub<T>::compile(std::list<std::string>& params)
230{ 227{
231 if (params.size() != 3) 228 if (params.size() != 3)
232 throw std::runtime_error("Invalid paramater count - must be 3"); 229 throw CInstructionError("Invalid paramater count - must be 3");
233 m_regidx1 = super::parseRegister(params.front()); 230 m_regidx1 = super::parseRegister(params.front());
234 params.pop_front(); 231 params.pop_front();
235 m_regidx2 = super::parseRegister(params.front()); 232 m_regidx2 = super::parseRegister(params.front());
@@ -240,11 +237,10 @@ void CInstructionSub<T>::compile(std::list<std::string>& params)
240 237
241/*----------------------------------------------------------------------------*/ 238/*----------------------------------------------------------------------------*/
242 239
243template<class T=CDat<int>, int width=0> 240template <class T>
244void CInstructionSub<T>::execute(CCPU<T> *cpu) 241void CInstructionSub<T>::execute(CCPU<T> *cpu)
245{ 242{
246 assert(cpu != NULL); 243 assert(cpu != NULL);
247 assert(cpu->getRegisters() != NULL);
248 super::checkRegister(cpu, m_regidx1); 244 super::checkRegister(cpu, m_regidx1);
249 super::checkRegister(cpu, m_regidx2); 245 super::checkRegister(cpu, m_regidx2);
250 super::checkRegister(cpu, m_regidx3); 246 super::checkRegister(cpu, m_regidx3);
@@ -261,7 +257,7 @@ void CInstructionSub<T>::execute(CCPU<T> *cpu)
261 * Syntax: mul R1, R2, R3 257 * Syntax: mul R1, R2, R3
262 * (R1 = R2 * R3) 258 * (R1 = R2 * R3)
263 */ 259 */
264template<class T=CDat<int>, int width=0> 260template <class T>
265class CInstructionMul 261class CInstructionMul
266 : public CInstruction<T> 262 : public CInstruction<T>
267{ 263{
@@ -291,11 +287,11 @@ class CInstructionMul
291 287
292/*----------------------------------------------------------------------------*/ 288/*----------------------------------------------------------------------------*/
293 289
294template<class T=CDat<int>, int width=0> 290template <class T>
295void CInstructionMul<T>::compile(std::list<std::string>& params) 291void CInstructionMul<T>::compile(std::list<std::string>& params)
296{ 292{
297 if (params.size() != 3) 293 if (params.size() != 3)
298 throw std::runtime_error("Invalid paramater count - must be 3"); 294 throw CInstructionError("Invalid paramater count - must be 3");
299 m_regidx1 = super::parseRegister(params.front()); 295 m_regidx1 = super::parseRegister(params.front());
300 params.pop_front(); 296 params.pop_front();
301 m_regidx2 = super::parseRegister(params.front()); 297 m_regidx2 = super::parseRegister(params.front());
@@ -306,7 +302,7 @@ void CInstructionMul<T>::compile(std::list<std::string>& params)
306 302
307/*----------------------------------------------------------------------------*/ 303/*----------------------------------------------------------------------------*/
308 304
309template<class T=CDat<int>, int width=0> 305template <class T>
310void CInstructionMul<T>::execute(CCPU<T> *cpu) 306void CInstructionMul<T>::execute(CCPU<T> *cpu)
311{ 307{
312 super::checkRegister(cpu, m_regidx1); 308 super::checkRegister(cpu, m_regidx1);
@@ -325,7 +321,7 @@ void CInstructionMul<T>::execute(CCPU<T> *cpu)
325 * Syntax: div R1, R2, R3 321 * Syntax: div R1, R2, R3
326 * (R1 = R2 / R3) 322 * (R1 = R2 / R3)
327 */ 323 */
328template<class T=CDat<int>, int width=0> 324template <class T>
329class CInstructionDiv 325class CInstructionDiv
330 : public CInstruction<T> 326 : public CInstruction<T>
331{ 327{
@@ -355,11 +351,11 @@ class CInstructionDiv
355 351
356/*----------------------------------------------------------------------------*/ 352/*----------------------------------------------------------------------------*/
357 353
358template<class T=CDat<int>, int width=0> 354template <class T>
359void CInstructionDiv<T>::compile(std::list<std::string>& params) 355void CInstructionDiv<T>::compile(std::list<std::string>& params)
360{ 356{
361 if (params.size() != 3) 357 if (params.size() != 3)
362 throw std::runtime_error("Invalid paramater count - must be 3"); 358 throw CInstructionError("Invalid paramater count - must be 3");
363 m_regidx1 = super::parseRegister(params.front()); 359 m_regidx1 = super::parseRegister(params.front());
364 params.pop_front(); 360 params.pop_front();
365 m_regidx2 = super::parseRegister(params.front()); 361 m_regidx2 = super::parseRegister(params.front());
@@ -370,11 +366,10 @@ void CInstructionDiv<T>::compile(std::list<std::string>& params)
370 366
371/*----------------------------------------------------------------------------*/ 367/*----------------------------------------------------------------------------*/
372 368
373template<class T=CDat<int>, int width=0> 369template <class T>
374void CInstructionDiv<T>::execute(CCPU<T> *cpu) 370void CInstructionDiv<T>::execute(CCPU<T> *cpu)
375{ 371{
376 assert(cpu != NULL); 372 assert(cpu != NULL);
377 assert(cpu->getRegisters() != NULL);
378 super::checkRegister(cpu, m_regidx1); 373 super::checkRegister(cpu, m_regidx1);
379 super::checkRegister(cpu, m_regidx2); 374 super::checkRegister(cpu, m_regidx2);
380 super::checkRegister(cpu, m_regidx3); 375 super::checkRegister(cpu, m_regidx3);
@@ -391,7 +386,7 @@ void CInstructionDiv<T>::execute(CCPU<T> *cpu)
391 * Syntax: load R1, R2 386 * Syntax: load R1, R2
392 * (R1 = memory[R2]) 387 * (R1 = memory[R2])
393 */ 388 */
394template<class T=CDat<int>, int width=0> 389template <class T>
395class CInstructionLoad 390class CInstructionLoad
396 : public CInstruction<T> 391 : public CInstruction<T>
397{ 392{
@@ -419,11 +414,11 @@ class CInstructionLoad
419 414
420/*----------------------------------------------------------------------------*/ 415/*----------------------------------------------------------------------------*/
421 416
422template<class T=CDat<int>, int width=0> 417template <class T>
423void CInstructionLoad<T>::compile(std::list<std::string>& params) 418void CInstructionLoad<T>::compile(std::list<std::string>& params)
424{ 419{
425 if (params.size() != 2) 420 if (params.size() != 2)
426 throw std::runtime_error("Invalid paramater count - must be 2"); 421 throw CInstructionError("Invalid paramater count - must be 2");
427 m_regidx1 = super::parseRegister(params.front()); 422 m_regidx1 = super::parseRegister(params.front());
428 params.pop_front(); 423 params.pop_front();
429 m_regidx2 = super::parseRegister(params.front()); 424 m_regidx2 = super::parseRegister(params.front());
@@ -432,11 +427,10 @@ void CInstructionLoad<T>::compile(std::list<std::string>& params)
432 427
433/*----------------------------------------------------------------------------*/ 428/*----------------------------------------------------------------------------*/
434 429
435template<class T=CDat<int>, int width=0> 430template <class T>
436void CInstructionLoad<T>::execute(CCPU<T> *cpu) 431void CInstructionLoad<T>::execute(CCPU<T> *cpu)
437{ 432{
438 assert(cpu != NULL); 433 assert(cpu != NULL);
439 assert(cpu->getRegisters() != NULL);
440 assert(cpu->getMemory() != NULL); 434 assert(cpu->getMemory() != NULL);
441 super::checkRegister(cpu, m_regidx1); 435 super::checkRegister(cpu, m_regidx1);
442 super::checkRegister(cpu, m_regidx2); 436 super::checkRegister(cpu, m_regidx2);
@@ -453,7 +447,7 @@ void CInstructionLoad<T>::execute(CCPU<T> *cpu)
453 * Syntax: store R1, R2 447 * Syntax: store R1, R2
454 * (memory[R2] = R1) 448 * (memory[R2] = R1)
455 */ 449 */
456template<class T=CDat<int>, int width=0> 450template <class T>
457class CInstructionStore 451class CInstructionStore
458 : public CInstruction<T> 452 : public CInstruction<T>
459{ 453{
@@ -481,11 +475,11 @@ class CInstructionStore
481 475
482/*----------------------------------------------------------------------------*/ 476/*----------------------------------------------------------------------------*/
483 477
484template<class T=CDat<int>, int width=0> 478template <class T>
485void CInstructionStore<T>::compile(std::list<std::string>& params) 479void CInstructionStore<T>::compile(std::list<std::string>& params)
486{ 480{
487 if (params.size() != 2) 481 if (params.size() != 2)
488 throw std::runtime_error("Invalid paramater count - must be 2"); 482 throw CInstructionError("Invalid paramater count - must be 2");
489 m_regidx1 = super::parseRegister(params.front()); 483 m_regidx1 = super::parseRegister(params.front());
490 params.pop_front(); 484 params.pop_front();
491 m_regidx2 = super::parseRegister(params.front()); 485 m_regidx2 = super::parseRegister(params.front());
@@ -494,11 +488,10 @@ void CInstructionStore<T>::compile(std::list<std::string>& params)
494 488
495/*----------------------------------------------------------------------------*/ 489/*----------------------------------------------------------------------------*/
496 490
497template<class T=CDat<int>, int width=0> 491template <class T>
498void CInstructionStore<T>::execute(CCPU<T> *cpu) 492void CInstructionStore<T>::execute(CCPU<T> *cpu)
499{ 493{
500 assert(cpu != NULL); 494 assert(cpu != NULL);
501 assert(cpu->getRegisters() != NULL);
502 assert(cpu->getMemory() != NULL); 495 assert(cpu->getMemory() != NULL);
503 super::checkRegister(cpu, m_regidx1); 496 super::checkRegister(cpu, m_regidx1);
504 super::checkRegister(cpu, m_regidx2); 497 super::checkRegister(cpu, m_regidx2);
@@ -515,7 +508,7 @@ void CInstructionStore<T>::execute(CCPU<T> *cpu)
515 * Syntax: test R1 508 * Syntax: test R1
516 * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) 509 * (R1 == 0: zeroflag: true, R1 < 0: signflag: true)
517 */ 510 */
518template<class T=CDat<int>, int width=0> 511template <class T>
519class CInstructionTest 512class CInstructionTest
520 : public CInstruction<T> 513 : public CInstruction<T>
521{ 514{
@@ -541,22 +534,21 @@ class CInstructionTest
541 534
542/*----------------------------------------------------------------------------*/ 535/*----------------------------------------------------------------------------*/
543 536
544template<class T=CDat<int>, int width=0> 537template <class T>
545void CInstructionTest<T>::compile(std::list<std::string>& params) 538void CInstructionTest<T>::compile(std::list<std::string>& params)
546{ 539{
547 if (params.size() != 1) 540 if (params.size() != 1)
548 throw std::runtime_error("Invalid paramater count - must be 1"); 541 throw CInstructionError("Invalid paramater count - must be 1");
549 m_regidx1 = super::parseRegister(params.front()); 542 m_regidx1 = super::parseRegister(params.front());
550 params.pop_front(); 543 params.pop_front();
551} 544}
552 545
553/*----------------------------------------------------------------------------*/ 546/*----------------------------------------------------------------------------*/
554 547
555template<class T=CDat<int>, int width=0> 548template <class T>
556void CInstructionTest<T>::execute(CCPU<T> *cpu) 549void CInstructionTest<T>::execute(CCPU<T> *cpu)
557{ 550{
558 assert(cpu != NULL); 551 assert(cpu != NULL);
559 assert(cpu->getRegisters() != NULL);
560 super::checkRegister(cpu, m_regidx1); 552 super::checkRegister(cpu, m_regidx1);
561 if (cpu->getRegisters()[ m_regidx1 ] == T(0)) 553 if (cpu->getRegisters()[ m_regidx1 ] == T(0))
562 cpu->setFlagZero(true); 554 cpu->setFlagZero(true);
@@ -572,7 +564,7 @@ void CInstructionTest<T>::execute(CCPU<T> *cpu)
572 * Implementation of assembler command "label" 564 * Implementation of assembler command "label"
573 * Syntax: label name: 565 * Syntax: label name:
574 */ 566 */
575template<class T=CDat<int>, int width=0> 567template <class T>
576class CInstructionLabel 568class CInstructionLabel
577 : public CInstruction<T> 569 : public CInstruction<T>
578{ 570{
@@ -604,7 +596,7 @@ class CInstructionLabel
604 * Syntax: jumpa labelname 596 * Syntax: jumpa labelname
605 * (jump to labelname) 597 * (jump to labelname)
606 */ 598 */
607template<class T=CDat<int>, int width=0> 599template <class T>
608class CInstructionJumpA 600class CInstructionJumpA
609 : public CInstruction<T> 601 : public CInstruction<T>
610{ 602{
@@ -630,26 +622,32 @@ class CInstructionJumpA
630 622
631/*----------------------------------------------------------------------------*/ 623/*----------------------------------------------------------------------------*/
632 624
633template<class T=CDat<int>, int width=0> 625template <class T>
634void CInstructionJumpA<T>::compile(std::list<std::string>& params) 626void CInstructionJumpA<T>::compile(std::list<std::string>& params)
635{ 627{
636 if (params.size() != 1) 628 if (params.size() != 1)
637 throw std::runtime_error("Invalid paramater count - must be 1"); 629 throw CInstructionError("Invalid paramater count - must be 1");
638 m_addr = params.front(); 630 m_addr = params.front();
639 params.pop_front(); 631 params.pop_front();
640} 632}
641 633
642/*----------------------------------------------------------------------------*/ 634/*----------------------------------------------------------------------------*/
643 635
644template<class T=CDat<int>, int width=0> 636template <class T>
645void CInstructionJumpA<T>::execute(CCPU<T> *cpu) 637void CInstructionJumpA<T>::execute(CCPU<T> *cpu)
646{ 638{
647 assert(cpu != NULL); 639 assert(cpu != NULL);
648 assert(cpu->getRegisters() != NULL);
649 assert(cpu->getProgram() != NULL); 640 assert(cpu->getProgram() != NULL);
650 if (m_addr.empty()) 641 if (m_addr.empty())
651 throw std::runtime_error("Empty address"); 642 throw CInstructionError("Empty address");
652 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 643 try
644 {
645 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
646 }
647 catch(CProgramError& ex)
648 {
649 throw CInstructionError(ex.what());
650 }
653} 651}
654 652
655/*============================================================================*/ 653/*============================================================================*/
@@ -661,7 +659,7 @@ void CInstructionJumpA<T>::execute(CCPU<T> *cpu)
661 * Syntax: jumpz labelname 659 * Syntax: jumpz labelname
662 * (jump to labelname if zeroflag) 660 * (jump to labelname if zeroflag)
663 */ 661 */
664template<class T=CDat<int>, int width=0> 662template <class T>
665class CInstructionJumpZ 663class CInstructionJumpZ
666 : public CInstruction<T> 664 : public CInstruction<T>
667{ 665{
@@ -687,28 +685,34 @@ class CInstructionJumpZ
687 685
688/*----------------------------------------------------------------------------*/ 686/*----------------------------------------------------------------------------*/
689 687
690template<class T=CDat<int>, int width=0> 688template <class T>
691void CInstructionJumpZ<T>::compile(std::list<std::string>& params) 689void CInstructionJumpZ<T>::compile(std::list<std::string>& params)
692{ 690{
693 if (params.size() != 1) 691 if (params.size() != 1)
694 throw std::runtime_error("Invalid paramater count - must be 1"); 692 throw CInstructionError("Invalid paramater count - must be 1");
695 m_addr = params.front(); 693 m_addr = params.front();
696 params.pop_front(); 694 params.pop_front();
697} 695}
698 696
699/*----------------------------------------------------------------------------*/ 697/*----------------------------------------------------------------------------*/
700 698
701template<class T=CDat<int>, int width=0> 699template <class T>
702void CInstructionJumpZ<T>::execute(CCPU<T> *cpu) 700void CInstructionJumpZ<T>::execute(CCPU<T> *cpu)
703{ 701{
704 assert(cpu != NULL); 702 assert(cpu != NULL);
705 assert(cpu->getRegisters() != NULL);
706 assert(cpu->getProgram() != NULL); 703 assert(cpu->getProgram() != NULL);
707 if (!cpu->getFlagZero()) 704 if (!cpu->getFlagZero())
708 return; 705 return;
709 if (m_addr.empty()) 706 if (m_addr.empty())
710 throw std::runtime_error("Empty address"); 707 throw CInstructionError("Empty address");
711 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 708 try
709 {
710 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
711 }
712 catch(CProgramError& ex)
713 {
714 throw CInstructionError(ex.what());
715 }
712} 716}
713 717
714/*============================================================================*/ 718/*============================================================================*/
@@ -720,7 +724,7 @@ void CInstructionJumpZ<T>::execute(CCPU<T> *cpu)
720 * Syntax: jumps labelname 724 * Syntax: jumps labelname
721 * (jump to labelname if signflag) 725 * (jump to labelname if signflag)
722 */ 726 */
723template<class T=CDat<int>, int width=0> 727template <class T>
724class CInstructionJumpS 728class CInstructionJumpS
725 : public CInstruction<T> 729 : public CInstruction<T>
726{ 730{
@@ -746,28 +750,34 @@ class CInstructionJumpS
746 750
747/*----------------------------------------------------------------------------*/ 751/*----------------------------------------------------------------------------*/
748 752
749template<class T=CDat<int>, int width=0> 753template <class T>
750void CInstructionJumpS<T>::compile(std::list<std::string>& params) 754void CInstructionJumpS<T>::compile(std::list<std::string>& params)
751{ 755{
752 if (params.size() != 1) 756 if (params.size() != 1)
753 throw std::runtime_error("Invalid paramater count - must be 1"); 757 throw CInstructionError("Invalid paramater count - must be 1");
754 m_addr = params.front(); 758 m_addr = params.front();
755 params.pop_front(); 759 params.pop_front();
756} 760}
757 761
758/*----------------------------------------------------------------------------*/ 762/*----------------------------------------------------------------------------*/
759 763
760template<class T=CDat<int>, int width=0> 764template <class T>
761void CInstructionJumpS<T>::execute(CCPU<T> *cpu) 765void CInstructionJumpS<T>::execute(CCPU<T> *cpu)
762{ 766{
763 assert(cpu != NULL); 767 assert(cpu != NULL);
764 assert(cpu->getRegisters() != NULL);
765 assert(cpu->getProgram() != NULL); 768 assert(cpu->getProgram() != NULL);
766 if (!cpu->getFlagSign()) 769 if (!cpu->getFlagSign())
767 return; 770 return;
768 if (m_addr.empty()) 771 if (m_addr.empty())
769 throw std::runtime_error("Empty address"); 772 throw CInstructionError("Empty address");
770 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 773 try
774 {
775 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
776 }
777 catch(CProgramError& ex)
778 {
779 throw CInstructionError(ex.what());
780 }
771} 781}
772 782
773/*============================================================================*/ 783/*============================================================================*/
@@ -779,7 +789,7 @@ void CInstructionJumpS<T>::execute(CCPU<T> *cpu)
779 * Syntax: write DEV, R1 789 * Syntax: write DEV, R1
780 * (write R1 to DEV, which is a name of a display) 790 * (write R1 to DEV, which is a name of a display)
781 */ 791 */
782template<class T=CDat<int>, int width=0> 792template <class T>
783class CInstructionWrite 793class CInstructionWrite
784 : public CInstruction<T> 794 : public CInstruction<T>
785{ 795{
@@ -808,11 +818,11 @@ class CInstructionWrite
808 818
809/*----------------------------------------------------------------------------*/ 819/*----------------------------------------------------------------------------*/
810 820
811template<class T=CDat<int>, int width=0> 821template <class T>
812void CInstructionWrite<T>::compile(std::list<std::string>& params) 822void CInstructionWrite<T>::compile(std::list<std::string>& params)
813{ 823{
814 if (params.size() != 2) 824 if (params.size() != 2)
815 throw std::runtime_error("Invalid paramater count - must be 2"); 825 throw CInstructionError("Invalid paramater count - must be 2");
816 m_dev = params.front(); 826 m_dev = params.front();
817 params.pop_front(); 827 params.pop_front();
818 m_regidx1 = super::parseRegister(params.front()); 828 m_regidx1 = super::parseRegister(params.front());
@@ -821,14 +831,13 @@ void CInstructionWrite<T>::compile(std::list<std::string>& params)
821 831
822/*----------------------------------------------------------------------------*/ 832/*----------------------------------------------------------------------------*/
823 833
824template<class T=CDat<int>, int width=0> 834template <class T>
825void CInstructionWrite<T>::execute(CCPU<T> *cpu) 835void CInstructionWrite<T>::execute(CCPU<T> *cpu)
826{ 836{
827 assert(cpu != NULL); 837 assert(cpu != NULL);
828 assert(cpu->getRegisters() != NULL);
829 super::checkRegister(cpu, m_regidx1); 838 super::checkRegister(cpu, m_regidx1);
830 if (m_dev.empty()) 839 if (m_dev.empty())
831 throw std::runtime_error("Empty device"); 840 throw CInstructionError("Empty device");
832 841
833 CDisplay<T> *display = NULL; 842 CDisplay<T> *display = NULL;
834 std::set<CDisplay<T> *> displays = cpu->getDisplays(); 843 std::set<CDisplay<T> *> displays = cpu->getDisplays();
@@ -841,7 +850,7 @@ void CInstructionWrite<T>::execute(CCPU<T> *cpu)
841 } 850 }
842 } 851 }
843 if (display == NULL) 852 if (display == NULL)
844 throw std::runtime_error("Unknown display"); 853 throw CInstructionError("Unknown display");
845 854
846 display->display(cpu->getRegisters()[ m_regidx1 ]); 855 display->display(cpu->getRegisters()[ m_regidx1 ]);
847} 856}