Subversion Repositories Kolibri OS

Rev

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