Subversion Repositories Kolibri OS

Rev

Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2006, Tomasz Grysztar.
109 heavyiron 3
; All rights reserved.
31 halyavin 4
5
 
6
        cmp     [code_type],64
109 heavyiron 7
        je      illegal_instruction
8
simple_instruction:
31 halyavin 9
        stos    byte [edi]
109 heavyiron 10
        jmp     instruction_assembled
11
simple_instruction_only64:
31 halyavin 12
        cmp     [code_type],64
109 heavyiron 13
        jne     illegal_instruction
14
        jmp     simple_instruction
15
simple_instruction_16bit_except64:
31 halyavin 16
        cmp     [code_type],64
109 heavyiron 17
        je      illegal_instruction
18
simple_instruction_16bit:
31 halyavin 19
        cmp     [code_type],16
109 heavyiron 20
        jne     size_prefix
21
        stos    byte [edi]
22
        jmp     instruction_assembled
23
      size_prefix:
31 halyavin 24
        mov     ah,al
109 heavyiron 25
        mov     al,66h
26
        stos    word [edi]
27
        jmp     instruction_assembled
28
simple_instruction_32bit_except64:
31 halyavin 29
        cmp     [code_type],64
109 heavyiron 30
        je      illegal_instruction
31
simple_instruction_32bit:
31 halyavin 32
        cmp     [code_type],16
109 heavyiron 33
        je      size_prefix
34
        stos    byte [edi]
35
        jmp     instruction_assembled
36
simple_instruction_64bit:
31 halyavin 37
        cmp     [code_type],64
109 heavyiron 38
        jne     illegal_instruction
39
        mov     ah,al
40
        mov     al,48h
41
        stos    word [edi]
42
        jmp     instruction_assembled
43
simple_extended_instruction:
31 halyavin 44
        mov     ah,al
109 heavyiron 45
        mov     al,0Fh
46
        stos    word [edi]
47
        jmp     instruction_assembled
48
prefix_instruction:
31 halyavin 49
        stos    byte [edi]
109 heavyiron 50
        or      [prefixed_instruction],-1
51
        jmp     continue_line
52
segment_prefix:
31 halyavin 53
        mov     ah,al
109 heavyiron 54
        shr     ah,4
55
        cmp     ah,6
56
        jne     illegal_instruction
57
        and     al,1111b
58
        mov     [segment_register],al
59
        call    store_segment_prefix
60
        or      [prefixed_instruction],-1
61
        jmp     continue_line
62
int_instruction:
31 halyavin 63
        lods    byte [esi]
109 heavyiron 64
        call    get_size_operator
65
        cmp     ah,1
66
        ja      invalid_operand_size
67
        cmp     al,'('
68
        jne     invalid_operand
69
        call    get_byte_value
70
        mov     ah,al
71
        mov     al,0CDh
72
        stos    word [edi]
73
        jmp     instruction_assembled
74
iret_instruction:
31 halyavin 75
        cmp     [code_type],64
109 heavyiron 76
        jne     simple_instruction
77
        call    operand_64bit
78
        jmp     simple_instruction
79
aa_instruction:
31 halyavin 80
        cmp     [code_type],64
109 heavyiron 81
        je      illegal_instruction
82
        push    eax
83
        mov     bl,10
84
        cmp     byte [esi],'('
85
        jne     aa_store
86
        inc     esi
87
        xor     al,al
88
        xchg    al,[operand_size]
89
        cmp     al,1
90
        ja      invalid_operand_size
91
        call    get_byte_value
92
        mov     bl,al
93
      aa_store:
31 halyavin 94
        cmp     [operand_size],0
109 heavyiron 95
        jne     invalid_operand
96
        pop     eax
97
        mov     ah,bl
98
        stos    word [edi]
99
        jmp     instruction_assembled
100
31 halyavin 101
 
102
        mov     [base_code],al
109 heavyiron 103
        lods    byte [esi]
104
        call    get_size_operator
105
        cmp     al,10h
106
        je      basic_reg
107
        cmp     al,'['
108
        jne     invalid_operand
109
      basic_mem:
31 halyavin 110
        call    get_address
109 heavyiron 111
        push    edx bx cx
112
        lods    byte [esi]
113
        cmp     al,','
114
        jne     invalid_operand
115
        lods    byte [esi]
116
        call    get_size_operator
117
        cmp     al,'('
118
        je      basic_mem_imm
119
        cmp     al,10h
120
        jne     invalid_operand
121
      basic_mem_reg:
31 halyavin 122
        lods    byte [esi]
109 heavyiron 123
        call    convert_register
124
        mov     [postbyte_register],al
125
        pop     cx bx edx
126
        mov     al,ah
127
        cmp     al,1
128
        je      basic_mem_reg_8bit
129
        call    operand_autodetect
130
        inc     [base_code]
131
      basic_mem_reg_8bit:
31 halyavin 132
        call    store_instruction
109 heavyiron 133
        jmp     instruction_assembled
134
      basic_mem_imm:
31 halyavin 135
        mov     al,[operand_size]
109 heavyiron 136
        cmp     al,1
137
        je      basic_mem_imm_8bit
138
        cmp     al,2
139
        je      basic_mem_imm_16bit
140
        cmp     al,4
141
        je      basic_mem_imm_32bit
142
        cmp     al,8
143
        je      basic_mem_imm_64bit
144
        or      al,al
145
        jnz     invalid_operand_size
146
        cmp     [error_line],0
147
        jne     basic_mem_imm_8bit
148
        mov     eax,[current_line]
149
        mov     [error_line],eax
150
        mov     [error],operand_size_not_specified
151
      basic_mem_imm_8bit:
31 halyavin 152
        call    get_byte_value
109 heavyiron 153
        mov     byte [value],al
154
        mov     al,[base_code]
155
        shr     al,3
156
        mov     [postbyte_register],al
157
        pop     cx bx edx
158
        mov     [base_code],80h
159
        call    store_instruction_with_imm8
160
        jmp     instruction_assembled
161
      basic_mem_imm_16bit:
31 halyavin 162
        call    operand_16bit
109 heavyiron 163
        call    get_word_value
164
        mov     word [value],ax
165
        mov     al,[base_code]
166
        shr     al,3
167
        mov     [postbyte_register],al
168
        pop     cx bx edx
169
        cmp     [value_type],0
170
        jne     basic_mem_imm_16bit_store
171
        cmp     [size_declared],0
172
        jne     basic_mem_imm_16bit_store
173
        cmp     word [value],80h
174
        jb      basic_mem_simm_8bit
175
        cmp     word [value],-80h
176
        jae     basic_mem_simm_8bit
177
      basic_mem_imm_16bit_store:
31 halyavin 178
        mov     [base_code],81h
109 heavyiron 179
        call    store_instruction_with_imm16
180
        jmp     instruction_assembled
181
      basic_mem_simm_8bit:
31 halyavin 182
        mov     [base_code],83h
109 heavyiron 183
        call    store_instruction_with_imm8
184
        jmp     instruction_assembled
185
      basic_mem_imm_32bit:
31 halyavin 186
        call    operand_32bit
109 heavyiron 187
        call    get_dword_value
188
      basic_mem_imm_32bit_ok:
31 halyavin 189
        mov     dword [value],eax
109 heavyiron 190
        mov     al,[base_code]
191
        shr     al,3
192
        mov     [postbyte_register],al
193
        pop     cx bx edx
194
        cmp     [value_type],0
195
        jne     basic_mem_imm_32bit_store
196
        cmp     [size_declared],0
197
        jne     basic_mem_imm_32bit_store
198
        cmp     dword [value],80h
199
        jb      basic_mem_simm_8bit
200
        cmp     dword [value],-80h
201
        jae     basic_mem_simm_8bit
202
      basic_mem_imm_32bit_store:
31 halyavin 203
        mov     [base_code],81h
109 heavyiron 204
        call    store_instruction_with_imm32
205
        jmp     instruction_assembled
206
      basic_mem_imm_64bit:
31 halyavin 207
        cmp     [size_declared],0
109 heavyiron 208
        jne     long_immediate_not_encodable
209
        call    operand_64bit
210
        call    get_simm32
211
        cmp     [value_type],4
212
        jae     long_immediate_not_encodable
213
        jmp     basic_mem_imm_32bit_ok
214
      get_simm32:
31 halyavin 215
        call    get_qword_value
109 heavyiron 216
        mov     ecx,edx
217
        cdq
218
        cmp     ecx,edx
219
        jne     value_out_of_range
220
        ret
221
      basic_reg:
31 halyavin 222
        lods    byte [esi]
109 heavyiron 223
        call    convert_register
224
        mov     [postbyte_register],al
225
        lods    byte [esi]
226
        cmp     al,','
227
        jne     invalid_operand
228
        lods    byte [esi]
229
        call    get_size_operator
230
        cmp     al,10h
231
        je      basic_reg_reg
232
        cmp     al,'('
233
        je      basic_reg_imm
234
        cmp     al,'['
235
        jne     invalid_operand
236
      basic_reg_mem:
31 halyavin 237
        call    get_address
109 heavyiron 238
        mov     al,[operand_size]
239
        cmp     al,1
240
        je      basic_reg_mem_8bit
241
        call    operand_autodetect
242
        add     [base_code],3
243
        call    store_instruction
244
        jmp     instruction_assembled
245
      basic_reg_mem_8bit:
31 halyavin 246
        add     [base_code],2
109 heavyiron 247
        call    store_instruction
248
        jmp     instruction_assembled
249
      basic_reg_reg:
31 halyavin 250
        lods    byte [esi]
109 heavyiron 251
        call    convert_register
252
        mov     bl,[postbyte_register]
253
        mov     [postbyte_register],al
254
        mov     al,ah
255
        cmp     al,1
256
        je      basic_reg_reg_8bit
257
        call    operand_autodetect
258
        inc     [base_code]
259
      basic_reg_reg_8bit:
31 halyavin 260
        call    store_nomem_instruction
109 heavyiron 261
        jmp     instruction_assembled
262
      basic_reg_imm:
31 halyavin 263
        mov     al,[operand_size]
109 heavyiron 264
        cmp     al,1
265
        je      basic_reg_imm_8bit
266
        cmp     al,2
267
        je      basic_reg_imm_16bit
268
        cmp     al,4
269
        je      basic_reg_imm_32bit
270
        cmp     al,8
271
        je      basic_reg_imm_64bit
272
        or      al,al
273
        jnz     invalid_operand_size
274
        cmp     [error_line],0
275
        jne     basic_reg_imm_32bit
276
        mov     eax,[current_line]
277
        mov     [error_line],eax
278
        mov     [error],operand_size_not_specified
279
        jmp     basic_reg_imm_32bit
280
      basic_reg_imm_8bit:
31 halyavin 281
        call    get_byte_value
109 heavyiron 282
        mov     dl,al
283
        mov     bl,[base_code]
284
        shr     bl,3
285
        xchg    bl,[postbyte_register]
286
        or      bl,bl
287
        jz      basic_al_imm
288
        mov     [base_code],80h
289
        call    store_nomem_instruction
290
        mov     al,dl
291
        stos    byte [edi]
292
        jmp     instruction_assembled
293
      basic_al_imm:
31 halyavin 294
        mov     al,[base_code]
109 heavyiron 295
        add     al,4
296
        stos    byte [edi]
297
        mov     al,dl
298
        stos    byte [edi]
299
        jmp     instruction_assembled
300
      basic_reg_imm_16bit:
31 halyavin 301
        call    operand_16bit
109 heavyiron 302
        call    get_word_value
303
        mov     dx,ax
304
        mov     bl,[base_code]
305
        shr     bl,3
306
        xchg    bl,[postbyte_register]
307
        cmp     [value_type],0
308
        jne     basic_reg_imm_16bit_store
309
        cmp     [size_declared],0
310
        jne     basic_reg_imm_16bit_store
311
        cmp     dx,80h
312
        jb      basic_reg_simm_8bit
313
        cmp     dx,-80h
314
        jae     basic_reg_simm_8bit
315
      basic_reg_imm_16bit_store:
31 halyavin 316
        or      bl,bl
109 heavyiron 317
        jz      basic_ax_imm
318
        mov     [base_code],81h
319
        call    store_nomem_instruction
320
        mov     ax,dx
321
        call    mark_relocation
322
        stos    word [edi]
323
        jmp     instruction_assembled
324
      basic_reg_simm_8bit:
31 halyavin 325
        mov     [base_code],83h
109 heavyiron 326
        call    store_nomem_instruction
327
        mov     al,dl
328
        stos    byte [edi]
329
        jmp     instruction_assembled
330
      basic_ax_imm:
31 halyavin 331
        add     [base_code],5
109 heavyiron 332
        call    store_instruction_code
333
        mov     ax,dx
334
        call    mark_relocation
335
        stos    word [edi]
336
        jmp     instruction_assembled
337
      basic_reg_imm_32bit:
31 halyavin 338
        call    operand_32bit
109 heavyiron 339
        call    get_dword_value
340
      basic_reg_imm_32bit_ok:
31 halyavin 341
        mov     edx,eax
109 heavyiron 342
        mov     bl,[base_code]
343
        shr     bl,3
344
        xchg    bl,[postbyte_register]
345
        cmp     [value_type],0
346
        jne     basic_reg_imm_32bit_store
347
        cmp     [size_declared],0
348
        jne     basic_reg_imm_32bit_store
349
        cmp     edx,80h
350
        jb      basic_reg_simm_8bit
351
        cmp     edx,-80h
352
        jae     basic_reg_simm_8bit
353
      basic_reg_imm_32bit_store:
31 halyavin 354
        or      bl,bl
109 heavyiron 355
        jz      basic_eax_imm
356
        mov     [base_code],81h
357
        call    store_nomem_instruction
358
        mov     eax,edx
359
        call    mark_relocation
360
        stos    dword [edi]
361
        jmp     instruction_assembled
362
      basic_eax_imm:
31 halyavin 363
        add     [base_code],5
109 heavyiron 364
        call    store_instruction_code
365
        mov     eax,edx
366
        call    mark_relocation
367
        stos    dword [edi]
368
        jmp     instruction_assembled
369
      basic_reg_imm_64bit:
31 halyavin 370
        cmp     [size_declared],0
109 heavyiron 371
        jne     long_immediate_not_encodable
372
        call    operand_64bit
373
        call    get_simm32
374
        cmp     [value_type],4
375
        jae     long_immediate_not_encodable
376
        jmp     basic_reg_imm_32bit_ok
377
single_operand_instruction:
31 halyavin 378
        mov     [base_code],0F6h
109 heavyiron 379
        mov     [postbyte_register],al
380
        lods    byte [esi]
381
        call    get_size_operator
382
        cmp     al,10h
383
        je      single_reg
384
        cmp     al,'['
385
        jne     invalid_operand
386
      single_mem:
31 halyavin 387
        call    get_address
109 heavyiron 388
        mov     al,[operand_size]
389
        cmp     al,1
390
        je      single_mem_8bit
391
        jb      single_mem_nosize
392
        call    operand_autodetect
393
        inc     [base_code]
394
        call    store_instruction
395
        jmp     instruction_assembled
396
      single_mem_nosize:
31 halyavin 397
        cmp     [error_line],0
109 heavyiron 398
        jne     single_mem_8bit
399
        mov     eax,[current_line]
400
        mov     [error_line],eax
401
        mov     [error],operand_size_not_specified
402
      single_mem_8bit:
31 halyavin 403
        call    store_instruction
109 heavyiron 404
        jmp     instruction_assembled
405
      single_reg:
31 halyavin 406
        lods    byte [esi]
109 heavyiron 407
        call    convert_register
408
        mov     bl,al
409
        mov     al,ah
410
        cmp     al,1
411
        je      single_reg_8bit
412
        call    operand_autodetect
413
        inc     [base_code]
414
      single_reg_8bit:
31 halyavin 415
        call    store_nomem_instruction
109 heavyiron 416
        jmp     instruction_assembled
417
mov_instruction:
31 halyavin 418
        mov     [base_code],88h
109 heavyiron 419
        lods    byte [esi]
420
        call    get_size_operator
421
        cmp     al,10h
422
        je      mov_reg
423
        cmp     al,'['
424
        jne     invalid_operand
425
      mov_mem:
31 halyavin 426
        call    get_address
109 heavyiron 427
        push    edx bx cx
428
        lods    byte [esi]
429
        cmp     al,','
430
        jne     invalid_operand
431
        lods    byte [esi]
432
        call    get_size_operator
433
        cmp     al,'('
434
        je      mov_mem_imm
435
        cmp     al,10h
436
        jne     invalid_operand
437
      mov_mem_reg:
31 halyavin 438
        lods    byte [esi]
109 heavyiron 439
        cmp     al,60h
440
        jb      mov_mem_general_reg
441
        cmp     al,70h
442
        jb      mov_mem_sreg
443
      mov_mem_general_reg:
31 halyavin 444
        call    convert_register
109 heavyiron 445
        mov     [postbyte_register],al
446
        pop     cx bx edx
447
        cmp     ah,1
448
        je      mov_mem_reg_8bit
449
        mov     al,ah
450
        call    operand_autodetect
451
        mov     al,[postbyte_register]
452
        or      al,bl
453
        or      al,bh
454
        jz      mov_mem_ax
455
        inc     [base_code]
456
        call    store_instruction
457
        jmp     instruction_assembled
458
      mov_mem_reg_8bit:
31 halyavin 459
        or      al,bl
109 heavyiron 460
        or      al,bh
461
        jz      mov_mem_al
462
        call    store_instruction
463
        jmp     instruction_assembled
464
      mov_mem_al:
31 halyavin 465
        test    ch,22h
109 heavyiron 466
        jnz     mov_mem_address16_al
467
        test    ch,44h
468
        jnz     mov_mem_address32_al
469
        test    ch,88h
470
        jnz     mov_mem_address64_al
471
        or      ch,ch
472
        jnz     invalid_address_size
473
        cmp     [code_type],64
474
        je      mov_mem_address64_al
475
        cmp     [code_type],32
476
        je      mov_mem_address32_al
477
        cmp     edx,10000h
478
        jb      mov_mem_address16_al
479
      mov_mem_address32_al:
31 halyavin 480
        call    store_segment_prefix_if_necessary
109 heavyiron 481
        call    address_32bit_prefix
482
        mov     [base_code],0A2h
483
      store_mov_address32:
31 halyavin 484
        call    store_instruction_code
109 heavyiron 485
        push    instruction_assembled
486
        jmp     store_address_32bit_value
487
      mov_mem_address16_al:
31 halyavin 488
        call    store_segment_prefix_if_necessary
109 heavyiron 489
        call    address_16bit_prefix
490
        mov     [base_code],0A2h
491
      store_mov_address16:
31 halyavin 492
        cmp     [code_type],64
109 heavyiron 493
        je      invalid_address
494
        call    store_instruction_code
495
        mov     eax,edx
496
        stos    word [edi]
497
        cmp     edx,10000h
498
        jge     value_out_of_range
499
        jmp     instruction_assembled
500
      mov_mem_address64_al:
31 halyavin 501
        call    store_segment_prefix_if_necessary
109 heavyiron 502
        mov     [base_code],0A2h
503
      store_mov_address64:
31 halyavin 504
        call    store_instruction_code
109 heavyiron 505
        push    instruction_assembled
506
        jmp     store_address_64bit_value
507
      mov_mem_ax:
31 halyavin 508
        test    ch,22h
109 heavyiron 509
        jnz     mov_mem_address16_ax
510
        test    ch,44h
511
        jnz     mov_mem_address32_ax
512
        test    ch,88h
513
        jnz     mov_mem_address64_ax
514
        or      ch,ch
515
        jnz     invalid_address_size
516
        cmp     [code_type],64
517
        je      mov_mem_address64_ax
518
        cmp     [code_type],32
519
        je      mov_mem_address32_ax
520
        cmp     edx,10000h
521
        jb      mov_mem_address16_ax
522
      mov_mem_address32_ax:
31 halyavin 523
        call    store_segment_prefix_if_necessary
109 heavyiron 524
        call    address_32bit_prefix
525
        mov     [base_code],0A3h
526
        jmp     store_mov_address32
527
      mov_mem_address16_ax:
31 halyavin 528
        call    store_segment_prefix_if_necessary
109 heavyiron 529
        call    address_16bit_prefix
530
        mov     [base_code],0A3h
531
        jmp     store_mov_address16
532
      mov_mem_address64_ax:
31 halyavin 533
        call    store_segment_prefix_if_necessary
109 heavyiron 534
        mov     [base_code],0A3h
535
        jmp     store_mov_address64
536
      mov_mem_sreg:
31 halyavin 537
        sub     al,61h
109 heavyiron 538
        mov     [postbyte_register],al
539
        pop     cx bx edx
540
        mov     ah,[operand_size]
541
        or      ah,ah
542
        jz      mov_mem_sreg_store
543
        cmp     ah,2
544
        jne     invalid_operand_size
545
      mov_mem_sreg_store:
31 halyavin 546
        mov     [base_code],8Ch
109 heavyiron 547
        call    store_instruction
548
        jmp     instruction_assembled
549
      mov_mem_imm:
31 halyavin 550
        mov     al,[operand_size]
109 heavyiron 551
        cmp     al,1
552
        je      mov_mem_imm_8bit
553
        cmp     al,2
554
        je      mov_mem_imm_16bit
555
        cmp     al,4
556
        je      mov_mem_imm_32bit
557
        cmp     al,8
558
        je      mov_mem_imm_64bit
559
        or      al,al
560
        jnz     invalid_operand_size
561
        cmp     [error_line],0
562
        jne     mov_mem_imm_32bit
563
        mov     eax,[current_line]
564
        mov     [error_line],eax
565
        mov     [error],operand_size_not_specified
566
        jmp     mov_mem_imm_32bit
567
      mov_mem_imm_8bit:
31 halyavin 568
        call    get_byte_value
109 heavyiron 569
        mov     byte [value],al
570
        mov     [postbyte_register],0
571
        mov     [base_code],0C6h
572
        pop     cx bx edx
573
        call    store_instruction_with_imm8
574
        jmp     instruction_assembled
575
      mov_mem_imm_16bit:
31 halyavin 576
        call    operand_16bit
109 heavyiron 577
        call    get_word_value
578
        mov     word [value],ax
579
        mov     [postbyte_register],0
580
        mov     [base_code],0C7h
581
        pop     cx bx edx
582
        call    store_instruction_with_imm16
583
        jmp     instruction_assembled
584
      mov_mem_imm_32bit:
31 halyavin 585
        call    operand_32bit
109 heavyiron 586
        call    get_dword_value
587
      mov_mem_imm_32bit_store:
31 halyavin 588
        mov     dword [value],eax
109 heavyiron 589
        mov     [postbyte_register],0
590
        mov     [base_code],0C7h
591
        pop     cx bx edx
592
        call    store_instruction_with_imm32
593
        jmp     instruction_assembled
594
      mov_mem_imm_64bit:
31 halyavin 595
        cmp     [size_declared],0
109 heavyiron 596
        jne     long_immediate_not_encodable
597
        call    operand_64bit
598
        call    get_simm32
599
        cmp     [value_type],4
600
        jae     long_immediate_not_encodable
601
        jmp     mov_mem_imm_32bit_store
602
      mov_reg:
31 halyavin 603
        lods    byte [esi]
109 heavyiron 604
        mov     ah,al
605
        sub     ah,10h
606
        and     ah,al
607
        test    ah,0F0h
608
        jnz     mov_sreg
609
        call    convert_register
610
        mov     [postbyte_register],al
611
        lods    byte [esi]
612
        cmp     al,','
613
        jne     invalid_operand
614
        lods    byte [esi]
615
        call    get_size_operator
616
        cmp     al,'['
617
        je      mov_reg_mem
618
        cmp     al,'('
619
        je      mov_reg_imm
620
        cmp     al,10h
621
        jne     invalid_operand
622
      mov_reg_reg:
31 halyavin 623
        lods    byte [esi]
109 heavyiron 624
        mov     ah,al
625
        sub     ah,10h
626
        and     ah,al
627
        test    ah,0F0h
628
        jnz     mov_reg_sreg
629
        call    convert_register
630
        mov     bl,[postbyte_register]
631
        mov     [postbyte_register],al
632
        mov     al,ah
633
        cmp     al,1
634
        je      mov_reg_reg_8bit
635
        call    operand_autodetect
636
        inc     [base_code]
637
      mov_reg_reg_8bit:
31 halyavin 638
        call    store_nomem_instruction
109 heavyiron 639
        jmp     instruction_assembled
640
      mov_reg_sreg:
31 halyavin 641
        mov     bl,[postbyte_register]
109 heavyiron 642
        mov     ah,al
643
        and     al,1111b
644
        mov     [postbyte_register],al
645
        shr     ah,4
646
        cmp     ah,5
647
        je      mov_reg_creg
648
        cmp     ah,7
649
        je      mov_reg_dreg
650
        ja      mov_reg_treg
651
        dec     [postbyte_register]
652
        cmp     [operand_size],8
653
        je      mov_reg_sreg64
654
        cmp     [operand_size],4
655
        je      mov_reg_sreg32
656
        cmp     [operand_size],2
657
        jne     invalid_operand_size
658
        call    operand_16bit
659
        jmp     mov_reg_sreg_store
660
      mov_reg_sreg64:
31 halyavin 661
        call    operand_64bit
109 heavyiron 662
        jmp     mov_reg_sreg_store
663
      mov_reg_sreg32:
31 halyavin 664
        call    operand_32bit
109 heavyiron 665
      mov_reg_sreg_store:
31 halyavin 666
        mov     [base_code],8Ch
109 heavyiron 667
        call    store_nomem_instruction
668
        jmp     instruction_assembled
669
      mov_reg_treg:
31 halyavin 670
        cmp     ah,9
109 heavyiron 671
        jne     invalid_operand
672
        mov     [extended_code],24h
673
        jmp     mov_reg_xrx
674
      mov_reg_dreg:
31 halyavin 675
        mov     [extended_code],21h
109 heavyiron 676
        jmp     mov_reg_xrx
677
      mov_reg_creg:
31 halyavin 678
        mov     [extended_code],20h
109 heavyiron 679
      mov_reg_xrx:
31 halyavin 680
        mov     [base_code],0Fh
109 heavyiron 681
        cmp     [code_type],64
682
        je      mov_reg_xrx_64bit
683
        cmp     [operand_size],4
684
        jne     invalid_operand_size
685
        cmp     [postbyte_register],8
686
        jne     mov_reg_xrx_store
687
        cmp     [extended_code],20h
688
        jne     mov_reg_xrx_store
689
        mov     al,0F0h
690
        stos    byte [edi]
691
        mov     [postbyte_register],0
692
      mov_reg_xrx_store:
693
        call    store_nomem_instruction
694
        jmp     instruction_assembled
695
      mov_reg_xrx_64bit:
31 halyavin 696
        cmp     [operand_size],8
109 heavyiron 697
        jne     invalid_operand_size
698
        call    store_nomem_instruction
699
        jmp     instruction_assembled
700
      mov_reg_mem:
31 halyavin 701
        call    get_address
109 heavyiron 702
        mov     al,[operand_size]
703
        cmp     al,1
704
        je      mov_reg_mem_8bit
705
        call    operand_autodetect
706
        mov     al,[postbyte_register]
707
        or      al,bl
708
        or      al,bh
709
        jz      mov_ax_mem
710
        add     [base_code],3
711
        call    store_instruction
712
        jmp     instruction_assembled
713
      mov_reg_mem_8bit:
31 halyavin 714
        mov     al,[postbyte_register]
109 heavyiron 715
        or      al,bl
716
        or      al,bh
717
        jz      mov_al_mem
718
        add     [base_code],2
719
        call    store_instruction
720
        jmp     instruction_assembled
721
      mov_al_mem:
31 halyavin 722
        test    ch,22h
109 heavyiron 723
        jnz     mov_al_mem_address16
724
        test    ch,44h
725
        jnz     mov_al_mem_address32
726
        test    ch,88h
727
        jnz     mov_al_mem_address64
728
        or      ch,ch
729
        jnz     invalid_address_size
730
        cmp     [code_type],64
731
        je      mov_al_mem_address64
732
        cmp     [code_type],32
733
        je      mov_al_mem_address32
734
        cmp     edx,10000h
735
        jb      mov_al_mem_address16
736
      mov_al_mem_address32:
31 halyavin 737
        call    store_segment_prefix_if_necessary
109 heavyiron 738
        call    address_32bit_prefix
739
        mov     [base_code],0A0h
740
        jmp     store_mov_address32
741
      mov_al_mem_address16:
31 halyavin 742
        call    store_segment_prefix_if_necessary
109 heavyiron 743
        call    address_16bit_prefix
744
        mov     [base_code],0A0h
745
        jmp     store_mov_address16
746
      mov_al_mem_address64:
31 halyavin 747
        call    store_segment_prefix_if_necessary
109 heavyiron 748
        mov     [base_code],0A0h
749
        jmp     store_mov_address64
750
      mov_ax_mem:
31 halyavin 751
        test    ch,22h
109 heavyiron 752
        jnz     mov_ax_mem_address16
753
        test    ch,44h
754
        jnz     mov_ax_mem_address32
755
        test    ch,88h
756
        jnz     mov_ax_mem_address64
757
        or      ch,ch
758
        jnz     invalid_address_size
759
        cmp     [code_type],64
760
        je      mov_ax_mem_address64
761
        cmp     [code_type],32
762
        je      mov_ax_mem_address32
763
        cmp     edx,10000h
764
        jb      mov_ax_mem_address16
765
      mov_ax_mem_address32:
31 halyavin 766
        call    store_segment_prefix_if_necessary
109 heavyiron 767
        call    address_32bit_prefix
768
        mov     [base_code],0A1h
769
        jmp     store_mov_address32
770
      mov_ax_mem_address16:
31 halyavin 771
        call    store_segment_prefix_if_necessary
109 heavyiron 772
        call    address_16bit_prefix
773
        mov     [base_code],0A1h
774
        jmp     store_mov_address16
775
      mov_ax_mem_address64:
31 halyavin 776
        call    store_segment_prefix_if_necessary
109 heavyiron 777
        mov     [base_code],0A1h
778
        jmp     store_mov_address64
779
      mov_reg_imm:
31 halyavin 780
        mov     al,[operand_size]
109 heavyiron 781
        cmp     al,1
782
        je      mov_reg_imm_8bit
783
        cmp     al,2
784
        je      mov_reg_imm_16bit
785
        cmp     al,4
786
        je      mov_reg_imm_32bit
787
        cmp     al,8
788
        je      mov_reg_imm_64bit
789
        or      al,al
790
        jnz     invalid_operand_size
791
        cmp     [error_line],0
792
        jne     mov_reg_imm_32bit
793
        mov     eax,[current_line]
794
        mov     [error_line],eax
795
        mov     [error],operand_size_not_specified
796
        jmp     mov_reg_imm_32bit
797
      mov_reg_imm_8bit:
31 halyavin 798
        call    get_byte_value
109 heavyiron 799
        mov     dl,al
800
        mov     al,0B0h
801
        call    store_mov_reg_imm_code
802
        mov     al,dl
803
        stos    byte [edi]
804
        jmp     instruction_assembled
805
      mov_reg_imm_16bit:
31 halyavin 806
        call    get_word_value
