-
Notifications
You must be signed in to change notification settings - Fork 2
/
x86todsl.py
1383 lines (1173 loc) · 64 KB
/
x86todsl.py
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
from x86todslHelper import *
import dslinstructions
import dslparse
import config
import sys
def ConvertRorl(x) :
# 32 bit rotate right operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = " + dest + ":32 >>> " + source + ":32;\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ":32, 32);\n"
# cf : The most significant bit of the result
tempString = tempString + "cf:1 = split(" + dest + ", 31, 31);\n"
# of : if source == 1, then of = the xor of the two most significant bits.
sourceVal = int(x[1], 0)
if sourceVal == 1 :
tempString = tempString + "of:1 = split(" + dest + ", 31, 31) ^ split(" + dest + ", 30, 30);\n"
else :
tempString = tempString + "of:1 = builtin_undef;\n"
rorAst = dslparse.dslToAst(tempString)
return rorAst
def ConvertRoll(x) :
# 32 bit rotate left operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = " + dest + " <<< " + source + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# cf : The least significant bit of the result
tempString = tempString + "cf:1 = split(" + dest + ", 0, 0);\n"
# of : if source == 1, then of = the xor of the most significant bit and cf
sourceVal = int(x[1], 0)
if sourceVal == 1 :
tempString = tempString + "of:1 = split(" + dest + ", 31, 31) ^ cf:1;\n"
else :
tempString = tempString + "of:1 = builtin_undef;\n"
rolAst = dslparse.dslToAst(tempString)
return rolAst
def ConvertAddl(x) :
# 32 bit addition operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + "oldDest = " + dest + ";\n"
tempString = tempString + dest + " = " + dest + " + " + source + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# zf : 1 if the result is 0?
tempString = tempString + "zf:1 = " + dest + " == 0 ? 1:1 : 0:1;\n"
# cf : (dest < oldDest) or (dest < source)
tempString = tempString + "cf_part1:1 = " + dest + " < oldDest ? 1:1 : 0:1;\n"
tempString = tempString + "cf_part2:1 = " + dest + " < " + source + " ? 1:1 : 0:1;\n"
tempString = tempString + "cf:1 = cf_part1:1 | cf_part2:1;\n"
# of : of:1 = (MSB(oldDest) == MSB(source)) and (MSB(source) != MSB(dest))
tempString = tempString + "of_part1:1 = split(oldDest, 31, 31) == split(" + source + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + source + ", 31, 31) != split(" + dest + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# sf : sign bit of the result
tempString = tempString + "sf:1 = split(" + dest + ", 31, 31);\n"
addAst = dslparse.dslToAst(tempString)
return addAst
def ConvertAdcl(x) :
# 32 bit addition operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + "oldDest = " + dest + ";\n"
tempString = tempString + dest + " = " + dest + " + " + source + " + zeroext(cf:1, 31)" + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# zf : 1 if the result is 0?
tempString = tempString + "zf:1 = " + dest + " == 0 ? 1:1 : 0:1;\n"
# cf : (dest < oldDest) or (dest < source)
tempString = tempString + "cf_part1:1 = " + dest + " < oldDest ? 1:1 : 0:1;\n"
tempString = tempString + "cf_part2:1 = " + dest + " < " + source + " ? 1:1 : 0:1;\n"
tempString = tempString + "cf:1 = cf_part1:1 | cf_part2:1;\n"
# of : of:1 = (MSB(oldDest) == MSB(source)) and (MSB(source) != MSB(dest))
tempString = tempString + "of_part1:1 = split(oldDest, 31, 31) == split(" + source + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + source + ", 31, 31) != split(" + dest + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# sf : sign bit of the result
tempString = tempString + "sf:1 = split(" + dest + ", 31, 31);\n"
addAst = dslparse.dslToAst(tempString)
return addAst
def ConvertShrl(x) :
# 32 bit shift right operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + "oldDest = " + dest + ";\n"
tempString = tempString + dest + " = " + dest + " >> " + source + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# cf : least significant bit of destination
tempString = tempString + "cf:1 = split(oldDest, " + str(int(source, 0) - 1) + ", " + str(int(source, 0) - 1) + ");\n"
# of : if source == 1, most significant bit of old destination
sourceVal = int(x[1], 0)
if sourceVal == 1 :
tempString = tempString + "of:1 = split(oldDest, 31, 31);\n"
else :
tempString = tempString + "of:1 = builtin_undef;\n"
shrAst = dslparse.dslToAst(tempString)
return shrAst
def ConvertXorl(x) :
# 32 bit xor operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = " + dest + " ^ " + source + ";"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# zf : dest == 0
tempString = tempString + "zf:1 = " + dest + " == 0 ? 1:1 : 0:1;\n"
# cf : 0
tempString = tempString + "cf:1 = 0:1;\n"
# of : 0
tempString = tempString + "of:1 = 0:1;\n"
# sf : most significant bit of dest
tempString = tempString + "sf:1 = split(" + dest + ", 31, 31);\n"
xorAst = dslparse.dslToAst(tempString)
return xorAst
def ConvertAndl(x) :
# 32 bit and operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = " + dest + " & " + source + ";"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
# zf : dest == 0
tempString = tempString + "zf:1 = " + dest + " == 0 ? 1:1 : 0:1;\n"
# cf : 0
tempString = tempString + "cf:1 = 0:1;\n"
# of : 0
tempString = tempString + "of:1 = 0:1;\n"
# sf : most significant bit of dest
tempString = tempString + "sf:1 = split(" + dest + ", 31, 31);\n"
andAst = dslparse.dslToAst(tempString)
return andAst
def ConvertMovl(x) :
# 32 bit mov operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = " + source + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovzl(x) :
# 32 bit mov if zf == 1 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = zf:1 == 1:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovncl(x) :
# 32 bit mov if zf == 1 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = cf:1 == 0:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovnol(x) :
# 32 bit mov if zf == 1 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = of:1 == 0:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovol(x) :
# 32 bit mov if of == 1 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = of:1 == 1:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovnzl(x) :
# 32 bit mov if zf == 0 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = zf:1 == 0:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovel(x) :
# 32 bit mov if zf == 1 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = zf:1 == 1:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovnel(x) :
# 32 bit mov if zf == 0 operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = zf:1 == 0:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovgel(x) :
# 32 bit mov if sf == of operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = sf:1 == of:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovll(x) :
# 32 bit mov if sf != of of operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = sf:1 != of:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovlel(x) :
# 32 bit mov if zf = 1 or sf != of of operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = ((sf:1 ^ of:1) | zf:1) == 1:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertCmovgl(x) :
# 32 bit mov if zf = 0 and sf == of of operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + dest + " = (!(sf:1 ^ of:1) & !zf:1) == 1:1 ? " + source + " : " + dest + ";\n"
if config.Is64BitArch() and Is32Register(x[2]) :
dest64 = GetRegister(x[2], 64)[0]
tempString = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
movAst = dslparse.dslToAst(tempString)
return movAst
def ConvertMovzbl(x) :
# 1 byte -> 8 byte zero extend.
destList, tempString = ConvertOperand(x[2])
dest = destList[0]
if isinstance(x[1], pp.ParseResults) or isinstance(x[1], list) :
base = x[1][1]
if base in reg64Rev :
base = base + ":64"
taddr = base
if len(x[1]) == 4 :
hasIndex = True
index = x[1][2]
if index in reg64Rev :
index = index + ":64"
multiplier = int(x[1][3])
if multiplier == 1 :
taddr = taddr + " + " + index
elif multiplier == 2 :
taddr = taddr + " + (" + index + " << 1:64) "
elif multiplier == 4 :
taddr = taddr + " + (" + index + " << 2:64) "
elif multiplier == 8 :
taddr = taddr + " + (" + index + " << 3:64) "
offset = 0 if x[1][0] == "OFFSET" else int(x[1][0])
if offset % 4 == 0 :
# Then we have no problem.
if not offset == 0 :
taddr = taddr + " + " + str(offset)
tempString = tempString + "movzbltemparray = mem[" + taddr + "]\n;"
tempString = tempString + "movzblmemval:8 = split(movzbltemparray, 0, 7)\n;"
source = "movzblmemval:8"
else :
# We gotta start thinking about offset memory loads.
newoffset = int(offset / 4)
offsetrem = offset % 4
taddr = taddr if newoffset == 0 else (taddr + " + " + str(newoffset))
tempString = tempString + "movzbltemparray = mem[" + taddr + "]\n;"
tempString = tempString + "movzblmemval:8 = split(movzbltemparray, " + str(offsetrem * 8) + ", " + str((offsetrem + 1) * 8 - 1) + ")\n;"
source = "movzblmemval:8"
else :
source = x[1] + ":8"
if x[1] in reg8lowRev :
index = reg8lowRev[x[1]]
base = reg32[index]
tempString = tempString + source + " = split(" + base + ", 0, 7);\n"
elif x[1] in reg8highRev :
index = reg8highRev[x[1]]
base = reg32[index]
tempString = tempString + source + " = split(" + base + ", 8, 15);\n"
tempString = tempString + dest + " = zeroext(" + source + ", 24);\n"
if config.Is64BitArch() :
dest64 = GetRegister(dest, 64)[0]
tempString = tempString + dest64 + " = zeroext(" + source + ", 56);\n"
movzblAst = dslparse.dslToAst(tempString)
return movzblAst
def ConvertCmpl(x) :
# Right side - left side.
# 32 bit cmp operation
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
tempString = tempString + "temp = " + dest + " - " + source + ";\n"
# zf
tempString = tempString + "zf:1 = temp == 0 ? 1:1 : 0:1;\n"
# of : (left side sign bit) != (right side sign bit) and (right side sign bit) == (result sign bit)
tempString = tempString + "of_part1:1 = split(" + source + ", 31, 31) != split(" + dest + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + dest + ", 31, 31) == split(temp, 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# cf : most significant bit requires carry if source is greater than dest.
tempString = tempString + "cf:1 = " + source + " > " + dest + " ? 1:1 : 0:1;\n"
# sf
tempString = tempString + "sf:1 = split(temp, 31, 31);\n"
cmpAst = dslparse.dslToAst(tempString)
return cmpAst
def ConvertCmpq(x) :
# 64 bit compare
sourceList, tempString = ConvertOperand(x[1], "", 64)
destList, tempString = ConvertOperand(x[2], tempString, 64)
if len(sourceList) == 1 :
# It's a register
source = sourceList[0]
elif len(sourceList) == 2 :
# It's a memory operation
tempString = tempString + "tempSourceOp:64 = merge(" + sourceList[1] + ", " + sourceList[0] + ");\n"
source = "tempSourceOp:64"
else :
sys.exit("ConvertCmpq. Encountered an unexpected operand: " + x[1])
if len(destList) == 1 :
# It's a register
dest = destList[0]
elif len(destList) == 2 :
# It's a memory operation
tempString = tempString + "tempDestOp:64 = merge(" + destList[1] + ", " + destList[0] + ");\n"
dest = "tempDestOp:64"
else :
sys.exit("ConvertCmpq. Encountered an unexpected operand: " + x[2])
tempString = tempString + "temp:64 = " + dest + " - " + source + ";\n"
# zf
tempString = tempString + "zf:1 = temp:64 == 0:64 ? 1:1 : 0:1;\n"
# of : (left side sign bit) != (right side sign bit) and (right side sign bit) == (result sign bit)
tempString = tempString + "of_part1:1 = split(" + source + ", 63, 63) != split(" + dest + ", 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + dest + ", 63, 63) == split(temp, 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# cf
tempString = tempString + "cf:1 = " + source + " > " + dest + " ? 1:1 : 0:1;\n"
# sf
tempString = tempString + "sf:1 = split(temp, 63, 63);\n"
cmpAst = dslparse.dslToAst(tempString)
return cmpAst
def ConvertCmpb(x) :
# Comparing a single byte.
# For time's sake, we will only implement it for ['cmpb', '0', ['3', 'base reg']]. Make sure we say error if not.
if (not isImmediate(x[1])) or (isinstance(x[2], str)) or (len(x[2]) != 2) :
sys.exit("Implementation of Cmpb is incomplete. Does not support " + str(x))
source = x[1]
offset = 0
byte_index = 0
if x[2][0] != "OFFSET" :
offset = int(x[2][0]) // int(4)
byte_index = int(x[2][0]) % int(4)
destOperand = "split(mem[" + x[2][1] + ":64 + " + str(offset) + ":64], " + str(byte_index * 8) + ", " + str(byte_index * 8 + 7) + ")"
tempString = "tempDest:8 = " + destOperand + ";\n"
tempString = tempString + "temp:8 = tempDest:8" + " - " + source + ":8;\n"
tempString = tempString + "zf:1 = temp:8 == 0:8 ? 1:1 : 0:1;\n"
tempString = tempString + "of_part1:1 = split(" + source + ":8, 7, 7) != split(tempDest:8, 7, 7) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(tempDest:8, 7, 7) == split(temp:8, 7, 7) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
tempString = tempString + "cf:1 = " + source + ":8 > tempDest:8 ? 1:1 : 0:1;\n"
tempString = tempString + "sf:1 = split(temp:8, 7, 7);\n"
cmpbAst = dslparse.dslToAst(tempString)
return cmpbAst
def ConvertDecl(x) :
# 32 bit dec operation
tempString = ""
destList, tempString = ConvertOperand(x[1], tempString)
dest = destList[0]
tempString = tempString + "tempDest = " + dest + ";\n"
tempString = tempString + dest + " = " + dest + " - 1;\n"
# zf : dest == 0
tempString = tempString + "zf:1 = " + dest + " == 0 ? 1:1 : 0:1;\n"
# cf : if old dest
tempString = tempString + "cf:1 = 1 > tempDest ? 1:1 : 0:1;\n"
# of
tempString = tempString + "of_part1:1 = 0 != split(tempDest, 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(tempDest, 31, 31) == split(" + dest + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# sf
tempString = tempString + "sf:1 = split(" + dest + ", 31, 31);\n"
if config.Is64BitArch() and Is32Register(x[1]) :
dest64 = GetRegister(x[1], 64)[0]
tempString = tempString + dest64 + " = " + "zeroext(" + dest + ", 32);\n"
declAst = dslparse.dslToAst(tempString)
return declAst
##### 64 bit operation
def ConvertShrq(x) :
# 64 bit shr
# Source : DNE or immediate
# Dest : 64-bit register or memory
if len(x) == 1 :
# There is no source, only dest
sop = "1"
dop = x[1]
else :
sop = x[1]
dop = x[2]
destList = []
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destName = ""
if IsMemory(dop) :
destList, blah = ConvertOperand(dop, "", 32, 64)
tempString = tempString + "tempD:64 = merge(" + destList[1] + ", " + destList[0] + ");\n"
destName = "tempD:64"
else :
destList, blah = ConvertOperand(dop, "", 64)
destName = destList[0]
tempString = tempString + "oldTempDestShrq:64 = " + destName + ";\n"
tempString = tempString + destName + " = " + destName + " >> " + source + ":64;\n"
destList, blah = ConvertOperand(dop, "", 32, 64)
tempString = tempString + destList[0] + " = split(" + destName + ", 0, 31);\n"
tempString = tempString + destList[1] + " = split(" + destName + ", 32, 63);\n"
# cf : least significant bit of destination
tempString = tempString + "cf:1 = split(" + destName + ", 0, 0);\n"
# of : if source == 1, most significant bit of old destination
sourceVal = int(x[1], 0)
if sourceVal == 1 :
tempString = tempString + "of:1 = split(oldTempDestShrq:64, 63, 63);\n"
else :
tempString = tempString + "of:1 = builtin_undef;\n"
shrqAst = dslparse.dslToAst(tempString)
return shrqAst
def ConvertShlq(x) :
# 64 bit shr
# Source : DNE or immediate
# Dest : 64-bit register or memory
if len(x) == 1 :
# There is no source, only dest
sop = "1"
dop = x[1]
else :
sop = x[1]
dop = x[2]
destList = []
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destName = ""
if IsMemory(dop) :
destList, blah = ConvertOperand(dop, "", 32, 64)
tempString = tempString + "tempD:64 = merge(" + destList[1] + ", " + destList[0] + ");\n"
destName = "tempD:64"
else :
destList, blah = ConvertOperand(dop, "", 64)
destName = destList[0]
tempString = tempString + "oldTempDestShlq:64 = " + destName + ";\n"
tempString = tempString + destName + " = " + destName + " << " + source + ":64;\n"
destList, blah = ConvertOperand(dop, "", 32, 64)
tempString = tempString + destList[0] + " = split(" + destName + ", 0, 31);\n"
tempString = tempString + destList[1] + " = split(" + destName + ", 32, 63);\n"
# cf : most significant bit of destination
tempString = tempString + "cf:1 = split(" + destName + ", 63, 63);\n"
# of : if source == 1, most significant bit of old destination
sourceVal = int(x[1], 0)
if sourceVal == 1 :
tempString = tempString + "of:1 = split(oldTempDestShlq:64, 63, 63) ^ cf:1;\n"
else :
tempString = tempString + "of:1 = builtin_undef;\n"
shrqAst = dslparse.dslToAst(tempString)
return shrqAst
def ConvertSubq(x) :
# 64 bit sub
sourceList, tempString = ConvertOperand(x[1])
destList, tempString = ConvertOperand(x[2], tempString)
ld = destList[0]
hd = destList[1]
tempString = "oldDestSubq:64 = " + x[2] + ":64;\n"
tempString = tempString + x[2] + ":64 = " + x[2] + ":64 - " + sourceList[0] + ":64;\n" \
+ ld + " = split(" + x[2] + ":64, 0, 31);\n" \
+ hd + " = split(" + x[2] + ":64, 32, 63);\n"
# zf
tempString = tempString + "zf:1 = " + x[2] + ":64 == 0:64 ? 1:1 : 0:1;"
# of : (left side sign bit) != (right side sign bit) and (right side sign bit) == (result sign bit)
tempString = tempString + "of_part1:1 = split(" + sourceList[0] + ":64, 63, 63) != split(oldDestSubq:64, 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(oldDestSubq:64, 63, 63) == split(" + x[2] + ":64, 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# cf
tempString = tempString + "cf:1 = " + sourceList[0] + ":64 > oldDestSubq:64 ? 1:1 : 0:1;\n"
# sf
tempString = tempString + "sf:1 = split(" + x[2] + ":64, 63, 63);\n"
shrqAst = dslparse.dslToAst(tempString)
return shrqAst
def ConvertAddq(x) :
# 64 bit sub
sourceList, tempString = ConvertOperand(x[1])
destList, tempString = ConvertOperand(x[2], tempString)
ld = destList[0]
hd = destList[1]
tempString = tempString + "tempDestAddq:64 = " + x[2] + ":64;\n"
tempString = tempString + x[2] + ":64 = " + x[2] + ":64 + " + sourceList[0] + ":64;\n" \
+ ld + " = split(" + x[2] + ":64, 0, 31);\n" \
+ hd + " = split(" + x[2] + ":64, 32, 63);\n"
# zf : 1 if the result is 0?
tempString = tempString + "zf:1 = " + x[2] + ":64 == 0:64 ? 1:1 : 0:1;"
# cf : (dest < tempDestAddq) or (dest < source)
tempString = tempString + "cf_part1:1 = " + x[2] + ":64 < tempDestAddq:64 ? 1:1 : 0:1;\n"
tempString = tempString + "cf_part2:1 = " + x[2] + ":64 < " + sourceList[0] + ":64 ? 1:1 : 0:1;\n"
tempString = tempString + "cf:1 = cf_part1:1 | cf_part2:1;\n"
# of : of:1 = (MSB(tempDestAddq) == MSB(source)) and (MSB(source) != MSB(dest))
tempString = tempString + "of_part1:1 = split(tempDestAddq:64, 63, 63) == split(" + sourceList[0] + ":64, 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + sourceList[0] + ":64, 63, 63) != split(" + x[2] + ":64, 63, 63) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# sf : sign bit of the result
tempString = tempString + "sf:1 = split(" + x[2] + ":64, 63, 63);\n"
shrqAst = dslparse.dslToAst(tempString)
return shrqAst
def ConvertAndq(x) :
# 64 bit And
sourceList, tempString = ConvertOperand(x[1])
destList, tempString = ConvertOperand(x[2], tempString)
ld = destList[0]
hd = destList[1]
tempString = tempString + x[2] + ":64 = merge(" + hd + ", " + ld + ");\n" \
+ x[2] + ":64 = " + x[2] + ":64 & " + sourceList[0] + ":64;\n" \
+ ld + " = split(" + x[2] + ":64, 0, 31);\n" \
+ hd + " = split(" + x[2] + ":64, 32, 63);\n"
# zf : dest == 0
tempString = tempString + "zf:1 = " + x[2] + ":64 == 0:64 ? 1:1 : 0:1;\n"
# cf : 0
tempString = tempString + "cf:1 = 0:1;\n"
# of : 0
tempString = tempString + "of:1 = 0:1;\n"
# sf : most significant bit of dest
tempString = tempString + "sf:1 = split(" + x[2] + ":64, 63, 63);\n"
shrqAst = dslparse.dslToAst(tempString)
return shrqAst
def ConvertSubl(x) :
# 32 bit subtract.
sourceList, tempString = ConvertOperand(x[1])
source = sourceList[0]
destList, tempString = ConvertOperand(x[2], tempString)
dest = destList[0]
sl = sourceList[0]
dl = destList[0]
tempString = tempString + "tempDestSubl = " + dl + ";\n"
tempString = tempString + dl + " = " + dl + " - " + sl + ";\n"
if config.Is64BitArch() :
dl64 = GetRegister(dl, 64)[0]
tempString = tempString + dl64 + " = zeroext(" + dl + ", 32);\n"
# zf
tempString = tempString + "zf:1 = " + dl + " == 0 ? 1:1 : 0:1;\n"
# of : (left side sign bit) != (right side sign bit) and (right side sign bit) == (result sign bit)
tempString = tempString + "of_part1:1 = split(tempDestSubl, 31, 31) != split(" + sl + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of_part2:1 = split(" + sl + ", 31, 31) == split(" + dl + ", 31, 31) ? 1:1 : 0:1;\n"
tempString = tempString + "of:1 = of_part1:1 & of_part2:1;\n"
# cf : most significant bit requires carry if source is greater than old dest.
tempString = tempString + "cf:1 = " + sl + " > tempDestSubl ? 1:1 : 0:1;\n"
# sf
tempString = tempString + "sf:1 = split(" + dl + ", 31, 31);\n"
sublAst = dslparse.dslToAst(tempString)
return sublAst
def ConvertBswapl(x) :
# 32 bit subtract.
assert(len(x) == 2)
destList, tempString = ConvertOperand(x[1])
dest = destList[0]
dest64 = GetRegister(dest, 64)[0]
tempString = tempString + dest + " = merge(split(" + dest + ", 0, 7), merge(split(" + dest + ", 8, 15), merge(split(" + dest + ", 16, 23), split(" + dest + ", 24, 31))));\n"
if config.Is64BitArch() :
dest64 = GetRegister(dest, 64)[0]
tempStrig = tempString + dest64 + " = zeroext(" + dest + ", 32);\n"
bswaplAst = dslparse.dslToAst(tempString)
return bswaplAst
def ConvertLeaq(x) :
# 64 bit load
if len(x[1]) == 2 :
source = x[1][1] + ":64"
if x[1][0] != "OFFSET" :
source = source + " + " + x[1][0] + ":64"
elif len(x[1]) == 4 :
source = x[1][1] + ":64"
if x[1][0] != "OFFSET" :
source = source + " + " + x[1][0] + ":64"
if x[1][3] == "1" :
source = source + " + " + x[1][2] + ":64" + ""
elif x[1][3] == "2" :
source = source + " + " + x[1][2] + ":64" + " << 1:64"
elif x[1][3] == "4" :
source = source + " + " + x[1][2] + ":64" + " << 2:64"
elif x[1][3] == "8" :
source = source + " + " + x[1][2] + ":64" + " << 3:64"
else :
sys.exit("Unexpected error." + str(x))
else :
sys.exit("We did not think of case when Leaq is not base(register). Please implement it." + str(x))
destList, blah = ConvertOperand(x[2], "", 64)
dest64 = destList[0]
tempString = dest64 + " = " + source + ";\n"
destList, blah = ConvertOperand(x[2])
ld = destList[0]
hd = destList[1]
tempString = tempString + ld + " = split(" + dest64 + ", 0, 31);\n" \
+ hd + " = split(" + dest64 + ", 32, 63);\n"
leaAst = dslparse.dslToAst(tempString)
return leaAst
def ConvertMovd(x) :
tempString = ""
if x[2] in reg128Rev :
# Moving lower 32bit of xmm to 32bit space
sourceList, tempString = ConvertOperand(x[1], tempString)
destList, tempString = ConvertOperand(x[2], tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
else :
# Moving 32bit data to lower 32bit of xmm
sourceList, tempString = ConvertOperand(x[1], tempString)
destList, tempString = ConvertOperand(x[2], tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
movdAst = dslparse.dslToAst(tempString)
return movdAst
def ConvertMovq(x) :
# Moving lower 2 32-bit to somewhere.
sop = x[1]
dop = x[2]
tempString = ""
if Is128Register(sop) and Is128Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
elif Is128Register(sop) and IsMemory(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString, 32, 64)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
elif Is64Register(sop) and IsMemory(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString, 32, 64)
tempString = tempString + sourceList[0] + " = " + "split(" + sop + ":64, 0, 31);\n"
tempString = tempString + sourceList[1] + " = " + "split(" + sop + ":64, 32, 63);\n"
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
elif IsMemory(sop) and Is128Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString, 32, 64)
destList, tempString = ConvertOperand(dop, tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
elif IsMemory(sop) and Is64Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString, 32, 64)
destList, tempString = ConvertOperand(dop, tempString, 32, 64)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
dest64 = GetRegister(dop, 64)[0]
tempString = tempString + dest64 + " = merge(" + destList[1] + ", " + destList[0] + ");\n"
elif Is64Register(sop) and Is128Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
elif Is128Register(sop) and Is64Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString)
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
dest64 = GetRegister(dop, 64)
tempString = tempString + dest64[0] + " = merge(" + destList[1] + ", " + destList[0] + ");\n"
elif Is64Register(sop) and Is64Register(dop) :
sourceList, tempString = ConvertOperand(sop, tempString)
destList, tempString = ConvertOperand(dop, tempString)
dest64 = GetRegister(dop, 64)[0]
tempString = tempString + destList[0] + " = " + sourceList[0] + ";\n"
tempString = tempString + destList[1] + " = " + sourceList[1] + ";\n"
tempString = tempString + dest64 + " = merge(" + destList[1] + ", " + destList[0] + ");\n"
else :
sys.exit("ConvertMovQ: Found a combination of operand I could not recognize\n %s" % (x))
movqAst = dslparse.dslToAst(tempString)
return movqAst
def ConvertMovdqa(x) :
# Mov xmm to 128 bit memory or 128 bit memory to xmm
tempString = ""
sourceList = []
destList = []
if IsMemory(x[1]) :
sourceList, tempString = ConvertOperand(x[1], tempString, 32, 128)
elif Is128Register(x[1]) :
sourceList, tempString = ConvertOperand(x[1], tempString)
else :
sys.exit("ConvertMovqda: unexpected source operand");
if IsMemory(x[2]) :
destList, tempString = ConvertOperand(x[2], tempString, 32, 128)
elif Is128Register(x[2]) :
destList, tempString = ConvertOperand(x[2], tempString)
else :
sys.exit("ConvertMovqda: unexpected source operand");
for s, d in zip(sourceList, destList) :
tempString = tempString + d + " = " + s + ";\n"
movdqaAst = dslparse.dslToAst(tempString)
return movdqaAst
def ConvertMovdqu(x) :
# Unaligned mov xmm to 128 bit memory or 128 bit memory to xmm
tempString = ""
sourceList = []
destList = []
if IsMemory(x[1]) :
sourceList, tempString = ConvertOperand(x[1], tempString, 32, 128)
elif Is128Register(x[1]) :
sourceList, tempString = ConvertOperand(x[1], tempString)
else :
sys.exit("ConvertMovqdu: unexpected source operand");
if IsMemory(x[2]) :
destList, tempString = ConvertOperand(x[2], tempString, 32, 128)
elif Is128Register(x[2]) :
destList, tempString = ConvertOperand(x[2], tempString)
else :
sys.exit("ConvertMovqdu: unexpected source operand");
for s, d in zip(sourceList, destList) :
tempString = tempString + d + " = " + s + ";\n"
movdquAst = dslparse.dslToAst(tempString)
return movdquAst
def ConvertPxor(x) :
tempString = ""
sourceList, tempString = ConvertOperand(x[1], tempString)
destList, tempString = ConvertOperand(x[2], tempString)
for sl, dl in zip(sourceList, destList) :
tempString = tempString + dl + " = " + dl + " ^ " + sl + ";\n"
pxorAst = dslparse.dslToAst(tempString)
return pxorAst
def ConvertPor(x) :
tempString = ""
sourceList, tempString = ConvertOperand(x[1], tempString)
destList, tempString = ConvertOperand(x[2], tempString)
for sl, dl in zip(sourceList, destList) :
tempString = tempString + dl + " = " + dl + " | " + sl + ";\n"
porAst = dslparse.dslToAst(tempString)
return porAst
def ConvertPaddd(x) :
# only vector instructions
tempString = ""
sourceList, tempString = ConvertOperand(x[1], tempString)
destList, tempString = ConvertOperand(x[2], tempString)
for sl, dl in zip(sourceList, destList) :
tempString = tempString + dl + " = " + dl + " + " + sl + ";\n"
padddAst = dslparse.dslToAst(tempString)
return padddAst
def ConvertPalignr(x) :
tempString = ""
shiftByte = int(x[3], 0)
sourceStr = x[2]
destStr = x[1]
# For now, we will only allow shiftByte % 4 == 0
if shiftByte % 4 != 0 :
sys.exit("ConvertPalignr only allows shiftByte to be a multiple of 4 for now")
sourceList, tempString = ConvertOperand(sourceStr, tempString)
destList, tempString = ConvertOperand(destStr, tempString)
tempList = ["palignr_temp0", "palignr_temp1", "palignr_temp2", "palignr_temp3"]
tempString = tempString + tempList[3] + " = " + destList[3] + ";\n" \
+ tempList[2] + " = " + destList[2] + ";\n" \
+ tempList[1] + " = " + destList[1] + ";\n" \
+ tempList[0] + " = " + destList[0] + ";\n"
tempList2 = ["palignr2_temp0", "palignr2_temp1", "palignr2_temp2", "palignr2_temp3"]
tempString = tempString + tempList2[3] + " = " + sourceList[3] + ";\n" \
+ tempList2[2] + " = " + sourceList[2] + ";\n" \
+ tempList2[1] + " = " + sourceList[1] + ";\n" \
+ tempList2[0] + " = " + sourceList[0] + ";\n"
# dest_3 dest_2 dest_1 dest_0 [src_3 src_2 src_1 src_0]
if shiftByte == 0 :
tempString = tempString + destList[3] + " = " + tempList2[3] + ";\n" \
+ destList[2] + " = " + tempList2[2] + ";\n" \
+ destList[1] + " = " + tempList2[1] + ";\n" \
+ destList[0] + " = " + tempList2[0] + ";\n"
# dest_3 dest_2 dest_1 [dest_0 src_3 src_2 src_1] src_0
elif shiftByte == 4 :
tempString = tempString + destList[3] + " = " + tempList[0] + ";\n" \
+ destList[2] + " = " + tempList2[3] + ";\n" \
+ destList[1] + " = " + tempList2[2] + ";\n" \
+ destList[0] + " = " + tempList2[1] + ";\n"
# dest_3 dest_2 [dest_1 dest_0 src_3 src_2] src_1 src_0
elif shiftByte == 8 :
tempString = tempString + destList[3] + " = " + tempList[1] + ";\n" \
+ destList[2] + " = " + tempList[0] + ";\n" \
+ destList[1] + " = " + tempList2[3] + ";\n" \
+ destList[0] + " = " + tempList2[2] + ";\n"
# dest_3 [dest_2 dest_1 dest_0 src_3] src_2 src_1 src_0
elif shiftByte == 12 :
tempString = tempString + destList[3] + " = " + tempList[2] + ";\n" \
+ destList[2] + " = " + tempList[1] + ";\n" \