-
Notifications
You must be signed in to change notification settings - Fork 0
/
system-b.html
1055 lines (989 loc) · 106 KB
/
system-b.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-W11-4 02:12 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>system/b</title>
<meta name="author" content="Inanna" />
<meta name="description" content="A simple memory-to-memory virtual machine implemented in C++." />
<meta name="generator" content="Org Mode" />
<link href="/site.css" rel="stylesheet" type="text/css" /><link href="images/website-icon.png" rel="icon" />
</head>
<body>
<div id="preamble" class="status">
<div><a href="/index.html"><img alt="An abstract logo representing a series of three assembly line stamping machines with the words CONS, DEV, and embalzoned in white on each machine." id="site-logo" src="/images/website-logo.png" /></a></div>
</div>
<div id="content" class="content">
<h1 class="title">system/b
<br />
<span class="subtitle">A modern computing system.</span>
</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#orga2bd7e5">Introduction</a></li>
<li><a href="#orga54f3a6">Example Programs</a>
<ul>
<li><a href="#org8e2cd13">mult.sba</a></li>
<li><a href="#org14f9cc7">subEX.sba</a></li>
</ul>
</li>
<li><a href="#orgca9234c">Source Code</a>
<ul>
<li><a href="#orgfd32513">systemBshell.cpp</a></li>
<li><a href="#orgddb254e">SystemBvm.h</a></li>
<li><a href="#org3d05a37">ioStrings.h</a></li>
<li><a href="#org559422c">assembler.h</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-orga2bd7e5" class="outline-2">
<h2 id="orga2bd7e5">Introduction</h2>
<div class="outline-text-2" id="text-orga2bd7e5">
<p>
Another project from my early days in programming <label class="sidenote-number" for="1"><sup>1</sup></label><input checked="checked" id="1" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 1</span> About three years ago now, wow! Amazing how time flies.</span>, a simple memory-to-memory virtual machine written in C++. I currently intend to upgrade it a bit eventually with interrupt codes, though maybe I will wait until I write a proper LISP machine with tagged memory / typed instructions. To compile it simply run GCC on systemBshell.cpp.
</p>
</div>
</div>
<div id="outline-container-orga54f3a6" class="outline-2">
<h2 id="orga54f3a6">Example Programs</h2>
<div class="outline-text-2" id="text-orga54f3a6">
</div>
<div id="outline-container-org8e2cd13" class="outline-3">
<h3 id="org8e2cd13">mult.sba</h3>
<div class="outline-text-3" id="text-org8e2cd13">
<div class="org-src-container">
<pre class="src src-asm"><span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">this is a program that finds c for ;</span>
<span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">a * b = c ;</span>
<span style="font-weight: bold; font-style: italic;">JIE</span> <span style="color: #E53935; font-style: italic;">05</span> 07 04 <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x00 jumps to the stop instruction if the counter equals a</span>
<span style="font-weight: bold; font-style: italic;">ADD</span> <span style="color: #E53935; font-style: italic;">06</span> 254 254 <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x01 adds b to c and places it in c</span>
<span style="font-weight: bold; font-style: italic;">ADD</span> <span style="color: #E53935; font-style: italic;">07</span> 082 07 <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x02 increments the counter up by one</span>
<span style="font-weight: bold; font-style: italic;">JMP</span> <span style="color: #E53935; font-style: italic;">00</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x03 jumps to address 0x00</span>
<span style="font-weight: bold; font-style: italic;">STP</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x04 stop instruction</span>
<span style="font-weight: bold; font-style: italic;">3</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x05t a</span>
<span style="font-weight: bold; font-style: italic;">256</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x06 b</span>
<span style="font-weight: bold; font-style: italic;">0</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x07 counter</span>
<span style="font-weight: bold; font-style: italic;">1</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x08 storage for 1</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org14f9cc7" class="outline-3">
<h3 id="org14f9cc7">subEX.sba</h3>
<div class="outline-text-3" id="text-org14f9cc7">
<div class="org-src-container">
<pre class="src src-asm"><span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">this is a program that finds c for ;</span>
<span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">a - b = c ;</span>
<span style="font-weight: bold; font-style: italic;">FLP</span> <span style="color: #E53935; font-style: italic;">4</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x00 this flips the value a</span>
<span style="font-weight: bold; font-style: italic;">ADD</span> <span style="color: #E53935; font-style: italic;">4</span> 5 4 <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x01 this adds one to a</span>
<span style="font-weight: bold; font-style: italic;">ADD</span> <span style="color: #E53935; font-style: italic;">3</span> 4 6 <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x02 this adds a to b, and places the ansewer c in address 0x6</span>
<span style="font-weight: bold; font-style: italic;">0</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x03 this stores the value a</span>
<span style="font-weight: bold; font-style: italic;">0</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x04 this stores the value of b</span>
<span style="font-weight: bold; font-style: italic;">1</span> <span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x05 this is where the one is stored for the add one operation</span>
<span style="color: #a4a4a4; font-style: italic;">; </span><span style="color: #a4a4a4; font-style: italic;">0x06 this is where the value c will go</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgca9234c" class="outline-2">
<h2 id="orgca9234c">Source Code</h2>
<div class="outline-text-2" id="text-orgca9234c">
</div>
<div id="outline-container-orgfd32513" class="outline-3">
<h3 id="orgfd32513">systemBshell.cpp</h3>
<div class="outline-text-3" id="text-orgfd32513">
<div class="org-src-container">
<pre class="src src-C++"><span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">iostream</span><span style="color: #494949;">></span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">string</span><span style="color: #494949;">></span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;">"ioStrings.h"</span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;">"assembler.h"</span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;">"SystemBvm.h"</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> * This is the system/b "shell" allows the user to interact with it. Feel free to write your own if you want.</span>
<span style="color: #a4a4a4; font-style: italic;"> * note : the shell is not complete and needs more work to add full functionality to system/b</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">int</span> <span style="font-weight: bold; font-style: italic;">main</span><span style="color: #494949;">()</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">quit</span> = <span style="color: #E53935;">false</span>;
<span style="color: #E53935;">SystemBvm1024</span> <span style="font-style: italic;">vm</span>;
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">cmdInput</span>,
<span style="font-style: italic;">command</span>,
<span style="font-style: italic;">argument1</span>,
<span style="font-style: italic;">argument2</span>;
<span style="color: #E53935;">std</span>::cout << welcomeText<span style="color: #bbb;">()</span>;
<span style="color: #E53935; font-style: italic;">do</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cin.clear<span style="color: #494949;">()</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"system/b> "</span>; <span style="color: #E53935;">std</span>::cin >> command;
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>command == <span style="color: #494949;">"m"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935;">std</span>::cout << manualText<span style="color: #bbb;">()</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #E53935;">std</span>::endl;
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"assemble"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"a"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"inFile> "</span>; <span style="color: #E53935;">std</span>::cin >> argument1;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"outFile> "</span>; <span style="color: #E53935;">std</span>::cin >> argument2;
assemble<span style="color: #494949;">(</span>argument1, argument2<span style="color: #494949;">)</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"file assembled sucessfully "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #E53935;">std</span>::endl;
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"boot"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"b"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"inFile> "</span>; <span style="color: #E53935;">std</span>::cin >> argument1;
vm.boot<span style="color: #494949;">(</span>argument1<span style="color: #494949;">)</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"boot completed "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"immDump"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"imm"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
vm.immDump<span style="color: #494949;">()</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"imm dump completed "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"immDump"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"idr"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
vm.idrDump<span style="color: #494949;">()</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"idr dump completed "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"stepCycle"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"sc"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
vm.stepCycle<span style="color: #494949;">()</span>;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"cycle step completed "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"checkCounter"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"cc"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"current instruction counter : "</span> << vm.getinstructionCounter<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"getOutput"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"go"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"output address contains : "</span> << vm.getOutput<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"setInput"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"si"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">try</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cin >> argument1;
vm.setInput<span style="color: #494949;">(</span>argument1<span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">catch</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">std</span>::<span style="color: #E53935;">invalid_argument</span>& <span style="font-style: italic;">e</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::cout << e.what<span style="color: #494949;">()</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>command == <span style="color: #494949;">"quit"</span><span style="color: #bbb;">)</span> || <span style="color: #bbb;">(</span>command == <span style="color: #494949;">"q"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
quit = <span style="color: #E53935;">true</span>;
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935;">std</span>::cout << errorText<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span> <span style="color: #E53935; font-style: italic;">while</span> <span style="color: #bbb;">(</span><span style="color: #000; font-weight: bold;">!</span>quit<span style="color: #bbb;">)</span>;
<span style="color: #E53935;">std</span>::cout << quitText<span style="color: #bbb;">()</span>;
<span style="color: #E53935; font-style: italic;">return</span> 0;
<span style="color: #494949;">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgddb254e" class="outline-3">
<h3 id="orgddb254e">SystemBvm.h</h3>
<div class="outline-text-3" id="text-orgddb254e">
<div class="org-src-container">
<pre class="src src-C++"><span style="color: #000; font-weight: bold;">#pragma</span> once
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">fstream</span><span style="color: #494949;">></span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">iostream</span><span style="color: #494949;">></span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">cmath</span><span style="color: #494949;">></span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> * This is the basic system\b vm with 1024 possible indirectly addressed locations in memory. The addresses FD and FE are used for input and output, repsectively</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">WORD_SIZE</span> = 32;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">IMM_ADDR_SPACE_SIZE</span> = 256;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">unsigned</span> <span style="color: #E53935;">int</span> <span style="font-style: italic;">IDR_ADDR_SPACE_SIZE</span> = 1024;
<span style="color: #E53935; font-style: italic;">class</span> <span style="color: #E53935;">SystemBvm1024</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">private</span>:
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">immediateAddressSpace</span><span style="color: #bbb;">[</span>IMM_ADDR_SPACE_SIZE<span style="color: #bbb;">][</span>WORD_SIZE<span style="color: #bbb;">]</span>;
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">indirectAddressSpace</span><span style="color: #bbb;">[</span>IDR_ADDR_SPACE_SIZE<span style="color: #bbb;">][</span>WORD_SIZE<span style="color: #bbb;">]</span>;
<span style="color: #E53935;">short</span> <span style="font-style: italic;">instructionCounter</span>;
<span style="color: #E53935;">short</span> <span style="font-weight: bold; font-style: italic;">addressToShort</span><span style="color: #bbb;">(</span><span style="color: #E53935;">short</span> <span style="font-style: italic;">start</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">short</span> <span style="font-style: italic;">address</span> = 0;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 8; i > 0; i--<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>i + start - 1<span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
address += pow<span style="color: #494949;">(</span>2,<span style="color: #bbb;">(</span>8 - i<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">return</span> address;
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">unsigned</span> <span style="color: #E53935;">int</span> <span style="font-weight: bold; font-style: italic;">addrToInt</span><span style="color: #bbb;">(</span><span style="color: #E53935;">short</span> <span style="font-style: italic;">addr</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">unsigned</span> <span style="color: #E53935;">int</span> <span style="font-style: italic;">address</span> = 0;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = WORD_SIZE; i > 0; i--<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>i - 1<span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
address += pow<span style="color: #494949;">(</span>2, <span style="color: #bbb;">(</span>8 - i<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">return</span> address;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : JIE</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1010</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> JIE [argument address] [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> jumps to the third argument address if the value of the first argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address equals the second argumet address</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">JIE</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">addrEquality</span> = <span style="color: #E53935;">true</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr1</span> = addressToShort<span style="color: #494949;">(</span>16<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr2</span> = addressToShort<span style="color: #494949;">(</span>24<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>immediateAddressSpace<span style="color: #494949;">[</span>argAddr0<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> != immediateAddressSpace<span style="color: #494949;">[</span>argAddr1<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
addrEquality = <span style="color: #E53935;">false</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">if</span><span style="color: #494949;">(</span>addrEquality<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
instructionCounter = argAddr2;
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #494949;">{</span>
instructionCounter++;
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : JMP</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0101</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> JMP [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> unconditionally jumps to the argument address provided</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">JMP</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
instructionCounter = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : MOV</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1100</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> MOV [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> copies the value stored in the first argument address to the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address unconditionally</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">MOV</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr1</span> = addressToShort<span style="color: #494949;">(</span>16<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
immediateAddressSpace<span style="color: #bbb;">[</span>argAddr1<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span> = immediateAddressSpace<span style="color: #bbb;">[</span>argAddr0<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #494949;">}</span>
instructionCounter++;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : ADD</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1011</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> ADD [argument address] [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> adds the contents of the first argument address to the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address and then places the result in the third argument address</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">ADD</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr1</span> = addressToShort<span style="color: #494949;">(</span>16<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr2</span> = addressToShort<span style="color: #494949;">(</span>24<span style="color: #494949;">)</span>;
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">carry</span> = <span style="color: #E53935;">false</span>,
<span style="font-style: italic;">bit0</span> = <span style="color: #E53935;">false</span>,
<span style="font-style: italic;">bit1</span> = <span style="color: #E53935;">false</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = WORD_SIZE; i >= 0; i--<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
bit0 = immediateAddressSpace<span style="color: #bbb;">[</span>argAddr0<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
bit1 = immediateAddressSpace<span style="color: #bbb;">[</span>argAddr1<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span><span style="color: #494949;">(</span>bit0 + bit1 == 1<span style="color: #494949;">)</span> && <span style="color: #494949;">(</span>carry == 0<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>argAddr2<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 1;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"1"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span><span style="color: #494949;">(</span>bit0 + bit1 == 0<span style="color: #494949;">)</span> && <span style="color: #494949;">(</span>carry == 1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>argAddr2<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 1;
carry = 0;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"2"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>bit0 + bit1 + carry == 0<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>argAddr2<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 0;
carry = 0;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"3"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>bit0 + bit1 + carry == 2<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>argAddr2<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 0;
carry = 1;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"4"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>bit0 + bit1 + carry == 3<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>argAddr2<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 1;
carry = 1;
<span style="color: #E53935;">std</span>::cout << <span style="color: #494949;">"5"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935;">std</span>::cout << <span style="color: #E53935;">std</span>::endl;
<span style="color: #E53935;">std</span>::cout << argAddr0 << <span style="color: #494949;">"::"</span> << argAddr1 << <span style="color: #494949;">"::"</span> << argAddr2 << <span style="color: #E53935;">std</span>::endl;
instructionCounter++;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : FLP</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0100</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> FLP [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> flips the bits in the argument address provided</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">FLP</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
immediateAddressSpace<span style="color: #bbb;">[</span>argAddr0<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span> = <span style="color: #000; font-weight: bold;">!</span>immediateAddressSpace<span style="color: #bbb;">[</span>argAddr0<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #494949;">}</span>
instructionCounter++;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : RED</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1101</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> RED [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> special instruction, reads the value located in the directly addressed</span>
<span style="color: #a4a4a4; font-style: italic;"> space to the second argument address, the first argument address provides</span>
<span style="color: #a4a4a4; font-style: italic;"> the pointer to the location of the data in the directly addressed space</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">RED</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr1</span> = addressToShort<span style="color: #494949;">(</span>16<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">unsigned</span> <span style="color: #E53935;">int</span> <span style="font-style: italic;">idrAddr</span> = addrToInt<span style="color: #494949;">(</span>argAddr0<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
immediateAddressSpace<span style="color: #bbb;">[</span>argAddr1<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span> = indirectAddressSpace<span style="color: #bbb;">[</span>idrAddr<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #494949;">}</span>
instructionCounter++;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : WRT</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0010</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> WRT [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> special instruction, writes the value located in the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address to an address located in the directly addressed space, the first</span>
<span style="color: #a4a4a4; font-style: italic;"> argument address provides the pointer to the location of the data in the</span>
<span style="color: #a4a4a4; font-style: italic;"> directly addresssed space</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">WRT</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr0</span> = addressToShort<span style="color: #494949;">(</span>8<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">short</span> <span style="font-style: italic;">argAddr1</span> = addressToShort<span style="color: #494949;">(</span>16<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">const</span> <span style="color: #E53935;">unsigned</span> <span style="color: #E53935;">int</span> <span style="font-style: italic;">idrAddr</span> = addrToInt<span style="color: #494949;">(</span>argAddr0<span style="color: #494949;">)</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
indirectAddressSpace<span style="color: #bbb;">[</span>idrAddr<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span> = immediateAddressSpace<span style="color: #bbb;">[</span>argAddr1<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #494949;">}</span>
instructionCounter++;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : STP</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1111</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> STP</span>
<span style="color: #a4a4a4; font-style: italic;"> Stops the execution of code by system/b</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">STP</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">public</span>:
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">stepCycle</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">i0</span>, <span style="font-style: italic;">i1</span>, <span style="font-style: italic;">i2</span>, <span style="font-style: italic;">i3</span>;
i0 = immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>4<span style="color: #494949;">]</span>;
i1 = immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>5<span style="color: #494949;">]</span>;
i2 = immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>6<span style="color: #494949;">]</span>;
i3 = immediateAddressSpace<span style="color: #494949;">[</span>instructionCounter<span style="color: #494949;">][</span>7<span style="color: #494949;">]</span>;
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">JIE</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>i0 && <span style="color: #000; font-weight: bold;">!</span>i1 && i2 && <span style="color: #000; font-weight: bold;">!</span>i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
JIE<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">JMP</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #000; font-weight: bold;">!</span>i0 && i1 && <span style="color: #000; font-weight: bold;">!</span>i2 && i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
JMP<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">MOV</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>i0 && i1 && <span style="color: #000; font-weight: bold;">!</span>i2 && <span style="color: #000; font-weight: bold;">!</span>i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
MOV<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">ADD</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>i0 && <span style="color: #000; font-weight: bold;">!</span>i1 && i2 && i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
ADD<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">FLP</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #000; font-weight: bold;">!</span>i0 && i1 && <span style="color: #000; font-weight: bold;">!</span>i2 && <span style="color: #000; font-weight: bold;">!</span>i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
FLP<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">RED</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>i0 && i1 && <span style="color: #000; font-weight: bold;">!</span>i2 && i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
RED<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">WRT</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span><span style="color: #000; font-weight: bold;">!</span>i0 && <span style="color: #000; font-weight: bold;">!</span>i1 && i2 && <span style="color: #000; font-weight: bold;">!</span>i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
WRT<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">//</span><span style="color: #a4a4a4; font-style: italic;">STP</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>i0 && i1 && i2 && i3<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
STP<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #494949;">{</span>
instructionCounter++;
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">writeInput</span><span style="color: #bbb;">(</span><span style="color: #E53935;">bool</span> <span style="font-style: italic;">input</span><span style="color: #494949;">[</span>WORD_SIZE<span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
input<span style="color: #bbb;">[</span>i<span style="color: #bbb;">]</span> = immediateAddressSpace<span style="color: #bbb;">[</span>254<span style="color: #bbb;">][</span>i<span style="color: #bbb;">]</span>;
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-weight: bold; font-style: italic;">getOutput</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">output</span> = <span style="color: #494949;">""</span>;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>immediateAddressSpace<span style="color: #494949;">[</span>254<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
output += <span style="color: #494949;">"1"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #bbb;">{</span>
output += <span style="color: #494949;">"0"</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">return</span> output;
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">setInput</span><span style="color: #bbb;">(</span><span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">input</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < WORD_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>input<span style="color: #494949;">[</span>i<span style="color: #494949;">]</span> == <span style="color: #494949;">'1'</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>253<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 1;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>253<span style="color: #494949;">][</span>i<span style="color: #494949;">]</span> = 0;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">short</span> <span style="font-weight: bold; font-style: italic;">getinstructionCounter</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">return</span> instructionCounter;
<span style="color: #bbb;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/* </span>
<span style="color: #a4a4a4; font-style: italic;"> * this is a dummy bootloader designed to clear the immediately addressable space and load the </span>
<span style="color: #a4a4a4; font-style: italic;"> * relevant system/b machine code file into the immediately addressable file space</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">boot</span><span style="color: #bbb;">(</span><span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">filename</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">ifstream</span> <span style="font-style: italic;">inFile</span><span style="color: #494949;">(</span>filename<span style="color: #494949;">)</span>;
<span style="color: #E53935;">char</span> <span style="font-style: italic;">bit</span>;
instructionCounter = 0;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < IMM_ADDR_SPACE_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #bbb;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">j</span> = 0; j < WORD_SIZE; j++<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>i<span style="color: #494949;">][</span>j<span style="color: #494949;">]</span> = 0;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < IMM_ADDR_SPACE_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #bbb;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">j</span> = 0; j < WORD_SIZE; j++<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
inFile >> bit;
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>inFile<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>bit == <span style="color: #494949;">'1'</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>i<span style="color: #494949;">][</span>j<span style="color: #494949;">]</span> = 1;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>bit == <span style="color: #494949;">'0'</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
immediateAddressSpace<span style="color: #494949;">[</span>i<span style="color: #494949;">][</span>j<span style="color: #494949;">]</span> = 0;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #494949;">{</span>
immediateAddressSpace<span style="color: #bbb;">[</span>i<span style="color: #bbb;">][</span>j<span style="color: #bbb;">]</span> = 0;
<span style="color: #494949;">}</span>
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>
instructionCounter = 0;
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">immDump</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">ofstream</span> <span style="font-style: italic;">otFile</span><span style="color: #494949;">(</span><span style="color: #494949;">"immDump.txt"</span><span style="color: #494949;">)</span>;
otFile << <span style="color: #494949;">"current instruction counter : "</span> << instructionCounter << <span style="color: #E53935;">std</span>::endl;
otFile << <span style="color: #494949;">"Immediate Address Space State :"</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < IMM_ADDR_SPACE_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #bbb;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">j</span> = 0; j < WORD_SIZE; j++<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
otFile << immediateAddressSpace<span style="color: #494949;">[</span>i<span style="color: #494949;">][</span>j<span style="color: #494949;">]</span>;
<span style="color: #bbb;">}</span>
otFile << <span style="color: #494949;">" "</span> << i << <span style="color: #E53935;">std</span>::endl;
<span style="color: #494949;">}</span>
otFile.close<span style="color: #494949;">()</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">idrDump</span><span style="color: #bbb;">()</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">ofstream</span> <span style="font-style: italic;">otFile</span><span style="color: #494949;">(</span><span style="color: #494949;">"idrDump.txt"</span><span style="color: #494949;">)</span>;
otFile << <span style="color: #494949;">"current instruction counter : "</span> << instructionCounter << <span style="color: #E53935;">std</span>::endl;
otFile << <span style="color: #494949;">"indirect address space state : "</span> << <span style="color: #E53935;">std</span>::endl;
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #494949;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">i</span> = 0; i < IDR_ADDR_SPACE_SIZE; i++<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">for</span> <span style="color: #bbb;">(</span><span style="color: #E53935;">int</span> <span style="font-style: italic;">j</span> = 0; j < WORD_SIZE; j++<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
otFile << indirectAddressSpace<span style="color: #494949;">[</span>i<span style="color: #494949;">][</span>j<span style="color: #494949;">]</span>;
<span style="color: #bbb;">}</span>
otFile << <span style="color: #494949;">" "</span> << i << <span style="color: #E53935;">std</span>::endl;
<span style="color: #494949;">}</span>
otFile.close<span style="color: #494949;">()</span>;
<span style="color: #bbb;">}</span>
<span style="color: #494949;">}</span>;
</pre>
</div>
</div>
</div>
<div id="outline-container-org3d05a37" class="outline-3">
<h3 id="org3d05a37">ioStrings.h</h3>
<div class="outline-text-3" id="text-org3d05a37">
<p>
This is a file that I used to store functions that would return strings. Honestly I probably should have just had a file of constant functions, but these were the old days when I didn't know better and wanted everything to be "functional" regardless of how good an idea that was. <label class="sidenote-number" for="2"><sup>2</sup></label><input checked="checked" id="2" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 2</span> Be glad I have spared you from the worst of it where I wrote several C++ programs with only recursion and constants, no loops or mutable variables. I probably gave my algorithms teacher nightmares.</span> As a consequence I did things a bit weirdly.
</p>
<div class="org-src-container">
<pre class="src src-C++"><span style="color: #000; font-weight: bold;">#pragma</span> once
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">string</span><span style="color: #494949;">></span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-weight: bold; font-style: italic;">welcomeText</span><span style="color: #494949;">()</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">return</span>
<span style="color: #494949;">" __ __ __ \n"</span>
<span style="color: #494949;">" _______ _______/ /____ ____ ___ _/_/ / /_ \n"</span>
<span style="color: #494949;">" / ___/ / / / ___/ __/ _ \\/ __ `__ \\ _/_/ / __ \\\n"</span>
<span style="color: #494949;">" (__ ) /_/ (__ ) /_/ __/ / / / / / _/_/ / /_/ /\n"</span>
<span style="color: #494949;">"/____/\\__, /____/\\__/\\___/_/ /_/ /_/ /_/ /_.___/ \n"</span>
<span style="color: #494949;">" /____/ \n"</span>
<span style="color: #494949;">"a simple virtual machine\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>;
<span style="color: #494949;">}</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-weight: bold; font-style: italic;">errorText</span><span style="color: #494949;">()</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">return</span>
<span style="color: #494949;">"Invalid input, could not parse.\n"</span>
<span style="color: #494949;">"Abort, Retry, Fail?\n"</span>
<span style="color: #494949;">"\n"</span>;
<span style="color: #494949;">}</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-weight: bold; font-style: italic;">manualText</span><span style="color: #494949;">()</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">return</span>
<span style="color: #494949;">"system/b manual : \n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"system/b is an evolution on the earlier system/a virtual machine archictecture using\n"</span>
<span style="color: #494949;">"a similar 32 bit word size and word addressed memory, but now with direct addressing\n"</span>
<span style="color: #494949;">"allowing for a signifigant expansion in the size of programs that can be run by\n"</span>
<span style="color: #494949;">"system/b from 1024 bytes to up to 17179869184 bytes of code. This is divided between\n"</span>
<span style="color: #494949;">"the 1024 bytes of immediately addressed space and 17179869184 bytes of directly\n"</span>
<span style="color: #494949;">"addressed space. Direct addressing is conducted using the RED and WRT instructions. An\n"</span>
<span style="color: #494949;">"explination of the instructions used by system/b and their use is contained in the\n"</span>
<span style="color: #494949;">"\"instruction setsection\" of the system/b manual.\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"sections :\n"</span>
<span style="color: #494949;">"0 basic operation \\ shell commands\n"</span>
<span style="color: #494949;">"1 instruction set\n"</span>
<span style="color: #494949;">"2 debugging code\n"</span>
<span style="color: #494949;">"3 system implmentation\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"0 basic operation \\ shell commands :\n"</span>
<span style="color: #494949;">"command, alias | arguments | description \n"</span>
<span style="color: #494949;">"assemble, a | input_file(sba), output_file(sbm) | assembles the input file\n"</span>
<span style="color: #494949;">"manual, m | null | displays this manual\n"</span>
<span style="color: #494949;">"quit, q | null | quits the shell\n"</span>
<span style="color: #494949;">"boot, b | input_file(sbm) | boots the systm/b vm with\n"</span>
<span style="color: #494949;">" | | the code in the immediately\n"</span>
<span style="color: #494949;">" | | addressed space.\n"</span>
<span style="color: #494949;">"stepCycle, sc | null | steps the system/b vm one cycle\n"</span>
<span style="color: #494949;">"immDump, imm | null | dumps the immediately addressed\n"</span>
<span style="color: #494949;">" | | space to the file \"immDump.txt\"\n"</span>
<span style="color: #494949;">"idrDump, idr | null | dumps the indirectly addressed\n"</span>
<span style="color: #494949;">" | | space to the file \"idrDump.txt\"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"1 instruction set :\n"</span>
<span style="color: #494949;">"The system/b instruction set is a fixed width instructon set containing eight\n"</span>
<span style="color: #494949;">"instructions, MOV, ADD, FLP, JIE, JMP, RED, WRT and STP. All instructions except the\n"</span>
<span style="color: #494949;">"special instructions RED and WRT only access data from the immediately addressed space.\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"standard instruction format :\n"</span>
<span style="color: #494949;">"[instruction] [argument address] [argument address] [argument address]\n"</span>
<span style="color: #494949;">" JIE AB 10 23 \n"</span>
<span style="color: #494949;">" 0000 1010 1010 1011 0001 0000 0010 0011 \n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : JIE\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 1010\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"JIE [argument address] [argument address] [argument address]\n"</span>
<span style="color: #494949;">"jumps to the third argument address if the value of the first argument\n"</span>
<span style="color: #494949;">"address equals the second argumet address\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : JMP\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 0101\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"JMP [argument address]\n"</span>
<span style="color: #494949;">"unconditionally jumps to the argument address provided\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : MOV\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 1100\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"MOV [argument address] [argument address]\n"</span>
<span style="color: #494949;">"copies the value stored in the first argument address to the second argument\n"</span>
<span style="color: #494949;">"address unconditionally\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : ADD\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 1011\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"ADD [argument address] [argument address] [argument address]\n"</span>
<span style="color: #494949;">"adds the contents of the first argument address to the second argument\n"</span>
<span style="color: #494949;">"address and then places the result in the third argument address\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : FLP\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 0100\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"FLP [argument address]\n"</span>
<span style="color: #494949;">"flips the bits in the argument address provided\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : RED\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 1101\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"RED [argument address] [argument address]\n"</span>
<span style="color: #494949;">"special instruction, reads the value located in the directly addressed\n"</span>
<span style="color: #494949;">"space to the second argument address, the first argument address provides\n"</span>
<span style="color: #494949;">"the pointer to the location of the data in the directly addressed space\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : WRT\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 0010\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"WRT [argument address] [argument address]\n"</span>
<span style="color: #494949;">"special instruction, writes the value located in the second argument\n"</span>
<span style="color: #494949;">"address to an address located in the directly addressed space, the first\n"</span>
<span style="color: #494949;">"argument address provides the pointer to the location of the data in the\n"</span>
<span style="color: #494949;">"directly addresssed space\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"instruction : STP\n"</span>
<span style="color: #494949;">"binary representatioin : 0000 1111\n"</span>
<span style="color: #494949;">"usage : \n"</span>
<span style="color: #494949;">"STP\n"</span>
<span style="color: #494949;">"Stops the execution of code by system/b\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"debugging code :\n"</span>
<span style="color: #494949;">"To debug system/b assembly programs, simply create a system/b instance\n"</span>
<span style="color: #494949;">"and load a system/b machine code file into the machine. Then step through\n"</span>
<span style="color: #494949;">"the code using the included assembler using the \"stepCycle\" command, it\n"</span>
<span style="color: #494949;">"may be advisable to use the immDump and idrDump commands to gain a \n"</span>
<span style="color: #494949;">"snapshot of the immediate address space and the indirect address space.\n"</span>
<span style="color: #494949;">"Viewing these snapshots, translate the binary to the assembly yourself and\n"</span>
<span style="color: #494949;">"use that to identify how the program is running\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"\n"</span>
<span style="color: #494949;">"system implmentation :\n"</span>
<span style="color: #494949;">"system/b is a simple machine modled loosely on the Analytical Engine\n"</span>
<span style="color: #494949;">"as created by Charles Babbage. The operation of system/b is simple to,\n"</span>
<span style="color: #494949;">"visualize. The code is loaded into the immediately addressable space as\n"</span>
<span style="color: #494949;">"a series of binary instructions that are read by the machine and then\n"</span>
<span style="color: #494949;">"executed, with all non-jump instructions iterating the instruction counter\n"</span>
<span style="color: #494949;">"by, causing the next instruction in the immediately addressed space to \n"</span>
<span style="color: #494949;">"be executed. Code can be loaded into the directly addressed space using the\n"</span>
<span style="color: #494949;">"special WRT instruction and read from it using the RED instruction. All numbers\n"</span>
<span style="color: #494949;">"are stored in a little endian two's complment format."</span>;
<span style="color: #494949;">}</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-weight: bold; font-style: italic;">quitText</span><span style="color: #494949;">()</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935; font-style: italic;">return</span>
<span style="color: #494949;">"Thank you for using system/b, have a nice day.\n"</span>;
<span style="color: #494949;">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org559422c" class="outline-3">
<h3 id="org559422c">assembler.h</h3>
<div class="outline-text-3" id="text-org559422c">
<div class="org-src-container">
<pre class="src src-C++"><span style="color: #000; font-weight: bold;">#pragma</span> once
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">fstream</span><span style="color: #494949;">></span>
<span style="color: #000; font-weight: bold;">#include</span> <span style="color: #494949;"><</span><span style="color: #494949;">bitset</span><span style="color: #494949;">></span>
<span style="color: #E53935;">void</span> <span style="font-weight: bold; font-style: italic;">assemble</span><span style="color: #494949;">(</span><span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">inputFile</span>, <span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">outputFile</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">ifstream</span> <span style="font-style: italic;">inFile</span>;
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">ofstream</span> <span style="font-style: italic;">otFile</span><span style="color: #bbb;">(</span>outputFile<span style="color: #bbb;">)</span>;
<span style="color: #E53935;">std</span>::<span style="color: #E53935;">string</span> <span style="font-style: italic;">instruction</span>,
<span style="font-style: italic;">argumentAddr1</span>,
<span style="font-style: italic;">argumentAddr2</span>,
<span style="font-style: italic;">argumentAddr3</span>,
<span style="font-style: italic;">machineLine</span>,
<span style="font-style: italic;">ignore</span>;
<span style="color: #E53935;">bool</span> <span style="font-style: italic;">complete</span> = <span style="color: #E53935;">false</span>;
inFile.open<span style="color: #bbb;">(</span>inputFile<span style="color: #bbb;">)</span>;
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span><span style="color: #000; font-weight: bold;">!</span>inFile<span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935; font-style: italic;">throw</span> <span style="color: #E53935;">std</span>::invalid_argument<span style="color: #494949;">(</span><span style="color: #494949;">"infile not accessable"</span><span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">while</span> <span style="color: #bbb;">(</span><span style="color: #000; font-weight: bold;">!</span>complete<span style="color: #bbb;">)</span> <span style="color: #bbb;">{</span>
inFile >> instruction;
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>inFile<span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> * this checks if the instruction is actually a comment</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>instruction == <span style="color: #494949;">";"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">{</span>
<span style="color: #E53935;">std</span>::getline<span style="color: #494949;">(</span>inFile, ignore<span style="color: #494949;">)</span>;
<span style="color: #bbb;">}</span>
<span style="color: #E53935; font-style: italic;">else</span>
<span style="color: #bbb;">{</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : JIE</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1010</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> JIE [argument address] [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> jumps to the third argument address if the value of the first argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address equals the second argumet address</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"JIE"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
inFile >> argumentAddr2;
inFile >> argumentAddr3;
machineLine = <span style="color: #494949;">"00001010"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr2<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr3<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : JMP</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0101</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> JMP [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> unconditionally jumps to the argument address provided</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"JMP"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
machineLine = <span style="color: #494949;">"00000101"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #494949;">"0000000000000000"</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : MOV</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1100</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> MOV [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> copies the value stored in the first argument address to the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address unconditionally</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"MOV"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
inFile >> argumentAddr2;
machineLine = <span style="color: #494949;">"00001100"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr2<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #494949;">"00000000"</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : ADD</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1011</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> ADD [argument address] [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> adds the contents of the first argument address to the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address and then places the result in the third argument address</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"ADD"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
inFile >> argumentAddr2;
inFile >> argumentAddr3;
machineLine = <span style="color: #494949;">"00001011"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr2<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr3<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : FLP</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0100</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> FLP [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> flips the bits in the argument address provided</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"FLP"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
machineLine = <span style="color: #494949;">"00000100"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #494949;">"0000000000000000"</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : RED</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 1101</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> RED [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> special instruction, reads the value located in the directly addressed</span>
<span style="color: #a4a4a4; font-style: italic;"> space to the second argument address, the first argument address provides</span>
<span style="color: #a4a4a4; font-style: italic;"> the pointer to the location of the data in the directly addressed space</span>
<span style="color: #a4a4a4; font-style: italic;"> */</span>
<span style="color: #E53935; font-style: italic;">else</span> <span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>instruction == <span style="color: #494949;">"RED"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">{</span>
inFile >> argumentAddr1;
inFile >> argumentAddr2;
machineLine = <span style="color: #494949;">"00001101"</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr1<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #E53935;">std</span>::bitset<span style="color: #bbb;"><</span>8<span style="color: #bbb;">>(</span>stoi<span style="color: #494949;">(</span>argumentAddr2<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>.to_string<span style="color: #bbb;">()</span> + <span style="color: #494949;">"00000000"</span>;
<span style="color: #494949;">}</span>
<span style="color: #a4a4a4; font-style: italic;">/*</span>
<span style="color: #a4a4a4; font-style: italic;"> instruction : WRT</span>
<span style="color: #a4a4a4; font-style: italic;"> binary representatioin : 0000 0010</span>
<span style="color: #a4a4a4; font-style: italic;"> usage :</span>
<span style="color: #a4a4a4; font-style: italic;"> WRT [argument address] [argument address]</span>
<span style="color: #a4a4a4; font-style: italic;"> special instruction, writes the value located in the second argument</span>
<span style="color: #a4a4a4; font-style: italic;"> address to an address located in the directly addressed space, the first</span>
<span style="color: #a4a4a4; font-style: italic;"> argument address provides the pointer to the location of the data in the</span>
<span style="color: #a4a4a4; font-style: italic;"> directly addresssed space</span>