109 heavyiron 807
        mov     dx,ax
808
        call    operand_16bit
809
        mov     al,0B8h
810
        call    store_mov_reg_imm_code
811
        mov     ax,dx
812
        call    mark_relocation
813
        stos    word [edi]
814
        jmp     instruction_assembled
815
      mov_reg_imm_32bit:
31 halyavin 816
        call    operand_32bit
109 heavyiron 817
        call    get_dword_value
818
        mov     edx,eax
819
        mov     al,0B8h
820
        call    store_mov_reg_imm_code
821
        mov     eax,edx
822
        call    mark_relocation
823
        stos    dword [edi]
824
        jmp     instruction_assembled
825
      mov_reg_imm_64bit:
31 halyavin 826
        call    operand_64bit
109 heavyiron 827
        call    get_qword_value
828
        mov     ecx,edx
829
        cmp     [size_declared],0
830
        jne     mov_reg_imm_64bit_store
831
        cmp     [value_type],4
832
        jae     mov_reg_imm_64bit_store
833
        cdq
834
        cmp     ecx,edx
835
        je      mov_reg_64bit_imm_32bit
836
      mov_reg_imm_64bit_store:
31 halyavin 837
        push    eax ecx
109 heavyiron 838
        mov     al,0B8h
839
        call    store_mov_reg_imm_code
840
        pop     edx eax
841
        call    mark_relocation
842
        stos    dword [edi]
843
        mov     eax,edx
844
        stos    dword [edi]
845
        jmp     instruction_assembled
846
      store_mov_reg_imm_code:
31 halyavin 847
        mov     ah,[postbyte_register]
109 heavyiron 848
        test    ah,1000b
849
        jz      mov_reg_imm_prefix_ok
850
        or      [rex_prefix],41h
851
      mov_reg_imm_prefix_ok:
31 halyavin 852
        and     ah,111b
109 heavyiron 853
        add     al,ah
854
        mov     [base_code],al
855
        call    store_instruction_code
856
        ret
857
      mov_reg_64bit_imm_32bit:
31 halyavin 858
        mov     edx,eax
109 heavyiron 859
        mov     bl,[postbyte_register]
860
        mov     [postbyte_register],0
861
        mov     [base_code],0C7h
862
        call    store_nomem_instruction
863
        mov     eax,edx
864
        call    mark_relocation
865
        stos    dword [edi]
866
        jmp     instruction_assembled
867
      mov_sreg:
31 halyavin 868
        mov     ah,al
109 heavyiron 869
        and     al,1111b
870
        mov     [postbyte_register],al
871
        shr     ah,4
872
        cmp     ah,5
873
        je      mov_creg
874
        cmp     ah,7
875
        je      mov_dreg
876
        ja      mov_treg
877
        cmp     al,2
878
        je      illegal_instruction
879
        dec     [postbyte_register]
880
        lods    byte [esi]
881
        cmp     al,','
882
        jne     invalid_operand
883
        lods    byte [esi]
884
        call    get_size_operator
885
        cmp     al,'['
886
        je      mov_sreg_mem
887
        cmp     al,10h
888
        jne     invalid_operand
889
      mov_sreg_reg:
31 halyavin 890
        lods    byte [esi]
109 heavyiron 891
        call    convert_register
892
        or      ah,ah
893
        jz      mov_sreg_reg_size_ok
894
        cmp     ah,2
895
        jne     invalid_operand_size
896
        mov     bl,al
897
      mov_sreg_reg_size_ok:
31 halyavin 898
        mov     [base_code],8Eh
109 heavyiron 899
        call    store_nomem_instruction
900
        jmp     instruction_assembled
901
      mov_sreg_mem:
31 halyavin 902
        call    get_address
109 heavyiron 903
        mov     al,[operand_size]
904
        or      al,al
905
        jz      mov_sreg_mem_size_ok
906
        cmp     al,2
907
        jne     invalid_operand_size
908
      mov_sreg_mem_size_ok:
31 halyavin 909
        mov     [base_code],8Eh
109 heavyiron 910
        call    store_instruction
911
        jmp     instruction_assembled
912
      mov_treg:
31 halyavin 913
        cmp     ah,9
109 heavyiron 914
        jne     invalid_operand
915
        mov     [extended_code],26h
916
        jmp     mov_xrx
917
      mov_dreg:
31 halyavin 918
        mov     [extended_code],23h
109 heavyiron 919
        jmp     mov_xrx
920
      mov_creg:
31 halyavin 921
        mov     [extended_code],22h
109 heavyiron 922
      mov_xrx:
31 halyavin 923
        mov     [base_code],0Fh
109 heavyiron 924
        lods    byte [esi]
925
        cmp     al,','
926
        jne     invalid_operand
927
        lods    byte [esi]
928
        cmp     al,10h
929
        jne     invalid_operand
930
        lods    byte [esi]
931
        call    convert_register
932
        mov     bl,al
933
        cmp     [code_type],64
934
        je      mov_xrx_64bit
935
        cmp     ah,4
936
        jne     invalid_operand_size
937
        cmp     [postbyte_register],8
938
        jne     mov_xrx_store
939
        cmp     [extended_code],22h
940
        jne     mov_xrx_store
941
        mov     al,0F0h
942
        stos    byte [edi]
943
        mov     [postbyte_register],0
944
      mov_xrx_store:
945
        call    store_nomem_instruction
946
        jmp     instruction_assembled
947
      mov_xrx_64bit:
31 halyavin 948
        cmp     ah,8
109 heavyiron 949
        jne     invalid_operand_size
950
        call    store_nomem_instruction
951
        jmp     instruction_assembled
952
cmov_instruction:
31 halyavin 953
        mov     [base_code],0Fh
109 heavyiron 954
        mov     [extended_code],al
955
        lods    byte [esi]
956
        call    get_size_operator
957
        cmp     al,10h
958
        jne     invalid_operand
959
        lods    byte [esi]
960
        call    convert_register
961
        mov     [postbyte_register],al
962
        lods    byte [esi]
963
        cmp     al,','
964
        jne     invalid_operand
965
        lods    byte [esi]
966
        call    get_size_operator
967
        cmp     al,'['
968
        je      cmov_reg_mem
969
        cmp     al,10h
970
        jne     invalid_operand
971
      cmov_reg_reg:
31 halyavin 972
        lods    byte [esi]
109 heavyiron 973
        call    convert_register
974
        mov     bl,al
975
        mov     al,ah
976
        call    operand_autodetect
977
        call    store_nomem_instruction
978
        jmp     instruction_assembled
979
      cmov_reg_mem:
31 halyavin 980
        call    get_address
109 heavyiron 981
        mov     al,[operand_size]
982
        call    operand_autodetect
983
        call    store_instruction
984
        jmp     instruction_assembled
985
test_instruction:
31 halyavin 986
        mov     [base_code],84h
109 heavyiron 987
        lods    byte [esi]
988
        call    get_size_operator
989
        cmp     al,10h
990
        je      test_reg
991
        cmp     al,'['
992
        jne     invalid_operand
993
      test_mem:
31 halyavin 994
        call    get_address
109 heavyiron 995
        push    edx bx cx
996
        lods    byte [esi]
997
        cmp     al,','
998
        jne     invalid_operand
999
        lods    byte [esi]
1000
        call    get_size_operator
1001
        cmp     al,'('
1002
        je      test_mem_imm
1003
        cmp     al,10h
1004
        jne     invalid_operand
1005
      test_mem_reg:
31 halyavin 1006
        lods    byte [esi]
109 heavyiron 1007
        call    convert_register
1008
        mov     [postbyte_register],al
1009
        pop     cx bx edx
1010
        mov     al,ah
1011
        cmp     al,1
1012
        je      test_mem_reg_8bit
1013
        call    operand_autodetect
1014
        inc     [base_code]
1015
      test_mem_reg_8bit:
31 halyavin 1016
        call    store_instruction
109 heavyiron 1017
        jmp     instruction_assembled
1018
      test_mem_imm:
31 halyavin 1019
        mov     al,[operand_size]
109 heavyiron 1020
        cmp     al,1
1021
        je      test_mem_imm_8bit
1022
        cmp     al,2
1023
        je      test_mem_imm_16bit
1024
        cmp     al,4
1025
        je      test_mem_imm_32bit
1026
        cmp     al,8
1027
        je      test_mem_imm_64bit
1028
        or      al,al
1029
        jnz     invalid_operand_size
1030
        cmp     [error_line],0
1031
        jne     test_mem_imm_32bit
1032
        mov     eax,[current_line]
1033
        mov     [error_line],eax
1034
        mov     [error],operand_size_not_specified
1035
        jmp     test_mem_imm_32bit
1036
      test_mem_imm_8bit:
31 halyavin 1037
        call    get_byte_value
109 heavyiron 1038
        mov     byte [value],al
1039
        mov     [postbyte_register],0
1040
        mov     [base_code],0F6h
1041
        pop     cx bx edx
1042
        call    store_instruction_with_imm8
1043
        jmp     instruction_assembled
1044
      test_mem_imm_16bit:
31 halyavin 1045
        call    operand_16bit
109 heavyiron 1046
        call    get_word_value
1047
        mov     word [value],ax
1048
        mov     [postbyte_register],0
1049
        mov     [base_code],0F7h
1050
        pop     cx bx edx
1051
        call    store_instruction_with_imm16
1052
        jmp     instruction_assembled
1053
      test_mem_imm_32bit:
31 halyavin 1054
        call    operand_32bit
109 heavyiron 1055
        call    get_dword_value
1056
      test_mem_imm_32bit_store:
31 halyavin 1057
        mov     dword [value],eax
109 heavyiron 1058
        mov     [postbyte_register],0
1059
        mov     [base_code],0F7h
1060
        pop     cx bx edx
1061
        call    store_instruction_with_imm32
1062
        jmp     instruction_assembled
1063
      test_mem_imm_64bit:
31 halyavin 1064
        cmp     [size_declared],0
109 heavyiron 1065
        jne     long_immediate_not_encodable
1066
        call    operand_64bit
1067
        call    get_simm32
1068
        cmp     [value_type],4
1069
        jae     long_immediate_not_encodable
1070
        jmp     test_mem_imm_32bit_store
1071
      test_reg:
31 halyavin 1072
        lods    byte [esi]
109 heavyiron 1073
        call    convert_register
1074
        mov     [postbyte_register],al
1075
        lods    byte [esi]
1076
        cmp     al,','
1077
        jne     invalid_operand
1078
        lods    byte [esi]
1079
        call    get_size_operator
1080
        cmp     al,'['
1081
        je      test_reg_mem
1082
        cmp     al,'('
1083
        je      test_reg_imm
1084
        cmp     al,10h
1085
        jne     invalid_operand
1086
      test_reg_reg:
31 halyavin 1087
        lods    byte [esi]
109 heavyiron 1088
        call    convert_register
1089
        mov     bl,[postbyte_register]
1090
        mov     [postbyte_register],al
1091
        mov     al,ah
1092
        cmp     al,1
1093
        je      test_reg_reg_8bit
1094
        call    operand_autodetect
1095
        inc     [base_code]
1096
      test_reg_reg_8bit:
31 halyavin 1097
        call    store_nomem_instruction
109 heavyiron 1098
        jmp     instruction_assembled
1099
      test_reg_imm:
31 halyavin 1100
        mov     al,[operand_size]
109 heavyiron 1101
        cmp     al,1
1102
        je      test_reg_imm_8bit
1103
        cmp     al,2
1104
        je      test_reg_imm_16bit
1105
        cmp     al,4
1106
        je      test_reg_imm_32bit
1107
        cmp     al,8
1108
        je      test_reg_imm_64bit
1109
        jmp     invalid_operand_size
1110
      test_reg_imm_8bit:
31 halyavin 1111
        call    get_byte_value
109 heavyiron 1112
        mov     dl,al
1113
        mov     bl,[postbyte_register]
1114
        mov     [postbyte_register],0
1115
        mov     [base_code],0F6h
1116
        or      bl,bl
1117
        jz      test_al_imm
1118
        call    store_nomem_instruction
1119
        mov     al,dl
1120
        stos    byte [edi]
1121
        jmp     instruction_assembled
1122
      test_al_imm:
31 halyavin 1123
        mov     [base_code],0A8h
109 heavyiron 1124
        call    store_instruction_code
1125
        mov     al,dl
1126
        stos    byte [edi]
1127
        jmp     instruction_assembled
1128
      test_reg_imm_16bit:
31 halyavin 1129
        call    operand_16bit
109 heavyiron 1130
        call    get_word_value
1131
        mov     dx,ax
1132
        mov     bl,[postbyte_register]
1133
        mov     [postbyte_register],0
1134
        mov     [base_code],0F7h
1135
        or      bl,bl
1136
        jz      test_ax_imm
1137
        call    store_nomem_instruction
1138
        mov     ax,dx
1139
        call    mark_relocation
1140
        stos    word [edi]
1141
        jmp     instruction_assembled
1142
      test_ax_imm:
31 halyavin 1143
        mov     [base_code],0A9h
109 heavyiron 1144
        call    store_instruction_code
1145
        mov     ax,dx
1146
        stos    word [edi]
1147
        jmp     instruction_assembled
1148
      test_reg_imm_32bit:
31 halyavin 1149
        call    operand_32bit
109 heavyiron 1150
        call    get_dword_value
1151
      test_reg_imm_32bit_store:
31 halyavin 1152
        mov     edx,eax
109 heavyiron 1153
        mov     bl,[postbyte_register]
1154
        mov     [postbyte_register],0
1155
        mov     [base_code],0F7h
1156
        or      bl,bl
1157
        jz      test_eax_imm
1158
        call    store_nomem_instruction
1159
        mov     eax,edx
1160
        call    mark_relocation
1161
        stos    dword [edi]
1162
        jmp     instruction_assembled
1163
      test_eax_imm:
31 halyavin 1164
        mov     [base_code],0A9h
109 heavyiron 1165
        call    store_instruction_code
1166
        mov     eax,edx
1167
        stos    dword [edi]
1168
        jmp     instruction_assembled
1169
      test_reg_imm_64bit:
31 halyavin 1170
        cmp     [size_declared],0
109 heavyiron 1171
        jne     long_immediate_not_encodable
1172
        call    operand_64bit
1173
        call    get_simm32
1174
        cmp     [value_type],4
1175
        jae     long_immediate_not_encodable
1176
        jmp     test_reg_imm_32bit_store
1177
      test_reg_mem:
31 halyavin 1178
        call    get_address
109 heavyiron 1179
        mov     al,[operand_size]
1180
        cmp     al,1
1181
        je      test_reg_mem_8bit
1182
        call    operand_autodetect
1183
        inc     [base_code]
1184
      test_reg_mem_8bit:
31 halyavin 1185
        call    store_instruction
109 heavyiron 1186
        jmp     instruction_assembled
1187
xchg_instruction:
31 halyavin 1188
        mov     [base_code],86h
109 heavyiron 1189
        lods    byte [esi]
1190
        call    get_size_operator
1191
        cmp     al,10h
1192
        je      xchg_reg
1193
        cmp     al,'['
1194
        jne     invalid_operand
1195
      xchg_mem:
31 halyavin 1196
        call    get_address
109 heavyiron 1197
        push    edx bx cx
1198
        lods    byte [esi]
1199
        cmp     al,','
1200
        jne     invalid_operand
1201
        lods    byte [esi]
1202
        call    get_size_operator
1203
        cmp     al,10h
1204
        je      test_mem_reg
1205
        jmp     invalid_operand
1206
      xchg_reg:
31 halyavin 1207
        lods    byte [esi]
109 heavyiron 1208
        call    convert_register
1209
        mov     [postbyte_register],al
1210
        lods    byte [esi]
1211
        cmp     al,','
1212
        jne     invalid_operand
1213
        lods    byte [esi]
1214
        call    get_size_operator
1215
        cmp     al,'['
1216
        je      test_reg_mem
1217
        cmp     al,10h
1218
        jne     invalid_operand
1219
      xchg_reg_reg:
31 halyavin 1220
        lods    byte [esi]
109 heavyiron 1221
        call    convert_register
1222
        mov     bl,al
1223
        mov     al,ah
1224
        cmp     al,1
1225
        je      xchg_reg_reg_8bit
1226
        call    operand_autodetect
1227
        cmp     [postbyte_register],0
1228
        je      xchg_ax_reg
1229
        or      bl,bl
1230
        jnz     xchg_reg_reg_store
1231
        mov     bl,[postbyte_register]
1232
      xchg_ax_reg:
31 halyavin 1233
        cmp     [code_type],64
109 heavyiron 1234
        jne     xchg_ax_reg_ok
1235
        cmp     ah,4
1236
        jne     xchg_ax_reg_ok
1237
        or      bl,bl
1238
        jz      xchg_reg_reg_store
1239
      xchg_ax_reg_ok:
31 halyavin 1240
        test    bl,1000b
109 heavyiron 1241
        jz      xchg_ax_reg_store
1242
        or      [rex_prefix],41h
1243
        and     bl,111b
1244
      xchg_ax_reg_store:
31 halyavin 1245
        add     bl,90h
109 heavyiron 1246
        mov     [base_code],bl
1247
        call    store_instruction_code
1248
        jmp     instruction_assembled
1249
      xchg_reg_reg_store:
31 halyavin 1250
        inc     [base_code]
109 heavyiron 1251
      xchg_reg_reg_8bit:
31 halyavin 1252
        call    store_nomem_instruction
109 heavyiron 1253
        jmp     instruction_assembled
1254
push_instruction:
31 halyavin 1255
        mov     [push_size],al
109 heavyiron 1256
      push_next:
31 halyavin 1257
        lods    byte [esi]
109 heavyiron 1258
        call    get_size_operator
1259
        cmp     al,10h
1260
        je      push_reg
1261
        cmp     al,'('
1262
        je      push_imm
1263
        cmp     al,'['
1264
        jne     invalid_operand
1265
      push_mem:
31 halyavin 1266
        call    get_address
109 heavyiron 1267
        mov     al,[operand_size]
1268
        mov     ah,[push_size]
1269
        cmp     al,2
1270
        je      push_mem_16bit
1271
        cmp     al,4
1272
        je      push_mem_32bit
1273
        cmp     al,8
1274
        je      push_mem_64bit
1275
        or      al,al
1276
        jnz     invalid_operand_size
1277
        cmp     ah,2
1278
        je      push_mem_16bit
1279
        cmp     ah,4
1280
        je      push_mem_32bit
1281
        cmp     ah,8
1282
        je      push_mem_64bit
1283
        cmp     [error_line],0
1284
        jne     push_mem_store
1285
        mov     eax,[current_line]
1286
        mov     [error_line],eax
1287
        mov     [error],operand_size_not_specified
1288
        jmp     push_mem_store
1289
      push_mem_16bit:
31 halyavin 1290
        test    ah,not 2
109 heavyiron 1291
        jnz     invalid_operand_size
1292
        call    operand_16bit
1293
        jmp     push_mem_store
1294
      push_mem_32bit:
31 halyavin 1295
        test    ah,not 4
109 heavyiron 1296
        jnz     invalid_operand_size
1297
        cmp     [code_type],64
1298
        je      illegal_instruction
1299
        call    operand_32bit
1300
        jmp     push_mem_store
1301
      push_mem_64bit:
31 halyavin 1302
        test    ah,not 8
109 heavyiron 1303
        jnz     invalid_operand_size
1304
        cmp     [code_type],64
1305
        jne     illegal_instruction
1306
      push_mem_store:
31 halyavin 1307
        mov     [base_code],0FFh
109 heavyiron 1308
        mov     [postbyte_register],110b
1309
        call    store_instruction
1310
        jmp     push_done
1311
      push_reg:
31 halyavin 1312
        lods    byte [esi]
109 heavyiron 1313
        mov     ah,al
1314
        sub     ah,10h
1315
        and     ah,al
1316
        test    ah,0F0h
1317
        jnz     push_sreg
1318
        call    convert_register
1319
        test    al,1000b
1320
        jz      push_reg_ok
1321
        or      [rex_prefix],41h
1322
        and     al,111b
1323
      push_reg_ok:
31 halyavin 1324
        add     al,50h
109 heavyiron 1325
        mov     [base_code],al
1326
        mov     al,ah
1327
        mov     ah,[push_size]
1328
        cmp     al,2
1329
        je      push_reg_16bit
1330
        cmp     al,4
1331
        je      push_reg_32bit
1332
        cmp     al,8
1333
        jne     invalid_operand_size
1334
      push_reg_64bit:
31 halyavin 1335
        test    ah,not 8
109 heavyiron 1336
        jnz     invalid_operand_size
1337
        cmp     [code_type],64
1338
        jne     illegal_instruction
1339
        jmp     push_reg_store
1340
      push_reg_32bit:
31 halyavin 1341
        test    ah,not 4
109 heavyiron 1342
        jnz     invalid_operand_size
1343
        cmp     [code_type],64
1344
        je      illegal_instruction
1345
        call    operand_32bit
1346
        jmp     push_reg_store
1347
      push_reg_16bit:
31 halyavin 1348
        test    ah,not 2
109 heavyiron 1349
        jnz     invalid_operand_size
1350
        call    operand_16bit
1351
      push_reg_store:
31 halyavin 1352
        call    store_instruction_code
109 heavyiron 1353
        jmp     push_done
1354
      push_sreg:
31 halyavin 1355
        mov     bl,al
109 heavyiron 1356
        mov     dl,[operand_size]
1357
        mov     dh,[push_size]
1358
        cmp     dl,2
1359
        je      push_sreg16
1360
        cmp     dl,4
1361
        je      push_sreg32
1362
        cmp     dl,8
1363
        je      push_sreg64
1364
        or      dl,dl
1365
        jnz     invalid_operand_size
1366
        cmp     dh,2
1367
        je      push_sreg16
1368
        cmp     dh,4
1369
        je      push_sreg32
1370
        cmp     dh,8
1371
        je      push_sreg64
1372
        jmp     push_sreg_store
1373
      push_sreg16:
31 halyavin 1374
        test    dh,not 2
109 heavyiron 1375
        jnz     invalid_operand_size
1376
        call    operand_16bit
1377
        jmp     push_sreg_store
1378
      push_sreg32:
31 halyavin 1379
        test    dh,not 4
109 heavyiron 1380
        jnz     invalid_operand_size
1381
        cmp     [code_type],64
1382
        je      illegal_instruction
1383
        call    operand_32bit
1384
        jmp     push_sreg_store
1385
      push_sreg64:
31 halyavin 1386
        test    dh,not 8
109 heavyiron 1387
        jnz     invalid_operand_size
1388
        cmp     [code_type],64
1389
        jne     illegal_instruction
1390
      push_sreg_store:
31 halyavin 1391
        mov     al,bl
109 heavyiron 1392
        cmp     al,70h
1393
        jae     invalid_operand
1394
        sub     al,61h
1395
        cmp     al,4
1396
        jae     push_sreg_386
1397
        shl     al,3
1398
        add     al,6
1399
        mov     [base_code],al
1400
        cmp     [code_type],64
1401
        je      illegal_instruction
1402
        jmp     push_reg_store
1403
      push_sreg_386:
31 halyavin 1404
        sub     al,4
109 heavyiron 1405
        shl     al,3
1406
        add     al,0A0h
1407
        mov     [extended_code],al
1408
        mov     [base_code],0Fh
1409
        jmp     push_reg_store
1410
      push_imm:
31 halyavin 1411
        mov     al,[operand_size]
109 heavyiron 1412
        mov     ah,[push_size]
1413
        or      al,al
1414
        je      push_imm_size_ok
1415
        or      ah,ah
1416
        je      push_imm_size_ok
1417
        cmp     al,ah
1418
        jne     invalid_operand_size
1419
      push_imm_size_ok:
31 halyavin 1420
        cmp     al,2
109 heavyiron 1421
        je      push_imm_16bit
1422
        cmp     al,4
1423
        je      push_imm_32bit
1424
        cmp     al,8
1425
        je      push_imm_64bit
1426
        cmp     ah,2
1427
        je      push_imm_optimized_16bit
1428
        cmp     ah,4
1429
        je      push_imm_optimized_32bit
1430
        cmp     ah,8
1431
        je      push_imm_optimized_64bit
1432
        or      al,al
1433
        jnz     invalid_operand_size
1434
        cmp     [code_type],16
1435
        je      push_imm_optimized_16bit
1436
        cmp     [code_type],32
1437
        je      push_imm_optimized_32bit
1438
      push_imm_optimized_64bit:
31 halyavin 1439
        cmp     [code_type],64
109 heavyiron 1440
        jne     illegal_instruction
1441
        call    get_simm32
1442
        mov     edx,eax
1443
        cmp     [value_type],0
1444
        jne     push_imm_32bit_store
1445
        cmp     eax,-80h
1446
        jl      push_imm_32bit_store
1447
        cmp     eax,80h
1448
        jge     push_imm_32bit_store
1449
        jmp     push_imm_8bit
1450
      push_imm_optimized_32bit:
31 halyavin 1451
        cmp     [code_type],64
109 heavyiron 1452
        je      illegal_instruction
1453
        call    get_dword_value
1454
        mov     edx,eax
1455
        call    operand_32bit
1456
        cmp     [value_type],0
1457
        jne     push_imm_32bit_store
1458
        cmp     eax,-80h
1459
        jl      push_imm_32bit_store
1460
        cmp     eax,80h
1461
        jge     push_imm_32bit_store
1462
        jmp     push_imm_8bit
1463
      push_imm_optimized_16bit:
31 halyavin 1464
        call    get_word_value
109 heavyiron 1465
        mov     dx,ax
1466
        call    operand_16bit
1467
        cmp     [value_type],0
1468
        jne     push_imm_16bit_store
1469
        cmp     ax,-80h
1470
        jl      push_imm_16bit_store
1471
        cmp     ax,80h
1472
        jge     push_imm_16bit_store
1473
      push_imm_8bit:
31 halyavin 1474
        mov     ah,al
109 heavyiron 1475
        mov     [base_code],6Ah
1476
        call    store_instruction_code
1477
        mov     al,ah
1478
        stos    byte [edi]
1479
        jmp     push_done
1480
      push_imm_16bit:
31 halyavin 1481
        call    get_word_value
109 heavyiron 1482
        mov     dx,ax
1483
        call    operand_16bit
1484
      push_imm_16bit_store:
31 halyavin 1485
        mov     [base_code],68h
109 heavyiron 1486
        call    store_instruction_code
1487
        mov     ax,dx
1488
        call    mark_relocation
1489
        stos    word [edi]
1490
        jmp     push_done
1491
      push_imm_64bit:
31 halyavin 1492
        cmp     [code_type],64
109 heavyiron 1493
        jne     illegal_instruction
1494
        call    get_simm32
1495
        mov     edx,eax
1496
        jmp     push_imm_32bit_store
1497
      push_imm_32bit:
31 halyavin 1498
        cmp     [code_type],64
109 heavyiron 1499
        je      illegal_instruction
1500
        call    get_dword_value
1501
        mov     edx,eax
1502
        call    operand_32bit
1503
      push_imm_32bit_store:
31 halyavin 1504
        mov     [base_code],68h
109 heavyiron 1505
        call    store_instruction_code
1506
        mov     eax,edx
1507
        call    mark_relocation
1508
        stos    dword [edi]
1509
      push_done:
31 halyavin 1510
        lods    byte [esi]
109 heavyiron 1511
        dec     esi
1512
        cmp     al,0Fh
1513
        je      instruction_assembled
1514
        or      al,al
1515
        jz      instruction_assembled
1516
        mov     [operand_size],0
1517
        mov     [size_override],0
1518
        mov     [operand_prefix],0
1519
        mov     [rex_prefix],0
1520
        jmp     push_next
1521
pop_instruction:
31 halyavin 1522
        mov     [push_size],al
109 heavyiron 1523
      pop_next:
31 halyavin 1524
        lods    byte [esi]
109 heavyiron 1525
        call    get_size_operator
1526
        cmp     al,10h
1527
        je      pop_reg
1528
        cmp     al,'['
1529
        jne     invalid_operand
1530
      pop_mem:
31 halyavin 1531
        call    get_address
109 heavyiron 1532
        mov     al,[operand_size]
1533
        mov     ah,[push_size]
1534
        cmp     al,2
1535
        je      pop_mem_16bit
1536
        cmp     al,4
1537
        je      pop_mem_32bit
1538
        cmp     al,8
1539
        je      pop_mem_64bit
1540
        or      al,al
1541
        jnz     invalid_operand_size
1542
        cmp     ah,2
1543
        je      pop_mem_16bit
1544
        cmp     ah,4
1545
        je      pop_mem_32bit
1546
        cmp     ah,8
1547
        je      pop_mem_64bit
1548
        cmp     [error_line],0
1549
        jne     pop_mem_store
1550
        mov     eax,[current_line]
1551
        mov     [error_line],eax
1552
        mov     [error],operand_size_not_specified
1553
        jmp     pop_mem_store
1554
      pop_mem_16bit:
31 halyavin 1555
        test    ah,not 2
109 heavyiron 1556
        jnz     invalid_operand_size
1557
        call    operand_16bit
1558
        jmp     pop_mem_store
1559
      pop_mem_32bit:
31 halyavin 1560
        test    ah,not 4
109 heavyiron 1561
        jnz     invalid_operand_size
1562
        cmp     [code_type],64
1563
        je      illegal_instruction
1564
        call    operand_32bit
1565
        jmp     pop_mem_store
1566
      pop_mem_64bit:
31 halyavin 1567
        test    ah,not 8
109 heavyiron 1568
        jnz     invalid_operand_size
1569
        cmp     [code_type],64
1570
        jne     illegal_instruction
1571
      pop_mem_store:
31 halyavin 1572
        mov     [base_code],08Fh
109 heavyiron 1573
        mov     [postbyte_register],0
1574
        call    store_instruction
1575
        jmp     pop_done
1576
      pop_reg:
31 halyavin 1577
        lods    byte [esi]
109 heavyiron 1578
        mov     ah,al
1579
        sub     ah,10h
1580
        and     ah,al
1581
        test    ah,0F0h
1582
        jnz     pop_sreg
1583
        call    convert_register
1584
        test    al,1000b
1585
        jz      pop_reg_ok
1586
        or      [rex_prefix],41h
1587
        and     al,111b
1588
      pop_reg_ok:
31 halyavin 1589
        add     al,58h
109 heavyiron 1590
        mov     [base_code],al
1591
        mov     al,ah
1592
        mov     ah,[push_size]
1593
        cmp     al,2
1594
        je      pop_reg_16bit
1595
        cmp     al,4
1596
        je      pop_reg_32bit
1597
        cmp     al,8
1598
        je      pop_reg_64bit
1599
        jmp     invalid_operand_size
1600
      pop_reg_64bit:
31 halyavin 1601
        test    ah,not 8
109 heavyiron 1602
        jnz     invalid_operand_size
1603
        cmp     [code_type],64
1604
        jne     illegal_instruction
1605
        jmp     pop_reg_store
1606
      pop_reg_32bit:
31 halyavin 1607
        test    ah,not 4
109 heavyiron 1608
        jnz     invalid_operand_size
1609
        cmp     [code_type],64
1610
        je      illegal_instruction
1611
        call    operand_32bit
1612
        jmp     pop_reg_store
1613
      pop_reg_16bit:
