-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx86_64.inc
7391 lines (7362 loc) · 149 KB
/
x86_64.inc
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
; flat assembler core
; Copyright (c) 1999-2022, Tomasz Grysztar.
; All rights reserved.
simple_instruction_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction:
stos byte [edi]
jmp instruction_assembled
simple_instruction_only64:
cmp [code_type],64
jne illegal_instruction
jmp simple_instruction
simple_instruction_16bit_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction_16bit:
cmp [code_type],16
jne size_prefix
stos byte [edi]
jmp instruction_assembled
size_prefix:
mov ah,al
mov al,66h
stos word [edi]
jmp instruction_assembled
simple_instruction_32bit_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction_32bit:
cmp [code_type],16
je size_prefix
stos byte [edi]
jmp instruction_assembled
iret_instruction:
cmp [code_type],64
jne simple_instruction
simple_instruction_64bit:
cmp [code_type],64
jne illegal_instruction
mov ah,al
mov al,48h
stos word [edi]
jmp instruction_assembled
simple_extended_instruction_64bit:
cmp [code_type],64
jne illegal_instruction
mov byte [edi],48h
inc edi
simple_extended_instruction:
mov ah,al
mov al,0Fh
stos word [edi]
jmp instruction_assembled
simple_extended_instruction_f3:
mov byte [edi],0F3h
inc edi
jmp simple_extended_instruction
prefix_instruction:
stos byte [edi]
or [prefix_flags],1
jmp continue_line
segment_prefix:
mov ah,al
shr ah,4
cmp ah,3
jne illegal_instruction
and al,1111b
mov [segment_register],al
call store_segment_prefix
or [prefix_flags],1
jmp continue_line
bnd_prefix_instruction:
stos byte [edi]
or [prefix_flags],1 + 10h
jmp continue_line
int_instruction:
lods byte [esi]
call get_size_operator
cmp ah,1
ja invalid_operand_size
cmp al,'('
jne invalid_operand
call get_byte_value
test eax,eax
jns int_imm_ok
call recoverable_overflow
int_imm_ok:
mov ah,al
mov al,0CDh
stos word [edi]
jmp instruction_assembled
aa_instruction:
cmp [code_type],64
je illegal_instruction
push eax
mov bl,10
cmp byte [esi],'('
jne aa_store
inc esi
xor al,al
xchg al,[operand_size]
cmp al,1
ja invalid_operand_size
call get_byte_value
mov bl,al
aa_store:
cmp [operand_size],0
jne invalid_operand
pop eax
mov ah,bl
stos word [edi]
jmp instruction_assembled
basic_instruction:
mov [base_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
je basic_reg
cmp al,'['
jne invalid_operand
basic_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je basic_mem_imm
cmp al,10h
jne invalid_operand
basic_mem_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
mov al,ah
cmp al,1
je instruction_ready
call operand_autodetect
inc [base_code]
instruction_ready:
call store_instruction
jmp instruction_assembled
basic_mem_imm:
mov al,[operand_size]
cmp al,1
jb basic_mem_imm_nosize
je basic_mem_imm_8bit
cmp al,2
je basic_mem_imm_16bit
cmp al,4
je basic_mem_imm_32bit
cmp al,8
jne invalid_operand_size
basic_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp basic_mem_imm_32bit_ok
basic_mem_imm_nosize:
call recoverable_unknown_size
basic_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
mov [base_code],80h
call store_instruction_with_imm8
jmp instruction_assembled
basic_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
cmp [value_type],0
jne basic_mem_imm_16bit_store
cmp [size_declared],0
jne basic_mem_imm_16bit_store
cmp word [value],80h
jb basic_mem_simm_8bit
cmp word [value],-80h
jae basic_mem_simm_8bit
basic_mem_imm_16bit_store:
mov [base_code],81h
call store_instruction_with_imm16
jmp instruction_assembled
basic_mem_simm_8bit:
mov [base_code],83h
call store_instruction_with_imm8
jmp instruction_assembled
basic_mem_imm_32bit:
call operand_32bit
call get_dword_value
basic_mem_imm_32bit_ok:
mov dword [value],eax
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
cmp [value_type],0
jne basic_mem_imm_32bit_store
cmp [size_declared],0
jne basic_mem_imm_32bit_store
cmp dword [value],80h
jb basic_mem_simm_8bit
cmp dword [value],-80h
jae basic_mem_simm_8bit
basic_mem_imm_32bit_store:
mov [base_code],81h
call store_instruction_with_imm32
jmp instruction_assembled
get_simm32:
call get_qword_value
mov ecx,edx
cdq
cmp ecx,edx
je simm32_range_ok
call recoverable_overflow
simm32_range_ok:
cmp [value_type],4
jne get_simm32_ok
mov [value_type],2
get_simm32_ok:
ret
basic_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
je basic_reg_reg
cmp al,'('
je basic_reg_imm
cmp al,'['
jne invalid_operand
basic_reg_mem:
call get_address
mov al,[operand_size]
cmp al,1
je basic_reg_mem_8bit
call operand_autodetect
add [base_code],3
jmp instruction_ready
basic_reg_mem_8bit:
add [base_code],2
jmp instruction_ready
basic_reg_reg:
lods byte [esi]
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
cmp al,1
je nomem_instruction_ready
call operand_autodetect
inc [base_code]
nomem_instruction_ready:
call store_nomem_instruction
jmp instruction_assembled
basic_reg_imm:
mov al,[operand_size]
cmp al,1
je basic_reg_imm_8bit
cmp al,2
je basic_reg_imm_16bit
cmp al,4
je basic_reg_imm_32bit
cmp al,8
jne invalid_operand_size
basic_reg_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp basic_reg_imm_32bit_ok
basic_reg_imm_8bit:
call get_byte_value
mov dl,al
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
or bl,bl
jz basic_al_imm
mov [base_code],80h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_al_imm:
mov al,[base_code]
add al,4
stos byte [edi]
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_reg_imm_16bit:
call operand_16bit
call get_word_value
mov dx,ax
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
cmp [value_type],0
jne basic_reg_imm_16bit_store
cmp [size_declared],0
jne basic_reg_imm_16bit_store
cmp dx,80h
jb basic_reg_simm_8bit
cmp dx,-80h
jae basic_reg_simm_8bit
basic_reg_imm_16bit_store:
or bl,bl
jz basic_ax_imm
mov [base_code],81h
call store_nomem_instruction
basic_store_imm_16bit:
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
basic_reg_simm_8bit:
mov [base_code],83h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_ax_imm:
add [base_code],5
call store_classic_instruction_code
jmp basic_store_imm_16bit
basic_reg_imm_32bit:
call operand_32bit
call get_dword_value
basic_reg_imm_32bit_ok:
mov edx,eax
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
cmp [value_type],0
jne basic_reg_imm_32bit_store
cmp [size_declared],0
jne basic_reg_imm_32bit_store
cmp edx,80h
jb basic_reg_simm_8bit
cmp edx,-80h
jae basic_reg_simm_8bit
basic_reg_imm_32bit_store:
or bl,bl
jz basic_eax_imm
mov [base_code],81h
call store_nomem_instruction
basic_store_imm_32bit:
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
basic_eax_imm:
add [base_code],5
call store_classic_instruction_code
jmp basic_store_imm_32bit
recoverable_unknown_size:
cmp [error_line],0
jne ignore_unknown_size
push [current_line]
pop [error_line]
mov [error],operand_size_not_specified
ignore_unknown_size:
ret
single_operand_instruction:
mov [base_code],0F6h
mov [postbyte_register],al
lods byte [esi]
call get_size_operator
cmp al,10h
je single_reg
cmp al,'['
jne invalid_operand
single_mem:
call get_address
mov al,[operand_size]
cmp al,1
je single_mem_8bit
jb single_mem_nosize
call operand_autodetect
inc [base_code]
jmp instruction_ready
single_mem_nosize:
call recoverable_unknown_size
single_mem_8bit:
jmp instruction_ready
single_reg:
lods byte [esi]
call convert_register
mov bl,al
mov al,ah
cmp al,1
je single_reg_8bit
call operand_autodetect
inc [base_code]
single_reg_8bit:
jmp nomem_instruction_ready
mov_instruction:
mov [base_code],88h
lods byte [esi]
call get_size_operator
cmp al,10h
je mov_reg
cmp al,14h
je mov_creg
cmp al,'['
jne invalid_operand
mov_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je mov_mem_imm
cmp al,10h
jne invalid_operand
mov_mem_reg:
lods byte [esi]
cmp al,30h
jb mov_mem_general_reg
cmp al,40h
jb mov_mem_sreg
mov_mem_general_reg:
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
cmp ah,1
je mov_mem_reg_8bit
inc [base_code]
mov al,ah
call operand_autodetect
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_mem_ax
jmp instruction_ready
mov_mem_reg_8bit:
or al,bl
or al,bh
jnz instruction_ready
mov_mem_al:
test ch,22h
jnz mov_mem_address16_al
test ch,44h
jnz mov_mem_address32_al
test ch,not 88h
jnz invalid_address_size
call check_mov_address64
cmp al,0
jg mov_mem_address64_al
jl instruction_ready
cmp [code_type],16
jne mov_mem_address32_al
cmp edx,10000h
jb mov_mem_address16_al
mov_mem_address32_al:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A2h
store_mov_address32:
call store_classic_instruction_code
call store_address_32bit_value
jmp instruction_assembled
mov_mem_address16_al:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A2h
store_mov_address16:
cmp [code_type],64
je invalid_address
call store_classic_instruction_code
mov eax,edx
stos word [edi]
cmp edx,10000h
jge value_out_of_range
jmp instruction_assembled
check_mov_address64:
cmp [code_type],64
jne no_address64
test ch,88h
jnz address64_required
mov eax,[address_high]
or eax,eax
jz no_address64
bt edx,31
adc eax,0
jz address64_simm32
address64_required:
mov al,1
ret
address64_simm32:
mov al,-1
ret
no_address64:
test ch,08h
jnz invalid_address_size
xor al,al
ret
mov_mem_address64_al:
call store_segment_prefix_if_necessary
mov [base_code],0A2h
store_mov_address64:
call store_classic_instruction_code
call store_address_64bit_value
jmp instruction_assembled
mov_mem_ax:
test ch,22h
jnz mov_mem_address16_ax
test ch,44h
jnz mov_mem_address32_ax
test ch,not 88h
jnz invalid_address_size
call check_mov_address64
cmp al,0
jg mov_mem_address64_ax
jl instruction_ready
cmp [code_type],16
jne mov_mem_address32_ax
cmp edx,10000h
jb mov_mem_address16_ax
mov_mem_address32_ax:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A3h
jmp store_mov_address32
mov_mem_address16_ax:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A3h
jmp store_mov_address16
mov_mem_address64_ax:
call store_segment_prefix_if_necessary
mov [base_code],0A3h
jmp store_mov_address64
mov_mem_sreg:
sub al,31h
mov [postbyte_register],al
pop ecx ebx edx
mov ah,[operand_size]
or ah,ah
jz mov_mem_sreg_store
cmp ah,2
jne invalid_operand_size
mov_mem_sreg_store:
mov [base_code],8Ch
jmp instruction_ready
mov_mem_imm:
mov al,[operand_size]
cmp al,1
jb mov_mem_imm_nosize
je mov_mem_imm_8bit
cmp al,2
je mov_mem_imm_16bit
cmp al,4
je mov_mem_imm_32bit
cmp al,8
jne invalid_operand_size
mov_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp mov_mem_imm_32bit_store
mov_mem_imm_nosize:
call recoverable_unknown_size
mov_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov [postbyte_register],0
mov [base_code],0C6h
pop ecx ebx edx
call store_instruction_with_imm8
jmp instruction_assembled
mov_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
mov [postbyte_register],0
mov [base_code],0C7h
pop ecx ebx edx
call store_instruction_with_imm16
jmp instruction_assembled
mov_mem_imm_32bit:
call operand_32bit
call get_dword_value
mov_mem_imm_32bit_store:
mov dword [value],eax
mov [postbyte_register],0
mov [base_code],0C7h
pop ecx ebx edx
call store_instruction_with_imm32
jmp instruction_assembled
mov_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz mov_sreg
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je mov_reg_mem
cmp al,'('
je mov_reg_imm
cmp al,14h
je mov_reg_creg
cmp al,10h
jne invalid_operand
mov_reg_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz mov_reg_sreg
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
cmp al,1
je mov_reg_reg_8bit
call operand_autodetect
inc [base_code]
mov_reg_reg_8bit:
jmp nomem_instruction_ready
mov_reg_sreg:
mov bl,[postbyte_register]
mov ah,al
and al,1111b
mov [postbyte_register],al
shr ah,4
cmp ah,3
jne invalid_operand
dec [postbyte_register]
cmp [operand_size],8
je mov_reg_sreg64
cmp [operand_size],4
je mov_reg_sreg32
cmp [operand_size],2
jne invalid_operand_size
call operand_16bit
jmp mov_reg_sreg_store
mov_reg_sreg64:
call operand_64bit
jmp mov_reg_sreg_store
mov_reg_sreg32:
call operand_32bit
mov_reg_sreg_store:
mov [base_code],8Ch
jmp nomem_instruction_ready
mov_reg_creg:
lods byte [esi]
mov bl,al
shr al,4
cmp al,4
ja invalid_operand
add al,20h
mov [extended_code],al
and bl,1111b
xchg bl,[postbyte_register]
mov [base_code],0Fh
cmp [code_type],64
je mov_reg_creg_64bit
cmp [operand_size],4
jne invalid_operand_size
cmp [postbyte_register],8
jne mov_reg_creg_store
cmp [extended_code],20h
jne mov_reg_creg_store
mov al,0F0h
stos byte [edi]
mov [postbyte_register],0
mov_reg_creg_store:
jmp nomem_instruction_ready
mov_reg_creg_64bit:
cmp [operand_size],8
jne invalid_operand_size
jmp nomem_instruction_ready
mov_reg_mem:
add [base_code],2
call get_address
mov al,[operand_size]
cmp al,1
je mov_reg_mem_8bit
inc [base_code]
call operand_autodetect
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_ax_mem
jmp instruction_ready
mov_reg_mem_8bit:
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_al_mem
jmp instruction_ready
mov_al_mem:
test ch,22h
jnz mov_al_mem_address16
test ch,44h
jnz mov_al_mem_address32
test ch,not 88h
jnz invalid_address_size
call check_mov_address64
cmp al,0
jg mov_al_mem_address64
jl instruction_ready
cmp [code_type],16
jne mov_al_mem_address32
cmp edx,10000h
jb mov_al_mem_address16
mov_al_mem_address32:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A0h
jmp store_mov_address32
mov_al_mem_address16:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A0h
jmp store_mov_address16
mov_al_mem_address64:
call store_segment_prefix_if_necessary
mov [base_code],0A0h
jmp store_mov_address64
mov_ax_mem:
test ch,22h
jnz mov_ax_mem_address16
test ch,44h
jnz mov_ax_mem_address32
test ch,not 88h
jnz invalid_address_size
call check_mov_address64
cmp al,0
jg mov_ax_mem_address64
jl instruction_ready
cmp [code_type],16
jne mov_ax_mem_address32
cmp edx,10000h
jb mov_ax_mem_address16
mov_ax_mem_address32:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A1h
jmp store_mov_address32
mov_ax_mem_address16:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A1h
jmp store_mov_address16
mov_ax_mem_address64:
call store_segment_prefix_if_necessary
mov [base_code],0A1h
jmp store_mov_address64
mov_reg_imm:
mov al,[operand_size]
cmp al,1
je mov_reg_imm_8bit
cmp al,2
je mov_reg_imm_16bit
cmp al,4
je mov_reg_imm_32bit
cmp al,8
jne invalid_operand_size
mov_reg_imm_64bit:
call operand_64bit
call get_qword_value
mov ecx,edx
cmp [size_declared],0
jne mov_reg_imm_64bit_store
cmp [value_type],4
jae mov_reg_imm_64bit_store
cdq
cmp ecx,edx
je mov_reg_64bit_imm_32bit
mov_reg_imm_64bit_store:
push eax ecx
mov al,0B8h
call store_mov_reg_imm_code
pop edx eax
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
jmp instruction_assembled
mov_reg_imm_8bit:
call get_byte_value
mov dl,al
mov al,0B0h
call store_mov_reg_imm_code
mov al,dl
stos byte [edi]
jmp instruction_assembled
mov_reg_imm_16bit:
call get_word_value
mov dx,ax
call operand_16bit
mov al,0B8h
call store_mov_reg_imm_code
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
mov_reg_imm_32bit:
call operand_32bit
call get_dword_value
mov edx,eax
mov al,0B8h
call store_mov_reg_imm_code
mov_store_imm_32bit:
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
store_mov_reg_imm_code:
mov ah,[postbyte_register]
test ah,1000b
jz mov_reg_imm_prefix_ok
or [rex_prefix],41h
mov_reg_imm_prefix_ok:
and ah,111b
add al,ah
mov [base_code],al
call store_classic_instruction_code
ret
mov_reg_64bit_imm_32bit:
mov edx,eax
mov bl,[postbyte_register]
mov [postbyte_register],0
mov [base_code],0C7h
call store_nomem_instruction
jmp mov_store_imm_32bit
mov_sreg:
mov ah,al
and al,1111b
mov [postbyte_register],al
shr ah,4
cmp ah,3
jne invalid_operand
cmp al,2
je illegal_instruction
dec [postbyte_register]
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je mov_sreg_mem
cmp al,10h
jne invalid_operand
mov_sreg_reg:
lods byte [esi]
call convert_register
or ah,ah
jz mov_sreg_reg_size_ok
cmp ah,2
jne invalid_operand_size
mov bl,al
mov_sreg_reg_size_ok:
mov [base_code],8Eh
jmp nomem_instruction_ready
mov_sreg_mem:
call get_address
mov al,[operand_size]
or al,al
jz mov_sreg_mem_size_ok
cmp al,2
jne invalid_operand_size
mov_sreg_mem_size_ok:
mov [base_code],8Eh
jmp instruction_ready
mov_creg:
lods byte [esi]
mov ah,al
shr ah,4
cmp ah,4
ja invalid_operand
add ah,22h
mov [extended_code],ah
and al,1111b
mov [postbyte_register],al
mov [base_code],0Fh
lods byte [esi]
cmp al,','
jne invalid_operand
call take_register
mov bl,al
cmp [code_type],64
je mov_creg_64bit
cmp ah,4
jne invalid_operand_size
cmp [postbyte_register],8
jne mov_creg_store
cmp [extended_code],22h
jne mov_creg_store
mov al,0F0h
stos byte [edi]
mov [postbyte_register],0
mov_creg_store:
jmp nomem_instruction_ready
mov_creg_64bit:
cmp ah,8
je mov_creg_store
jmp invalid_operand_size
test_instruction:
mov [base_code],84h
lods byte [esi]
call get_size_operator
cmp al,10h
je test_reg
cmp al,'['
jne invalid_operand
test_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je test_mem_imm
cmp al,10h
jne invalid_operand
test_mem_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
mov al,ah
cmp al,1
je test_mem_reg_8bit
call operand_autodetect
inc [base_code]
test_mem_reg_8bit:
jmp instruction_ready
test_mem_imm:
mov al,[operand_size]
cmp al,1
jb test_mem_imm_nosize
je test_mem_imm_8bit
cmp al,2
je test_mem_imm_16bit
cmp al,4
je test_mem_imm_32bit
cmp al,8
jne invalid_operand_size
test_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp test_mem_imm_32bit_store
test_mem_imm_nosize:
call recoverable_unknown_size
test_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov [postbyte_register],0
mov [base_code],0F6h
pop ecx ebx edx