-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcpu_basics.mac
More file actions
3617 lines (3590 loc) · 110 KB
/
cpu_basics.mac
File metadata and controls
3617 lines (3590 loc) · 110 KB
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
; $Id: cpu_basics.mac 1388 2023-05-19 15:18:42Z mueller $
; SPDX-License-Identifier: GPL-3.0-or-later
; Copyright 2015-2023 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
;
; Revision History:
; Date Rev Version Comment
; 2023-03-27 1388 1.1.1 A4.4: change exemptions, e11 now like 11/70 and w11
; 2023-01-27 1358 1.1 use .mcall and mlib
; 2023-01-07 1347 1.0 Initial version
; 2015-08-30 710 0.1 First draft
;
; Test CPU basics: most instructions except traps, EIS and FPP
; Section A: ccops + flow control bxx, sob, jmp, jsr, rts, mark
; Section B: unary instructions (word)
; Section C: binary instructions (word)
; Section D: unary instructions (byte)
; Section E: binary instructions (byte)
; Section F: miscellaneous (spl, reset, bpt, m*p*, ...)
;
.include |lib/tcode_std_base.mac|
.include |lib/defs_kwl.mac|
;
.mcall push
.mcall hcmpeq,hcmbeq,htsteq,htsbeq,hbiteq,hbitne
.mcall vecset,vecclr
;
; Section A: ccops + flow control bxx, sob, jmp, jsr, rts, mark ==============
; A1 ccop + bbx
; A1.1 ccop + psw
; A1.2 ccop + bxx
; A2 sob
; A3 jmp
; A3.1 jmp + dsta
; A3.2 jmp + cc
; A4 jsr + rts
; A4.1 jsr + dsta
; A4.2 jsr + cc
; A4.3 jsr r0-r5
; A4.4 jsr sp and rts sp
; A4.5 jsr r1,(r1)+ and jsr r2,@(r2)+
; A5 mark
;
; Test A1: ccop + bxx +++++++++++++++++++++++++++++++++++++++++++++++++++++++
; This sub-section verifies
; x xxx xxx xxx xxx xxx NZVC Instruction / Remark
; 0 000 000 010 10n zvc NZVC CLx
; 0 000 000 010 11n zvc NZVC SEx
;
; 0 000 000 1bb bbb bbb ---- BR always
;
; 0 000 001 0bb bbb bbb ---- BNE if Z = 0
; 0 000 001 1bb bbb bbb ---- BEQ if Z = 1
; 0 000 010 0bb bbb bbb ---- BGE if (N xor V) = 0
; 0 000 010 1bb bbb bbb ---- BLT if (N xor V) = 1
; 0 000 011 0bb bbb bbb ---- BGT if (Z or (N xor V)) = 0
; 0 000 011 1bb bbb bbb ---- BLE if (Z or (N xor V)) = 1
;
; 1 000 000 0bb bbb bbb ---- BPL if N = 0
; 1 000 000 1bb bbb bbb ---- BMI if N = 1
; 1 000 001 0bb bbb bbb ---- BHI if (C or Z) = 0
; 1 000 001 1bb bbb bbb ---- BLOS if (C or Z) = 1
; 1 000 010 0bb bbb bbb ---- BVC if V = 0
; 1 000 010 1bb bbb bbb ---- BVS if V = 1
; 1 000 011 0bb bbb bbb ---- BCC if C = 0
; 1 000 011 1bb bbb bbb ---- BCS if C = 1
;
; Test A1.1 -- ccop + psw ++++++++++++++++++++++++++++++++++++++++++++
; This test sets and clears all four condition codes and verifies that
; the psw properly reflects this.
;
ta0101: mov #cp.psw,r0
clr (r0)
;
ccc ; nzvc = 0000
hcmpeq (r0),#cp0000
; sec
ccc
sec ; nzvc = 0001
hcmpeq (r0),#cp000c
; sev
ccc
sev ; nzvc = 0010
hcmpeq (r0),#cp00v0
; sez
ccc
sez ; nzvc = 0100
hcmpeq (r0),#cp0z00
; sen
ccc
sen ; nzvc = 1000
hcmpeq (r0),#cpn000
; sen!sec
ccc
<sen!sec> ; nzvc = 1001
hcmpeq (r0),#cpn00c
; sez!sev
ccc
<sez!sev> ; nzvc = 1001
hcmpeq (r0),#cp0zv0
;
scc ; nzvc = 1111
hcmpeq (r0),#cpnzvc
; clc
scc
clc ; nzvc = 1110
hcmpeq (r0),#cpnzv0
; clv
scc
clv ; nzvc = 1101
hcmpeq (r0),#cpnz0c
; clz
scc
clz ; nzvc = 1011
hcmpeq (r0),#cpn0vc
; cln
scc
cln ; nzvc = 0111
hcmpeq (r0),#cp0zvc
; cln!clc
scc
<cln!clc> ; nzvc = 0110
hcmpeq (r0),#cp0zv0
; clz!clv
scc
<clz!clv> ; nzvc = 1001
hcmpeq (r0),#cpn00c
;
9999$: iot ; end of test A1.1
; Test A1.2 -- ccop + bxx ++++++++++++++++++++++++++++++++++++++++++++
; This test sets all possible combinations of condition code bits
; (with cc ops) and verifies the branch instruction response
; Note: after normal compares N will never be 1 if Z=1 (a number can not
; zero and negative simultaneously). Thus not all combinations are
; used in normal code execution.
;
ta0102: clr @#cp.psw
;
; case NZVC = 0000 -- N=0 Z=0 V=0 C=0 ------------------------
;
ccc
;
;
bne 1$ ; yes Z=0
halt
1$: beq 99$ ; no Z=1
;
2$: bge 3$ ; yes (N xor V) = 0
halt
3$: blt 99$ ; no (N xor V) = 1
;
4$: bgt 5$ ; yes (Z or (N xor V)) = 0
halt
5$: ble 99$ ; no (Z or (N xor V)) = 1
;
6$: bpl 7$ ; yes N = 0
halt
7$: bmi 99$ ; no N = 1
;
8$: bhi 9$ ; yes (C or Z) = 0
halt
9$: blos 99$ ; no (C or Z) = 1
;
10$: bvc 11$ ; yes V = 0
halt
11$: bvs 99$ ; no V = 1
;
12$: bcc 13$ ; yes C = 0
halt
13$: bcs 99$ ; no C = 1
;
14$: br 100$
99$: halt
;
; case NZVC = 0001 -- N=0 Z=0 V=0 C=1 ------------------------
;
100$: ccc
sec
;
bne 101$ ; yes Z=0
halt
101$: beq 199$ ; no Z=1
;
102$: bge 103$ ; yes (N xor V) = 0
halt
103$: blt 199$ ; no (N xor V) = 1
;
104$: bgt 105$ ; yes (Z or (N xor V)) = 0
halt
105$: ble 199$ ; no (Z or (N xor V)) = 1
;
106$: bpl 107$ ; yes N = 0
halt
107$: bmi 199$ ; no N = 1
;
108$: bhi 199$ ; no (C or Z) = 0
;
109$: blos 110$ ; yes (C or Z) = 1
halt
110$: bvc 111$ ; yes V = 0
halt
111$: bvs 199$ ; no V = 1
;
112$: bcc 199$ ; no C = 0
;
113$: bcs 114$ ; yes C = 1
halt
114$: br 200$
199$: halt
;
; case NZVC = 0010 -- N=0 Z=0 V=1 C=0 ------------------------
;
200$: ccc
sev
;
bne 201$ ; yes Z=0
halt
201$: beq 299$ ; no Z=1
;
202$: bge 299$ ; no (N xor V) = 0
;
203$: blt 204$ ; yes (N xor V) = 1
halt
204$: bgt 299$ ; no (Z or (N xor V)) = 0
;
205$: ble 206$ ; yes (Z or (N xor V)) = 1
halt
206$: bpl 207$ ; yes N = 0
halt
207$: bmi 299$ ; no N = 1
;
208$: bhi 209$ ; yes (C or Z) = 0
halt
209$: blos 299$ ; no (C or Z) = 1
;
210$: bvc 299$ ; no V = 0
;
211$: bvs 212$ ; yes V = 1
halt
212$: bcc 213$ ; yes C = 0
halt
213$: bcs 299$ ; no C = 1
;
214$: br 300$
299$: halt
;
; case NZVC = 0011 -- N=0 Z=0 V=1 C=1 ------------------------
;
300$: ccc
<sev!sec>
;
bne 301$ ; yes Z=0
halt
301$: beq 399$ ; no Z=1
;
302$: bge 399$ ; no (N xor V) = 0
;
303$: blt 304$ ; yes (N xor V) = 1
halt
304$: bgt 399$ ; no (Z or (N xor V)) = 0
;
305$: ble 306$ ; yes (Z or (N xor V)) = 1
halt
306$: bpl 307$ ; yes N = 0
halt
307$: bmi 399$ ; no N = 1
;
308$: bhi 399$ ; no (C or Z) = 0
;
309$: blos 310$ ; yes (C or Z) = 1
halt
310$: bvc 399$ ; no V = 0
;
311$: bvs 312$ ; yes V = 1
halt
312$: bcc 399$ ; no C = 0
;
313$: bcs 314$ ; yes C = 1
halt
314$: br 400$
399$: halt
;
; case NZVC = 0100 -- N=0 Z=1 V=0 C=0 ------------------------
;
400$: ccc
sez
;
bne 499$ ; no Z=0
;
401$: beq 402$ ; yes Z=1
halt
402$: bge 403$ ; yes (N xor V) = 0
halt
403$: blt 499$ ; no (N xor V) = 1
;
404$: bgt 499$ ; no (Z or (N xor V)) = 0
;
405$: ble 406$ ; yes (Z or (N xor V)) = 1
halt
406$: bpl 407$ ; yes N = 0
halt
407$: bmi 499$ ; no N = 1
;
408$: bhi 499$ ; no (C or Z) = 0
;
409$: blos 410$ ; yes (C or Z) = 1
halt
410$: bvc 411$ ; yes V = 0
halt
411$: bvs 499$ ; no V = 1
;
412$: bcc 413$ ; yes C = 0
halt
413$: bcs 499$ ; no C = 1
;
414$: br 500$
499$: halt
;
; case NZVC = 0101 -- N=0 Z=1 V=0 C=1 ------------------------
;
500$: ccc
<sez!sec>
;
bne 599$ ; no Z=0
;
501$: beq 502$ ; yes Z=1
halt
502$: bge 503$ ; yes (N xor V) = 0
halt
503$: blt 599$ ; no (N xor V) = 1
;
504$: bgt 599$ ; no (Z or (N xor V)) = 0
;
505$: ble 506$ ; yes (Z or (N xor V)) = 1
halt
506$: bpl 507$ ; yes N = 0
halt
507$: bmi 599$ ; no N = 1
;
508$: bhi 599$ ; no (C or Z) = 0
;
509$: blos 510$ ; yes (C or Z) = 1
halt
510$: bvc 511$ ; yes V = 0
halt
511$: bvs 599$ ; no V = 1
;
512$: bcc 599$ ; no C = 0
;
513$: bcs 514$ ; yes C = 1
halt
514$: br 600$
599$: halt
;
; case NZVC = 0110 -- N=0 Z=1 V=1 C=0 ------------------------
;
600$: ccc
<sez!sev>
;
bne 699$ ; no Z=0
;
601$: beq 602$ ; yes Z=1
halt
602$: bge 699$ ; no (N xor V) = 0
;
603$: blt 604$ ; yes (N xor V) = 1
halt
604$: bgt 699$ ; no (Z or (N xor V)) = 0
;
605$: ble 606$ ; yes (Z or (N xor V)) = 1
halt
606$: bpl 607$ ; yes N = 0
halt
607$: bmi 699$ ; no N = 1
;
608$: bhi 699$ ; no (C or Z) = 0
;
609$: blos 610$ ; yes (C or Z) = 1
halt
610$: bvc 699$ ; no V = 0
;
611$: bvs 612$ ; yes V = 1
halt
612$: bcc 613$ ; yes C = 0
halt
613$: bcs 699$ ; no C = 1
;
614$: br 700$
699$: halt
;
; case NZVC = 0111 -- N=0 Z=1 V=1 C=1 ------------------------
;
700$: scc
cln
;
bne 799$ ; no Z=0
;
701$: beq 702$ ; yes Z=1
halt
702$: bge 799$ ; no (N xor V) = 0
;
703$: blt 704$ ; yes (N xor V) = 1
halt
704$: bgt 799$ ; no (Z or (N xor V)) = 0
;
705$: ble 706$ ; yes (Z or (N xor V)) = 1
halt
706$: bpl 707$ ; yes N = 0
halt
707$: bmi 799$ ; no N = 1
;
708$: bhi 799$ ; no (C or Z) = 0
;
709$: blos 710$ ; yes (C or Z) = 1
halt
710$: bvc 799$ ; no V = 0
;
711$: bvs 712$ ; yes V = 1
halt
712$: bcc 799$ ; no C = 0
;
713$: bcs 714$ ; yes C = 1
halt
714$: br 1000$
799$: halt
;
; case NZVC = 1000 -- N=1 Z=0 V=0 C=0 ------------------------
;
1000$: ccc
sen
;
bne 1001$ ; yes Z=0
halt
1001$: beq 1099$ ; no Z=1
;
1002$: bge 1099$ ; no (N xor V) = 0
;
1003$: blt 1004$ ; yes (N xor V) = 1
halt
1004$: bgt 1099$ ; no (Z or (N xor V)) = 0
;
1005$: ble 1006$ ; yes (Z or (N xor V)) = 1
halt
1006$: bpl 1099$ ; no N = 0
;
1007$: bmi 1008$ ; yes N = 1
halt
1008$: bhi 1009$ ; yes (C or Z) = 0
halt
1009$: blos 1099$ ; no (C or Z) = 1
;
1010$: bvc 1011$ ; yes V = 0
halt
1011$: bvs 1099$ ; no V = 1
;
1012$: bcc 1013$ ; yes C = 0
halt
1013$: bcs 1099$ ; no C = 1
;
1014$: br 1100$
1099$: halt
;
; case NZVC = 1001 -- N=1 Z=0 V=0 C=1 ------------------------
;
1100$: ccc
<sen!sec>
;
bne 1101$ ; yes Z=0
halt
1101$: beq 1199$ ; no Z=1
;
1102$: bge 1199$ ; no (N xor V) = 0
;
1103$: blt 1104$ ; yes (N xor V) = 1
halt
1104$: bgt 1199$ ; no (Z or (N xor V)) = 0
;
1105$: ble 1106$ ; yes (Z or (N xor V)) = 1
halt
1106$: bpl 1199$ ; no N = 0
;
1107$: bmi 1108$ ; yes N = 1
halt
1108$: bhi 1199$ ; no (C or Z) = 0
;
1109$: blos 1110$ ; yes (C or Z) = 1
halt
1110$: bvc 1111$ ; yes V = 0
halt
1111$: bvs 1199$ ; no V = 1
;
1112$: bcc 1199$ ; no C = 0
;
1113$: bcs 1114$ ; yes C = 1
halt
1114$: br 1200$
1199$: halt
;
; case NZVC = 1010 -- N=1 Z=0 V=1 C=0 ------------------------
;
1200$: ccc
<sen!sev>
;
bne 1201$ ; yes Z=0
halt
1201$: beq 1299$ ; no Z=1
;
1202$: bge 1203$ ; yes (N xor V) = 0
halt
1203$: blt 1299$ ; no (N xor V) = 1
;
1204$: bgt 1205$ ; yes (Z or (N xor V)) = 0
halt
1205$: ble 1299$ ; no (Z or (N xor V)) = 1
;
1206$: bpl 1299$ ; no N = 0
;
1207$: bmi 1208$ ; yes N = 1
halt
1208$: bhi 1209$ ; yes (C or Z) = 0
halt
1209$: blos 1299$ ; no (C or Z) = 1
;
1210$: bvc 1299$ ; no V = 0
;
1211$: bvs 1212$ ; yes V = 1
halt
1212$: bcc 1213$ ; yes C = 0
halt
1213$: bcs 1299$ ; no C = 1
;
1214$: br 1300$
1299$: halt
;
; case NZVC = 1011 -- N=1 Z=0 V=1 C=1 ------------------------
;
1300$: scc
clz
;
bne 1301$ ; yes Z=0
halt
1301$: beq 1399$ ; no Z=1
;
1302$: bge 1303$ ; yes (N xor V) = 0
halt
1303$: blt 1399$ ; no (N xor V) = 1
;
1304$: bgt 1305$ ; yes (Z or (N xor V)) = 0
halt
1305$: ble 1399$ ; no (Z or (N xor V)) = 1
;
1306$: bpl 1399$ ; no N = 0
;
1307$: bmi 1308$ ; yes N = 1
halt
1308$: bhi 1399$ ; no (C or Z) = 0
;
1309$: blos 1310$ ; yes (C or Z) = 1
halt
1310$: bvc 1399$ ; no V = 0
;
1311$: bvs 1312$ ; yes V = 1
halt
1312$: bcc 1399$ ; no C = 0
;
1313$: bcs 1314$ ; yes C = 1
halt
1314$: br 1400$
1399$: halt
;
; case NZVC = 1100 -- N=1 Z=1 V=0 C=0 ------------------------
;
1400$: ccc
<sen!sez>
;
bne 1499$ ; no Z=0
;
1401$: beq 1402$ ; yes Z=1
halt
1402$: bge 1499$ ; no (N xor V) = 0
;
1403$: blt 1404$ ; yes (N xor V) = 1
halt
1404$: bgt 1499$ ; no (Z or (N xor V)) = 0
;
1405$: ble 1406$ ; yes (Z or (N xor V)) = 1
halt
1406$: bpl 1499$ ; no N = 0
;
1407$: bmi 1408$ ; yes N = 1
halt
1408$: bhi 1499$ ; no (C or Z) = 0
;
1409$: blos 1410$ ; yes (C or Z) = 1
halt
1410$: bvc 1411$ ; yes V = 0
halt
1411$: bvs 1499$ ; no V = 1
;
1412$: bcc 1413$ ; yes C = 0
halt
1413$: bcs 1499$ ; no C = 1
;
1414$: br 1500$
1499$: halt
;
; case NZVC = 1101 -- N=1 Z=1 V=0 C=1 ------------------------
;
1500$: scc
clv
;
bne 1599$ ; no Z=0
;
1501$: beq 1502$ ; yes Z=1
halt
1502$: bge 1599$ ; no (N xor V) = 0
;
1503$: blt 1504$ ; yes (N xor V) = 1
halt
1504$: bgt 1599$ ; no (Z or (N xor V)) = 0
;
1505$: ble 1506$ ; yes (Z or (N xor V)) = 1
halt
1506$: bpl 1599$ ; no N = 0
;
1507$: bmi 1508$ ; yes N = 1
halt
1508$: bhi 1599$ ; no (C or Z) = 0
;
1509$: blos 1510$ ; yes (C or Z) = 1
halt
1510$: bvc 1511$ ; yes V = 0
halt
1511$: bvs 1599$ ; no V = 1
;
1512$: bcc 1599$ ; no C = 0
;
1513$: bcs 1514$ ; yes C = 1
halt
1514$: br 1600$
1599$: halt
;
; case NZVC = 1110 -- N=1 Z=1 V=1 C=0 ------------------------
;
1600$: scc
clc
;
bne 1699$ ; no Z=0
;
1601$: beq 1602$ ; yes Z=1
halt
1602$: bge 1603$ ; yes (N xor V) = 0
halt
1603$: blt 1699$ ; no (N xor V) = 1
;
1604$: bgt 1699$ ; no (Z or (N xor V)) = 0
;
1605$: ble 1606$ ; yes (Z or (N xor V)) = 1
halt
1606$: bpl 1699$ ; no N = 0
;
1607$: bmi 1608$ ; yes N = 1
halt
1608$: bhi 1699$ ; no (C or Z) = 0
;
1609$: blos 1610$ ; yes (C or Z) = 1
halt
1610$: bvc 1699$ ; no V = 0
;
1611$: bvs 1612$ ; yes V = 1
halt
1612$: bcc 1613$ ; yes C = 0
halt
1613$: bcs 1699$ ; no C = 1
;
1614$: br 1700$
1699$: halt
;
; case NZVC = 1111 -- N=1 Z=1 V=1 C=1 ------------------------
;
1700$: scc
;
bne 1799$ ; no Z=0
;
1701$: beq 1702$ ; yes Z=1
halt
1702$: bge 1703$ ; yes (N xor V) = 0
halt
1703$: blt 1799$ ; no (N xor V) = 1
;
1704$: bgt 1799$ ; no (Z or (N xor V)) = 0
;
1705$: ble 1706$ ; yes (Z or (N xor V)) = 1
halt
1706$: bpl 1799$ ; no N = 0
;
1707$: bmi 1708$ ; yes N = 1
halt
1708$: bhi 1799$ ; no (C or Z) = 0
;
1709$: blos 1710$ ; yes (C or Z) = 1
halt
1710$: bvc 1799$ ; no V = 0
;
1711$: bvs 1712$ ; yes V = 1
halt
1712$: bcc 1799$ ; no C = 0
;
1713$: bcs 1714$ ; yes C = 1
;
1714$: br 9999$
1799$: halt
;
;
9999$: iot ; end of test A1.2
;
; Test A2 -- sob +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; This sub-section verifies
; x xxx xxx xxx xxx xxx NZVC Instruction / Remark
; 0 111 111 rrr bbb bbb ---- SOB
;
; Test A2.1 -- sob +++++++++++++++++++++++++++++++++++++++++++++++++++
; check that SOB
; a. decrements register
; b. does not change cc
; c. only falls through when register decremented to zero
;
ta0201: mov #cp.psw,r5
clr (r5)
mov #3,r0 ; setup loop count
ccc ; nzvc = 0000
br 11$ ; branch to 1st SOB
;
10$: hcmpeq (r5),#cp0000 ; cc still 0000 ?
hcmpeq r0,#2 ; counter dec-ed ?
scc ; now nzvc = 1111
br 21$ ; branch to 2nd SOB
;
11$: sob r0,10$ ; 1st SOB (r0=3)
halt ; should not fall through
;
20$: hcmpeq (r5),#cpnzvc ; cc still 1111 ?
hcmpeq r0,#1 ; counter dec-ed ?
ccc
<sen!sez> ; now nzvc = 1100
br 31$ ; branch to 3rd SOB
;
21$: sob r0,20$ ; 2nd SOB (r0=2)
halt ; should not fall through
;
30$: halt ; should not branch now !
31$: sob r0,30$ ; 3rd SOB (r0=1 -> fall through)
hcmpeq (r5),#cpnz00 ; cc still 1100 ?
htsteq r0 ; counter dec-ed ?
;
; finally a typical simple SOB loop
;
mov #2,r0
clr r1
100$: inc r1
sob r0,100$
;
htsteq r0
hcmpeq r1,#2
;
9999$: iot ; end of test A2.1
;
; Test A3 -- jmp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; This sub-section verifies
; x xxx xxx xxx xxx xxx NZVC Instruction / Remark
; 0 000 000 001 ddd ddd ---- JMP (mode /= R !!)
;
; Test A3.1 -- jmp + dsta +++++++++++++++++++++++++++++++++++++++++++++
; check that JMP works for all modes
;
ta0301: mov #10$,r2
jmp (r2) ; mode = 1,reg
halt
;
10$: mov #20$,r2
jmp (r2)+ ; mode = 2,reg
halt
20$: hcmpeq r2,#20$+2
;
mov #40$+2,r2
jmp -(r2) ; mode = 4,reg
halt
40$: hcmpeq r2,#40$
;
mov #60$-10,r2
jmp 10(r2) ; mode = 6,reg
;
60$: jmp 67$ ; mode = 6,pc (rel)
halt
;
67$: jmp @#37$ ; mode = 3,pc (abs)
halt
;
37$: mov #1030$,r3
jmp @(r3)+ ; mode = 3,reg
halt
30$: hcmpeq r3,#1030$+2
;
mov #1050$+2,r3
jmp @-(r3) ; mode = 5,reg
halt
50$: hcmpeq r3,#1050$
;
mov #1070$-20,r3
jmp @20(r3) ; mode = 7,reg
halt
;
70$: jmp @1077$ ; mode = 7,pc (ind)
halt
;
77$: br 9999$
;
1030$: .word 30$
1050$: .word 50$
1070$: .word 70$
1077$: .word 77$
;
9999$: iot ; end of test A3.1
;
; Test A3.2 -- jmp + cc +++++++++++++++++++++++++++++++++++++++++++++++
; check that JMP doesnt change cc
;
ta0302: mov #cp.psw,r5
clr (r5)
;
ccc ; nzvc = 0000
jmp 1$
halt
1$: hcmpeq (r5),#cp0000 ; cc still 0000 ?
;
scc ; nzvc = 1111
jmp @1002$
halt
2$: hcmpeq (r5),#cpnzvc ; cc still 1111 ?
br 9999$
;
1002$: .word 2$
;
9999$: iot ; end of test A3.2
;
; Test A4 -- jsr + rts +++++++++++++++++++++++++++++++++++++++++++++++++++++++
; This sub-section verifies
; x xxx xxx xxx xxx xxx NZVC Instruction / Remark
; 0 000 100 rrr ddd ddd ---- JSR (mode /= R !!)
; 0 000 000 010 000 rrr ---- RTS
;
; Test A4.1 -- jsr + dsta +++++++++++++++++++++++++++++++++++++++++++++
; check that JSR PC,xxx works for all modes
;
ta0401: mov #1006$,r2
mov #2000$,r3
mov #3000$,r5
clr r4
;
jsr pc,(r2)+ ; mode = 2,reg -> 1006 inc 6
jsr pc,(r2) ; mode = 1,reg -> 1005 inc 5
jsr pc,2(r2) ; mode = 6,reg -> 1004 inc 4
jsr pc,-(r2) ; mode = 4,reg -> 1006 inc 6
jsr pc,@(r3)+ ; mode = 3,reg -> 1003 inc 3
jsr pc,@2(r3) ; mode = 7,reg -> 1001 inc 1
jsr pc,@-(r3) ; mode = 5,reg -> 1003 inc 3
;
jmp 9999$
;
1006$: inc r4
1005$: inc r4
1004$: inc r4
1003$: inc r4
1002$: inc r4
1001$: inc r4
hcmpeq r4,(r5)+
rts pc
;
2000$: .word 1003$
.word 1002$
.word 1001$
;
3000$: .word 6
.word 6+5
.word 6+5+4
.word 6+5+4+6
.word 6+5+4+6+3
.word 6+5+4+6+3+1
.word 6+5+4+6+3+1+3
;
9999$: iot ; end of test A4.1
;
; Test A4.2 -- jsr + cc +++++++++++++++++++++++++++++++++++++++++++++++
; check that JSR and RTS doesnt change cc
;
ta0402: mov #cp.psw,r5
clr (r5)
;
ccc ; nzvc = 0000
jsr pc,100$ ; call with cp0000
hcmpeq (r5),#cpnzvc ; expect cpnzvc
scc
jsr pc,200$
hcmpeq (r5),#cp0000
jmp 9999$
;
100$: hcmpeq (r5),#cp0000 ; expect cp0000
scc ; return with cpnzvc
rts pc
;
200$: hcmpeq (r5),#cpnzvc ; expect cpnzvc
ccc ; return with cp0000
rts pc
;
9999$: iot ; end of test A4.2
;
; Test A4.3 -- jsr r0-r5 ++++++++++++++++++++++++++++++++++++++++++++++
; check that JSR and RTS for R0...R5 linkage
; Note: use reserved opcodes as arguments to detect fall through
;
ta0403: clr 900$ ; reset call counter
jsr r0,100$
jsr r1,110$
.word 000211
jsr r2,120$
.word 000212
jsr r3,130$
.word 000213
jsr r4,140$
.word 000214
jsr r5,150$
.word 000215
.word 000216
.word 000217
hcmpeq 900$,#6. ; check number of calls
jmp 9999$
;
100$: inc 900$
rts r0
;
110$: inc 900$
hcmpeq (r1)+,#000211
rts r1
;
120$: inc 900$
hcmpeq (r2)+,#000212
rts r2
;
130$: inc 900$
hcmpeq (r3)+,#000213
rts r3
;
140$: inc 900$
hcmpeq (r4)+,#000214
rts r4
;
150$: inc 900$
hcmpeq (r5)+,#000215
hcmpeq (r5)+,#000216
hcmpeq (r5)+,#000217
rts r5
;
900$: .word 0
;
9999$: iot ; end of test A4.3
;
; Test A4.4 -- jsr sp and rts sp ++++++++++++++++++++++++++++++++++++++
; In case of jsr sp and rts sp, the sp register is used both as linkage
; register and implicitly as stack pointer. That interferes and gives
; quite bizarre behavior, certainly never used, but should work
; - jsr sp,<dst> will
; - push current SP onto stack
; - set SP to the location of following instruction
; - jump to <dst>
; - rts sp will
; - set PC to current SP
; - pop SP of the current stack
; that will set SP to the opcode of instruction being returned to !
;
ta0404: hcmpeq sp,#stack ; check stack is default
clr 100$ ; clear 'args' after jsr
clr 100$+2
;
jsr sp,300$ ; will push SP to current stack
100$: .word 0 ; 'args', will be overwritten
.word 0 ;
;
200$: clr r1 ; return instruction, also loaded SP
hcmpeq sp,200$ ; check loaded SP
mov #stack-2,sp ; restore stack to where jsr pushed it
;
; w11 saves original sp, like 11/70, and e11
; SimH saves sp after it was decremented
;
mov #stack,r1
cmpb systyp,#sy.sih ; on SimH ?
bne 210$
sub #2,r1 ; if yes, subtract 2 (now sp-2)
210$: hcmpeq (sp)+,r1 ; check jsr stored stack pointer
hcmpeq 100$,#123 ; check writes via SP in routine