31 halyavin 1614
        test    ah,not 2
109 heavyiron 1615
        jnz     invalid_operand_size
1616
        call    operand_16bit
1617
      pop_reg_store:
31 halyavin 1618
        call    store_instruction_code
109 heavyiron 1619
      pop_done:
31 halyavin 1620
        lods    byte [esi]
109 heavyiron 1621
        dec     esi
1622
        cmp     al,0Fh
1623
        je      instruction_assembled
1624
        or      al,al
1625
        jz      instruction_assembled
1626
        mov     [operand_size],0
1627
        mov     [size_override],0
1628
        mov     [operand_prefix],0
1629
        mov     [rex_prefix],0
1630
        jmp     pop_next
1631
      pop_sreg:
31 halyavin 1632
        mov     dl,[operand_size]
109 heavyiron 1633
        mov     dh,[push_size]
1634
        cmp     al,62h
1635
        je      pop_cs
1636
        mov     bl,al
1637
        cmp     dl,2
1638
        je      pop_sreg16
1639
        cmp     dl,4
1640
        je      pop_sreg32
1641
        cmp     dl,8
1642
        je      pop_sreg64
1643
        or      dl,dl
1644
        jnz     invalid_operand_size
1645
        cmp     dh,2
1646
        je      pop_sreg16
1647
        cmp     dh,4
1648
        je      pop_sreg32
1649
        cmp     dh,8
1650
        je      pop_sreg64
1651
        jmp     pop_sreg_store
1652
      pop_sreg16:
31 halyavin 1653
        test    dh,not 2
109 heavyiron 1654
        jnz     invalid_operand_size
1655
        call    operand_16bit
1656
        jmp     pop_sreg_store
1657
      pop_sreg32:
31 halyavin 1658
        test    dh,not 4
109 heavyiron 1659
        jnz     invalid_operand_size
1660
        cmp     [code_type],64
1661
        je      illegal_instruction
1662
        call    operand_32bit
1663
        jmp     pop_sreg_store
1664
      pop_sreg64:
31 halyavin 1665
        test    dh,not 8
109 heavyiron 1666
        jnz     invalid_operand_size
1667
        cmp     [code_type],64
1668
        jne     illegal_instruction
1669
      pop_sreg_store:
31 halyavin 1670
        mov     al,bl
109 heavyiron 1671
        cmp     al,70h
1672
        jae     invalid_operand
1673
        sub     al,61h
1674
        cmp     al,4
1675
        jae     pop_sreg_386
1676
        shl     al,3
1677
        add     al,7
1678
        mov     [base_code],al
1679
        cmp     [code_type],64
1680
        je      illegal_instruction
1681
        jmp     pop_reg_store
1682
      pop_cs:
1683
        cmp     [code_type],16
1684
        jne     illegal_instruction
1685
        cmp     dl,2
1686
        je      pop_cs_store
1687
        or      dl,dl
1688
        jnz     invalid_operand_size
1689
        cmp     dh,2
1690
        je      pop_cs_store
1691
        or      dh,dh
1692
        jnz     illegal_instruction
1693
      pop_cs_store:
1694
        test    dh,not 2
1695
        jnz     invalid_operand_size
1696
        mov     al,0Fh
1697
        stos    byte [edi]
1698
        jmp     pop_done
1699
      pop_sreg_386:
31 halyavin 1700
        sub     al,4
109 heavyiron 1701
        shl     al,3
1702
        add     al,0A1h
1703
        mov     [extended_code],al
1704
        mov     [base_code],0Fh
1705
        jmp     pop_reg_store
1706
inc_instruction:
31 halyavin 1707
        mov     [base_code],al
109 heavyiron 1708
        lods    byte [esi]
1709
        call    get_size_operator
1710
        cmp     al,10h
1711
        je      inc_reg
1712
        cmp     al,'['
1713
        je      inc_mem
1714
        jne     invalid_operand
1715
      inc_mem:
31 halyavin 1716
        call    get_address
109 heavyiron 1717
        mov     al,[operand_size]
1718
        cmp     al,1
1719
        je      inc_mem_8bit
1720
        jb      inc_mem_nosize
1721
        call    operand_autodetect
1722
        mov     al,0FFh
1723
        xchg    al,[base_code]
1724
        mov     [postbyte_register],al
1725
        call    store_instruction
1726
        jmp     instruction_assembled
1727
      inc_mem_nosize:
31 halyavin 1728
        cmp     [error_line],0
109 heavyiron 1729
        jne     inc_mem_8bit
1730
        mov     eax,[current_line]
1731
        mov     [error_line],eax
1732
        mov     [error],operand_size_not_specified
1733
      inc_mem_8bit:
31 halyavin 1734
        mov     al,0FEh
109 heavyiron 1735
        xchg    al,[base_code]
1736
        mov     [postbyte_register],al
1737
        call    store_instruction
1738
        jmp     instruction_assembled
1739
      inc_reg:
31 halyavin 1740
        lods    byte [esi]
109 heavyiron 1741
        call    convert_register
1742
        mov     bl,al
1743
        mov     al,0FEh
1744
        xchg    al,[base_code]
1745
        mov     [postbyte_register],al
1746
        mov     al,ah
1747
        cmp     al,1
1748
        je      inc_reg_8bit
1749
        call    operand_autodetect
1750
        cmp     [code_type],64
1751
        je      inc_reg_long_form
1752
        mov     al,[postbyte_register]
1753
        shl     al,3
1754
        add     al,bl
1755
        add     al,40h
1756
        mov     [base_code],al
1757
        call    store_instruction_code
1758
        jmp     instruction_assembled
1759
      inc_reg_long_form:
31 halyavin 1760
        inc     [base_code]
109 heavyiron 1761
      inc_reg_8bit:
31 halyavin 1762
        call    store_nomem_instruction
109 heavyiron 1763
        jmp     instruction_assembled
1764
set_instruction:
31 halyavin 1765
        mov     [base_code],0Fh
109 heavyiron 1766
        mov     [extended_code],al
1767
        lods    byte [esi]
1768
        call    get_size_operator
1769
        cmp     al,10h
1770
        je      set_reg
1771
        cmp     al,'['
1772
        jne     invalid_operand
1773
      set_mem:
31 halyavin 1774
        call    get_address
109 heavyiron 1775
        cmp     [operand_size],1
1776
        ja      invalid_operand_size
1777
        mov     [postbyte_register],0
1778
        call    store_instruction
1779
        jmp     instruction_assembled
1780
      set_reg:
31 halyavin 1781
        lods    byte [esi]
109 heavyiron 1782
        call    convert_register
1783
        cmp     ah,1
1784
        jne     invalid_operand_size
1785
        mov     bl,al
1786
        mov     [postbyte_register],0
1787
        call    store_nomem_instruction
1788
        jmp     instruction_assembled
1789
arpl_instruction:
31 halyavin 1790
        cmp     [code_type],64
109 heavyiron 1791
        je      illegal_instruction
1792
        mov     [base_code],63h
1793
        lods    byte [esi]
1794
        call    get_size_operator
1795
        cmp     al,10h
1796
        je      arpl_reg
1797
        cmp     al,'['
1798
        jne     invalid_operand
1799
        call    get_address
1800
        lods    byte [esi]
1801
        cmp     al,','
1802
        jne     invalid_operand
1803
        lods    byte [esi]
1804
        cmp     al,10h
1805
        jne     invalid_operand
1806
        lods    byte [esi]
1807
        call    convert_register
1808
        mov     [postbyte_register],al
1809
        cmp     ah,2
1810
        jne     invalid_operand_size
1811
        call    store_instruction
1812
        jmp     instruction_assembled
1813
      arpl_reg:
31 halyavin 1814
        lods    byte [esi]
109 heavyiron 1815
        call    convert_register
1816
        cmp     ah,2
1817
        jne     invalid_operand_size
1818
        mov     bl,al
1819
        lods    byte [esi]
1820
        cmp     al,','
1821
        jne     invalid_operand
1822
        lods    byte [esi]
1823
        cmp     al,10h
1824
        jne     invalid_operand
1825
        lods    byte [esi]
1826
        call    convert_register
1827
        cmp     ah,2
1828
        jne     invalid_operand_size
1829
        mov     [postbyte_register],al
1830
        call    store_nomem_instruction
1831
        jmp     instruction_assembled
1832
bound_instruction:
31 halyavin 1833
        cmp     [code_type],64
109 heavyiron 1834
        je      illegal_instruction
1835
        lods    byte [esi]
1836
        call    get_size_operator
1837
        cmp     al,10h
1838
        jne     invalid_operand
1839
        lods    byte [esi]
1840
        call    convert_register
1841
        mov     [postbyte_register],al
1842
        lods    byte [esi]
1843
        cmp     al,','
1844
        jne     invalid_operand
1845
        lods    byte [esi]
1846
        call    get_size_operator
1847
        cmp     al,'['
1848
        jne     invalid_operand
1849
        call    get_address
1850
        mov     al,[operand_size]
1851
        cmp     al,2
1852
        je      bound_16bit
1853
        cmp     al,4
1854
        je      bound_32bit
1855
        jmp     invalid_operand_size
1856
      bound_32bit:
31 halyavin 1857
        call    operand_32bit
109 heavyiron 1858
        mov     [base_code],62h
1859
        call    store_instruction
1860
        jmp     instruction_assembled
1861
      bound_16bit:
31 halyavin 1862
        call    operand_16bit
109 heavyiron 1863
        mov     [base_code],62h
1864
        call    store_instruction
1865
        jmp     instruction_assembled
1866
enter_instruction:
31 halyavin 1867
        lods    byte [esi]
109 heavyiron 1868
        call    get_size_operator
1869
        cmp     ah,2
1870
        je      enter_imm16_size_ok
1871
        or      ah,ah
1872
        jnz     invalid_operand_size
1873
      enter_imm16_size_ok:
31 halyavin 1874
        cmp     al,'('
109 heavyiron 1875
        jne     invalid_operand
1876
        call    get_word_value
1877
        cmp     [next_pass_needed],0
1878
        jne     enter_imm16_ok
1879
        cmp     [value_type],0
1880
        jne     invalid_use_of_symbol
1881
      enter_imm16_ok:
31 halyavin 1882
        push    eax
109 heavyiron 1883
        mov     [operand_size],0
1884
        lods    byte [esi]
1885
        cmp     al,','
1886
        jne     invalid_operand
1887
        lods    byte [esi]
1888
        call    get_size_operator
1889
        cmp     ah,1
1890
        je      enter_imm8_size_ok
1891
        or      ah,ah
1892
        jnz     invalid_operand_size
1893
      enter_imm8_size_ok:
31 halyavin 1894
        cmp     al,'('
109 heavyiron 1895
        jne     invalid_operand
1896
        call    get_byte_value
1897
        mov     dl,al
1898
        pop     ebx
1899
        mov     al,0C8h
1900
        stos    byte [edi]
1901
        mov     ax,bx
1902
        stos    word [edi]
1903
        mov     al,dl
1904
        stos    byte [edi]
1905
        jmp     instruction_assembled
1906
ret_instruction_only64:
31 halyavin 1907
        cmp     [code_type],64
109 heavyiron 1908
        jne     illegal_instruction
1909
        jmp     ret_instruction
1910
ret_instruction_32bit_except64:
31 halyavin 1911
        cmp     [code_type],64
109 heavyiron 1912
        je      illegal_instruction
1913
ret_instruction_32bit:
31 halyavin 1914
        call    operand_32bit
109 heavyiron 1915
        jmp     ret_instruction
1916
ret_instruction_16bit:
31 halyavin 1917
        call    operand_16bit
109 heavyiron 1918
        jmp     ret_instruction
1919
retf_instruction:
31 halyavin 1920
        cmp     [code_type],64
109 heavyiron 1921
        jne     ret_instruction
1922
ret_instruction_64bit:
31 halyavin 1923
        call    operand_64bit
109 heavyiron 1924
ret_instruction:
31 halyavin 1925
        mov     [base_code],al
109 heavyiron 1926
        lods    byte [esi]
1927
        dec     esi
1928
        or      al,al
1929
        jz      simple_ret
1930
        cmp     al,0Fh
1931
        je      simple_ret
1932
        lods    byte [esi]
1933
        call    get_size_operator
1934
        or      ah,ah
1935
        jz      ret_imm
1936
        cmp     ah,2
1937
        je      ret_imm
1938
        jmp     invalid_operand_size
1939
      ret_imm:
31 halyavin 1940
        cmp     al,'('
109 heavyiron 1941
        jne     invalid_operand
1942
        call    get_word_value
1943
        cmp     [next_pass_needed],0
1944
        jne     ret_imm_ok
1945
        cmp     [value_type],0
1946
        jne     invalid_use_of_symbol
1947
      ret_imm_ok:
31 halyavin 1948
        cmp     [size_declared],0
109 heavyiron 1949
        jne     ret_imm_store
1950
        or      ax,ax
1951
        jz      simple_ret
1952
      ret_imm_store:
1953
        mov     dx,ax
1954
        call    store_instruction_code
1955
        mov     ax,dx
1956
        stos    word [edi]
1957
        jmp     instruction_assembled
1958
      simple_ret:
31 halyavin 1959
        inc     [base_code]
109 heavyiron 1960
        call    store_instruction_code
1961
        jmp     instruction_assembled
1962
lea_instruction:
31 halyavin 1963
        mov     [base_code],8Dh
109 heavyiron 1964
        lods    byte [esi]
1965
        call    get_size_operator
1966
        cmp     al,10h
1967
        jne     invalid_operand
1968
        lods    byte [esi]
1969
        call    convert_register
1970
        mov     [postbyte_register],al
1971
        lods    byte [esi]
1972
        cmp     al,','
1973
        jne     invalid_operand
1974
        xor     al,al
1975
        xchg    al,[operand_size]
1976
        push    eax
1977
        lods    byte [esi]
1978
        call    get_size_operator
1979
        cmp     al,'['
1980
        jne     invalid_operand
1981
        mov     [size_override],-1
1982
        call    get_address
1983
        pop     eax
1984
        mov     [operand_size],al
1985
        call    operand_autodetect
1986
        call    store_instruction
1987
        jmp     instruction_assembled
1988
ls_instruction:
31 halyavin 1989
        or      al,al
109 heavyiron 1990
        jz      les_instruction
1991
        cmp     al,3
1992
        jz      lds_instruction
1993
        add     al,0B0h
1994
        mov     [extended_code],al
1995
        mov     [base_code],0Fh
1996
        jmp     ls_code_ok
1997
      les_instruction:
31 halyavin 1998
        mov     [base_code],0C4h
109 heavyiron 1999
        jmp     ls_short_code
2000
      lds_instruction:
31 halyavin 2001
        mov     [base_code],0C5h
109 heavyiron 2002
      ls_short_code:
31 halyavin 2003
        cmp     [code_type],64
109 heavyiron 2004
        je      illegal_instruction
2005
      ls_code_ok:
31 halyavin 2006
        lods    byte [esi]
109 heavyiron 2007
        call    get_size_operator
2008
        cmp     al,10h
2009
        jne     invalid_operand
2010
        lods    byte [esi]
2011
        call    convert_register
2012
        mov     [postbyte_register],al
2013
        lods    byte [esi]
2014
        cmp     al,','
2015
        jne     invalid_operand
2016
        add     [operand_size],2
2017
        lods    byte [esi]
2018
        call    get_size_operator
2019
        cmp     al,'['
2020
        jne     invalid_operand
2021
        call    get_address
2022
        mov     al,[operand_size]
2023
        cmp     al,4
2024
        je      ls_16bit
2025
        cmp     al,6
2026
        je      ls_32bit
2027
        cmp     al,10
2028
        je      ls_64bit
2029
        jmp     invalid_operand_size
2030
      ls_16bit:
31 halyavin 2031
        call    operand_16bit
109 heavyiron 2032
        call    store_instruction
2033
        jmp     instruction_assembled
2034
      ls_32bit:
31 halyavin 2035
        call    operand_32bit
109 heavyiron 2036
        call    store_instruction
2037
        jmp     instruction_assembled
2038
      ls_64bit:
31 halyavin 2039
        call    operand_64bit
109 heavyiron 2040
        call    store_instruction
2041
        jmp     instruction_assembled
2042
sh_instruction:
31 halyavin 2043
        mov     [postbyte_register],al
109 heavyiron 2044
        lods    byte [esi]
2045
        call    get_size_operator
2046
        cmp     al,10h
2047
        je      sh_reg
2048
        cmp     al,'['
2049
        jne     invalid_operand
2050
      sh_mem:
31 halyavin 2051
        call    get_address
109 heavyiron 2052
        push    edx bx cx
2053
        mov     al,[operand_size]
2054
        push    eax
2055
        mov     [operand_size],0
2056
        lods    byte [esi]
2057
        cmp     al,','
2058
        jne     invalid_operand
2059
        lods    byte [esi]
2060
        call    get_size_operator
2061
        cmp     al,'('
2062
        je      sh_mem_imm
2063
        cmp     al,10h
2064
        jne     invalid_operand
2065
      sh_mem_reg:
31 halyavin 2066
        lods    byte [esi]
109 heavyiron 2067
        cmp     al,11h
2068
        jne     invalid_operand
2069
        pop     eax cx bx edx
2070
        cmp     al,1
2071
        je      sh_mem_cl_8bit
2072
        jb      sh_mem_cl_nosize
2073
        call    operand_autodetect
2074
        mov     [base_code],0D3h
2075
        call    store_instruction
2076
        jmp     instruction_assembled
2077
      sh_mem_cl_nosize:
31 halyavin 2078
        cmp     [error_line],0
109 heavyiron 2079
        jne     sh_mem_cl_8bit
2080
        mov     eax,[current_line]
2081
        mov     [error_line],eax
2082
        mov     [error],operand_size_not_specified
2083
      sh_mem_cl_8bit:
31 halyavin 2084
        mov     [base_code],0D2h
109 heavyiron 2085
        call    store_instruction
2086
        jmp     instruction_assembled
2087
      sh_mem_imm:
31 halyavin 2088
        mov     al,[operand_size]
109 heavyiron 2089
        or      al,al
2090
        jz      sh_mem_imm_size_ok
2091
        cmp     al,1
2092
        jne     invalid_operand_size
2093
      sh_mem_imm_size_ok:
31 halyavin 2094
        call    get_byte_value
109 heavyiron 2095
        mov     byte [value],al
2096
        pop     eax cx bx edx
2097
        cmp     al,1
2098
        je      sh_mem_imm_8bit
2099
        jb      sh_mem_imm_nosize
2100
        call    operand_autodetect
2101
        cmp     byte [value],1
2102
        je      sh_mem_1
2103
        mov     [base_code],0C1h
2104
        call    store_instruction_with_imm8
2105
        jmp     instruction_assembled
2106
      sh_mem_1:
31 halyavin 2107
        mov     [base_code],0D1h
109 heavyiron 2108
        call    store_instruction
2109
        jmp     instruction_assembled
2110
      sh_mem_imm_nosize:
31 halyavin 2111
        cmp     [error_line],0
109 heavyiron 2112
        jne     sh_mem_imm_8bit
2113
        mov     eax,[current_line]
2114
        mov     [error_line],eax
2115
        mov     [error],operand_size_not_specified
2116
      sh_mem_imm_8bit:
31 halyavin 2117
        cmp     byte [value],1
109 heavyiron 2118
        je      sh_mem_1_8bit
2119
        mov     [base_code],0C0h
2120
        call    store_instruction_with_imm8
2121
        jmp     instruction_assembled
2122
      sh_mem_1_8bit:
31 halyavin 2123
        mov     [base_code],0D0h
109 heavyiron 2124
        call    store_instruction
2125
        jmp     instruction_assembled
2126
      sh_reg:
31 halyavin 2127
        lods    byte [esi]
109 heavyiron 2128
        call    convert_register
2129
        mov     bx,ax
2130
        mov     [operand_size],0
2131
        lods    byte [esi]
2132
        cmp     al,','
2133
        jne     invalid_operand
2134
        lods    byte [esi]
2135
        call    get_size_operator
2136
        cmp     al,'('
2137
        je      sh_reg_imm
2138
        cmp     al,10h
2139
        jne     invalid_operand
2140
      sh_reg_reg:
31 halyavin 2141
        lods    byte [esi]
109 heavyiron 2142
        cmp     al,11h
2143
        jne     invalid_operand
2144
        mov     al,bh
2145
        cmp     al,1
2146
        je      sh_reg_cl_8bit
2147
        call    operand_autodetect
2148
        mov     [base_code],0D3h
2149
        call    store_nomem_instruction
2150
        jmp     instruction_assembled
2151
      sh_reg_cl_8bit:
31 halyavin 2152
        mov     [base_code],0D2h
109 heavyiron 2153
        call    store_nomem_instruction
2154
        jmp     instruction_assembled
2155
      sh_reg_imm:
31 halyavin 2156
        mov     al,[operand_size]
109 heavyiron 2157
        or      al,al
2158
        jz      sh_reg_imm_size_ok
2159
        cmp     al,1
2160
        jne     invalid_operand_size
2161
      sh_reg_imm_size_ok:
31 halyavin 2162
        push    ebx
109 heavyiron 2163
        call    get_byte_value
2164
        mov     dl,al
2165
        pop     ebx
2166
        mov     al,bh
2167
        cmp     al,1
2168
        je      sh_reg_imm_8bit
2169
        call    operand_autodetect
2170
        cmp     dl,1
2171
        je      sh_reg_1
2172
        mov     [base_code],0C1h
2173
        call    store_nomem_instruction
2174
        mov     al,dl
2175
        stos    byte [edi]
2176
        jmp     instruction_assembled
2177
      sh_reg_1:
31 halyavin 2178
        mov     [base_code],0D1h
109 heavyiron 2179
        call    store_nomem_instruction
2180
        jmp     instruction_assembled
2181
      sh_reg_imm_8bit:
31 halyavin 2182
        cmp     dl,1
109 heavyiron 2183
        je      sh_reg_1_8bit
2184
        mov     [base_code],0C0h
2185
        call    store_nomem_instruction
2186
        mov     al,dl
2187
        stos    byte [edi]
2188
        jmp     instruction_assembled
2189
      sh_reg_1_8bit:
31 halyavin 2190
        mov     [base_code],0D0h
109 heavyiron 2191
        call    store_nomem_instruction
2192
        jmp     instruction_assembled
2193
shd_instruction:
31 halyavin 2194
        mov     [base_code],0Fh
109 heavyiron 2195
        mov     [extended_code],al
2196
        lods    byte [esi]
2197
        call    get_size_operator
2198
        cmp     al,10h
2199
        je      shd_reg
2200
        cmp     al,'['
2201
        jne     invalid_operand
2202
      shd_mem:
31 halyavin 2203
        call    get_address
109 heavyiron 2204
        push    edx bx cx
2205
        lods    byte [esi]
2206
        cmp     al,','
2207
        jne     invalid_operand
2208
        lods    byte [esi]
2209
        call    get_size_operator
2210
        cmp     al,10h
2211
        jne     invalid_operand
2212
        lods    byte [esi]
2213
        call    convert_register
2214
        mov     [postbyte_register],al
2215
        lods    byte [esi]
2216
        cmp     al,','
2217
        jne     invalid_operand
2218
        mov     al,ah
2219
        mov     [operand_size],0
2220
        push    eax
2221
        lods    byte [esi]
2222
        call    get_size_operator
2223
        cmp     al,'('
2224
        je      shd_mem_reg_imm
2225
        cmp     al,10h
2226
        jne     invalid_operand
2227
        lods    byte [esi]
2228
        cmp     al,11h
2229
        jne     invalid_operand
2230
        pop     eax cx bx edx
2231
        call    operand_autodetect
2232
        inc     [extended_code]
2233
        call    store_instruction
2234
        jmp     instruction_assembled
2235
      shd_mem_reg_imm:
31 halyavin 2236
        mov     al,[operand_size]
109 heavyiron 2237
        or      al,al
2238
        jz      shd_mem_reg_imm_size_ok
2239
        cmp     al,1
2240
        jne     invalid_operand_size
2241
      shd_mem_reg_imm_size_ok:
31 halyavin 2242
        call    get_byte_value
109 heavyiron 2243
        mov     byte [value],al
2244
        pop     eax cx bx edx
2245
        call    operand_autodetect
2246
        call    store_instruction_with_imm8
2247
        jmp     instruction_assembled
2248
      shd_reg:
31 halyavin 2249
        lods    byte [esi]
109 heavyiron 2250
        call    convert_register
2251
        mov     [postbyte_register],al
2252
        lods    byte [esi]
2253
        cmp     al,','
2254
        jne     invalid_operand
2255
        lods    byte [esi]
2256
        call    get_size_operator
2257
        cmp     al,10h
2258
        jne     invalid_operand
2259
        lods    byte [esi]
2260
        call    convert_register
2261
        mov     bl,[postbyte_register]
2262
        mov     [postbyte_register],al
2263
        mov     al,ah
2264
        push    eax ebx
2265
        lods    byte [esi]
2266
        cmp     al,','
2267
        jne     invalid_operand
2268
        mov     [operand_size],0
2269
        lods    byte [esi]
2270
        call    get_size_operator
2271
        cmp     al,'('
2272
        je      shd_reg_reg_imm
2273
        cmp     al,10h
2274
        jne     invalid_operand
2275
        lods    byte [esi]
2276
        cmp     al,11h
2277
        jne     invalid_operand
2278
        pop     ebx eax
2279
        call    operand_autodetect
2280
        inc     [extended_code]
2281
        call    store_nomem_instruction
2282
        jmp     instruction_assembled
2283
      shd_reg_reg_imm:
31 halyavin 2284
        mov     al,[operand_size]
109 heavyiron 2285
        or      al,al
2286
        jz      shd_reg_reg_imm_size_ok
2287
        cmp     al,1
2288
        jne     invalid_operand_size
2289
      shd_reg_reg_imm_size_ok:
31 halyavin 2290
        call    get_byte_value
109 heavyiron 2291
        mov     dl,al
2292
        pop     ebx eax
2293
        call    operand_autodetect
2294
        call    store_nomem_instruction
2295
        mov     al,dl
2296
        stos    byte [edi]
2297
        jmp     instruction_assembled
2298
movx_instruction:
31 halyavin 2299
        mov     [base_code],0Fh
109 heavyiron 2300
        mov     [extended_code],al
2301
        lods    byte [esi]
2302
        call    get_size_operator
2303
        cmp     al,10h
2304
        jne     invalid_operand
2305
        lods    byte [esi]
2306
        call    convert_register
2307
        mov     [postbyte_register],al
2308
        mov     al,ah
2309
        push    eax
2310
        lods    byte [esi]
2311
        cmp     al,','
2312
        jne     invalid_operand
2313
        mov     [operand_size],0
2314
        lods    byte [esi]
2315
        call    get_size_operator
2316
        cmp     al,10h
2317
        je      movx_reg
2318
        cmp     al,'['
2319
        jne     invalid_operand
2320
        call    get_address
2321
        pop     eax
2322
        mov     ah,[operand_size]
2323
        or      ah,ah
2324
        jz      movx_unknown_size
2325
        cmp     ah,al
2326
        jae     invalid_operand_size
2327
        cmp     ah,1
2328
        je      movx_mem_8bit
2329
        cmp     ah,2
2330
        jne     invalid_operand_size
2331
      movx_mem_16bit:
2332
        inc     [extended_code]
2333
        call    operand_autodetect
2334
        call    store_instruction
2335
        jmp     instruction_assembled
2336
      movx_unknown_size:
2337
        cmp     [error_line],0
2338
        jne     movx_mem_8bit
2339
        mov     eax,[current_line]
2340
        mov     [error_line],eax
2341
        mov     [error],operand_size_not_specified
2342
      movx_mem_8bit:
31 halyavin 2343
        call    operand_autodetect
109 heavyiron 2344
        call    store_instruction
2345
        jmp     instruction_assembled
2346
      movx_reg:
31 halyavin 2347
        lods    byte [esi]
109 heavyiron 2348
        call    convert_register
2349
        pop     ebx
2350
        xchg    bl,al
2351
        cmp     ah,al
2352
        jae     invalid_operand_size
2353
        cmp     ah,1
2354
        je      movx_reg_8bit
2355
        cmp     ah,2
2356
        je      movx_reg_16bit
2357
        jmp     invalid_operand_size
2358
      movx_reg_8bit:
31 halyavin 2359
        call    operand_autodetect
109 heavyiron 2360
        call    store_nomem_instruction
2361
        jmp     instruction_assembled
2362
      movx_reg_16bit:
31 halyavin 2363
        call    operand_autodetect
109 heavyiron 2364
        inc     [extended_code]
2365
        call    store_nomem_instruction
2366
        jmp     instruction_assembled
2367
movsxd_instruction:
31 halyavin 2368
        mov     [base_code],al
109 heavyiron 2369
        lods    byte [esi]
2370
        call    get_size_operator
2371
        cmp     al,10h
2372
        jne     invalid_operand
2373
        lods    byte [esi]
2374
        call    convert_register
2375
        mov     [postbyte_register],al
2376
        cmp     ah,8
2377
        jne     invalid_operand_size
2378
        lods    byte [esi]
2379
        cmp     al,','
2380
        jne     invalid_operand
2381
        mov     [operand_size],0
2382
        lods    byte [esi]
2383
        call    get_size_operator
2384
        cmp     al,10h
2385
        je      movsxd_reg
2386
        cmp     al,'['
2387
        jne     invalid_operand
2388
        call    get_address
2389
        cmp     [operand_size],4
2390
        je      movsxd_mem_store
2391
        cmp     [operand_size],0
2392
        jne     invalid_operand_size
2393
      movsxd_mem_store:
31 halyavin 2394
        call    operand_64bit
109 heavyiron 2395
        call    store_instruction
2396
        jmp     instruction_assembled
2397
      movsxd_reg:
31 halyavin 2398
        lods    byte [esi]
109 heavyiron 2399
        call    convert_register
2400
        cmp     ah,4
2401
        jne     invalid_operand_size
2402
        mov     bl,al
2403
        call    operand_64bit
2404
        call    store_nomem_instruction
2405
        jmp     instruction_assembled
2406
bt_instruction:
31 halyavin 2407
        mov     [postbyte_register],al
109 heavyiron 2408
        shl     al,3
2409
        add     al,83h
2410
        mov     [extended_code],al
2411
        mov     [base_code],0Fh
2412
        lods    byte [esi]
2413
        call    get_size_operator
2414
        cmp     al,10h
2415
        je      bt_reg
2416
        cmp     al,'['
2417
        jne     invalid_operand
2418
        call    get_address
2419
        push    eax bx cx
2420
        lods    byte [esi]
2421
        cmp     al,','
2422
        jne     invalid_operand
2423
        cmp     byte [esi],'('
2424
        je      bt_mem_imm
2425
        cmp     byte [esi],11h
2426
        jne     bt_mem_reg
2427
        cmp     byte [esi+2],'('
2428
        je      bt_mem_imm
2429
      bt_mem_reg:
31 halyavin 2430
        lods    byte [esi]
109 heavyiron 2431
        call    get_size_operator
2432
        cmp     al,10h
2433
        jne     invalid_operand
2434
        lods    byte [esi]
2435
        call    convert_register
2436
        mov     [postbyte_register],al
2437
        pop     cx bx edx
2438
        mov     al,ah
2439
        call    operand_autodetect
2440
        call    store_instruction
2441
        jmp     instruction_assembled
2442
      bt_mem_imm:
31 halyavin 2443
        xor     al,al
109 heavyiron 2444
        xchg    al,[operand_size]
2445
        push    eax
2446
        lods    byte [esi]
2447
        call    get_size_operator
2448
        cmp     al,'('
2449
        jne     invalid_operand
2450
        mov     al,[operand_size]
2451
        or      al,al
2452
        jz      bt_mem_imm_size_ok
2453
        cmp     al,1
2454
        jne     invalid_operand_size
2455
      bt_mem_imm_size_ok:
31 halyavin 2456
        call    get_byte_value
109 heavyiron 2457
        mov     byte [value],al
2458
        pop     eax
2459
        or      al,al
2460
        jz      bt_mem_imm_nosize
2461
        call    operand_autodetect
2462
      bt_mem_imm_store:
31 halyavin 2463
        pop     cx bx edx
109 heavyiron 2464
        mov     [extended_code],0BAh
2465
        call    store_instruction_with_imm8
2466
        jmp     instruction_assembled
2467
      bt_mem_imm_nosize:
31 halyavin 2468
        cmp     [error_line],0
109 heavyiron 2469
        jne     bt_mem_imm_store
2470
        mov     eax,[current_line]
2471
        mov     [error_line],eax
2472
        mov     [error],operand_size_not_specified
2473
        jmp     bt_mem_imm_store
2474
      bt_reg:
31 halyavin 2475
        lods    byte [esi]
109 heavyiron 2476
        call    convert_register
2477
        mov     bl,al
2478
        lods    byte [esi]
2479
        cmp     al,','
2480
        jne     invalid_operand
2481
        cmp     byte [esi],'('
2482
        je      bt_reg_imm
2483
        cmp     byte [esi],11h
2484
        jne     bt_reg_reg
2485
        cmp     byte [esi+2],'('
2486
        je      bt_reg_imm
2487
      bt_reg_reg:
31 halyavin 2488
        lods    byte [esi]
109 heavyiron 2489
        call    get_size_operator
2490
        cmp     al,10h
2491
        jne     invalid_operand
2492
        lods    byte [esi]
2493
        call    convert_register
2494
        mov     [postbyte_register],al
2495
        mov     al,ah
2496
        call    operand_autodetect
2497
        call    store_nomem_instruction
2498
        jmp     instruction_assembled
2499
      bt_reg_imm:
31 halyavin 2500
        xor     al,al
109 heavyiron 2501
        xchg    al,[operand_size]
2502
        push    eax ebx
2503
        lods    byte [esi]
2504
        call    get_size_operator
2505
        cmp     al,'('
2506
        jne     invalid_operand
2507
        mov     al,[operand_size]
2508
        or      al,al
2509
        jz      bt_reg_imm_size_ok
2510
        cmp     al,1
2511
        jne     invalid_operand_size
2512
      bt_reg_imm_size_ok:
31 halyavin 2513
        call    get_byte_value
109 heavyiron 2514
        mov     byte [value],al
2515
        pop     ebx eax
2516
        call    operand_autodetect
2517
      bt_reg_imm_store:
31 halyavin 2518
        mov     [extended_code],0BAh
109 heavyiron 2519
        call    store_nomem_instruction
2520
        mov     al,byte [value]
2521
        stos    byte [edi]
2522
        jmp     instruction_assembled
2523
bs_instruction:
31 halyavin 2524
        mov     [extended_code],al
109 heavyiron 2525
        mov     [base_code],0Fh
2526
        lods    byte [esi]
2527
        call    get_size_operator
2528
        cmp     al,10h
2529
        jne     invalid_operand
2530
        lods    byte [esi]
2531
        call    convert_register
2532
        mov     [postbyte_register],al
2533
        lods    byte [esi]
2534
        cmp     al,','
2535
        jne     invalid_operand
2536
        lods    byte [esi]
2537
        call    get_size_operator
2538
        cmp     al,10h
2539
        je      bs_reg_reg
2540
        cmp     al,'['
2541
        jne     invalid_argument
2542
        call    get_address
2543
        mov     al,[operand_size]
2544
        call    operand_autodetect
2545
        call    store_instruction
2546
        jmp     instruction_assembled
2547
      bs_reg_reg:
31 halyavin 2548
        lods    byte [esi]
109 heavyiron 2549
        call    convert_register
2550
        mov     bl,al
2551
        mov     al,ah
2552
        call    operand_autodetect
2553
        call    store_nomem_instruction
2554
        jmp     instruction_assembled
2555
imul_instruction:
31 halyavin 2556
        mov     [base_code],0F6h
109 heavyiron 2557
        mov     [postbyte_register],5
2558
        lods    byte [esi]
2559
        call    get_size_operator
2560
        cmp     al,10h
2561
        je      imul_reg
2562
        cmp     al,'['
2563
        jne     invalid_operand
2564
      imul_mem:
31 halyavin 2565
        call    get_address
109 heavyiron 2566
        mov     al,[operand_size]
2567
        cmp     al,1
2568
        je      imul_mem_8bit
2569
        jb      imul_mem_nosize
2570
        call    operand_autodetect
2571
        inc     [base_code]
2572
        call    store_instruction
2573
        jmp     instruction_assembled
2574
      imul_mem_nosize:
31 halyavin 2575
        cmp     [error_line],0
109 heavyiron 2576
        jne     imul_mem_8bit
2577
        mov     eax,[current_line]
2578
        mov     [error_line],eax
2579
        mov     [error],operand_size_not_specified
2580
      imul_mem_8bit:
31 halyavin 2581
        call    store_instruction
109 heavyiron 2582
        jmp     instruction_assembled
2583
      imul_reg:
31 halyavin 2584
        lods    byte [esi]
109 heavyiron 2585
        call    convert_register
2586
        cmp     byte [esi],','
2587
        je      imul_reg_
2588
        mov     bl,al
2589
        mov     al,ah
2590
        cmp     al,1
2591
        je      imul_reg_8bit
2592
        call    operand_autodetect
2593
        inc     [base_code]
2594
        call    store_nomem_instruction
2595
        jmp     instruction_assembled
2596
      imul_reg_8bit:
31 halyavin 2597
        call    store_nomem_instruction
109 heavyiron 2598
        jmp     instruction_assembled
2599
      imul_reg_:
31 halyavin 2600
        mov     [postbyte_register],al
109 heavyiron 2601
        inc     esi
2602
        cmp     byte [esi],'('
2603
        je      imul_reg_imm
2604
        cmp     byte [esi],11h
2605
        jne     imul_reg_noimm
2606
        cmp     byte [esi+2],'('
2607
        je      imul_reg_imm
2608
      imul_reg_noimm:
31 halyavin 2609
        lods    byte [esi]
109 heavyiron 2610
        call    get_size_operator
2611
        cmp     al,10h
2612
        je      imul_reg_reg
2613
        cmp     al,'['
2614
        jne     invalid_operand
2615
      imul_reg_mem:
31 halyavin 2616
        call    get_address
109 heavyiron 2617
        push    edx bx cx
2618
        cmp     byte [esi],','
2619
        je      imul_reg_mem_imm
2620
        mov     al,[operand_size]
2621
        call    operand_autodetect
2622
        pop     cx bx edx
2623
        mov     [base_code],0Fh
2624
        mov     [extended_code],0AFh
2625
        call    store_instruction
2626
        jmp     instruction_assembled
2627
      imul_reg_mem_imm:
31 halyavin 2628
        inc     esi
109 heavyiron 2629
        lods    byte [esi]
2630
        call    get_size_operator
2631
        cmp     al,'('
2632
        jne     invalid_operand
2633
        mov     al,[operand_size]
2634
        cmp     al,2
2635
        je      imul_reg_mem_imm_16bit
2636
        cmp     al,4
2637
        je      imul_reg_mem_imm_32bit
2638
        cmp     al,8
2639
        je      imul_reg_mem_imm_64bit
2640
        jmp     invalid_operand_size
2641
      imul_reg_mem_imm_16bit:
31 halyavin 2642
        call    operand_16bit
109 heavyiron 2643
        call    get_word_value
2644
        mov     word [value],ax
2645
        cmp     [value_type],0
2646
        jne     imul_reg_mem_imm_16bit_store
2647
        cmp     [size_declared],0
2648
        jne     imul_reg_mem_imm_16bit_store
2649
        cmp     ax,-80h
2650
        jl      imul_reg_mem_imm_16bit_store
2651
        cmp     ax,80h
2652
        jl      imul_reg_mem_imm_8bit_store
2653
      imul_reg_mem_imm_16bit_store:
31 halyavin 2654
        pop     cx bx edx
109 heavyiron 2655
        mov     [base_code],69h
2656
        call    store_instruction_with_imm16
2657
        jmp     instruction_assembled
2658
      imul_reg_mem_imm_32bit:
31 halyavin 2659
        call    operand_32bit
109 heavyiron 2660
        call    get_dword_value
2661
      imul_reg_mem_imm_32bit_ok:
31 halyavin 2662
        mov     dword [value],eax
109 heavyiron 2663
        cmp     [value_type],0
2664
        jne     imul_reg_mem_imm_32bit_store
2665
        cmp     [size_declared],0
2666
        jne     imul_reg_mem_imm_32bit_store
2667
        cmp     eax,-80h
2668
        jl      imul_reg_mem_imm_32bit_store
2669
        cmp     eax,80h
2670
        jl      imul_reg_mem_imm_8bit_store
2671
      imul_reg_mem_imm_32bit_store:
31 halyavin 2672
        pop     cx bx edx
109 heavyiron 2673
        mov     [base_code],69h
2674
        call    store_instruction_with_imm32
2675
        jmp     instruction_assembled
2676
      imul_reg_mem_imm_64bit:
31 halyavin 2677
        cmp     [size_declared],0
109 heavyiron 2678
        jne     long_immediate_not_encodable
2679
        call    operand_64bit
2680
        call    get_simm32
2681
        cmp     [value_type],4
2682
        jae     long_immediate_not_encodable
2683
        jmp     imul_reg_mem_imm_32bit_ok
2684
      imul_reg_mem_imm_8bit_store:
31 halyavin 2685
        pop     cx bx edx
109 heavyiron 2686
        mov     [base_code],6Bh
2687
        call    store_instruction_with_imm8
2688
        jmp     instruction_assembled
2689
      imul_reg_imm:
31 halyavin 2690
        mov     bl,[postbyte_register]
109 heavyiron 2691
        dec     esi
2692
        jmp     imul_reg_reg_imm
2693
      imul_reg_reg:
31 halyavin 2694
        lods    byte [esi]
109 heavyiron 2695
        call    convert_register
2696
        mov     bl,al
2697
        cmp     byte [esi],','
2698
        je      imul_reg_reg_imm
2699
        mov     al,ah
2700
        call    operand_autodetect
2701
        mov     [base_code],0Fh
2702
        mov     [extended_code],0AFh
2703
        call    store_nomem_instruction
2704
        jmp     instruction_assembled
2705
      imul_reg_reg_imm:
31 halyavin 2706
        inc     esi
109 heavyiron 2707
        lods    byte [esi]
2708
        call    get_size_operator
2709
        cmp     al,'('
2710
        jne     invalid_operand
2711
        mov     al,[operand_size]
2712
        cmp     al,2
2713
        je      imul_reg_reg_imm_16bit
2714
        cmp     al,4
2715
        je      imul_reg_reg_imm_32bit
2716
        cmp     al,8
2717
        je      imul_reg_reg_imm_64bit
2718
        jmp     invalid_operand_size
2719
      imul_reg_reg_imm_16bit:
31 halyavin 2720
        call    operand_16bit
109 heavyiron 2721
        push    ebx
2722
        call    get_word_value
2723
        pop     ebx
2724
        mov     dx,ax
2725
        cmp     [value_type],0
2726
        jne     imul_reg_reg_imm_16bit_store
2727
        cmp     [size_declared],0
2728
        jne     imul_reg_reg_imm_16bit_store
2729
        cmp     ax,-80h
2730
        jl      imul_reg_reg_imm_16bit_store
2731
        cmp     ax,80h
2732
        jl      imul_reg_reg_imm_8bit_store
2733
      imul_reg_reg_imm_16bit_store:
31 halyavin 2734
        mov     [base_code],69h
109 heavyiron 2735
        call    store_nomem_instruction
2736
        mov     ax,dx
2737
        call    mark_relocation
2738
        stos    word [edi]
2739
        jmp     instruction_assembled
2740
      imul_reg_reg_imm_32bit:
31 halyavin 2741
        call    operand_32bit
109 heavyiron 2742
        push    ebx
2743
        call    get_dword_value
2744
      imul_reg_reg_imm_32bit_ok:
31 halyavin 2745
        pop     ebx
109 heavyiron 2746
        mov     edx,eax
2747
        cmp     [value_type],0
2748
        jne     imul_reg_reg_imm_32bit_store
2749
        cmp     [size_declared],0
2750
        jne     imul_reg_reg_imm_32bit_store
2751
        cmp     eax,-80h
2752
        jl      imul_reg_reg_imm_32bit_store
2753
        cmp     eax,80h
2754
        jl      imul_reg_reg_imm_8bit_store
2755
      imul_reg_reg_imm_32bit_store:
31 halyavin 2756
        mov     [base_code],69h
109 heavyiron 2757
        call    store_nomem_instruction
2758
        mov     eax,edx
2759
        call    mark_relocation
2760
        stos    dword [edi]
2761
        jmp     instruction_assembled
2762
      imul_reg_reg_imm_64bit:
31 halyavin 2763
        cmp     [size_declared],0
109 heavyiron 2764
        jne     long_immediate_not_encodable
2765
        call    operand_64bit
2766
        push    ebx
2767
        call    get_simm32
2768
        cmp     [value_type],4
2769
        jae     long_immediate_not_encodable
2770
        jmp     imul_reg_reg_imm_32bit_ok
2771
      imul_reg_reg_imm_8bit_store:
31 halyavin 2772
        mov     [base_code],6Bh
109 heavyiron 2773
        call    store_nomem_instruction
2774
        mov     al,dl
2775
        stos    byte [edi]
2776
        jmp     instruction_assembled
2777
in_instruction:
31 halyavin 2778
        lods    byte [esi]
109 heavyiron 2779
        call    get_size_operator
2780
        cmp     al,10h
2781
        jne     invalid_operand
2782
        lods    byte [esi]
2783
        call    convert_register
2784
        or      al,al
2785
        jnz     invalid_operand
2786
        lods    byte [esi]
2787
        cmp     al,','
2788
        jne     invalid_operand
2789
        mov     al,ah
2790
        push    eax
2791
        mov     [operand_size],0
2792
        lods    byte [esi]
2793
        call    get_size_operator
2794
        cmp     al,'('
2795
        je      in_imm
2796
        cmp     al,10h
2797
        je      in_reg
2798
        jmp     invalid_operand
2799
      in_reg:
31 halyavin 2800
        lods    byte [esi]
109 heavyiron 2801
        cmp     al,22h
2802
        jne     invalid_operand
2803
        pop     eax
2804
        cmp     al,1
2805
        je      in_al_dx
2806
        cmp     al,2
2807
        je      in_ax_dx
2808
        cmp     al,4
2809
        je      in_eax_dx
2810
        jmp     invalid_operand_size
2811
      in_al_dx:
31 halyavin 2812
        mov     al,0ECh
109 heavyiron 2813
        stos    byte [edi]
2814
        jmp     instruction_assembled
2815
      in_ax_dx:
31 halyavin 2816
        call    operand_16bit
109 heavyiron 2817
        mov     [base_code],0EDh
2818
        call    store_instruction_code
2819
        jmp     instruction_assembled
2820
      in_eax_dx:
31 halyavin 2821
        call    operand_32bit
109 heavyiron 2822
        mov     [base_code],0EDh
2823
        call    store_instruction_code
2824
        jmp     instruction_assembled
2825
      in_imm:
31 halyavin 2826
        mov     al,[operand_size]
109 heavyiron 2827
        or      al,al
2828
        jz      in_imm_size_ok
2829
        cmp     al,1
2830
        jne     invalid_operand_size
2831
      in_imm_size_ok:
31 halyavin 2832
        call    get_byte_value
109 heavyiron 2833
        mov     dl,al
2834
        pop     eax
2835
        cmp     al,1
2836
        je      in_al_imm
2837
        cmp     al,2
2838
        je      in_ax_imm
2839
        cmp     al,4
2840
        je      in_eax_imm
2841
        jmp     invalid_operand_size
2842
      in_al_imm:
31 halyavin 2843
        mov     al,0E4h
109 heavyiron 2844
        stos    byte [edi]
2845
        mov     al,dl
2846
        stos    byte [edi]
2847
        jmp     instruction_assembled
2848
      in_ax_imm:
31 halyavin 2849
        call    operand_16bit
109 heavyiron 2850
        mov     [base_code],0E5h
2851
        call    store_instruction_code
2852
        mov     al,dl
2853
        stos    byte [edi]
2854
        jmp     instruction_assembled
2855
      in_eax_imm:
31 halyavin 2856
        call    operand_32bit
109 heavyiron 2857
        mov     [base_code],0E5h
2858
        call    store_instruction_code
2859
        mov     al,dl
2860
        stos    byte [edi]
2861
        jmp     instruction_assembled
2862
out_instruction:
31 halyavin 2863
        lods    byte [esi]
109 heavyiron 2864
        call    get_size_operator
2865
        cmp     al,'('
2866
        je      out_imm
2867
        cmp     al,10h
2868
        jne     invalid_operand
2869
        lods    byte [esi]
2870
        cmp     al,22h
2871
        jne     invalid_operand
2872
        lods    byte [esi]
2873
        cmp     al,','
2874
        jne     invalid_operand
2875
        mov     [operand_size],0
2876
        lods    byte [esi]
2877
        call    get_size_operator
2878
        cmp     al,10h
2879
        jne     invalid_operand
2880
        lods    byte [esi]
2881
        call    convert_register
2882
        or      al,al
2883
        jnz     invalid_operand
2884
        mov     al,ah
2885
        cmp     al,1
2886
        je      out_dx_al
2887
        cmp     al,2
2888
        je      out_dx_ax
2889
        cmp     al,4
2890
        je      out_dx_eax
2891
        jmp     invalid_operand_size
2892
      out_dx_al:
31 halyavin 2893
        mov     al,0EEh
109 heavyiron 2894
        stos    byte [edi]
2895
        jmp     instruction_assembled
2896
      out_dx_ax:
31 halyavin 2897
        call    operand_16bit
109 heavyiron 2898
        mov     [base_code],0EFh
2899
        call    store_instruction_code
2900
        jmp     instruction_assembled
2901
      out_dx_eax:
31 halyavin 2902
        call    operand_32bit
109 heavyiron 2903
        mov     [base_code],0EFh
2904
        call    store_instruction_code
2905
        jmp     instruction_assembled
2906
      out_imm:
31 halyavin 2907
        mov     al,[operand_size]
109 heavyiron 2908
        or      al,al
2909
        jz      out_imm_size_ok
2910
        cmp     al,1
2911
        jne     invalid_operand_size
2912
      out_imm_size_ok:
31 halyavin 2913
        call    get_byte_value
109 heavyiron 2914
        mov     dl,al
2915
        lods    byte [esi]
2916
        cmp     al,','
2917
        jne     invalid_operand
2918
        mov     [operand_size],0
2919
        lods    byte [esi]
2920
        call    get_size_operator
2921
        cmp     al,10h
2922
        jne     invalid_operand
2923
        lods    byte [esi]
2924
        call    convert_register
2925
        or      al,al
2926
        jnz     invalid_operand
2927
        mov     al,ah
2928
        cmp     al,1
2929
        je      out_imm_al
2930
        cmp     al,2
2931
        je      out_imm_ax
2932
        cmp     al,4
2933
        je      out_imm_eax
2934
        jmp     invalid_operand_size
2935
      out_imm_al:
31 halyavin 2936
        mov     al,0E6h
109 heavyiron 2937
        stos    byte [edi]
2938
        mov     al,dl
2939
        stos    byte [edi]
2940
        jmp     instruction_assembled
2941
      out_imm_ax:
31 halyavin 2942
        call    operand_16bit
109 heavyiron 2943
        mov     [base_code],0E7h
2944
        call    store_instruction_code
2945
        mov     al,dl
2946
        stos    byte [edi]
2947
        jmp     instruction_assembled
2948
      out_imm_eax:
31 halyavin 2949
        call    operand_32bit
109 heavyiron 2950
        mov     [base_code],0E7h
2951
        call    store_instruction_code
2952
        mov     al,dl
2953
        stos    byte [edi]
2954
        jmp     instruction_assembled
2955
31 halyavin 2956
 
2957
        mov     [postbyte_register],10b
109 heavyiron 2958
        mov     [base_code],0E8h
2959
        mov     [extended_code],9Ah
2960
        jmp     process_jmp
2961
jmp_instruction:
31 halyavin 2962
        mov     [postbyte_register],100b
109 heavyiron 2963
        mov     [base_code],0E9h
2964
        mov     [extended_code],0EAh
2965
      process_jmp:
31 halyavin 2966
        lods    byte [esi]
109 heavyiron 2967
        call    get_jump_operator
2968
        call    get_size_operator
2969
        cmp     al,'('
2970
        je      jmp_imm
2971
        mov     [base_code],0FFh
2972
        cmp     al,10h
2973
        je      jmp_reg
2974
        cmp     al,'['
2975
        jne     invalid_operand
2976
      jmp_mem:
31 halyavin 2977
        cmp     [jump_type],1
109 heavyiron 2978
        je      illegal_instruction
2979
        call    get_address
2980
        mov     edx,eax
2981
        mov     al,[operand_size]
2982
        or      al,al
2983
        jz      jmp_mem_size_not_specified
2984
        cmp     al,2
2985
        je      jmp_mem_16bit
2986
        cmp     al,4
2987
        je      jmp_mem_32bit
2988
        cmp     al,6
2989
        je      jmp_mem_48bit
2990
        cmp     al,8
2991
        je      jmp_mem_64bit
2992
        cmp     al,10
2993
        je      jmp_mem_80bit
2994
        jmp     invalid_operand_size
2995
      jmp_mem_size_not_specified:
31 halyavin 2996
        cmp     [jump_type],3
109 heavyiron 2997
        je      jmp_mem_far
2998
        cmp     [jump_type],2
2999
        je      jmp_mem_near
3000
        cmp     [error_line],0
3001
        jne     jmp_mem_near
3002
        mov     eax,[current_line]
3003
        mov     [error_line],eax
3004
        mov     [error],operand_size_not_specified
3005
      jmp_mem_near:
31 halyavin 3006
        cmp     [code_type],16
109 heavyiron 3007
        je      jmp_mem_16bit
3008
        cmp     [code_type],32
3009
        je      jmp_mem_near_32bit
3010
      jmp_mem_64bit:
31 halyavin 3011
        cmp     [jump_type],3
109 heavyiron 3012
        je      invalid_operand_size
3013
        cmp     [code_type],64
3014
        jne     illegal_instruction
3015
        call    store_instruction
3016
        jmp     instruction_assembled
3017
      jmp_mem_far:
31 halyavin 3018
        cmp     [code_type],16
109 heavyiron 3019
        je      jmp_mem_far_32bit
3020
      jmp_mem_48bit:
31 halyavin 3021
        call    operand_32bit
109 heavyiron 3022
      jmp_mem_far_store:
31 halyavin 3023
        cmp     [jump_type],2
109 heavyiron 3024
        je      invalid_operand_size
3025
        inc     [postbyte_register]
3026
        call    store_instruction
3027
        jmp     instruction_assembled
3028
      jmp_mem_80bit:
31 halyavin 3029
        call    operand_64bit
109 heavyiron 3030
        jmp     jmp_mem_far_store
3031
      jmp_mem_far_32bit:
31 halyavin 3032
        call    operand_16bit
109 heavyiron 3033
        jmp     jmp_mem_far_store
3034
      jmp_mem_32bit:
31 halyavin 3035
        cmp     [jump_type],3
109 heavyiron 3036
        je      jmp_mem_far_32bit
3037
        cmp     [jump_type],2
3038
        je      jmp_mem_near_32bit
3039
        cmp     [code_type],16
3040
        je      jmp_mem_far_32bit
3041
      jmp_mem_near_32bit:
31 halyavin 3042
        cmp     [code_type],64
109 heavyiron 3043
        je      illegal_instruction
3044
        call    operand_32bit
3045
        call    store_instruction
3046
        jmp     instruction_assembled
3047
      jmp_mem_16bit:
31 halyavin 3048
        cmp     [jump_type],3
109 heavyiron 3049
        je      invalid_operand_size
3050
        call    operand_16bit
3051
        call    store_instruction
3052
        jmp     instruction_assembled
3053
      jmp_reg:
31 halyavin 3054
        test    [jump_type],1
109 heavyiron 3055
        jnz     invalid_operand
3056
        lods    byte [esi]
3057
        call    convert_register
3058
        mov     bl,al
3059
        mov     al,ah
3060
        cmp     al,2
3061
        je      jmp_reg_16bit
3062
        cmp     al,4
3063
        je      jmp_reg_32bit
3064
        cmp     al,8
3065
        jne     invalid_operand_size
3066
      jmp_reg_64bit:
31 halyavin 3067
        cmp     [code_type],64
109 heavyiron 3068
        jne     illegal_instruction
3069
        call    store_nomem_instruction
3070
        jmp     instruction_assembled
3071
      jmp_reg_32bit:
31 halyavin 3072
        cmp     [code_type],64
109 heavyiron 3073
        je      illegal_instruction
3074
        call    store_nomem_instruction
3075
        jmp     instruction_assembled
3076
      jmp_reg_16bit:
31 halyavin 3077
        call    operand_16bit
109 heavyiron 3078
        call    store_nomem_instruction
3079
        jmp     instruction_assembled
3080
      jmp_imm:
31 halyavin 3081
        cmp     byte [esi],'.'
109 heavyiron 3082
        je      invalid_value
3083
        mov     ebx,esi
3084
        dec     esi
3085
        call    skip_symbol
3086
        xchg    esi,ebx
3087
        cmp     byte [ebx],':'
3088
        je      jmp_far
3089
        cmp     [jump_type],3
3090
        je      invalid_operand
3091
      jmp_near:
3092
        mov     al,[operand_size]
3093
        cmp     al,2
3094
        je      jmp_imm_16bit
3095
        cmp     al,4
3096
        je      jmp_imm_32bit
3097
        cmp     al,8
3098
        je      jmp_imm_64bit
3099
        or      al,al
3100
        jnz     invalid_operand_size
3101
        cmp     [code_type],16
3102
        je      jmp_imm_16bit
3103
        cmp     [code_type],64
3104
        je      jmp_imm_64bit
3105
      jmp_imm_32bit:
3106
        cmp     [code_type],64
3107
        je      invalid_operand_size
3108
        call    get_dword_value
3109
        cmp     [code_type],16
3110
        jne     jmp_imm_32bit_prefix_ok
3111
        mov     byte [edi],66h
3112
        inc     edi
3113
      jmp_imm_32bit_prefix_ok:
3114
        call    calculate_jump_offset
3115
        cdq
3116
        call    check_for_short_jump
3117
        jc      jmp_short
3118
      jmp_imm_32bit_store:
3119
        mov     edx,eax
3120
        sub     edx,3
3121
        mov     al,[base_code]
3122
        stos    byte [edi]
3123
        mov     eax,edx
3124
        call    mark_relocation
3125
        stos    dword [edi]
3126
        jmp     instruction_assembled
3127
      jmp_imm_64bit:
3128
        cmp     [code_type],64
3129
        jne     invalid_operand_size
3130
        call    get_qword_value
3131
        call    calculate_jump_offset
3132
        mov     ecx,edx
3133
        cdq
3134
        cmp     edx,ecx
3135
        jne     value_out_of_range
3136
        call    check_for_short_jump
3137
        jnc     jmp_imm_32bit_store
3138
      jmp_short:
3139
        mov     ah,al
3140
        mov     al,0EBh
3141
        stos    word [edi]
3142
        jmp     instruction_assembled
3143
      jmp_imm_16bit:
3144
        call    get_word_value
3145
        cmp     [code_type],16
3146
        je      jmp_imm_16bit_prefix_ok
3147
        mov     byte [edi],66h
3148
        inc     edi
3149
      jmp_imm_16bit_prefix_ok:
3150
        call    calculate_jump_offset
3151
        cwde
3152
        cdq
3153
        call    check_for_short_jump
3154
        jc      jmp_short
3155
        cmp     [value_type],0
3156
        jne     invalid_use_of_symbol
3157
        mov     edx,eax
3158
        dec     edx
3159
        mov     al,[base_code]
3160
        stos    byte [edi]
3161
        mov     eax,edx
3162
        stos    word [edi]
3163
        jmp     instruction_assembled
3164
      calculate_jump_offset:
3165
        cmp     [value_undefined],0
3166
        jne     jump_offset_ok
3167
        add     eax,dword [org_origin]
3168
        adc     edx,dword [org_origin+4]
3169
        lea     ebx,[edi+2]
3170
        sub     eax,ebx
3171
        sbb     edx,0
3172
        mov     bl,[value_type]
3173
        or      bl,bl
3174
        je      jump_offset_ok
3175
        test    bl,1
3176
        jnz     invalid_use_of_symbol
3177
        cmp     bl,[labels_type]
3178
        jne     invalid_use_of_symbol
3179
        mov     [value_type],0
3180
        mov     ecx,[symbol_identifier]
3181
        cmp     ecx,[org_symbol]
3182
        je      jump_offset_ok
3183
        mov     [value_type],3
3184
      jump_offset_ok:
3185
        ret
3186
      check_for_short_jump:
3187
        cmp     [jump_type],1
3188
        je      forced_short
3189
        ja      no_short_jump
3190
        cmp     [base_code],0E8h
3191
        je      no_short_jump
3192
        cmp     [value_type],0
3193
        jne     no_short_jump
3194
        cmp     eax,80h
3195
        jb      short_jump
3196
        cmp     eax,-80h
3197
        jae     short_jump
3198
      no_short_jump:
3199
        clc
3200
        ret
3201
      forced_short:
3202
        cmp     [base_code],0E8h
3203
        je      illegal_instruction
3204
        cmp     [next_pass_needed],0
3205
        jne     jmp_short_value_type_ok
3206
        cmp     [value_type],0
3207
        jne     invalid_use_of_symbol
3208
      jmp_short_value_type_ok:
3209
        cmp     eax,-80h
3210
        jae     short_jump
3211
        cmp     eax,80h
3212
        jae     jump_out_of_range
3213
      short_jump:
3214
        stc
3215
        ret
3216
      jump_out_of_range:
3217
        cmp     [error_line],0
3218
        jne     instruction_assembled
3219
        mov     eax,[current_line]
3220
        mov     [error_line],eax
3221
        mov     [error],relative_jump_out_of_range
3222
        jmp     instruction_assembled
3223
      jmp_far:
31 halyavin 3224
        cmp     [jump_type],2
109 heavyiron 3225
        je      invalid_operand
3226
        cmp     [code_type],64
3227
        je      illegal_instruction
3228
        mov     al,[extended_code]
3229
        mov     [base_code],al
3230
        call    get_word_value
3231
        push    eax
3232
        inc     esi
3233
        lods    byte [esi]
3234
        cmp     al,'('
3235
        jne     invalid_operand
3236
        mov     al,[value_type]
3237
        push    eax [symbol_identifier]
3238
        cmp     byte [esi],'.'
3239
        je      invalid_value
3240
        mov     al,[operand_size]
3241
        cmp     al,4
3242
        je      jmp_far_16bit
3243
        cmp     al,6
3244
        je      jmp_far_32bit
3245
        or      al,al
3246
        jnz     invalid_operand_size
3247
        cmp     [code_type],16
3248
        jne     jmp_far_32bit
3249
      jmp_far_16bit:
31 halyavin 3250
        call    get_word_value
109 heavyiron 3251
        mov     ebx,eax
3252
        call    operand_16bit
3253
        call    store_instruction_code
3254
        mov     ax,bx
3255
        call    mark_relocation
3256
        stos    word [edi]
3257
      jmp_far_segment:
31 halyavin 3258
        pop     [symbol_identifier] eax
109 heavyiron 3259
        mov     [value_type],al
3260
        pop     eax
3261
        call    mark_relocation
3262
        stos    word [edi]
3263
        jmp     instruction_assembled
3264
      jmp_far_32bit:
31 halyavin 3265
        call    get_dword_value
109 heavyiron 3266
        mov     ebx,eax
3267
        call    operand_32bit
3268
        call    store_instruction_code
3269
        mov     eax,ebx
3270
        call    mark_relocation
3271
        stos    dword [edi]
3272
        jmp     jmp_far_segment
3273
conditional_jump:
3274
        mov     [base_code],al
3275
        lods    byte [esi]
3276
        call    get_jump_operator
3277
        cmp     [jump_type],3
3278
        je      invalid_operand
3279
        call    get_size_operator
3280
        cmp     al,'('
3281
        jne     invalid_operand
3282
        cmp     byte [esi],'.'
3283
        je      invalid_value
3284
        mov     al,[operand_size]
3285
        cmp     al,2
3286
        je      conditional_jump_16bit
3287
        cmp     al,4
3288
        je      conditional_jump_32bit
3289
        cmp     al,8
3290
        je      conditional_jump_64bit
3291
        or      al,al
3292
        jnz     invalid_operand_size
3293
        cmp     [code_type],16
3294
        je      conditional_jump_16bit
3295
        cmp     [code_type],64
3296
        je      conditional_jump_64bit
3297
      conditional_jump_32bit:
3298
        cmp     [code_type],64
3299
        je      invalid_operand_size
3300
        call    get_dword_value
3301
        cmp     [code_type],16
3302
        jne     conditional_jump_32bit_prefix_ok
3303
        mov     byte [edi],66h
3304
        inc     edi
3305
      conditional_jump_32bit_prefix_ok:
3306
        call    calculate_jump_offset
3307
        cdq
3308
        call    check_for_short_jump
3309
        jc      conditional_jump_short
3310
      conditional_jump_32bit_store:
3311
        mov     edx,eax
3312
        sub     edx,4
3313
        mov     ah,[base_code]
3314
        add     ah,10h
3315
        mov     al,0Fh
3316
        stos    word [edi]
3317
        mov     eax,edx
3318
        call    mark_relocation
3319
        stos    dword [edi]
3320
        jmp     instruction_assembled
3321
      conditional_jump_64bit:
3322
        cmp     [code_type],64
3323
        jne     invalid_operand_size
3324
        call    get_qword_value
3325
        call    calculate_jump_offset
3326
        mov     ecx,edx
3327
        cdq
3328
        cmp     edx,ecx
3329
        jne     value_out_of_range
3330
        call    check_for_short_jump
3331
        jnc     conditional_jump_32bit_store
3332
      conditional_jump_short:
3333
        mov     ah,al
3334
        mov     al,[base_code]
3335
        stos    word [edi]
3336
        jmp     instruction_assembled
3337
      conditional_jump_16bit:
3338
        call    get_word_value
3339
        cmp     [code_type],16
3340
        je      conditional_jump_16bit_prefix_ok
3341
        mov     byte [edi],66h
3342
        inc     edi
3343
      conditional_jump_16bit_prefix_ok:
3344
        call    calculate_jump_offset
3345
        cwde
3346
        cdq
3347
        call    check_for_short_jump
3348
        jc      conditional_jump_short
3349
        cmp     [value_type],0
3350
        jne     invalid_use_of_symbol
3351
        mov     edx,eax
3352
        sub     edx,2
3353
        mov     ah,[base_code]
3354
        add     ah,10h
3355
        mov     al,0Fh
3356
        stos    word [edi]
3357
        mov     eax,edx
3358
        stos    word [edi]
3359
        jmp     instruction_assembled
3360
loop_instruction_16bit:
3361
        cmp     [code_type],64
3362
        je      illegal_instruction
3363
        mov     dl,al
3364
        call    address_16bit_prefix
3365
        mov     al,dl
3366
        jmp     loop_instruction
3367
loop_instruction_32bit:
3368
        mov     dl,al
3369
        call    address_32bit_prefix
3370
        mov     al,dl
3371
        jmp     loop_instruction
3372
loop_instruction_64bit:
3373
        cmp     [code_type],64
3374
        jne     illegal_instruction
3375
loop_instruction:
3376
        mov     [base_code],al
3377
        lods    byte [esi]
3378
        call    get_jump_operator
3379
        cmp     [jump_type],1
3380
        ja      invalid_operand
3381
        call    get_size_operator
3382
        cmp     al,'('
3383
        jne     invalid_operand
3384
        cmp     byte [esi],'.'
3385
        je      invalid_value
3386
        mov     al,[operand_size]
3387
        cmp     al,2
3388
        je      loop_jump_16bit
3389
        cmp     al,4
3390
        je      loop_jump_32bit
3391
        cmp     al,8
3392
        je      loop_jump_64bit
3393
        or      al,al
3394
        jnz     invalid_operand_size
3395
        cmp     [code_type],16
3396
        je      loop_jump_16bit
3397
        cmp     [code_type],64
3398
        je      loop_jump_64bit
3399
      loop_jump_32bit:
3400
        cmp     [code_type],64
3401
        je      invalid_operand_size
3402
        call    get_dword_value
3403
        cmp     [code_type],16
3404
        jne     loop_jump_32bit_prefix_ok
3405
        mov     byte [edi],66h
3406
        inc     edi
3407
      loop_jump_32bit_prefix_ok:
3408
        call    calculate_jump_offset
3409
        cdq
3410
      make_loop_jump:
3411
        call    check_for_short_jump
3412
        jc      conditional_jump_short
3413
        jmp     jump_out_of_range
3414
      loop_jump_64bit:
3415
        cmp     [code_type],64
3416
        jne     invalid_operand_size
3417
        call    get_qword_value
3418
        call    calculate_jump_offset
3419
        mov     ecx,edx
3420
        cdq
3421
        cmp     edx,ecx
3422
        jne     value_out_of_range
3423
        jmp     make_loop_jump
3424
      loop_jump_16bit:
3425
        call    get_word_value
3426
        cmp     [code_type],16
3427
        je      loop_jump_16bit_prefix_ok
3428
        mov     byte [edi],66h
3429
        inc     edi
3430
      loop_jump_16bit_prefix_ok:
3431
        call    calculate_jump_offset
3432
        cwde
3433
        cdq
3434
        jmp     make_loop_jump
3435
31 halyavin 3436
 
3437
        lods    byte [esi]
109 heavyiron 3438
        call    get_size_operator
3439
        cmp     al,'['
3440
        jne     invalid_operand
3441
        call    get_address
3442
        or      eax,eax
3443
        jnz     invalid_address
3444
        or      bl,ch
3445
        jnz     invalid_address
3446
        cmp     [segment_register],1
3447
        ja      invalid_address
3448
        push    ebx
3449
        lods    byte [esi]
3450
        cmp     al,','
3451
        jne     invalid_operand
3452
        lods    byte [esi]
3453
        call    get_size_operator
3454
        cmp     al,'['
3455
        jne     invalid_operand
3456
        call    get_address
3457
        pop     edx
3458
        or      eax,eax
3459
        jnz     invalid_address
3460
        or      bl,ch
3461
        jnz     invalid_address
3462
        mov     al,dh
3463
        mov     ah,bh
3464
        shr     al,4
3465
        shr     ah,4
3466
        cmp     al,ah
3467
        jne     address_sizes_do_not_agree
3468
        and     bh,111b
3469
        and     dh,111b
3470
        cmp     bh,6
3471
        jne     invalid_address
3472
        cmp     dh,7
3473
        jne     invalid_address
3474
        cmp     al,2
3475
        je      movs_address_16bit
3476
        cmp     al,4
3477
        je      movs_address_32bit
3478
        cmp     [code_type],64
3479
        jne     invalid_address_size
3480
        jmp     movs_store
3481
      movs_address_32bit:
31 halyavin 3482
        call    address_32bit_prefix
109 heavyiron 3483
        jmp     movs_store
3484
      movs_address_16bit:
31 halyavin 3485
        cmp     [code_type],64
109 heavyiron 3486
        je      invalid_address_size
3487
        call    address_16bit_prefix
3488
      movs_store:
31 halyavin 3489
        cmp     [segment_register],4
109 heavyiron 3490
        je      movs_segment_ok
3491
        call    store_segment_prefix
3492
      movs_segment_ok:
31 halyavin 3493
        mov     al,0A4h
109 heavyiron 3494
        mov     bl,[operand_size]
3495
        cmp     bl,1
3496
        je      simple_instruction
3497
        inc     al
3498
        cmp     bl,2
3499
        je      simple_instruction_16bit
3500
        cmp     bl,4
3501
        je      simple_instruction_32bit
3502
        cmp     bl,8
3503
        je      simple_instruction_64bit
3504
        or      bl,bl
3505
        jz      operand_size_not_specified
3506
        jmp     invalid_operand_size
3507
lods_instruction:
31 halyavin 3508
        lods    byte [esi]
109 heavyiron 3509
        call    get_size_operator
3510
        cmp     al,'['
3511
        jne     invalid_operand
3512
        call    get_address
3513
        or      eax,eax
3514
        jnz     invalid_address
3515
        or      bl,ch
3516
        jnz     invalid_address
3517
        cmp     bh,26h
3518
        je      lods_address_16bit
3519
        cmp     bh,46h
3520
        je      lods_address_32bit
3521
        cmp     bh,86h
3522
        jne     invalid_address
3523
        cmp     [code_type],64
3524
        jne     invalid_address_size
3525
        jmp     lods_store
3526
      lods_address_32bit:
31 halyavin 3527
        call    address_32bit_prefix
109 heavyiron 3528
        jmp     lods_store
3529
      lods_address_16bit:
31 halyavin 3530
        cmp     [code_type],64
109 heavyiron 3531
        je      invalid_address_size
3532
        call    address_16bit_prefix
3533
      lods_store:
31 halyavin 3534
        cmp     [segment_register],4
109 heavyiron 3535
        je      lods_segment_ok
3536
        call    store_segment_prefix
3537
      lods_segment_ok:
31 halyavin 3538
        mov     al,0ACh
109 heavyiron 3539
        mov     bl,[operand_size]
3540
        cmp     bl,1
3541
        je      simple_instruction
3542
        inc     al
3543
        cmp     bl,2
3544
        je      simple_instruction_16bit
3545
        cmp     bl,4
3546
        je      simple_instruction_32bit
3547
        cmp     bl,8
3548
        je      simple_instruction_64bit
3549
        or      bl,bl
3550
        jz      operand_size_not_specified
3551
        jmp     invalid_operand_size
3552
stos_instruction:
31 halyavin 3553
        mov     [base_code],al
109 heavyiron 3554
        lods    byte [esi]
3555
        call    get_size_operator
3556
        cmp     al,'['
3557
        jne     invalid_operand
3558
        call    get_address
3559
        or      eax,eax
3560
        jnz     invalid_address
3561
        or      bl,ch
3562
        jnz     invalid_address
3563
        cmp     bh,27h
3564
        je      stos_address_16bit
3565
        cmp     bh,47h
3566
        je      stos_address_32bit
3567
        cmp     bh,87h
3568
        jne     invalid_address
3569
        cmp     [code_type],64
3570
        jne     invalid_address_size
3571
        jmp     stos_store
3572
      stos_address_32bit:
31 halyavin 3573
        call    address_32bit_prefix
109 heavyiron 3574
        jmp     stos_store
3575
      stos_address_16bit:
31 halyavin 3576
        cmp     [code_type],64
109 heavyiron 3577
        je      invalid_address_size
3578
        call    address_16bit_prefix
3579
      stos_store:
31 halyavin 3580
        cmp     [segment_register],1
109 heavyiron 3581
        ja      invalid_address
3582
        mov     al,[base_code]
3583
        mov     bl,[operand_size]
3584
        cmp     bl,1
3585
        je      simple_instruction
3586
        inc     al
3587
        cmp     bl,2
3588
        je      simple_instruction_16bit
3589
        cmp     bl,4
3590
        je      simple_instruction_32bit
3591
        cmp     bl,8
3592
        je      simple_instruction_64bit
3593
        or      bl,bl
3594
        jz      operand_size_not_specified
3595
        jmp     invalid_operand_size
3596
cmps_instruction:
31 halyavin 3597
        lods    byte [esi]
109 heavyiron 3598
        call    get_size_operator
3599
        cmp     al,'['
3600
        jne     invalid_operand
3601
        call    get_address
3602
        or      eax,eax
3603
        jnz     invalid_address
3604
        or      bl,ch
3605
        jnz     invalid_address
3606
        mov     al,[segment_register]
3607
        push    ax bx
3608
        lods    byte [esi]
3609
        cmp     al,','
3610
        jne     invalid_operand
3611
        lods    byte [esi]
3612
        call    get_size_operator
3613
        cmp     al,'['
3614
        jne     invalid_operand
3615
        call    get_address
3616
        or      eax,eax
3617
        jnz     invalid_address
3618
        or      bl,ch
3619
        jnz     invalid_address
3620
        pop     dx ax
3621
        cmp     [segment_register],1
3622
        ja      invalid_address
3623
        mov     [segment_register],al
3624
        mov     al,dh
3625
        mov     ah,bh
3626
        shr     al,4
3627
        shr     ah,4
3628
        cmp     al,ah
3629
        jne     address_sizes_do_not_agree
3630
        and     bh,111b
3631
        and     dh,111b
3632
        cmp     bh,7
3633
        jne     invalid_address
3634
        cmp     dh,6
3635
        jne     invalid_address
3636
        cmp     al,2
3637
        je      cmps_address_16bit
3638
        cmp     al,4
3639
        je      cmps_address_32bit
3640
        cmp     [code_type],64
3641
        jne     invalid_address_size
3642
        jmp     cmps_store
3643
      cmps_address_32bit:
31 halyavin 3644
        call    address_32bit_prefix
109 heavyiron 3645
        jmp     cmps_store
3646
      cmps_address_16bit:
31 halyavin 3647
        cmp     [code_type],64
109 heavyiron 3648
        je      invalid_address_size
3649
        call    address_16bit_prefix
3650
      cmps_store:
31 halyavin 3651
        cmp     [segment_register],4
109 heavyiron 3652
        je      cmps_segment_ok
3653
        call    store_segment_prefix
3654
      cmps_segment_ok:
31 halyavin 3655
        mov     al,0A6h
109 heavyiron 3656
        mov     bl,[operand_size]
3657
        cmp     bl,1
3658
        je      simple_instruction
3659
        inc     al
3660
        cmp     bl,2
3661
        je      simple_instruction_16bit
3662
        cmp     bl,4
3663
        je      simple_instruction_32bit
3664
        cmp     bl,8
3665
        je      simple_instruction_64bit
3666
        or      bl,bl
3667
        jz      operand_size_not_specified
3668
        jmp     invalid_operand_size
3669
ins_instruction:
31 halyavin 3670
        lods    byte [esi]
109 heavyiron 3671
        call    get_size_operator
3672
        cmp     al,'['
3673
        jne     invalid_operand
3674
        call    get_address
3675
        or      eax,eax
3676
        jnz     invalid_address
3677
        or      bl,ch
3678
        jnz     invalid_address
3679
        cmp     bh,27h
3680
        je      ins_address_16bit
3681
        cmp     bh,47h
3682
        je      ins_address_32bit
3683
        cmp     bh,87h
3684
        jne     invalid_address
3685
        cmp     [code_type],64
3686
        jne     invalid_address_size
3687
        jmp     ins_store
3688
      ins_address_32bit:
31 halyavin 3689
        call    address_32bit_prefix
109 heavyiron 3690
        jmp     ins_store
3691
      ins_address_16bit:
31 halyavin 3692
        cmp     [code_type],64
109 heavyiron 3693
        je      invalid_address_size
3694
        call    address_16bit_prefix
3695
      ins_store:
31 halyavin 3696
        cmp     [segment_register],1
109 heavyiron 3697
        ja      invalid_address
3698
        lods    byte [esi]
3699
        cmp     al,','
3700
        jne     invalid_operand
3701
        lods    byte [esi]
3702
        cmp     al,10h
3703
        jne     invalid_operand
3704
        lods    byte [esi]
3705
        cmp     al,22h
3706
        jne     invalid_operand
3707
        mov     al,6Ch
3708
        mov     bl,[operand_size]
3709
        cmp     bl,1
3710
        je      simple_instruction
3711
        inc     al
3712
        cmp     bl,2
3713
        je      simple_instruction_16bit
3714
        cmp     bl,4
3715
        je      simple_instruction_32bit
3716
        or      bl,bl
3717
        jz      operand_size_not_specified
3718
        jmp     invalid_operand_size
3719
outs_instruction:
31 halyavin 3720
        lods    byte [esi]
109 heavyiron 3721
        cmp     al,10h
3722
        jne     invalid_operand
3723
        lods    byte [esi]
3724
        cmp     al,22h
3725
        jne     invalid_operand
3726
        lods    byte [esi]
3727
        cmp     al,','
3728
        jne     invalid_operand
3729
        lods    byte [esi]
3730
        call    get_size_operator
3731
        cmp     al,'['
3732
        jne     invalid_operand
3733
        call    get_address
3734
        or      eax,eax
3735
        jnz     invalid_address
3736
        or      bl,ch
3737
        jnz     invalid_address
3738
        cmp     bh,26h
3739
        je      outs_address_16bit
3740
        cmp     bh,46h
3741
        je      outs_address_32bit
3742
        cmp     bh,86h
3743
        jne     invalid_address
3744
        cmp     [code_type],64
3745
        jne     invalid_address_size
3746
        jmp     outs_store
3747
      outs_address_32bit:
31 halyavin 3748
        call    address_32bit_prefix
109 heavyiron 3749
        jmp     outs_store
3750
      outs_address_16bit:
31 halyavin 3751
        cmp     [code_type],64
109 heavyiron 3752
        je      invalid_address_size
3753
        call    address_16bit_prefix
3754
      outs_store:
31 halyavin 3755
        cmp     [segment_register],4
109 heavyiron 3756
        je      outs_segment_ok
3757
        call    store_segment_prefix
3758
      outs_segment_ok:
31 halyavin 3759
        mov     al,6Eh
109 heavyiron 3760
        mov     bl,[operand_size]
3761
        cmp     bl,1
3762
        je      simple_instruction
3763
        inc     al
3764
        cmp     bl,2
3765
        je      simple_instruction_16bit
3766
        cmp     bl,4
3767
        je      simple_instruction_32bit
3768
        or      bl,bl
3769
        jz      operand_size_not_specified
3770
        jmp     invalid_operand_size
3771
xlat_instruction:
31 halyavin 3772
        lods    byte [esi]
109 heavyiron 3773
        call    get_size_operator
3774
        cmp     al,'['
3775
        jne     invalid_operand
3776
        call    get_address
3777
        or      eax,eax
3778
        jnz     invalid_address
3779
        or      bl,ch
3780
        jnz     invalid_address
3781
        cmp     bh,23h
3782
        je      xlat_address_16bit
3783
        cmp     bh,43h
3784
        je      xlat_address_32bit
3785
        cmp     bh,83h
3786
        jne     invalid_address
3787
        cmp     [code_type],64
3788
        jne     invalid_address_size
3789
        jmp     xlat_store
3790
      xlat_address_32bit:
31 halyavin 3791
        call    address_32bit_prefix
109 heavyiron 3792
        jmp     xlat_store
3793
      xlat_address_16bit:
31 halyavin 3794
        cmp     [code_type],64
109 heavyiron 3795
        je      invalid_address_size
3796
        call    address_16bit_prefix
3797
      xlat_store:
31 halyavin 3798
        call    store_segment_prefix_if_necessary
109 heavyiron 3799
        mov     al,0D7h
3800
        cmp     [operand_size],1
3801
        jbe     simple_instruction
3802
        jmp     invalid_operand_size
3803
31 halyavin 3804
 
3805
        mov     ah,al
109 heavyiron 3806
        shr     ah,4
3807
        and     al,111b
3808
        mov     [base_code],0Fh
3809
        mov     [extended_code],ah
3810
        mov     [postbyte_register],al
3811
        lods    byte [esi]
3812
        call    get_size_operator
3813
        cmp     al,10h
3814
        je      pm_reg
3815
      pm_mem:
31 halyavin 3816
        cmp     al,'['
109 heavyiron 3817
        jne     invalid_operand
3818
        call    get_address
3819
        mov     al,[operand_size]
3820
        cmp     al,2
3821
        je      pm_mem_store
3822
        or      al,al
3823
        jnz     invalid_operand_size
3824
      pm_mem_store:
31 halyavin 3825
        call    store_instruction
109 heavyiron 3826
        jmp     instruction_assembled
3827
      pm_reg:
31 halyavin 3828
        lods    byte [esi]
109 heavyiron 3829
        call    convert_register
3830
        mov     bl,al
3831
        cmp     ah,2
3832
        jne     invalid_operand_size
3833
        call    store_nomem_instruction
3834
        jmp     instruction_assembled
3835
pm_store_word_instruction:
31 halyavin 3836
        mov     ah,al
109 heavyiron 3837
        shr     ah,4
3838
        and     al,111b
3839
        mov     [base_code],0Fh
3840
        mov     [extended_code],ah
3841
        mov     [postbyte_register],al
3842
        lods    byte [esi]
3843
        call    get_size_operator
3844
        cmp     al,10h
3845
        jne     pm_mem
3846
        lods    byte [esi]
3847
        call    convert_register
3848
        mov     bl,al
3849
        mov     al,ah
3850
        call    operand_autodetect
3851
        call    store_nomem_instruction
3852
        jmp     instruction_assembled
3853
lgdt_instruction:
31 halyavin 3854
        mov     [base_code],0Fh
109 heavyiron 3855
        mov     [extended_code],1
3856
        mov     [postbyte_register],al
3857
        lods    byte [esi]
3858
        call    get_size_operator
3859
        cmp     al,'['
3860
        jne     invalid_operand
3861
        call    get_address
3862
        mov     al,[operand_size]
3863
        cmp     al,6
3864
        je      lgdt_mem_48bit
3865
        cmp     al,10
3866
        je      lgdt_mem_80bit
3867
        or      al,al
3868
        jnz     invalid_operand_size
3869
        jmp     lgdt_mem_store
3870
      lgdt_mem_80bit:
3871
        cmp     [code_type],64
3872
        jne     illegal_instruction
3873
        jmp     lgdt_mem_store
3874
      lgdt_mem_48bit:
31 halyavin 3875
        cmp     [code_type],64
109 heavyiron 3876
        je      illegal_instruction
3877
        cmp     [postbyte_register],2
3878
        jb      lgdt_mem_store
3879
        call    operand_32bit
3880
      lgdt_mem_store:
3881
        call    store_instruction
3882
        jmp     instruction_assembled
3883
lar_instruction:
31 halyavin 3884
        mov     [extended_code],al
109 heavyiron 3885
        mov     [base_code],0Fh
3886
        lods    byte [esi]
3887
        call    get_size_operator
3888
        cmp     al,10h
3889
        jne     invalid_operand
3890
        lods    byte [esi]
3891
        call    convert_register
3892
        mov     [postbyte_register],al
3893
        lods    byte [esi]
3894
        cmp     al,','
3895
        jne     invalid_operand
3896
        xor     al,al
3897
        xchg    al,[operand_size]
3898
        call    operand_autodetect
3899
        lods    byte [esi]
3900
        call    get_size_operator
3901
        cmp     al,10h
3902
        je      lar_reg_reg
3903
        cmp     al,'['
3904
        jne     invalid_operand
3905
        call    get_address
3906
        mov     al,[operand_size]
3907
        or      al,al
3908
        jz      lar_reg_mem
3909
        cmp     al,2
3910
        jne     invalid_operand_size
3911
      lar_reg_mem:
31 halyavin 3912
        call    store_instruction
109 heavyiron 3913
        jmp     instruction_assembled
3914
      lar_reg_reg:
31 halyavin 3915
        lods    byte [esi]
109 heavyiron 3916
        call    convert_register
3917
        cmp     ah,2
3918
        jne     invalid_operand_size
3919
        mov     bl,al
3920
        call    store_nomem_instruction
3921
        jmp     instruction_assembled
3922
invlpg_instruction:
31 halyavin 3923
        mov     [base_code],0Fh
109 heavyiron 3924
        mov     [extended_code],1
3925
        mov     [postbyte_register],7
3926
        lods    byte [esi]
3927
        call    get_size_operator
3928
        cmp     al,'['
3929
        jne     invalid_operand
3930
        call    get_address
3931
        call    store_instruction
3932
        jmp     instruction_assembled
3933
swapgs_instruction:
31 halyavin 3934
        mov     [base_code],0Fh
109 heavyiron 3935
        mov     [extended_code],1
3936
        mov     [postbyte_register],7
3937
        mov     bl,al
3938
        call    store_nomem_instruction
3939
        jmp     instruction_assembled
3940
31 halyavin 3941
 
3942
        mov     [base_code],0Fh
109 heavyiron 3943
        mov     [extended_code],al
3944
        lods    byte [esi]
3945
        call    get_size_operator
3946
        cmp     al,10h
3947
        je      basic_486_reg
3948
        cmp     al,'['
3949
        jne     invalid_operand
3950
        call    get_address
3951
        push    edx bx cx
3952
        lods    byte [esi]
3953
        cmp     al,','
3954
        jne     invalid_operand
3955
        lods    byte [esi]
3956
        call    get_size_operator
3957
        cmp     al,10h
3958
        jne     invalid_operand
3959
        lods    byte [esi]
3960
        call    convert_register
3961
        mov     [postbyte_register],al
3962
        pop     cx bx edx
3963
        mov     al,ah
3964
        cmp     al,1
3965
        je      basic_486_mem_reg_8bit
3966
        call    operand_autodetect
3967
        inc     [extended_code]
3968
      basic_486_mem_reg_8bit:
31 halyavin 3969
        call    store_instruction
109 heavyiron 3970
        jmp     instruction_assembled
3971
      basic_486_reg:
31 halyavin 3972
        lods    byte [esi]
109 heavyiron 3973
        call    convert_register
3974
        mov     [postbyte_register],al
3975
        lods    byte [esi]
3976
        cmp     al,','
3977
        jne     invalid_operand
3978
        lods    byte [esi]
3979
        call    get_size_operator
3980
        cmp     al,10h
3981
        jne     invalid_operand
3982
        lods    byte [esi]
3983
        call    convert_register
3984
        mov     bl,[postbyte_register]
3985
        mov     [postbyte_register],al
3986
        mov     al,ah
3987
        cmp     al,1
3988
        je      basic_486_reg_reg_8bit
3989
        call    operand_autodetect
3990
        inc     [extended_code]
3991
      basic_486_reg_reg_8bit:
31 halyavin 3992
        call    store_nomem_instruction
109 heavyiron 3993
        jmp     instruction_assembled
3994
bswap_instruction:
31 halyavin 3995
        lods    byte [esi]
109 heavyiron 3996
        call    get_size_operator
3997
        cmp     al,10h
3998
        jne     invalid_operand
3999
        lods    byte [esi]
4000
        call    convert_register
4001
        test    al,1000b
4002
        jz      bswap_reg_code_ok
4003
        or      [rex_prefix],41h
4004
        and     al,111b
4005
      bswap_reg_code_ok:
4006
        add     al,0C8h
4007
        mov     [extended_code],al
4008
        mov     [base_code],0Fh
4009
        cmp     ah,8
4010
        je      bswap_reg64
4011
        cmp     ah,4
4012
        jne     invalid_operand_size
4013
        call    operand_32bit
4014
        call    store_instruction_code
4015
        jmp     instruction_assembled
4016
      bswap_reg64:
31 halyavin 4017
        call    operand_64bit
109 heavyiron 4018
        call    store_instruction_code
4019
        jmp     instruction_assembled
4020
cmpxchgx_instruction:
31 halyavin 4021
        mov     [base_code],0Fh
109 heavyiron 4022
        mov     [extended_code],0C7h
4023
        mov     [postbyte_register],al
4024
        lods    byte [esi]
4025
        call    get_size_operator
4026
        cmp     al,'['
4027
        jne     invalid_operand
4028
        call    get_address
4029
        mov     ah,1
4030
        xchg    [postbyte_register],ah
4031
        mov     al,[operand_size]
4032
        or      al,al
4033
        jz      cmpxchgx_size_ok
4034
        cmp     al,ah
4035
        jne     invalid_operand_size
4036
      cmpxchgx_size_ok:
31 halyavin 4037
        cmp     ah,16
109 heavyiron 4038
        jne     cmpxchgx_store
4039
        call    operand_64bit
4040
      cmpxchgx_store:
31 halyavin 4041
        call    store_instruction
109 heavyiron 4042
        jmp     instruction_assembled
4043
31 halyavin 4044
 
4045
        mov     [postbyte_register],al
109 heavyiron 4046
        mov     [base_code],0D8h
4047
        lods    byte [esi]
4048
        call    get_size_operator
4049
        cmp     al,10h
4050
        je      basic_fpu_streg
4051
        cmp     al,'['
4052
        je      basic_fpu_mem
4053
        dec     esi
4054
        mov     ah,[postbyte_register]
4055
        cmp     ah,2
4056
        jb      invalid_operand
4057
        cmp     ah,3
4058
        ja      invalid_operand
4059
        mov     bl,1
4060
        call    store_nomem_instruction
4061
        jmp     instruction_assembled
4062
      basic_fpu_mem:
31 halyavin 4063
        call    get_address
109 heavyiron 4064
        mov     al,[operand_size]
4065
        cmp     al,4
4066
        je      basic_fpu_mem_32bit
4067
        cmp     al,8
4068
        je      basic_fpu_mem_64bit
4069
        or      al,al
4070
        jnz     invalid_operand_size
4071
        cmp     [error_line],0
4072
        jne     basic_fpu_mem_32bit
4073
        mov     eax,[current_line]
4074
        mov     [error_line],eax
4075
        mov     [error],operand_size_not_specified
4076
      basic_fpu_mem_32bit:
31 halyavin 4077
        call    store_instruction
109 heavyiron 4078
        jmp     instruction_assembled
4079
      basic_fpu_mem_64bit:
31 halyavin 4080
        mov     [base_code],0DCh
109 heavyiron 4081
        call    store_instruction
4082
        jmp     instruction_assembled
4083
      basic_fpu_streg:
31 halyavin 4084
        lods    byte [esi]
109 heavyiron 4085
        call    convert_fpu_register
4086
        mov     bl,al
4087
        mov     ah,[postbyte_register]
4088
        cmp     ah,2
4089
        je      basic_fpu_single_streg
4090
        cmp     ah,3
4091
        je      basic_fpu_single_streg
4092
        or      al,al
4093
        jz      basic_fpu_st0
4094
        test    ah,110b
4095
        jz      basic_fpu_streg_st0
4096
        xor     [postbyte_register],1
4097
      basic_fpu_streg_st0:
31 halyavin 4098
        lods    byte [esi]
109 heavyiron 4099
        cmp     al,','
4100
        jne     invalid_operand
4101
        lods    byte [esi]
4102
        call    get_size_operator
4103
        cmp     al,10h
4104
        jne     invalid_operand
4105
        lods    byte [esi]
4106
        call    convert_fpu_register
4107
        or      al,al
4108
        jnz     invalid_operand
4109
        mov     [base_code],0DCh
4110
        call    store_nomem_instruction
4111
        jmp     instruction_assembled
4112
      basic_fpu_st0:
31 halyavin 4113
        lods    byte [esi]
109 heavyiron 4114
        cmp     al,','
4115
        jne     invalid_operand
4116
        lods    byte [esi]
4117
        call    get_size_operator
4118
        cmp     al,10h
4119
        jne     invalid_operand
4120
        lods    byte [esi]
4121
        call    convert_fpu_register
4122
        mov     bl,al
4123
      basic_fpu_single_streg:
31 halyavin 4124
        mov     [base_code],0D8h
109 heavyiron 4125
        call    store_nomem_instruction
4126
        jmp     instruction_assembled
4127
simple_fpu_instruction:
31 halyavin 4128
        mov     ah,al
109 heavyiron 4129
        or      ah,11000000b
4130
        mov     al,0D9h
4131
        stos    word [edi]
4132
        jmp     instruction_assembled
4133
fi_instruction:
31 halyavin 4134
        mov     [postbyte_register],al
109 heavyiron 4135
        lods    byte [esi]
4136
        call    get_size_operator
4137
        cmp     al,'['
4138
        jne     invalid_operand
4139
        call    get_address
4140
        mov     al,[operand_size]
4141
        cmp     al,2
4142
        je      fi_mem_16bit
4143
        cmp     al,4
4144
        je      fi_mem_32bit
4145
        or      al,al
4146
        jnz     invalid_operand_size
4147
        cmp     [error_line],0
4148
        jne     fi_mem_32bit
4149
        mov     eax,[current_line]
4150
        mov     [error_line],eax
4151
        mov     [error],operand_size_not_specified
4152
      fi_mem_32bit:
31 halyavin 4153
        mov     [base_code],0DAh
109 heavyiron 4154
        call    store_instruction
4155
        jmp     instruction_assembled
4156
      fi_mem_16bit:
31 halyavin 4157
        mov     [base_code],0DEh
109 heavyiron 4158
        call    store_instruction
4159
        jmp     instruction_assembled
4160
fld_instruction:
31 halyavin 4161
        mov     [postbyte_register],al
109 heavyiron 4162
        lods    byte [esi]
4163
        call    get_size_operator
4164
        cmp     al,10h
4165
        je      fld_streg
4166
        cmp     al,'['
4167
        jne     invalid_operand
4168
        call    get_address
4169
        mov     al,[operand_size]
4170
        cmp     al,4
4171
        je      fld_mem_32bit
4172
        cmp     al,8
4173
        je      fld_mem_64bit
4174
        cmp     al,10
4175
        je      fld_mem_80bit
4176
        or      al,al
4177
        jnz     invalid_operand_size
4178
        cmp     [error_line],0
4179
        jne     fld_mem_32bit
4180
        mov     eax,[current_line]
4181
        mov     [error_line],eax
4182
        mov     [error],operand_size_not_specified
4183
      fld_mem_32bit:
31 halyavin 4184
        mov     [base_code],0D9h
109 heavyiron 4185
        call    store_instruction
4186
        jmp     instruction_assembled
4187
      fld_mem_64bit:
31 halyavin 4188
        mov     [base_code],0DDh
109 heavyiron 4189
        call    store_instruction
4190
        jmp     instruction_assembled
4191
      fld_mem_80bit:
31 halyavin 4192
        mov     al,[postbyte_register]
109 heavyiron 4193
        cmp     al,0
4194
        je      fld_mem_80bit_store
4195
        dec     [postbyte_register]
4196
        cmp     al,3
4197
        je      fld_mem_80bit_store
4198
        jmp     invalid_operand_size
4199
      fld_mem_80bit_store:
31 halyavin 4200
        add     [postbyte_register],5
109 heavyiron 4201
        mov     [base_code],0DBh
4202
        call    store_instruction
4203
        jmp     instruction_assembled
4204
      fld_streg:
31 halyavin 4205
        lods    byte [esi]
109 heavyiron 4206
        call    convert_fpu_register
4207
        mov     bl,al
4208
        cmp     [postbyte_register],2
4209
        jae     fst_streg
4210
        mov     [base_code],0D9h
4211
        call    store_nomem_instruction
4212
        jmp     instruction_assembled
4213
      fst_streg:
31 halyavin 4214
        mov     [base_code],0DDh
109 heavyiron 4215
        call    store_nomem_instruction
4216
        jmp     instruction_assembled
4217
fild_instruction:
31 halyavin 4218
        mov     [postbyte_register],al
109 heavyiron 4219
        lods    byte [esi]
4220
        call    get_size_operator
4221
        cmp     al,'['
4222
        jne     invalid_operand
4223
        call    get_address
4224
        mov     al,[operand_size]
4225
        cmp     al,2
4226
        je      fild_mem_16bit
4227
        cmp     al,4
4228
        je      fild_mem_32bit
4229
        cmp     al,8
4230
        je      fild_mem_64bit
4231
        or      al,al
4232
        jnz     invalid_operand_size
4233
        cmp     [error_line],0
4234
        jne     fild_mem_32bit
4235
        mov     eax,[current_line]
4236
        mov     [error_line],eax
4237
        mov     [error],operand_size_not_specified
4238
      fild_mem_32bit:
31 halyavin 4239
        mov     [base_code],0DBh
109 heavyiron 4240
        call    store_instruction
4241
        jmp     instruction_assembled
4242
      fild_mem_16bit:
31 halyavin 4243
        mov     [base_code],0DFh
109 heavyiron 4244
        call    store_instruction
4245
        jmp     instruction_assembled
4246
      fild_mem_64bit:
31 halyavin 4247
        mov     al,[postbyte_register]
109 heavyiron 4248
        cmp     al,1
4249
        je      fisttp_64bit_store
4250
        jb      fild_mem_64bit_store
4251
        dec     [postbyte_register]
4252
        cmp     al,3
4253
        je      fild_mem_64bit_store
4254
        jmp     invalid_operand_size
4255
      fild_mem_64bit_store:
31 halyavin 4256
        add     [postbyte_register],5
109 heavyiron 4257
        mov     [base_code],0DFh
4258
        call    store_instruction
4259
        jmp     instruction_assembled
4260
      fisttp_64bit_store:
31 halyavin 4261
        mov     [base_code],0DDh
109 heavyiron 4262
        call    store_instruction
4263
        jmp     instruction_assembled
4264
fbld_instruction:
31 halyavin 4265
        mov     [postbyte_register],al
109 heavyiron 4266
        lods    byte [esi]
4267
        call    get_size_operator
4268
        cmp     al,'['
4269
        jne     invalid_operand
4270
        call    get_address
4271
        mov     al,[operand_size]
4272
        or      al,al
4273
        jz      fbld_mem_80bit
4274
        cmp     al,10
4275
        je      fbld_mem_80bit
4276
        jmp     invalid_operand_size
4277
      fbld_mem_80bit:
31 halyavin 4278
        mov     [base_code],0DFh
109 heavyiron 4279
        call    store_instruction
4280
        jmp     instruction_assembled
4281
faddp_instruction:
31 halyavin 4282
        mov     [postbyte_register],al
109 heavyiron 4283
        mov     [base_code],0DEh
4284
        mov     edx,esi
4285
        lods    byte [esi]
4286
        call    get_size_operator
4287
        cmp     al,10h
4288
        je      faddp_streg
4289
        mov     esi,edx
4290
        mov     bl,1
4291
        call    store_nomem_instruction
4292
        jmp     instruction_assembled
4293
      faddp_streg:
31 halyavin 4294
        lods    byte [esi]
109 heavyiron 4295
        call    convert_fpu_register
4296
        mov     bl,al
4297
        lods    byte [esi]
4298
        cmp     al,','
4299
        jne     invalid_operand
4300
        lods    byte [esi]
4301
        call    get_size_operator
4302
        cmp     al,10h
4303
        jne     invalid_operand
4304
        lods    byte [esi]
4305
        call    convert_fpu_register
4306
        or      al,al
4307
        jnz     invalid_operand
4308
        call    store_nomem_instruction
4309
        jmp     instruction_assembled
4310
fcompp_instruction:
31 halyavin 4311
        mov     ax,0D9DEh
109 heavyiron 4312
        stos    word [edi]
4313
        jmp     instruction_assembled
4314
fucompp_instruction:
31 halyavin 4315
        mov     ax,0E9DAh
109 heavyiron 4316
        stos    word [edi]
4317
        jmp     instruction_assembled
4318
fxch_instruction:
31 halyavin 4319
        mov     dx,01D9h
109 heavyiron 4320
        jmp     fpu_single_operand
4321
ffreep_instruction:
31 halyavin 4322
        mov     dx,00DFh
109 heavyiron 4323
        jmp     fpu_single_operand
4324
ffree_instruction:
31 halyavin 4325
        mov     dl,0DDh
109 heavyiron 4326
        mov     dh,al
4327
      fpu_single_operand:
31 halyavin 4328
        mov     ebx,esi
109 heavyiron 4329
        lods    byte [esi]
4330
        call    get_size_operator
4331
        cmp     al,10h
4332
        je      fpu_streg
4333
        or      dh,dh
4334
        jz      invalid_operand
4335
        mov     esi,ebx
4336
        shl     dh,3
4337
        or      dh,11000001b
4338
        mov     ax,dx
4339
        stos    word [edi]
4340
        jmp     instruction_assembled
4341
      fpu_streg:
31 halyavin 4342
        lods    byte [esi]
109 heavyiron 4343
        call    convert_fpu_register
4344
        shl     dh,3
4345
        or      dh,al
4346
        or      dh,11000000b
4347
        mov     ax,dx
4348
        stos    word [edi]
4349
        jmp     instruction_assembled
4350
fstenv_instruction:
31 halyavin 4351
        mov     byte [edi],9Bh
109 heavyiron 4352
        inc     edi
4353
fldenv_instruction:
31 halyavin 4354
        mov     [base_code],0D9h
109 heavyiron 4355
        jmp     fpu_mem
4356
fsave_instruction:
31 halyavin 4357
        mov     byte [edi],9Bh
109 heavyiron 4358
        inc     edi
4359
fnsave_instruction:
31 halyavin 4360
        mov     [base_code],0DDh
109 heavyiron 4361
      fpu_mem:
31 halyavin 4362
        mov     [postbyte_register],al
109 heavyiron 4363
        lods    byte [esi]
4364
        call    get_size_operator
4365
        cmp     al,'['
4366
        jne     invalid_operand
4367
        call    get_address
4368
        cmp     [operand_size],0
4369
        jne     invalid_operand_size
4370
        call    store_instruction
4371
        jmp     instruction_assembled
4372
fstcw_instruction:
31 halyavin 4373
        mov     byte [edi],9Bh
109 heavyiron 4374
        inc     edi
4375
fldcw_instruction:
31 halyavin 4376
        mov     [postbyte_register],al
109 heavyiron 4377
        mov     [base_code],0D9h
4378
        lods    byte [esi]
4379
        call    get_size_operator
4380
        cmp     al,'['
4381
        jne     invalid_operand
4382
        call    get_address
4383
        mov     al,[operand_size]
4384
        or      al,al
4385
        jz      fldcw_mem_16bit
4386
        cmp     al,2
4387
        je      fldcw_mem_16bit
4388
        jmp     invalid_operand_size
4389
      fldcw_mem_16bit:
31 halyavin 4390
        call    store_instruction
109 heavyiron 4391
        jmp     instruction_assembled
4392
fstsw_instruction:
31 halyavin 4393
        mov     al,9Bh
109 heavyiron 4394
        stos    byte [edi]
4395
fnstsw_instruction:
31 halyavin 4396
        mov     [base_code],0DDh
109 heavyiron 4397
        mov     [postbyte_register],7
4398
        lods    byte [esi]
4399
        call    get_size_operator
4400
        cmp     al,10h
4401
        je      fstsw_reg
4402
        cmp     al,'['
4403
        jne     invalid_operand
4404
        call    get_address
4405
        mov     al,[operand_size]
4406
        or      al,al
4407
        jz      fstsw_mem_16bit
4408
        cmp     al,2
4409
        je      fstsw_mem_16bit
4410
        jmp     invalid_operand_size
4411
      fstsw_mem_16bit:
31 halyavin 4412
        call    store_instruction
109 heavyiron 4413
        jmp     instruction_assembled
4414
      fstsw_reg:
31 halyavin 4415
        lods    byte [esi]
109 heavyiron 4416
        call    convert_register
4417
        cmp     ax,0200h
4418
        jne     invalid_operand
4419
        mov     ax,0E0DFh
4420
        stos    word [edi]
4421
        jmp     instruction_assembled
4422
finit_instruction:
31 halyavin 4423
        mov     byte [edi],9Bh
109 heavyiron 4424
        inc     edi
4425
fninit_instruction:
31 halyavin 4426
        mov     ah,al
109 heavyiron 4427
        mov     al,0DBh
4428
        stos    word [edi]
4429
        jmp     instruction_assembled
4430
fcmov_instruction:
31 halyavin 4431
        mov     dh,0DAh
109 heavyiron 4432
        jmp     fcomi_streg
4433
fcomi_instruction:
31 halyavin 4434
        mov     dh,0DBh
109 heavyiron 4435
        jmp     fcomi_streg
4436
fcomip_instruction:
31 halyavin 4437
        mov     dh,0DFh
109 heavyiron 4438
      fcomi_streg:
31 halyavin 4439
        mov     dl,al
109 heavyiron 4440
        lods    byte [esi]
4441
        call    get_size_operator
4442
        cmp     al,10h
4443
        jne     invalid_operand
4444
        lods    byte [esi]
4445
        call    convert_fpu_register
4446
        mov     ah,al
4447
        cmp     byte [esi],','
4448
        je      fcomi_st0_streg
4449
        add     ah,dl
4450
        mov     al,dh
4451
        stos    word [edi]
4452
        jmp     instruction_assembled
4453
      fcomi_st0_streg:
31 halyavin 4454
        or      ah,ah
109 heavyiron 4455
        jnz     invalid_operand
4456
        inc     esi
4457
        lods    byte [esi]
4458
        call    get_size_operator
4459
        cmp     al,10h
4460
        jne     invalid_operand
4461
        lods    byte [esi]
4462
        call    convert_fpu_register
4463
        mov     ah,al
4464
        add     ah,dl
4465
        mov     al,dh
4466
        stos    word [edi]
4467
        jmp     instruction_assembled
4468
31 halyavin 4469
 
4470
        mov     [base_code],0Fh
109 heavyiron 4471
        mov     [extended_code],al
4472
        lods    byte [esi]
4473
        call    get_size_operator
4474
        cmp     al,10h
4475
        jne     invalid_operand
4476
        lods    byte [esi]
4477
        call    convert_mmx_register
4478
        call    make_mmx_prefix
4479
        mov     [postbyte_register],al
4480
        lods    byte [esi]
4481
        cmp     al,','
4482
        jne     invalid_operand
4483
        lods    byte [esi]
4484
        call    get_size_operator
4485
        cmp     al,10h
4486
        je      mmx_mmreg_mmreg
4487
        cmp     al,'['
4488
        jne     invalid_operand
4489
      mmx_mmreg_mem:
31 halyavin 4490
        call    get_address
109 heavyiron 4491
        call    store_instruction
4492
        jmp     instruction_assembled
4493
      mmx_mmreg_mmreg:
31 halyavin 4494
        lods    byte [esi]
109 heavyiron 4495
        call    convert_mmx_register
4496
        mov     bl,al
4497
        call    store_nomem_instruction
4498
        jmp     instruction_assembled
4499
mmx_ps_instruction:
31 halyavin 4500
        mov     [base_code],0Fh
109 heavyiron 4501
        mov     [extended_code],al
4502
        lods    byte [esi]
4503
        call    get_size_operator
4504
        cmp     al,10h
4505
        jne     invalid_operand
4506
        lods    byte [esi]
4507
        call    convert_mmx_register
4508
        call    make_mmx_prefix
4509
        mov     [postbyte_register],al
4510
        lods    byte [esi]
4511
        cmp     al,','
4512
        jne     invalid_operand
4513
        mov     [operand_size],0
4514
        lods    byte [esi]
4515
        call    get_size_operator
4516
        cmp     al,10h
4517
        je      mmx_mmreg_mmreg
4518
        cmp     al,'('
4519
        je      mmx_ps_mmreg_imm8
4520
        cmp     al,'['
4521
        je      mmx_mmreg_mem
4522
        jmp     invalid_operand
4523
      mmx_ps_mmreg_imm8:
31 halyavin 4524
        call    get_byte_value
109 heavyiron 4525
        mov     byte [value],al
4526
        test    [operand_size],not 1
4527
        jnz     invalid_value
4528
        mov     bl,[extended_code]
4529
        mov     al,bl
4530
        shr     bl,4
4531
        and     al,1111b
4532
        add     al,70h
4533
        mov     [extended_code],al
4534
        sub     bl,0Ch
4535
        shl     bl,1
4536
        xchg    bl,[postbyte_register]
4537
        call    store_nomem_instruction
4538
        mov     al,byte [value]
4539
        stos    byte [edi]
4540
        jmp     instruction_assembled
4541
pextrw_instruction:
31 halyavin 4542
        mov     [base_code],0Fh
109 heavyiron 4543
        mov     [extended_code],al
4544
        lods    byte [esi]
4545
        call    get_size_operator
4546
        cmp     al,10h
4547
        jne     invalid_operand
4548
        lods    byte [esi]
4549
        call    convert_register
4550
        cmp     ah,4
4551
        jnz     invalid_operand_size
4552
        mov     [postbyte_register],al
4553
        mov     [operand_size],0
4554
        lods    byte [esi]
4555
        cmp     al,','
4556
        jne     invalid_operand
4557
        lods    byte [esi]
4558
        call    get_size_operator
4559
        cmp     al,10h
4560
        jne     invalid_operand
4561
        lods    byte [esi]
4562
        call    convert_mmx_register
4563
        mov     bl,al
4564
        call    make_mmx_prefix
4565
        cmp     [extended_code],0C5h
4566
        je      mmx_nomem_imm8
4567
        call    store_nomem_instruction
4568
        jmp     instruction_assembled
4569
      mmx_imm8:
31 halyavin 4570
        push    bx cx edx
109 heavyiron 4571
        mov     [operand_size],0
4572
        lods    byte [esi]
4573
        cmp     al,','
4574
        jne     invalid_operand
4575
        lods    byte [esi]
4576
        call    get_size_operator
4577
        test    ah,not 1
4578
        jnz     invalid_operand_size
4579
        cmp     al,'('
4580
        jne     invalid_operand
4581
        call    get_byte_value
4582
        mov     byte [value],al
4583
        pop     edx cx bx
4584
        call    store_instruction_with_imm8
4585
        jmp     instruction_assembled
4586
      mmx_nomem_imm8:
31 halyavin 4587
        call    store_nomem_instruction
109 heavyiron 4588
        mov     [operand_size],0
4589
        lods    byte [esi]
4590
        cmp     al,','
4591
        jne     invalid_operand
4592
        lods    byte [esi]
4593
        call    get_size_operator
4594
        test    ah,not 1
4595
        jnz     invalid_operand_size
4596
        cmp     al,'('
4597
        jne     invalid_operand
4598
        call    get_byte_value
4599
        stosb
4600
        jmp     instruction_assembled
4601
pinsrw_instruction:
31 halyavin 4602
        mov     [extended_code],al
109 heavyiron 4603
        mov     [base_code],0Fh
4604
        lods    byte [esi]
4605
        call    get_size_operator
4606
        cmp     al,10h
4607
        jne     invalid_operand
4608
        lods    byte [esi]
4609
        call    convert_mmx_register
4610
        call    make_mmx_prefix
4611
        mov     [postbyte_register],al
4612
        mov     [operand_size],0
4613
        lods    byte [esi]
4614
        cmp     al,','
4615
        jne     invalid_operand
4616
        lods    byte [esi]
4617
        call    get_size_operator
4618
        cmp     al,10h
4619
        je      pinsrw_mmreg_reg
4620
        cmp     al,'['
4621
        jne     invalid_operand
4622
        call    get_address
4623
        cmp     [operand_size],0
4624
        je      mmx_imm8
4625
        cmp     [operand_size],2
4626
        jne     invalid_operand_size
4627
        jmp     mmx_imm8
4628
      pinsrw_mmreg_reg:
31 halyavin 4629
        lods    byte [esi]
109 heavyiron 4630
        call    convert_register
4631
        cmp     ah,4
4632
        jne     invalid_operand_size
4633
        mov     bl,al
4634
        jmp     mmx_nomem_imm8
4635
pshufw_instruction:
31 halyavin 4636
        mov     [mmx_size],8
109 heavyiron 4637
        mov     [operand_prefix],al
4638
        jmp     pshuf_instruction
4639
pshufd_instruction:
31 halyavin 4640
        mov     [mmx_size],16
109 heavyiron 4641
        mov     [operand_prefix],al
4642
      pshuf_instruction:
31 halyavin 4643
        mov     [base_code],0Fh
109 heavyiron 4644
        mov     [extended_code],70h
4645
        lods    byte [esi]
4646
        call    get_size_operator
4647
        cmp     al,10h
4648
        jne     invalid_operand
4649
        lods    byte [esi]
4650
        call    convert_mmx_register
4651
        cmp     ah,[mmx_size]
4652
        jne     invalid_operand_size
4653
        mov     [postbyte_register],al
4654
        lods    byte [esi]
4655
        cmp     al,','
4656
        jne     invalid_operand
4657
        lods    byte [esi]
4658
        call    get_size_operator
4659
        cmp     al,10h
4660
        je      pshuf_mmreg_mmreg
4661
        cmp     al,'['
4662
        jne     invalid_operand
4663
        call    get_address
4664
        jmp     mmx_imm8
4665
      pshuf_mmreg_mmreg:
31 halyavin 4666
        lods    byte [esi]
109 heavyiron 4667
        call    convert_mmx_register
4668
        mov     bl,al
4669
        jmp     mmx_nomem_imm8
4670
movd_instruction:
31 halyavin 4671
        mov     [base_code],0Fh
109 heavyiron 4672
        mov     [extended_code],7Eh
4673
        lods    byte [esi]
4674
        call    get_size_operator
4675
        cmp     al,10h
4676
        je      movd_reg
4677
        cmp     al,'['
4678
        jne     invalid_operand
4679
        call    get_address
4680
        test    [operand_size],not 4
4681
        jnz     invalid_operand_size
4682
        mov     [operand_size],0
4683
        lods    byte [esi]
4684
        cmp     al,','
4685
        jne     invalid_operand
4686
        lods    byte [esi]
4687
        call    get_size_operator
4688
        cmp     al,10h
4689
        jne     invalid_operand
4690
        lods    byte [esi]
4691
        call    convert_mmx_register
4692
        call    make_mmx_prefix
4693
        mov     [postbyte_register],al
4694
        call    store_instruction
4695
        jmp     instruction_assembled
4696
      movd_reg:
31 halyavin 4697
        lods    byte [esi]
109 heavyiron 4698
        cmp     al,0B0h
4699
        jae     movd_mmreg
4700
        call    convert_register
4701
        cmp     ah,4
4702
        jne     invalid_operand_size
4703
        mov     [operand_size],0
4704
        mov     bl,al
4705
        lods    byte [esi]
4706
        cmp     al,','
4707
        jne     invalid_operand
4708
        lods    byte [esi]
4709
        call    get_size_operator
4710
        cmp     al,10h
4711
        jne     invalid_operand
4712
        lods    byte [esi]
4713
        call    convert_mmx_register
4714
        mov     [postbyte_register],al
4715
        call    make_mmx_prefix
4716
        call    store_nomem_instruction
4717
        jmp     instruction_assembled
4718
      movd_mmreg:
31 halyavin 4719
        mov     [extended_code],6Eh
109 heavyiron 4720
        call    convert_mmx_register
4721
        call    make_mmx_prefix
4722
        mov     [postbyte_register],al
4723
        mov     [operand_size],0
4724
        lods    byte [esi]
4725
        cmp     al,','
4726
        jne     invalid_operand
4727
        lods    byte [esi]
4728
        call    get_size_operator
4729
        cmp     al,10h
4730
        je      movd_mmreg_reg
4731
        cmp     al,'['
4732
        jne     invalid_operand
4733
        call    get_address
4734
        test    [operand_size],not 4
4735
        jnz     invalid_operand_size
4736
        call    store_instruction
4737
        jmp     instruction_assembled
4738
      movd_mmreg_reg:
31 halyavin 4739
        lods    byte [esi]
109 heavyiron 4740
        call    convert_register
4741
        cmp     ah,4
4742
        jne     invalid_operand_size
4743
        mov     bl,al
4744
        call    store_nomem_instruction
4745
        jmp     instruction_assembled
4746
      make_mmx_prefix:
31 halyavin 4747
        cmp     [operand_size],16
109 heavyiron 4748
        jne     no_mmx_prefix
4749
        mov     [operand_prefix],66h
4750
      no_mmx_prefix:
31 halyavin 4751
        ret
109 heavyiron 4752
movq_instruction:
31 halyavin 4753
        mov     [base_code],0Fh
109 heavyiron 4754
        lods    byte [esi]
4755
        call    get_size_operator
4756
        cmp     al,10h
4757
        je      movq_reg
4758
        cmp     al,'['
4759
        jne     invalid_operand
4760
        call    get_address
4761
        test    [operand_size],not 8
4762
        jnz     invalid_operand_size
4763
        mov     [operand_size],0
4764
        lods    byte [esi]
4765
        cmp     al,','
4766
        jne     invalid_operand
4767
        lods    byte [esi]
4768
        cmp     al,10h
4769
        jne     invalid_operand
4770
        lods    byte [esi]
4771
        call    convert_mmx_register
4772
        mov     [postbyte_register],al
4773
        cmp     ah,16
4774
        je      movq_mem_xmmreg
4775
        mov     [extended_code],7Fh
4776
        call    store_instruction
4777
        jmp     instruction_assembled
4778
     movq_mem_xmmreg:
31 halyavin 4779
        mov     [extended_code],0D6h
109 heavyiron 4780
        mov     [operand_prefix],66h
4781
        call    store_instruction
4782
        jmp     instruction_assembled
4783
     movq_reg:
31 halyavin 4784
        lods    byte [esi]
109 heavyiron 4785
        cmp     al,0B0h
4786
        jae     movq_mmreg
4787
        call    convert_register
4788
        cmp     ah,8
4789
        jne     invalid_operand_size
4790
        mov     bl,al
4791
        lods    byte [esi]
4792
        cmp     al,','
4793
        jne     invalid_operand
4794
        lods    byte [esi]
4795
        call    get_size_operator
4796
        cmp     al,10h
4797
        jne     invalid_operand
4798
        lods    byte [esi]
4799
        call    convert_mmx_register
4800
        mov     [postbyte_register],al
4801
        call    make_mmx_prefix
4802
        mov     [extended_code],7Eh
4803
        call    operand_64bit
4804
        call    store_nomem_instruction
4805
        jmp     instruction_assembled
4806
     movq_mmreg:
31 halyavin 4807
        call    convert_mmx_register
109 heavyiron 4808
        mov     [postbyte_register],al
4809
        mov     [extended_code],6Fh
4810
        mov     [mmx_size],ah
4811
        cmp     ah,16
4812
        jne     movq_mmreg_
4813
        mov     [extended_code],7Eh
4814
        mov     [operand_prefix],0F3h
4815
      movq_mmreg_:
31 halyavin 4816
        lods    byte [esi]
109 heavyiron 4817
        cmp     al,','
4818
        jne     invalid_operand
4819
        lods    byte [esi]
4820
        call    get_size_operator
4821
        cmp     al,10h
4822
        je      movq_mmreg_reg
4823
        call    get_address
4824
        test    [operand_size],not 8
4825
        jnz     invalid_operand_size
4826
        call    store_instruction
4827
        jmp     instruction_assembled
4828
      movq_mmreg_reg:
31 halyavin 4829
        lods    byte [esi]
109 heavyiron 4830
        cmp     al,0B0h
4831
        jae     movq_mmreg_mmreg
4832
        mov     [operand_size],0
4833
        call    convert_register
4834
        cmp     ah,8
4835
        jne     invalid_operand_size
4836
        mov     [extended_code],6Eh
4837
        mov     [operand_prefix],0
4838
        mov     bl,al
4839
        cmp     [mmx_size],16
4840
        jne     movq_mmreg_reg_store
4841
        mov     [operand_prefix],66h
4842
      movq_mmreg_reg_store:
4843
        call    operand_64bit
4844
        call    store_nomem_instruction
4845
        jmp     instruction_assembled
4846
      movq_mmreg_mmreg:
31 halyavin 4847
        call    convert_mmx_register
109 heavyiron 4848
        mov     bl,al
4849
        call    store_nomem_instruction
4850
        jmp     instruction_assembled
4851
movdq_instruction:
31 halyavin 4852
        mov     [operand_prefix],al
109 heavyiron 4853
        mov     [base_code],0Fh
4854
        mov     [extended_code],6Fh
4855
        lods    byte [esi]
4856
        call    get_size_operator
4857
        cmp     al,10h
4858
        je      movdq_mmreg
4859
        cmp     al,'['
4860
        jne     invalid_operand
4861
        call    get_address
4862
        lods    byte [esi]
4863
        cmp     al,','
4864
        jne     invalid_operand
4865
        lods    byte [esi]
4866
        call    get_size_operator
4867
        cmp     al,10h
4868
        jne     invalid_operand
4869
        lods    byte [esi]
4870
        call    convert_mmx_register
4871
        cmp     ah,16
4872
        jne     invalid_operand_size
4873
        mov     [postbyte_register],al
4874
        mov     [extended_code],7Fh
4875
        call    store_instruction
4876
        jmp     instruction_assembled
4877
      movdq_mmreg:
31 halyavin 4878
        lods    byte [esi]
109 heavyiron 4879
        call    convert_mmx_register
4880
        cmp     ah,16
4881
        jne     invalid_operand_size
4882
        mov     [postbyte_register],al
4883
        lods    byte [esi]
4884
        cmp     al,','
4885
        jne     invalid_operand
4886
        lods    byte [esi]
4887
        call    get_size_operator
4888
        cmp     al,10h
4889
        je      movdq_mmreg_mmreg
4890
        cmp     al,'['
4891
        jne     invalid_operand
4892
        call    get_address
4893
        call    store_instruction
4894
        jmp     instruction_assembled
4895
      movdq_mmreg_mmreg:
31 halyavin 4896
        lods    byte [esi]
109 heavyiron 4897
        call    convert_mmx_register
4898
        cmp     ah,16
4899
        jne     invalid_operand_size
4900
        mov     bl,al
4901
        call    store_nomem_instruction
4902
        jmp     instruction_assembled
4903
lddqu_instruction:
31 halyavin 4904
        lods    byte [esi]
109 heavyiron 4905
        call    get_size_operator
4906
        cmp     al,10h
4907
        jne     invalid_operand
4908
        lods    byte [esi]
4909
        call    convert_mmx_register
4910
        cmp     ah,16
4911
        jne     invalid_operand_size
4912
        push    eax
4913
        lods    byte [esi]
4914
        cmp     al,','
4915
        jne     invalid_operand
4916
        lods    byte [esi]
4917
        call    get_size_operator
4918
        cmp     al,'['
4919
        jne     invalid_operand
4920
        call    get_address
4921
        pop     eax
4922
        mov     [postbyte_register],al
4923
        mov     [operand_prefix],0F2h
4924
        mov     [base_code],0Fh
4925
        mov     [extended_code],0F0h
4926
        call    store_instruction
4927
        jmp     instruction_assembled
4928
movq2dq_instruction:
31 halyavin 4929
        lods    byte [esi]
109 heavyiron 4930
        call    get_size_operator
4931
        cmp     al,10h
4932
        jne     invalid_operand
4933
        lods    byte [esi]
4934
        call    convert_mmx_register
4935
        cmp     ah,16
4936
        jne     invalid_operand_size
4937
        mov     [postbyte_register],al
4938
        mov     [operand_size],0
4939
        lods    byte [esi]
4940
        cmp     al,','
4941
        jne     invalid_operand
4942
        lods    byte [esi]
4943
        call    get_size_operator
4944
        cmp     al,10h
4945
        jne     invalid_operand
4946
        lods    byte [esi]
4947
        call    convert_mmx_register
4948
        cmp     ah,8
4949
        jne     invalid_operand_size
4950
        mov     bl,al
4951
        mov     [operand_prefix],0F3h
4952
        mov     [base_code],0Fh
4953
        mov     [extended_code],0D6h
4954
        call    store_nomem_instruction
4955
        jmp     instruction_assembled
4956
movdq2q_instruction:
31 halyavin 4957
        lods    byte [esi]
109 heavyiron 4958
        call    get_size_operator
4959
        cmp     al,10h
4960
        jne     invalid_operand
4961
        lods    byte [esi]
4962
        call    convert_mmx_register
4963
        cmp     ah,8
4964
        jne     invalid_operand_size
4965
        mov     [postbyte_register],al
4966
        mov     [operand_size],0
4967
        lods    byte [esi]
4968
        cmp     al,','
4969
        jne     invalid_operand
4970
        lods    byte [esi]
4971
        call    get_size_operator
4972
        cmp     al,10h
4973
        jne     invalid_operand
4974
        lods    byte [esi]
4975
        call    convert_mmx_register
4976
        cmp     ah,16
4977
        jne     invalid_operand_size
4978
        mov     bl,al
4979
        mov     [operand_prefix],0F2h
4980
        mov     [base_code],0Fh
4981
        mov     [extended_code],0D6h
4982
        call    store_nomem_instruction
4983
        jmp     instruction_assembled
4984
31 halyavin 4985
 
4986
        mov     [mmx_size],16
109 heavyiron 4987
        jmp     sse_instruction
4988
sse_pd_instruction:
31 halyavin 4989
        mov     [mmx_size],16
109 heavyiron 4990
        mov     [operand_prefix],66h
4991
        jmp     sse_instruction
4992
sse_ss_instruction:
31 halyavin 4993
        mov     [mmx_size],4
109 heavyiron 4994
        mov     [operand_prefix],0F3h
4995
        jmp     sse_instruction
4996
sse_sd_instruction:
31 halyavin 4997
        mov     [mmx_size],8
109 heavyiron 4998
        mov     [operand_prefix],0F2h
4999
        jmp     sse_instruction
5000
comiss_instruction:
31 halyavin 5001
        mov     [mmx_size],4
109 heavyiron 5002
        jmp     sse_instruction
5003
comisd_instruction:
31 halyavin 5004
        mov     [mmx_size],8
109 heavyiron 5005
        mov     [operand_prefix],66h
5006
        jmp     sse_instruction
5007
cvtps2pd_instruction:
31 halyavin 5008
        mov     [mmx_size],8
109 heavyiron 5009
        jmp     sse_instruction
5010
cvtpd2dq_instruction:
31 halyavin 5011
        mov     [mmx_size],16
109 heavyiron 5012
        mov     [operand_prefix],0F2h
5013
        jmp     sse_instruction
5014
cvtdq2pd_instruction:
31 halyavin 5015
        mov     [mmx_size],16
109 heavyiron 5016
        mov     [operand_prefix],0F3h
5017
sse_instruction:
31 halyavin 5018
        mov     [base_code],0Fh
109 heavyiron 5019
        mov     [extended_code],al
5020
        lods    byte [esi]
5021
        call    get_size_operator
5022
        cmp     al,10h
5023
        jne     invalid_operand
5024
      sse_xmmreg:
31 halyavin 5025
        lods    byte [esi]
109 heavyiron 5026
        call    convert_mmx_register
5027
        cmp     ah,16
5028
        jne     invalid_operand_size
5029
      sse_reg:
31 halyavin 5030
        mov     [postbyte_register],al
109 heavyiron 5031
        mov     [operand_size],0
5032
        lods    byte [esi]
5033
        cmp     al,','
5034
        jne     invalid_operand
5035
        lods    byte [esi]
5036
        call    get_size_operator
5037
        cmp     al,10h
5038
        je      sse_xmmreg_xmmreg
5039
      sse_reg_mem:
31 halyavin 5040
        cmp     al,'['
109 heavyiron 5041
        jne     invalid_operand
5042
        call    get_address
5043
        cmp     [operand_size],0
5044
        je      sse_mem_size_ok
5045
        mov     al,[mmx_size]
5046
        cmp     [operand_size],al
5047
        jne     invalid_operand_size
5048
      sse_mem_size_ok:
31 halyavin 5049
        cmp     [extended_code],0C6h
109 heavyiron 5050
        je      mmx_imm8
5051
        call    store_instruction
5052
        jmp     instruction_assembled
5053
      sse_xmmreg_xmmreg:
31 halyavin 5054
        cmp     [operand_prefix],66h
109 heavyiron 5055
        jne     sse_xmmreg_xmmreg_ok
5056
        cmp     [extended_code],12h
5057
        je      invalid_operand
5058
        cmp     [extended_code],16h
5059
        je      invalid_operand
5060
      sse_xmmreg_xmmreg_ok:
31 halyavin 5061
        lods    byte [esi]
109 heavyiron 5062
        call    convert_mmx_register
5063
        cmp     ah,16
5064
        jne     invalid_operand_size
5065
        mov     bl,al
5066
        cmp     [extended_code],0C6h
5067
        je      mmx_nomem_imm8
5068
        call    store_nomem_instruction
5069
        jmp     instruction_assembled
5070
ps_dq_instruction:
31 halyavin 5071
        mov     [postbyte_register],al
109 heavyiron 5072
        mov     [operand_prefix],66h
5073
        mov     [base_code],0Fh
5074
        mov     [extended_code],73h
5075
        lods    byte [esi]
5076
        call    get_size_operator
5077
        cmp     al,10h
5078
        jne     invalid_operand
5079
        lods    byte [esi]
5080
        call    convert_mmx_register
5081
        cmp     ah,16
5082
        jne     invalid_operand_size
5083
        mov     bl,al
5084
        jmp     mmx_nomem_imm8
5085
movpd_instruction:
31 halyavin 5086
        mov     [operand_prefix],66h
109 heavyiron 5087
movps_instruction:
31 halyavin 5088
        mov     [base_code],0Fh
109 heavyiron 5089
        mov     [extended_code],al
5090
        mov     [mmx_size],16
5091
        jmp     sse_mov_instruction
5092
movss_instruction:
31 halyavin 5093
        mov     [mmx_size],4
109 heavyiron 5094
        mov     [operand_prefix],0F3h
5095
        jmp     sse_movs
5096
movsd_instruction:
31 halyavin 5097
        mov     al,0A5h
109 heavyiron 5098
        mov     ah,[esi]
5099
        or      ah,ah
5100
        jz      simple_instruction_32bit
5101
        cmp     ah,0Fh
5102
        je      simple_instruction_32bit
5103
        mov     [mmx_size],8
5104
        mov     [operand_prefix],0F2h
5105
      sse_movs:
31 halyavin 5106
        mov     [base_code],0Fh
109 heavyiron 5107
        mov     [extended_code],10h
5108
        jmp     sse_mov_instruction
5109
sse_mov_instruction:
31 halyavin 5110
        lods    byte [esi]
109 heavyiron 5111
        call    get_size_operator
5112
        cmp     al,10h
5113
        je      sse_xmmreg
5114
      sse_mem:
31 halyavin 5115
        cmp     al,'['
109 heavyiron 5116
        jne     invalid_operand
5117
        inc     [extended_code]
5118
        call    get_address
5119
        cmp     [operand_size],0
5120
        je      sse_mem_xmmreg
5121
        mov     al,[mmx_size]
5122
        cmp     [operand_size],al
5123
        jne     invalid_operand_size
5124
        mov     [operand_size],0
5125
      sse_mem_xmmreg:
31 halyavin 5126
        lods    byte [esi]
109 heavyiron 5127
        cmp     al,','
5128
        jne     invalid_operand
5129
        lods    byte [esi]
5130
        call    get_size_operator
5131
        cmp     al,10h
5132
        jne     invalid_operand
5133
        lods    byte [esi]
5134
        call    convert_mmx_register
5135
        cmp     ah,16
5136
        jne     invalid_operand_size
5137
        mov     [postbyte_register],al
5138
        call    store_instruction
5139
        jmp     instruction_assembled
5140
movlpd_instruction:
31 halyavin 5141
        mov     [operand_prefix],66h
109 heavyiron 5142
movlps_instruction:
31 halyavin 5143
        mov     [base_code],0Fh
109 heavyiron 5144
        mov     [extended_code],al
5145
        mov     [mmx_size],8
5146
        lods    byte [esi]
5147
        call    get_size_operator
5148
        cmp     al,10h
5149
        jne     sse_mem
5150
        lods    byte [esi]
5151
        call    convert_mmx_register
5152
        cmp     ah,16
5153
        jne     invalid_operand_size
5154
        mov     [postbyte_register],al
5155
        mov     [operand_size],0
5156
        lods    byte [esi]
5157
        cmp     al,','
5158
        jne     invalid_operand
5159
        lods    byte [esi]
5160
        call    get_size_operator
5161
        jmp     sse_reg_mem
5162
movhlps_instruction:
31 halyavin 5163
        mov     [base_code],0Fh
109 heavyiron 5164
        mov     [extended_code],al
5165
        mov     [mmx_size],0
5166
        lods    byte [esi]
5167
        call    get_size_operator
5168
        cmp     al,10h
5169
        jne     invalid_operand
5170
        lods    byte [esi]
5171
        call    convert_mmx_register
5172
        cmp     ah,16
5173
        jne     invalid_operand_size
5174
        mov     [postbyte_register],al
5175
        lods    byte [esi]
5176
        cmp     al,','
5177
        jne     invalid_operand
5178
        lods    byte [esi]
5179
        call    get_size_operator
5180
        cmp     al,10h
5181
        je      sse_xmmreg_xmmreg_ok
5182
        jmp     invalid_operand
5183
maskmovq_instruction:
31 halyavin 5184
        mov     cl,8
109 heavyiron 5185
        jmp     maskmov_instruction
5186
maskmovdqu_instruction:
31 halyavin 5187
        mov     cl,16
109 heavyiron 5188
        mov     [operand_prefix],66h
5189
      maskmov_instruction:
31 halyavin 5190
        mov     [base_code],0Fh
109 heavyiron 5191
        mov     [extended_code],0F7h
5192
        lods    byte [esi]
5193
        call    get_size_operator
5194
        cmp     al,10h
5195
        jne     invalid_operand
5196
        lods    byte [esi]
5197
        call    convert_mmx_register
5198
        cmp     ah,cl
5199
        jne     invalid_operand_size
5200
        mov     [postbyte_register],al
5201
        lods    byte [esi]
5202
        cmp     al,','
5203
        jne     invalid_operand
5204
        lods    byte [esi]
5205
        call    get_size_operator
5206
        cmp     al,10h
5207
        jne     invalid_operand
5208
        lods    byte [esi]
5209
        call    convert_mmx_register
5210
        mov     bl,al
5211
        call    store_nomem_instruction
5212
        jmp     instruction_assembled
5213
movmskpd_instruction:
31 halyavin 5214
        mov     [operand_prefix],66h
109 heavyiron 5215
movmskps_instruction:
31 halyavin 5216
        mov     [base_code],0Fh
109 heavyiron 5217
        mov     [extended_code],50h
5218
        lods    byte [esi]
5219
        call    get_size_operator
5220
        cmp     al,10h
5221
        jne     invalid_operand
5222
        lods    byte [esi]
5223
        call    convert_register
5224
        cmp     ah,4
5225
        jne     invalid_operand_size
5226
        mov     [operand_size],0
5227
        mov     [postbyte_register],al
5228
        lods    byte [esi]
5229
        cmp     al,','
5230
        jne     invalid_operand
5231
        lods    byte [esi]
5232
        call    get_size_operator
5233
        cmp     al,10h
5234
        jne     invalid_operand
5235
        lods    byte [esi]
5236
        call    convert_mmx_register
5237
        cmp     ah,16
5238
        jne     invalid_operand_size
5239
        mov     bl,al
5240
        call    store_nomem_instruction
5241
        jmp     instruction_assembled
5242
cmppd_instruction:
31 halyavin 5243
        mov     [operand_prefix],66h
109 heavyiron 5244
cmpps_instruction:
31 halyavin 5245
        mov     [base_code],0Fh
109 heavyiron 5246
        mov     [extended_code],0C2h
5247
        mov     [mmx_size],16
5248
        mov     byte [value],-1
5249
        jmp     sse_cmp_instruction
5250
cmp_pd_instruction:
31 halyavin 5251
        mov     [operand_prefix],66h
109 heavyiron 5252
cmp_ps_instruction:
31 halyavin 5253
        mov     [base_code],0Fh
109 heavyiron 5254
        mov     [extended_code],0C2h
5255
        mov     [mmx_size],16
5256
        mov     byte [value],al
5257
        jmp     sse_cmp_instruction
5258
cmpss_instruction:
31 halyavin 5259
        mov     [mmx_size],4
109 heavyiron 5260
        mov     [operand_prefix],0F3h
5261
        jmp     cmpsx_instruction
5262
cmpsd_instruction:
31 halyavin 5263
        mov     al,0A7h
109 heavyiron 5264
        mov     ah,[esi]
5265
        or      ah,ah
5266
        jz      simple_instruction_32bit
5267
        cmp     ah,0Fh
5268
        je      simple_instruction_32bit
5269
        mov     [mmx_size],8
5270
        mov     [operand_prefix],0F2h
5271
      cmpsx_instruction:
31 halyavin 5272
        mov     [base_code],0Fh
109 heavyiron 5273
        mov     [extended_code],0C2h
5274
        mov     byte [value],-1
5275
        jmp     sse_cmp_instruction
5276
cmp_ss_instruction:
31 halyavin 5277
        mov     [mmx_size],4
109 heavyiron 5278
        mov     [operand_prefix],0F3h
5279
        jmp     cmp_sx_instruction
5280
cmp_sd_instruction:
31 halyavin 5281
        mov     [mmx_size],8
109 heavyiron 5282
        mov     [operand_prefix],0F2h
5283
      cmp_sx_instruction:
31 halyavin 5284
        mov     [base_code],0Fh
109 heavyiron 5285
        mov     [extended_code],0C2h
5286
        mov     byte [value],al
5287
sse_cmp_instruction:
31 halyavin 5288
        lods    byte [esi]
109 heavyiron 5289
        call    get_size_operator
5290
        cmp     al,10h
5291
        jne     invalid_operand
5292
        lods    byte [esi]
5293
        call    convert_mmx_register
5294
        cmp     ah,16
5295
        jne     invalid_operand_size
5296
        mov     [postbyte_register],al
5297
        lods    byte [esi]
5298
        cmp     al,','
5299
        jne     invalid_operand
5300
        mov     [operand_size],0
5301
        lods    byte [esi]
5302
        call    get_size_operator
5303
        cmp     al,10h
5304
        je      sse_cmp_xmmreg_xmmreg
5305
        cmp     al,'['
5306
        jne     invalid_operand
5307
        call    get_address
5308
        mov     al,[operand_size]
5309
        or      al,al
5310
        jz      sse_cmp_size_ok
5311
        cmp     al,[mmx_size]
5312
        jne     invalid_operand_size
5313
      sse_cmp_size_ok:
31 halyavin 5314
        push    bx cx edx
109 heavyiron 5315
        call    get_nextbyte
5316
        pop     edx cx bx
5317
        call    store_instruction_with_imm8
5318
        jmp     instruction_assembled
5319
      sse_cmp_xmmreg_xmmreg:
31 halyavin 5320
        lods    byte [esi]
109 heavyiron 5321
        call    convert_mmx_register
5322
        cmp     ah,16
5323
        jne     invalid_operand_size
5324
        mov     bl,al
5325
        call    store_nomem_instruction
5326
        call    get_nextbyte
5327
        mov     al,byte [value]
5328
        stos    byte [edi]
5329
        jmp     instruction_assembled
5330
      get_nextbyte:
31 halyavin 5331
        cmp     byte [value],-1
109 heavyiron 5332
        jne     nextbyte_ok
5333
        mov     [operand_size],0
5334
        lods    byte [esi]
5335
        cmp     al,','
5336
        jne     invalid_operand
5337
        lods    byte [esi]
5338
        call    get_size_operator
5339
        test    [operand_size],not 1
5340
        jnz     invalid_value
5341
        cmp     al,'('
5342
        jne     invalid_operand
5343
        call    get_byte_value
5344
        cmp     al,7
5345
        ja      invalid_value
5346
        mov     byte [value],al
5347
      nextbyte_ok:
31 halyavin 5348
        ret
109 heavyiron 5349
cvtpi2pd_instruction:
31 halyavin 5350
        mov     [operand_prefix],66h
109 heavyiron 5351
cvtpi2ps_instruction:
31 halyavin 5352
        mov     [base_code],0Fh
109 heavyiron 5353
        mov     [extended_code],al
5354
        lods    byte [esi]
5355
        call    get_size_operator
5356
        cmp     al,10h
5357
        jne     invalid_operand
5358
        lods    byte [esi]
5359
        call    convert_mmx_register
5360
        cmp     ah,16
5361
        jne     invalid_operand_size
5362
        mov     [postbyte_register],al
5363
        mov     [operand_size],0
5364
        lods    byte [esi]
5365
        cmp     al,','
5366
        jne     invalid_operand
5367
        lods    byte [esi]
5368
        call    get_size_operator
5369
        cmp     al,10h
5370
        je      cvtpi_xmmreg_xmmreg
5371
        cmp     al,'['
5372
        jne     invalid_operand
5373
        call    get_address
5374
        cmp     [operand_size],0
5375
        je      cvtpi_size_ok
5376
        cmp     [operand_size],8
5377
        jne     invalid_operand_size
5378
      cvtpi_size_ok:
31 halyavin 5379
        call    store_instruction
109 heavyiron 5380
        jmp     instruction_assembled
5381
      cvtpi_xmmreg_xmmreg:
31 halyavin 5382
        lods    byte [esi]
109 heavyiron 5383
        call    convert_mmx_register
5384
        cmp     ah,8
5385
        jne     invalid_operand_size
5386
        mov     bl,al
5387
        call    store_nomem_instruction
5388
        jmp     instruction_assembled
5389
cvtsi2ss_instruction:
31 halyavin 5390
        mov     [operand_prefix],0F3h
109 heavyiron 5391
        jmp     cvtsi_instruction
5392
cvtsi2sd_instruction:
31 halyavin 5393
        mov     [operand_prefix],0F2h
109 heavyiron 5394
      cvtsi_instruction:
31 halyavin 5395
        mov     [base_code],0Fh
109 heavyiron 5396
        mov     [extended_code],al
5397
        lods    byte [esi]
5398
        call    get_size_operator
5399
        cmp     al,10h
5400
        jne     invalid_operand
5401
        lods    byte [esi]
5402
        call    convert_mmx_register
5403
        cmp     ah,16
5404
        jne     invalid_operand_size
5405
        mov     [postbyte_register],al
5406
        mov     [operand_size],0
5407
        lods    byte [esi]
5408
        cmp     al,','
5409
        jne     invalid_operand
5410
        lods    byte [esi]
5411
        call    get_size_operator
5412
        cmp     al,10h
5413
        je      cvtsi_xmmreg_reg
5414
        cmp     al,'['
5415
        jne     invalid_operand
5416
        call    get_address
5417
        cmp     [operand_size],0
5418
        je      cvtsi_size_ok
5419
        cmp     [operand_size],4
5420
        jne     invalid_operand_size
5421
      cvtsi_size_ok:
31 halyavin 5422
        call    store_instruction
109 heavyiron 5423
        jmp     instruction_assembled
5424
      cvtsi_xmmreg_reg:
31 halyavin 5425
        lods    byte [esi]
109 heavyiron 5426
        call    convert_register
5427
        cmp     ah,4
5428
        je      cvtsi_xmmreg_reg_store
5429
        cmp     ah,8
5430
        jne     invalid_operand_size
5431
        call    operand_64bit
5432
      cvtsi_xmmreg_reg_store:
31 halyavin 5433
        mov     bl,al
109 heavyiron 5434
        call    store_nomem_instruction
5435
        jmp     instruction_assembled
5436
cvtps2pi_instruction:
31 halyavin 5437
        mov     [mmx_size],8
109 heavyiron 5438
        jmp     cvtpd_instruction
5439
cvtpd2pi_instruction:
31 halyavin 5440
        mov     [operand_prefix],66h
109 heavyiron 5441
        mov     [mmx_size],16
5442
      cvtpd_instruction:
31 halyavin 5443
        mov     [base_code],0Fh
109 heavyiron 5444
        mov     [extended_code],al
5445
        lods    byte [esi]
5446
        call    get_size_operator
5447
        cmp     al,10h
5448
        jne     invalid_operand
5449
        lods    byte [esi]
5450
        call    convert_mmx_register
5451
        cmp     ah,8
5452
        jne     invalid_operand_size
5453
        mov     [operand_size],0
5454
        jmp     sse_reg
5455
cvtss2si_instruction:
31 halyavin 5456
        mov     [operand_prefix],0F3h
109 heavyiron 5457
        mov     [mmx_size],4
5458
        jmp     cvt2si_instruction
5459
cvtsd2si_instruction:
31 halyavin 5460
        mov     [operand_prefix],0F2h
109 heavyiron 5461
        mov     [mmx_size],8
5462
      cvt2si_instruction:
31 halyavin 5463
        mov     [extended_code],al
109 heavyiron 5464
        mov     [base_code],0Fh
5465
        lods    byte [esi]
5466
        call    get_size_operator
5467
        cmp     al,10h
5468
        jne     invalid_operand
5469
        lods    byte [esi]
5470
        call    convert_register
5471
        mov     [operand_size],0
5472
        cmp     ah,4
5473
        je      sse_reg
5474
        cmp     ah,8
5475
        jne     invalid_operand_size
5476
        call    operand_64bit
5477
        jmp     sse_reg
5478
amd3dnow_instruction:
31 halyavin 5479
        mov     [base_code],0Fh
109 heavyiron 5480
        mov     [extended_code],0Fh
5481
        mov     byte [value],al
5482
        lods    byte [esi]
5483
        call    get_size_operator
5484
        cmp     al,10h
5485
        jne     invalid_operand
5486
        lods    byte [esi]
5487
        call    convert_mmx_register
5488
        cmp     ah,8
5489
        jne     invalid_operand_size
5490
        mov     [postbyte_register],al
5491
        lods    byte [esi]
5492
        cmp     al,','
5493
        jne     invalid_operand
5494
        lods    byte [esi]
5495
        call    get_size_operator
5496
        cmp     al,10h
5497
        je      amd3dnow_mmreg_mmreg
5498
        cmp     al,'['
5499
        jne     invalid_operand
5500
        call    get_address
5501
        call    store_instruction_with_imm8
5502
        jmp     instruction_assembled
5503
      amd3dnow_mmreg_mmreg:
31 halyavin 5504
        lods    byte [esi]
109 heavyiron 5505
        call    convert_mmx_register
5506
        cmp     ah,8
5507
        jne     invalid_operand_size
5508
        mov     bl,al
5509
        call    store_nomem_instruction
5510
        mov     al,byte [value]
5511
        stos    byte [edi]
5512
        jmp     instruction_assembled
5513
31 halyavin 5514
 
5515
        mov     [extended_code],0AEh
109 heavyiron 5516
        mov     [base_code],0Fh
5517
        mov     [postbyte_register],al
5518
        lods    byte [esi]
5519
        call    get_size_operator
5520
        cmp     al,'['
5521
        jne     invalid_operand
5522
        call    get_address
5523
        mov     ah,[operand_size]
5524
        or      ah,ah
5525
        jz      fxsave_size_ok
5526
        mov     al,[postbyte_register]
5527
        cmp     al,111b
5528
        je      clflush_size_check
5529
        cmp     al,10b
5530
        jb      invalid_operand_size
5531
        cmp     al,11b
5532
        ja      invalid_operand_size
5533
        cmp     ah,4
5534
        jne     invalid_operand_size
5535
        jmp     fxsave_size_ok
5536
      clflush_size_check:
31 halyavin 5537
        cmp     ah,1
109 heavyiron 5538
        jne     invalid_operand_size
5539
      fxsave_size_ok:
31 halyavin 5540
        call    store_instruction
109 heavyiron 5541
        jmp     instruction_assembled
5542
prefetch_instruction:
31 halyavin 5543
        mov     [extended_code],18h
109 heavyiron 5544
      prefetch_mem_8bit:
31 halyavin 5545
        mov     [base_code],0Fh
109 heavyiron 5546
        mov     [postbyte_register],al
5547
        lods    byte [esi]
5548
        call    get_size_operator
5549
        cmp     al,'['
5550
        jne     invalid_operand
5551
        or      ah,ah
5552
        jz      prefetch_size_ok
5553
        cmp     ah,1
5554
        jne     invalid_operand_size
5555
      prefetch_size_ok:
31 halyavin 5556
        call    get_address
109 heavyiron 5557
        call    store_instruction
5558
        jmp     instruction_assembled
5559
amd_prefetch_instruction:
31 halyavin 5560
        mov     [extended_code],0Dh
109 heavyiron 5561
        jmp     prefetch_mem_8bit
5562
fence_instruction:
31 halyavin 5563
        mov     bl,al
109 heavyiron 5564
        mov     ax,0AE0Fh
5565
        stos    word [edi]
5566
        mov     al,bl
5567
        stos    byte [edi]
5568
        jmp     instruction_assembled
5569
pause_instruction:
31 halyavin 5570
        mov     ax,90F3h
109 heavyiron 5571
        stos    word [edi]
5572
        jmp     instruction_assembled
5573
movntq_instruction:
31 halyavin 5574
        mov     [mmx_size],8
109 heavyiron 5575
        jmp     movnt_instruction
5576
movntps_instruction:
31 halyavin 5577
        mov     [mmx_size],16
109 heavyiron 5578
        jmp     movnt_instruction
5579
movntdq_instruction:
31 halyavin 5580
        mov     [operand_prefix],66h
109 heavyiron 5581
        mov     [mmx_size],16
5582
      movnt_instruction:
31 halyavin 5583
        mov     [extended_code],al
109 heavyiron 5584
        mov     [base_code],0Fh
5585
        lods    byte [esi]
5586
        call    get_size_operator
5587
        cmp     al,'['
5588
        jne     invalid_operand
5589
        call    get_address
5590
        lods    byte [esi]
5591
        cmp     al,','
5592
        jne     invalid_operand
5593
        lods    byte [esi]
5594
        call    get_size_operator
5595
        cmp     al,10h
5596
        jne     invalid_operand
5597
        lods    byte [esi]
5598
        call    convert_mmx_register
5599
        cmp     ah,[mmx_size]
5600
        jne     invalid_operand_size
5601
        mov     [postbyte_register],al
5602
        call    store_instruction
5603
        jmp     instruction_assembled
5604
movnti_instruction:
31 halyavin 5605
        mov     [base_code],0Fh
109 heavyiron 5606
        mov     [extended_code],al
5607
        lods    byte [esi]
5608
        call    get_size_operator
5609
        cmp     al,'['
5610
        jne     invalid_operand
5611
        call    get_address
5612
        lods    byte [esi]
5613
        cmp     al,','
5614
        jne     invalid_operand
5615
        lods    byte [esi]
5616
        call    get_size_operator
5617
        cmp     al,10h
5618
        jne     invalid_operand
5619
        lods    byte [esi]
5620
        call    convert_register
5621
        cmp     ah,4
5622
        je      movnti_store
5623
        cmp     ah,8
5624
        jne     invalid_operand_size
5625
        call    operand_64bit
5626
      movnti_store:
31 halyavin 5627
        mov     [postbyte_register],al
109 heavyiron 5628
        call    store_instruction
5629
        jmp     instruction_assembled
5630
monitor_instruction:
31 halyavin 5631
        mov     [postbyte_register],al
109 heavyiron 5632
        lods    byte [esi]
5633
        call    get_size_operator
5634
        cmp     al,10h
5635
        jne     invalid_operand
5636
        lods    byte [esi]
5637
        call    convert_register
5638
        cmp     ax,0400h
5639
        jne     invalid_operand
5640
        lods    byte [esi]
5641
        cmp     al,','
5642
        jne     invalid_operand
5643
        lods    byte [esi]
5644
        call    get_size_operator
5645
        cmp     al,10h
5646
        jne     invalid_operand
5647
        lods    byte [esi]
5648
        call    convert_register
5649
        cmp     ax,0401h
5650
        jne     invalid_operand
5651
        cmp     [postbyte_register],0C8h
5652
        jne     monitor_instruction_store
5653
        lods    byte [esi]
5654
        cmp     al,','
5655
        jne     invalid_operand
5656
        lods    byte [esi]
5657
        call    get_size_operator
5658
        cmp     al,10h
5659
        jne     invalid_operand
5660
        lods    byte [esi]
5661
        call    convert_register
5662
        cmp     ax,0402h
5663
        jne     invalid_operand
5664
      monitor_instruction_store:
31 halyavin 5665
        mov     ax,010Fh
109 heavyiron 5666
        stos    word [edi]
5667
        mov     al,[postbyte_register]
5668
        stos    byte [edi]
5669
        jmp     instruction_assembled
5670
31 halyavin 5671
 
5672
        mov     ah,al
109 heavyiron 5673
        mov     al,0Fh
5674
        stos    byte [edi]
5675
        mov     al,1
5676
        stos    word [edi]
5677
        jmp     instruction_assembled
5678
vmclear_instruction:
31 halyavin 5679
        mov     [operand_prefix],66h
109 heavyiron 5680
        jmp     vmx_instruction
5681
vmxon_instruction:
31 halyavin 5682
        mov     [operand_prefix],0F3h
109 heavyiron 5683
vmx_instruction:
31 halyavin 5684
        mov     [postbyte_register],al
109 heavyiron 5685
        mov     [extended_code],0C7h
5686
        lods    byte [esi]
5687
        call    get_size_operator
5688
        cmp     al,'['
5689
        jne     invalid_operand
5690
        call    get_address
5691
        mov     al,[operand_size]
5692
        or      al,al
5693
        jz      vmx_size_ok
5694
        cmp     al,8
5695
        jne     invalid_operand_size
5696
      vmx_size_ok:
31 halyavin 5697
        mov     [base_code],0Fh
109 heavyiron 5698
        call    store_instruction
5699
        jmp     instruction_assembled
5700
vmread_instruction:
31 halyavin 5701
        mov     [extended_code],78h
109 heavyiron 5702
        lods    byte [esi]
5703
        call    get_size_operator
5704
        cmp     al,'['
5705
        jne     invalid_operand
5706
        call    get_address
5707
        lods    byte [esi]
5708
        cmp     al,','
5709
        jne     invalid_operand
5710
        lods    byte [esi]
5711
        call    get_size_operator
5712
        cmp     al,10h
5713
        jne     invalid_operand
5714
        lods    byte [esi]
5715
        call    convert_register
5716
        mov     [postbyte_register],al
5717
      vmread_check_size:
31 halyavin 5718
        cmp     [code_type],64
109 heavyiron 5719
        je      vmread_long
5720
        cmp     [operand_size],4
5721
        je      vmx_size_ok
5722
        jmp     invalid_operand_size
5723
      vmread_long:
31 halyavin 5724
        cmp     [operand_size],8
109 heavyiron 5725
        je      vmx_size_ok
5726
        jmp     invalid_operand_size
5727
vmwrite_instruction:
31 halyavin 5728
        mov     [extended_code],79h
109 heavyiron 5729
        lods    byte [esi]
5730
        call    get_size_operator
5731
        cmp     al,10h
5732
        jne     invalid_operand
5733
        lods    byte [esi]
5734
        call    convert_register
5735
        mov     [postbyte_register],al
5736
        lods    byte [esi]
5737
        cmp     al,','
5738
        jne     invalid_operand
5739
        lods    byte [esi]
5740
        call    get_size_operator
5741
        cmp     al,'['
5742
        jne     invalid_operand
5743
        call    get_address
5744
        jmp     vmread_check_size
5745
simple_svm_instruction:
5746
        push    eax
5747
        mov     [base_code],0Fh
5748
        mov     [extended_code],1
5749
        lods    byte [esi]
5750
        call    get_size_operator
5751
        cmp     al,10h
5752
        jne     invalid_operand
5753
        lods    byte [esi]
5754
        call    convert_register
5755
        or      al,al
5756
        jnz     invalid_operand
5757
      simple_svm_detect_size:
5758
        cmp     ah,2
5759
        je      simple_svm_16bit
5760
        cmp     ah,4
5761
        je      simple_svm_32bit
5762
        cmp     [code_type],64
5763
        jne     invalid_operand_size
5764
        jmp     simple_svm_store
5765
      simple_svm_16bit:
5766
        cmp     [code_type],16
5767
        je      simple_svm_store
5768
        cmp     [code_type],64
5769
        je      invalid_operand_size
5770
        jmp     prefixed_svm_store
5771
      simple_svm_32bit:
5772
        cmp     [code_type],32
5773
        je      simple_svm_store
5774
      prefixed_svm_store:
5775
        mov     al,67h
5776
        stos    byte [edi]
5777
      simple_svm_store:
5778
        call    store_instruction_code
5779
        pop     eax
5780
        stos    byte [edi]
5781
        jmp     instruction_assembled
5782
skinit_instruction:
5783
        lods    byte [esi]
5784
        call    get_size_operator
5785
        cmp     al,10h
5786
        jne     invalid_operand
5787
        lods    byte [esi]
5788
        call    convert_register
5789
        cmp     ax,0400h
5790
        jne     invalid_operand
5791
        mov     al,0DEh
5792
        jmp     simple_vmx_instruction
5793
invlpga_instruction:
5794
        push    eax
5795
        mov     [base_code],0Fh
5796
        mov     [extended_code],1
5797
        lods    byte [esi]
5798
        call    get_size_operator
5799
        cmp     al,10h
5800
        jne     invalid_operand
5801
        lods    byte [esi]
5802
        call    convert_register
5803
        or      al,al
5804
        jnz     invalid_operand
5805
        mov     bl,ah
5806
        mov     [operand_size],0
5807
        lods    byte [esi]
5808
        cmp     al,','
5809
        jne     invalid_operand
5810
        lods    byte [esi]
5811
        call    get_size_operator
5812
        cmp     al,10h
5813
        jne     invalid_operand
5814
        lods    byte [esi]
5815
        call    convert_register
5816
        cmp     ax,0401h
5817
        jne     invalid_operand
5818
        mov     ah,bl
5819
        jmp     simple_svm_detect_size
5820
31 halyavin 5821
 
5822
        mov     ah,al
109 heavyiron 5823
        shr     ah,4
5824
        and     al,0Fh
5825
        cmp     ah,8
5826
        je      match_register_size
5827
        cmp     ah,4
5828
        ja      invalid_operand
5829
        cmp     ah,1
5830
        ja      match_register_size
5831
        cmp     al,4
5832
        jb      match_register_size
5833
        or      ah,ah
5834
        jz      high_byte_register
5835
        or      [rex_prefix],40h
5836
      match_register_size:
31 halyavin 5837
        cmp     ah,[operand_size]
109 heavyiron 5838
        je      register_size_ok
5839
        cmp     [operand_size],0
5840
        jne     operand_sizes_do_not_match
5841
        mov     [operand_size],ah
5842
      register_size_ok:
31 halyavin 5843
        ret
109 heavyiron 5844
      high_byte_register:
31 halyavin 5845
        mov     ah,1
109 heavyiron 5846
        or      [rex_prefix],80h
5847
        jmp     match_register_size
5848
convert_fpu_register:
31 halyavin 5849
        mov     ah,al
109 heavyiron 5850
        shr     ah,4
5851
        and     al,111b
5852
        cmp     ah,10
5853
        jne     invalid_operand
5854
        jmp     match_register_size
5855
convert_mmx_register:
31 halyavin 5856
        mov     ah,al
109 heavyiron 5857
        shr     ah,4
5858
        cmp     ah,0Ch
5859
        je      xmm_register
5860
        ja      invalid_operand
5861
        and     al,111b
5862
        cmp     ah,0Bh
5863
        jne     invalid_operand
5864
        mov     ah,8
5865
        jmp     match_register_size
5866
      xmm_register:
31 halyavin 5867
        and     al,0Fh
109 heavyiron 5868
        mov     ah,16
5869
        cmp     al,8
5870
        jb      match_register_size
5871
        cmp     [code_type],64
5872
        jne     invalid_operand
5873
        jmp     match_register_size
5874
get_size_operator:
31 halyavin 5875
        xor     ah,ah
109 heavyiron 5876
        cmp     al,11h
5877
        jne     no_size_operator
5878
        mov     [size_declared],1
5879
        lods    word [esi]
5880
        xchg    al,ah
5881
        mov     [size_override],1
5882
        cmp     ah,[operand_size]
5883
        je      size_operator_ok
5884
        cmp     [operand_size],0
5885
        jne     operand_sizes_do_not_match
5886
        mov     [operand_size],ah
5887
      size_operator_ok:
31 halyavin 5888
        ret
109 heavyiron 5889
      no_size_operator:
31 halyavin 5890
        mov     [size_declared],0
109 heavyiron 5891
        cmp     al,'['
5892
        jne     size_operator_ok
5893
        mov     [size_override],0
5894
        ret
5895
get_jump_operator:
31 halyavin 5896
        mov     [jump_type],0
109 heavyiron 5897
        cmp     al,12h
5898
        jne     jump_operator_ok
5899
        lods    word [esi]
5900
        mov     [jump_type],al
5901
        mov     al,ah
5902
      jump_operator_ok:
31 halyavin 5903
        ret
109 heavyiron 5904
get_address:
31 halyavin 5905
        mov     [segment_register],0
109 heavyiron 5906
        mov     [address_size],0
5907
        mov     al,[code_type]
5908
        shr     al,3
5909
        mov     [value_size],al
5910
        mov     al,[esi]
5911
        and     al,11110000b
5912
        cmp     al,60h
5913
        jne     get_size_prefix
5914
        lods    byte [esi]
5915
        sub     al,60h
5916
        mov     [segment_register],al
5917
        mov     al,[esi]
5918
        and     al,11110000b
5919
      get_size_prefix:
31 halyavin 5920
        cmp     al,70h
109 heavyiron 5921
        jne     address_size_prefix_ok
5922
        lods    byte [esi]
5923
        sub     al,70h
5924
        cmp     al,2
5925
        jb      invalid_address_size
5926
        cmp     al,8
5927
        ja      invalid_address_size
5928
        mov     [address_size],al
5929
        mov     [value_size],al
5930
      address_size_prefix_ok:
31 halyavin 5931
        call    calculate_address
109 heavyiron 5932
        cmp     byte [esi-1],']'
5933
        jne     invalid_address
5934
        mov     [address_high],edx
5935
        mov     edx,eax
5936
        cmp     [code_type],64
5937
        jne     address_ok
5938
        or      bx,bx
5939
        jnz     address_ok
5940
        test    ch,0Fh
5941
        jnz     address_ok
5942
      calculate_relative_address:
31 halyavin 5943
        call    calculate_relative_offset
109 heavyiron 5944
        cmp     byte [esi-1],']'
5945
        jne     invalid_address
5946
        mov     [address_high],edx
5947
        mov     edx,[symbol_identifier]
5948
        mov     [address_symbol],edx
5949
        mov     edx,eax
5950
        mov     ch,[value_type]
5951
        mov     bx,0FF00h
5952
        xor     cl,cl
5953
      address_ok:
31 halyavin 5954
        ret
109 heavyiron 5955
31 halyavin 5956
 
5957
        cmp     [code_type],16
109 heavyiron 5958
        je      size_prefix_ok
5959
        mov     [operand_prefix],66h
5960
        ret
5961
operand_32bit:
31 halyavin 5962
        cmp     [code_type],16
109 heavyiron 5963
        jne     size_prefix_ok
5964
        mov     [operand_prefix],66h
5965
      size_prefix_ok:
31 halyavin 5966
        ret
109 heavyiron 5967
operand_64bit:
31 halyavin 5968
        cmp     [code_type],64
109 heavyiron 5969
        jne     illegal_instruction
5970
        or      [rex_prefix],48h
5971
        ret
5972
operand_autodetect:
31 halyavin 5973
        cmp     al,2
109 heavyiron 5974
        je      operand_16bit
5975
        cmp     al,4
5976
        je      operand_32bit
5977
        cmp     al,8
5978
        je      operand_64bit
5979
        jmp     invalid_operand_size
5980
store_segment_prefix_if_necessary:
31 halyavin 5981
        mov     al,[segment_register]
109 heavyiron 5982
        or      al,al
5983
        jz      segment_prefix_ok
5984
        cmp     al,3
5985
        je      ss_prefix
5986
        cmp     al,4
5987
        ja      segment_prefix_386
5988
        jb      segment_prefix_86
5989
        cmp     bl,25h
5990
        je      segment_prefix_86
5991
        cmp     bh,25h
5992
        je      segment_prefix_86
5993
        cmp     bh,45h
5994
        je      segment_prefix_86
5995
        cmp     bh,44h
5996
        je      segment_prefix_86
5997
        ret
5998
      ss_prefix:
31 halyavin 5999
        cmp     bl,25h
109 heavyiron 6000
        je      segment_prefix_ok
6001
        cmp     bh,25h
6002
        je      segment_prefix_ok
6003
        cmp     bh,45h
6004
        je      segment_prefix_ok
6005
        cmp     bh,44h
6006
        je      segment_prefix_ok
6007
        jmp     segment_prefix_86
6008
store_segment_prefix:
31 halyavin 6009
        mov     al,[segment_register]
109 heavyiron 6010
        or      al,al
6011
        jz      segment_prefix_ok
6012
        cmp     al,5
6013
        jae     segment_prefix_386
6014
      segment_prefix_86:
31 halyavin 6015
        dec     al
109 heavyiron 6016
        shl     al,3
6017
        add     al,26h
6018
        stos    byte [edi]
6019
        jmp     segment_prefix_ok
6020
      segment_prefix_386:
31 halyavin 6021
        add     al,64h-5
109 heavyiron 6022
        stos    byte [edi]
6023
      segment_prefix_ok:
31 halyavin 6024
        ret
109 heavyiron 6025
store_instruction_code:
31 halyavin 6026
        mov     al,[operand_prefix]
109 heavyiron 6027
        or      al,al
6028
        jz      operand_prefix_ok
6029
        stos    byte [edi]
6030
      operand_prefix_ok:
31 halyavin 6031
        mov     al,[rex_prefix]
109 heavyiron 6032
        test    al,40h
6033
        jz      rex_prefix_ok
6034
        cmp     [code_type],64
6035
        jne     invalid_operand
6036
        test    al,0B0h
6037
        jnz     prefix_conflict
6038
        stos    byte [edi]
6039
      rex_prefix_ok:
31 halyavin 6040
        mov     al,[base_code]
109 heavyiron 6041
        stos    byte [edi]
6042
        cmp     al,0Fh
6043
        jne     instruction_code_ok
6044
      store_extended_code:
31 halyavin 6045
        mov     al,[extended_code]
109 heavyiron 6046
        stos    byte [edi]
6047
      instruction_code_ok:
31 halyavin 6048
        ret
109 heavyiron 6049
store_nomem_instruction:
31 halyavin 6050
        test    [postbyte_register],1000b
109 heavyiron 6051
        jz      nomem_reg_code_ok
6052
        or      [rex_prefix],44h
6053
        and     [postbyte_register],111b
6054
      nomem_reg_code_ok:
31 halyavin 6055
        test    bl,1000b
109 heavyiron 6056
        jz      nomem_rm_code_ok
6057
        or      [rex_prefix],41h
6058
        and     bl,111b
6059
      nomem_rm_code_ok:
31 halyavin 6060
        call    store_instruction_code
109 heavyiron 6061
        mov     al,[postbyte_register]
6062
        shl     al,3
6063
        or      al,bl
6064
        or      al,11000000b
6065
        stos    byte [edi]
6066
        ret
6067
store_instruction:
31 halyavin 6068
        mov     [current_offset],edi
109 heavyiron 6069
        test    [postbyte_register],1000b
6070
        jz      reg_code_ok
6071
        or      [rex_prefix],44h
6072
        and     [postbyte_register],111b
6073
      reg_code_ok:
31 halyavin 6074
        call    store_segment_prefix_if_necessary
109 heavyiron 6075
        or      bx,bx
6076
        jz      address_immediate
6077
        cmp     bx,0F000h
6078
        je      address_rip_based
6079
        cmp     bx,0FF00h
6080
        je      address_relative
6081
        mov     al,bl
6082
        or      al,bh
6083
        and     al,11110000b
6084
        cmp     al,80h
6085
        je      postbyte_64bit
6086
        cmp     al,40h
6087
        je      postbyte_32bit
6088
        cmp     al,20h
6089
        jne     invalid_address
6090
        cmp     [code_type],64
6091
        je      invalid_address_size
6092
        call    address_16bit_prefix
6093
        call    store_instruction_code
6094
        cmp     bx,2326h
6095
        je      address_bx_si
6096
        cmp     bx,2623h
6097
        je      address_bx_si
6098
        cmp     bx,2327h
6099
        je      address_bx_di
6100
        cmp     bx,2723h
6101
        je      address_bx_di
6102
        cmp     bx,2526h
6103
        je      address_bp_si
6104
        cmp     bx,2625h
6105
        je      address_bp_si
6106
        cmp     bx,2527h
6107
        je      address_bp_di
6108
        cmp     bx,2725h
6109
        je      address_bp_di
6110
        cmp     bx,2600h
6111
        je      address_si
6112
        cmp     bx,2700h
6113
        je      address_di
6114
        cmp     bx,2300h
6115
        je      address_bx
6116
        cmp     bx,2500h
6117
        je      address_bp
6118
        jmp     invalid_address
6119
      address_bx_si:
31 halyavin 6120
        xor     al,al
109 heavyiron 6121
        jmp     postbyte_16bit
6122
      address_bx_di:
31 halyavin 6123
        mov     al,1
109 heavyiron 6124
        jmp     postbyte_16bit
6125
      address_bp_si:
31 halyavin 6126
        mov     al,10b
109 heavyiron 6127
        jmp     postbyte_16bit
6128
      address_bp_di:
31 halyavin 6129
        mov     al,11b
109 heavyiron 6130
        jmp     postbyte_16bit
6131
      address_si:
31 halyavin 6132
        mov     al,100b
109 heavyiron 6133
        jmp     postbyte_16bit
6134
      address_di:
31 halyavin 6135
        mov     al,101b
109 heavyiron 6136
        jmp     postbyte_16bit
6137
      address_bx:
31 halyavin 6138
        mov     al,111b
109 heavyiron 6139
        jmp     postbyte_16bit
6140
      address_bp:
31 halyavin 6141
        mov     al,110b
109 heavyiron 6142
      postbyte_16bit:
31 halyavin 6143
        test    ch,22h
109 heavyiron 6144
        jnz     address_16bit_value
6145
        or      ch,ch
6146
        jnz     address_sizes_do_not_agree
6147
        cmp     edx,10000h
6148
        jge     value_out_of_range
6149
        cmp     edx,-8000h
6150
        jl      value_out_of_range
6151
        or      dx,dx
6152
        jz      address
6153
        cmp     dx,80h
6154
        jb      address_8bit_value
6155
        cmp     dx,-80h
6156
        jae     address_8bit_value
6157
      address_16bit_value:
31 halyavin 6158
        or      al,10000000b
109 heavyiron 6159
        mov     cl,[postbyte_register]
6160
        shl     cl,3
6161
        or      al,cl
6162
        stos    byte [edi]
6163
        mov     eax,edx
6164
        stos    word [edi]
6165
        ret
6166
      address_8bit_value:
31 halyavin 6167
        or      al,01000000b
109 heavyiron 6168
        mov     cl,[postbyte_register]
6169
        shl     cl,3
6170
        or      al,cl
6171
        stos    byte [edi]
6172
        mov     al,dl
6173
        stos    byte [edi]
6174
        cmp     dx,80h
6175
        jge     value_out_of_range
6176
        cmp     dx,-80h
6177
        jl      value_out_of_range
6178
        ret
6179
      address:
31 halyavin 6180
        cmp     al,110b
109 heavyiron 6181
        je      address_8bit_value
6182
        mov     cl,[postbyte_register]
6183
        shl     cl,3
6184
        or      al,cl
6185
        stos    byte [edi]
6186
        ret
6187
      postbyte_32bit:
31 halyavin 6188
        call    address_32bit_prefix
109 heavyiron 6189
        jmp     address_prefix_ok
6190
      postbyte_64bit:
31 halyavin 6191
        cmp     [code_type],64
109 heavyiron 6192
        jne     invalid_address_size
6193
      address_prefix_ok:
6194
        test    bh,1000b
6195
        jz      base_code_ok
6196
        or      [rex_prefix],41h
6197
      base_code_ok:
31 halyavin 6198
        test    bl,1000b
109 heavyiron 6199
        jz      index_code_ok
6200
        or      [rex_prefix],42h
6201
      index_code_ok:
31 halyavin 6202
        call    store_instruction_code
109 heavyiron 6203
        cmp     bl,44h
6204
        je      swap_base_with_index
6205
        cmp     bl,84h
6206
        jne     base_register_ok
6207
      swap_base_with_index:
6208
        cmp     cl,1
6209
        jne     invalid_address
6210
        xchg    bl,bh
6211
        cmp     bl,44h
6212
        je      invalid_address
6213
        cmp     bl,84h
6214
        je      invalid_address
6215
      base_register_ok:
6216
        or      cl,cl
6217
        jz      only_base_register
6218
      base_and_index:
31 halyavin 6219
        mov     al,100b
109 heavyiron 6220
        xor     ah,ah
6221
        cmp     cl,1
6222
        je      scale_ok
6223
        cmp     cl,2
6224
        je      scale_1
6225
        cmp     cl,4
6226
        je      scale_2
6227
        or      ah,11000000b
6228
        jmp     scale_ok
6229
      scale_2:
31 halyavin 6230
        or      ah,10000000b
109 heavyiron 6231
        jmp     scale_ok
6232
      scale_1:
31 halyavin 6233
        or      ah,01000000b
109 heavyiron 6234
      scale_ok:
31 halyavin 6235
        or      bh,bh
109 heavyiron 6236
        jz      only_index_register
6237
        and     bl,111b
6238
        shl     bl,3
6239
        or      ah,bl
6240
        and     bh,111b
6241
        or      ah,bh
6242
        test    ch,44h
6243
        jnz     sib_address_32bit_value
6244
        test    ch,88h
6245
        jnz     sib_address_32bit_value
6246
        or      ch,ch
6247
        jnz     address_sizes_do_not_agree
6248
        cmp     bh,5
6249
        je      address_value
6250
        or      edx,edx
6251
        jz      sib_address
6252
      address_value:
31 halyavin 6253
        cmp     edx,80h
109 heavyiron 6254
        jb      sib_address_8bit_value
6255
        cmp     edx,-80h
6256
        jae     sib_address_8bit_value
6257
      sib_address_32bit_value:
31 halyavin 6258
        or      al,10000000b
109 heavyiron 6259
        mov     cl,[postbyte_register]
6260
        shl     cl,3
6261
        or      al,cl
6262
        stos    word [edi]
6263
        jmp     store_address_32bit_value
6264
      sib_address_8bit_value:
31 halyavin 6265
        or      al,01000000b
109 heavyiron 6266
        mov     cl,[postbyte_register]
6267
        shl     cl,3
6268
        or      al,cl
6269
        stos    word [edi]
6270
        mov     al,dl
6271
        stos    byte [edi]
6272
        cmp     edx,80h
6273
        jge     value_out_of_range
6274
        cmp     edx,-80h
6275
        jl      value_out_of_range
6276
        ret
6277
      sib_address:
31 halyavin 6278
        mov     cl,[postbyte_register]
109 heavyiron 6279
        shl     cl,3
6280
        or      al,cl
6281
        stos    word [edi]
6282
        ret
6283
      only_index_register:
31 halyavin 6284
        or      ah,101b
109 heavyiron 6285
        and     bl,111b
6286
        shl     bl,3
6287
        or      ah,bl
6288
        mov     cl,[postbyte_register]
6289
        shl     cl,3
6290
        or      al,cl
6291
        stos    word [edi]
6292
        test    ch,44h
6293
        jnz     store_address_32bit_value
6294
        or      ch,ch
6295
        jnz     invalid_address_size
6296
        jmp     store_address_32bit_value
6297
      zero_index_register:
31 halyavin 6298
        mov     bl,4
109 heavyiron 6299
        mov     cl,1
6300
        jmp     base_and_index
6301
      only_base_register:
31 halyavin 6302
        mov     al,bh
109 heavyiron 6303
        and     al,111b
6304
        cmp     al,4
6305
        je      zero_index_register
6306
        test    ch,44h
6307
        jnz     simple_address_32bit_value
6308
        test    ch,88h
6309
        jnz     simple_address_32bit_value
6310
        or      ch,ch
6311
        jnz     address_sizes_do_not_agree
6312
        or      edx,edx
6313
        jz      simple_address
6314
        cmp     edx,80h
6315
        jb      simple_address_8bit_value
6316
        cmp     edx,-80h
6317
        jae     simple_address_8bit_value
6318
      simple_address_32bit_value:
31 halyavin 6319
        or      al,10000000b
109 heavyiron 6320
        mov     cl,[postbyte_register]
6321
        shl     cl,3
6322
        or      al,cl
6323
        stos    byte [edi]
6324
        jmp     store_address_32bit_value
6325
      simple_address_8bit_value:
31 halyavin 6326
        or      al,01000000b
109 heavyiron 6327
        mov     cl,[postbyte_register]
6328
        shl     cl,3
6329
        or      al,cl
6330
        stos    byte [edi]
6331
        mov     al,dl
6332
        stos    byte [edi]
6333
        cmp     edx,80h
6334
        jge     value_out_of_range
6335
        cmp     edx,-80h
6336
        jl      value_out_of_range
6337
        ret
6338
      simple_address:
31 halyavin 6339
        cmp     al,5
109 heavyiron 6340
        je      simple_address_8bit_value
6341
        mov     cl,[postbyte_register]
6342
        shl     cl,3
6343
        or      al,cl
6344
        stos    byte [edi]
6345
        ret
6346
      address_immediate:
31 halyavin 6347
        cmp     [code_type],64
109 heavyiron 6348
        je      address_immediate_sib
6349
        test    ch,44h
6350
        jnz     address_immediate_32bit
6351
        test    ch,22h
6352
        jnz     address_immediate_16bit
6353
        or      ch,ch
6354
        jnz     invalid_address_size
6355
        cmp     [code_type],16
6356
        je      addressing_16bit
6357
      address_immediate_32bit:
31 halyavin 6358
        call    address_32bit_prefix
109 heavyiron 6359
        call    store_instruction_code
6360
      store_immediate_address:
31 halyavin 6361
        mov     al,101b
109 heavyiron 6362
        mov     cl,[postbyte_register]
6363
        shl     cl,3
6364
        or      al,cl
6365
        stos    byte [edi]
6366
      store_address_32bit_value:
31 halyavin 6367
        test    ch,0F0h
109 heavyiron 6368
        jz      address_32bit_relocation_ok
6369
        mov     al,2
6370
        xchg    [value_type],al
6371
        mov     ebx,[address_symbol]
6372
        xchg    ebx,[symbol_identifier]
6373
        call    mark_relocation
6374
        mov     [value_type],al
6375
        mov     [symbol_identifier],ebx
6376
      address_32bit_relocation_ok:
31 halyavin 6377
        mov     eax,edx
109 heavyiron 6378
        stos    dword [edi]
6379
        ret
6380
      store_address_64bit_value:
31 halyavin 6381
        test    ch,0F0h
109 heavyiron 6382
        jz      address_64bit_relocation_ok
6383
        mov     al,4
6384
        xchg    [value_type],al
6385
        mov     ebx,[address_symbol]
6386
        xchg    ebx,[symbol_identifier]
6387
        call    mark_relocation
6388
        mov     [value_type],al
6389
        mov     [symbol_identifier],ebx
6390
      address_64bit_relocation_ok:
31 halyavin 6391
        mov     eax,edx
109 heavyiron 6392
        stos    dword [edi]
6393
        mov     eax,[address_high]
6394
        stos    dword [edi]
6395
        ret
6396
      address_immediate_sib:
31 halyavin 6397
        test    ch,not 44h
109 heavyiron 6398
        jnz     invalid_address_size
6399
        cmp     [value_type],0
6400
        jne     address_immediate_sib_nosignextend
6401
        test    edx,80000000h
6402
        jz      address_immediate_sib_prefix_ok
6403
      address_immediate_sib_nosignextend:
6404
        call    address_32bit_prefix
6405
      address_immediate_sib_prefix_ok:
6406
        call    store_instruction_code
6407
        mov     al,100b
6408
        mov     ah,100101b
6409
        mov     cl,[postbyte_register]
6410
        shl     cl,3
6411
        or      al,cl
6412
        stos    word [edi]
6413
        jmp     store_address_32bit_value
6414
      address_rip_based:
31 halyavin 6415
        cmp     [code_type],64
109 heavyiron 6416
        jne     invalid_address
6417
        call    store_instruction_code
6418
        jmp     store_immediate_address
6419
      address_relative:
31 halyavin 6420
        call    store_instruction_code
109 heavyiron 6421
        movzx   eax,[immediate_size]
6422
        add     eax,edi
6423
        sub     eax,[current_offset]
6424
        add     eax,5
6425
        sub     edx,eax
6426
        jo      value_out_of_range
6427
        mov     al,101b
6428
        mov     cl,[postbyte_register]
6429
        shl     cl,3
6430
        or      al,cl
6431
        stos    byte [edi]
6432
        xchg    [value_type],ch
6433
        mov     ebx,[address_symbol]
6434
        xchg    ebx,[symbol_identifier]
6435
        mov     eax,edx
6436
        call    mark_relocation
6437
        mov     [value_type],ch
6438
        mov     [symbol_identifier],ebx
6439
        stos    dword [edi]
6440
        ret
6441
      addressing_16bit:
31 halyavin 6442
        cmp     edx,10000h
109 heavyiron 6443
        jge     address_immediate_32bit
6444
        cmp     edx,-8000h
6445
        jl      address_immediate_32bit
6446
        movzx   edx,dx
6447
      address_immediate_16bit:
31 halyavin 6448
        call    address_16bit_prefix
109 heavyiron 6449
        call    store_instruction_code
6450
        mov     al,110b
6451
        mov     cl,[postbyte_register]
6452
        shl     cl,3
6453
        or      al,cl
6454
        stos    byte [edi]
6455
        mov     eax,edx
6456
        stos    word [edi]
6457
        cmp     edx,10000h
6458
        jge     value_out_of_range
6459
        cmp     edx,-8000h
6460
        jl      value_out_of_range
6461
        ret
6462
      address_16bit_prefix:
31 halyavin 6463
        cmp     [code_type],16
109 heavyiron 6464
        je      instruction_prefix_ok
6465
        mov     al,67h
6466
        stos    byte [edi]
6467
        ret
6468
      address_32bit_prefix:
31 halyavin 6469
        cmp     [code_type],32
109 heavyiron 6470
        je      instruction_prefix_ok
6471
        mov     al,67h
6472
        stos    byte [edi]
6473
      instruction_prefix_ok:
31 halyavin 6474
        ret
109 heavyiron 6475
store_instruction_with_imm8:
31 halyavin 6476
        mov     [immediate_size],1
109 heavyiron 6477
        call    store_instruction
6478
        mov     al,byte [value]
6479
        stos    byte [edi]
6480
        ret
6481
store_instruction_with_imm16:
31 halyavin 6482
        mov     [immediate_size],2
109 heavyiron 6483
        call    store_instruction
6484
        mov     ax,word [value]
6485
        call    mark_relocation
6486
        stos    word [edi]
6487
        ret
6488
store_instruction_with_imm32:
31 halyavin 6489
        mov     [immediate_size],4
109 heavyiron 6490
        call    store_instruction
6491
        mov     eax,dword [value]
6492
        call    mark_relocation
6493
        stos    dword [edi]
6494
        ret
6495