Subversion Repositories Kolibri OS

Rev

Rev 3010 | 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-2013, Tomasz Grysztar.
4039 heavyiron 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
	mov	ebp,[addressing_space]
4039 heavyiron 2992
	call	calculate_relative_offset
174 heavyiron 2993
	sub	edi,2
2994
	ret
157 heavyiron 2995
      check_for_short_jump:
109 heavyiron 2996
	cmp	[jump_type],1
157 heavyiron 2997
	je	forced_short
2998
	ja	no_short_jump
2999
	cmp	[base_code],0E8h
3000
	je	no_short_jump
3001
	cmp	[value_type],0
3002
	jne	no_short_jump
3003
	cmp	eax,80h
3004
	jb	short_jump
3005
	cmp	eax,-80h
3006
	jae	short_jump
3007
      no_short_jump:
109 heavyiron 3008
	clc
157 heavyiron 3009
	ret
3010
      forced_short:
109 heavyiron 3011
	cmp	[base_code],0E8h
157 heavyiron 3012
	je	illegal_instruction
3013
	cmp	[next_pass_needed],0
3014
	jne	jmp_short_value_type_ok
3015
	cmp	[value_type],0
3016
	jne	invalid_use_of_symbol
3017
      jmp_short_value_type_ok:
109 heavyiron 3018
	cmp	eax,-80h
157 heavyiron 3019
	jae	short_jump
3020
	cmp	eax,80h
3021
	jae	jump_out_of_range
3022
      short_jump:
109 heavyiron 3023
	stc
157 heavyiron 3024
	ret
3025
      jump_out_of_range:
109 heavyiron 3026
	cmp	[error_line],0
157 heavyiron 3027
	jne	instruction_assembled
3028
	mov	eax,[current_line]
3029
	mov	[error_line],eax
3030
	mov	[error],relative_jump_out_of_range
3031
	jmp	instruction_assembled
3032
      jmp_far:
31 halyavin 3033
	cmp	[jump_type],2
157 heavyiron 3034
	je	invalid_operand
3035
	cmp	[code_type],64
3036
	je	illegal_instruction
3037
	mov	al,[extended_code]
3038
	mov	[base_code],al
3039
	call	get_word_value
3040
	push	eax
3041
	inc	esi
3042
	lods	byte [esi]
3043
	cmp	al,'('
3044
	jne	invalid_operand
3045
	mov	al,[value_type]
3046
	push	eax [symbol_identifier]
3047
	cmp	byte [esi],'.'
3048
	je	invalid_value
3049
	mov	al,[operand_size]
3050
	cmp	al,4
3051
	je	jmp_far_16bit
3052
	cmp	al,6
3053
	je	jmp_far_32bit
3054
	or	al,al
3055
	jnz	invalid_operand_size
3056
	cmp	[code_type],16
3057
	jne	jmp_far_32bit
3058
      jmp_far_16bit:
31 halyavin 3059
	call	get_word_value
157 heavyiron 3060
	mov	ebx,eax
3061
	call	operand_16bit
3062
	call	store_instruction_code
3063
	mov	ax,bx
3064
	call	mark_relocation
3065
	stos	word [edi]
3066
      jmp_far_segment:
31 halyavin 3067
	pop	[symbol_identifier] eax
157 heavyiron 3068
	mov	[value_type],al
3069
	pop	eax
3070
	call	mark_relocation
3071
	stos	word [edi]
3072
	jmp	instruction_assembled
3073
      jmp_far_32bit:
31 halyavin 3074
	call	get_dword_value
157 heavyiron 3075
	mov	ebx,eax
3076
	call	operand_32bit
3077
	call	store_instruction_code
3078
	mov	eax,ebx
3079
	call	mark_relocation
3080
	stos	dword [edi]
3081
	jmp	jmp_far_segment
3082
conditional_jump:
109 heavyiron 3083
	mov	[base_code],al
157 heavyiron 3084
	lods	byte [esi]
3085
	call	get_jump_operator
3086
	cmp	[jump_type],3
3087
	je	invalid_operand
3088
	call	get_size_operator
3089
	cmp	al,'('
3090
	jne	invalid_operand
3091
	cmp	byte [esi],'.'
3092
	je	invalid_value
3093
	mov	al,[operand_size]
3094
	cmp	al,2
3095
	je	conditional_jump_16bit
3096
	cmp	al,4
3097
	je	conditional_jump_32bit
3098
	cmp	al,8
3099
	je	conditional_jump_64bit
3100
	or	al,al
3101
	jnz	invalid_operand_size
3102
	cmp	[code_type],16
3103
	je	conditional_jump_16bit
3104
	cmp	[code_type],64
3105
	je	conditional_jump_64bit
3106
      conditional_jump_32bit:
109 heavyiron 3107
	cmp	[code_type],64
157 heavyiron 3108
	je	invalid_operand_size
3109
	call	get_address_dword_value
220 heavyiron 3110
	cmp	[code_type],16
157 heavyiron 3111
	jne	conditional_jump_32bit_prefix_ok
3112
	mov	byte [edi],66h
3113
	inc	edi
3114
      conditional_jump_32bit_prefix_ok:
109 heavyiron 3115
	call	calculate_jump_offset
157 heavyiron 3116
	cdq
3117
	call	check_for_short_jump
3118
	jc	conditional_jump_short
3119
      conditional_jump_32bit_store:
109 heavyiron 3120
	mov	edx,eax
157 heavyiron 3121
	sub	edx,4
3122
	jno	conditional_jump_32bit_range_ok
2287 heavyiron 3123
	cmp	[code_type],64
3124
	je	relative_jump_out_of_range
3125
      conditional_jump_32bit_range_ok:
3126
	mov	ah,[base_code]
157 heavyiron 3127
	add	ah,10h
3128
	mov	al,0Fh
3129
	stos	word [edi]
3130
	mov	eax,edx
3131
	call	mark_relocation
3132
	stos	dword [edi]
3133
	jmp	instruction_assembled
3134
      conditional_jump_64bit:
109 heavyiron 3135
	cmp	[code_type],64
157 heavyiron 3136
	jne	invalid_operand_size
3137
	call	get_address_qword_value
220 heavyiron 3138
	call	calculate_jump_offset
157 heavyiron 3139
	mov	ecx,edx
3140
	cdq
3141
	cmp	edx,ecx
3142
	jne	relative_jump_out_of_range
2665 dunkaist 3143
	call	check_for_short_jump
157 heavyiron 3144
	jnc	conditional_jump_32bit_store
3145
      conditional_jump_short:
109 heavyiron 3146
	mov	ah,al
157 heavyiron 3147
	mov	al,[base_code]
3148
	stos	word [edi]
3149
	jmp	instruction_assembled
3150
      conditional_jump_16bit:
109 heavyiron 3151
	call	get_address_word_value
220 heavyiron 3152
	cmp	[code_type],16
157 heavyiron 3153
	je	conditional_jump_16bit_prefix_ok
3154
	mov	byte [edi],66h
3155
	inc	edi
3156
      conditional_jump_16bit_prefix_ok:
109 heavyiron 3157
	call	calculate_jump_offset
157 heavyiron 3158
	cwde
3159
	cdq
3160
	call	check_for_short_jump
3161
	jc	conditional_jump_short
3162
	cmp	[value_type],0
3163
	jne	invalid_use_of_symbol
3164
	mov	edx,eax
3165
	sub	dx,2
2287 heavyiron 3166
	mov	ah,[base_code]
157 heavyiron 3167
	add	ah,10h
3168
	mov	al,0Fh
3169
	stos	word [edi]
3170
	mov	eax,edx
3171
	stos	word [edi]
3172
	jmp	instruction_assembled
3173
loop_instruction_16bit:
109 heavyiron 3174
	cmp	[code_type],64
157 heavyiron 3175
	je	illegal_instruction
3176
	cmp	[code_type],16
872 heavyiron 3177
	je	loop_instruction
3178
	mov	[operand_prefix],67h
3179
	jmp	loop_instruction
157 heavyiron 3180
loop_instruction_32bit:
109 heavyiron 3181
	cmp	[code_type],32
872 heavyiron 3182
	je	loop_instruction
3183
	mov	[operand_prefix],67h
3184
      jmp     loop_instruction
3185
loop_instruction_64bit:
109 heavyiron 3186
	cmp	[code_type],64
157 heavyiron 3187
	jne	illegal_instruction
3188
loop_instruction:
109 heavyiron 3189
	mov	[base_code],al
157 heavyiron 3190
	lods	byte [esi]
3191
	call	get_jump_operator
3192
	cmp	[jump_type],1
3193
	ja	invalid_operand
3194
	call	get_size_operator
3195
	cmp	al,'('
3196
	jne	invalid_operand
3197
	cmp	byte [esi],'.'
3198
	je	invalid_value
3199
	mov	al,[operand_size]
3200
	cmp	al,2
3201
	je	loop_jump_16bit
3202
	cmp	al,4
3203
	je	loop_jump_32bit
3204
	cmp	al,8
3205
	je	loop_jump_64bit
3206
	or	al,al
3207
	jnz	invalid_operand_size
3208
	cmp	[code_type],16
3209
	je	loop_jump_16bit
3210
	cmp	[code_type],64
3211
	je	loop_jump_64bit
3212
      loop_jump_32bit:
109 heavyiron 3213
	cmp	[code_type],64
157 heavyiron 3214
	je	invalid_operand_size
3215
	call	get_address_dword_value
220 heavyiron 3216
	cmp	[code_type],16
157 heavyiron 3217
	jne	loop_jump_32bit_prefix_ok
3218
	mov	byte [edi],66h
3219
	inc	edi
3220
      loop_jump_32bit_prefix_ok:
109 heavyiron 3221
	call	loop_counter_size
872 heavyiron 3222
	call	calculate_jump_offset
157 heavyiron 3223
	cdq
3224
      make_loop_jump:
109 heavyiron 3225
	call	check_for_short_jump
157 heavyiron 3226
	jc	conditional_jump_short
3227
	scas	word [edi]
2287 heavyiron 3228
	jmp	jump_out_of_range
157 heavyiron 3229
      loop_counter_size:
872 heavyiron 3230
	cmp	[operand_prefix],0
3231
	je	loop_counter_size_ok
3232
	push	eax
3233
	mov	al,[operand_prefix]
3234
	stos	byte [edi]
3235
	pop	eax
3236
      loop_counter_size_ok:
3237
	ret
3238
      loop_jump_64bit:
109 heavyiron 3239
	cmp	[code_type],64
157 heavyiron 3240
	jne	invalid_operand_size
3241
	call	get_address_qword_value
220 heavyiron 3242
	call	loop_counter_size
1189 heavyiron 3243
	call	calculate_jump_offset
157 heavyiron 3244
	mov	ecx,edx
3245
	cdq
3246
	cmp	edx,ecx
3247
	jne	relative_jump_out_of_range
2665 dunkaist 3248
	jmp	make_loop_jump
157 heavyiron 3249
      loop_jump_16bit:
109 heavyiron 3250
	call	get_address_word_value
220 heavyiron 3251
	cmp	[code_type],16
157 heavyiron 3252
	je	loop_jump_16bit_prefix_ok
3253
	mov	byte [edi],66h
3254
	inc	edi
3255
      loop_jump_16bit_prefix_ok:
109 heavyiron 3256
	call	loop_counter_size
872 heavyiron 3257
	call	calculate_jump_offset
157 heavyiron 3258
	cwde
3259
	cdq
3260
	jmp	make_loop_jump
3261
31 halyavin 3262
 
3263
	lods	byte [esi]
157 heavyiron 3264
	call	get_size_operator
3265
	cmp	al,'['
3266
	jne	invalid_operand
3267
	call	get_address
3268
	or	eax,eax
3269
	jnz	invalid_address
3270
	or	bl,ch
3271
	jnz	invalid_address
3272
	cmp	[segment_register],1
3273
	ja	invalid_address
3274
	push	ebx
3275
	lods	byte [esi]
3276
	cmp	al,','
3277
	jne	invalid_operand
3278
	lods	byte [esi]
3279
	call	get_size_operator
3280
	cmp	al,'['
3281
	jne	invalid_operand
3282
	call	get_address
3283
	pop	edx
3284
	or	eax,eax
3285
	jnz	invalid_address
3286
	or	bl,ch
3287
	jnz	invalid_address
3288
	mov	al,dh
3289
	mov	ah,bh
3290
	shr	al,4
3291
	shr	ah,4
3292
	cmp	al,ah
3293
	jne	address_sizes_do_not_agree
3294
	and	bh,111b
3295
	and	dh,111b
3296
	cmp	bh,6
3297
	jne	invalid_address
3298
	cmp	dh,7
3299
	jne	invalid_address
3300
	cmp	al,2
3301
	je	movs_address_16bit
3302
	cmp	al,4
3303
	je	movs_address_32bit
3304
	cmp	[code_type],64
3305
	jne	invalid_address_size
3306
	jmp	movs_store
3307
      movs_address_32bit:
31 halyavin 3308
	call	address_32bit_prefix
157 heavyiron 3309
	jmp	movs_store
3310
      movs_address_16bit:
31 halyavin 3311
	cmp	[code_type],64
157 heavyiron 3312
	je	invalid_address_size
3313
	call	address_16bit_prefix
3314
      movs_store:
31 halyavin 3315
	xor	ebx,ebx
3010 dunkaist 3316
	call	store_segment_prefix_if_necessary
3317
	mov	al,0A4h
157 heavyiron 3318
      movs_check_size:
1053 heavyiron 3319
	mov	bl,[operand_size]
157 heavyiron 3320
	cmp	bl,1
3321
	je	simple_instruction
3322
	inc	al
3323
	cmp	bl,2
3324
	je	simple_instruction_16bit
3325
	cmp	bl,4
3326
	je	simple_instruction_32bit
3327
	cmp	bl,8
3328
	je	simple_instruction_64bit
3329
	or	bl,bl
3330
	jnz	invalid_operand_size
1053 heavyiron 3331
	call	recoverable_unknown_size
2665 dunkaist 3332
	jmp	simple_instruction
1053 heavyiron 3333
lods_instruction:
31 halyavin 3334
	lods	byte [esi]
157 heavyiron 3335
	call	get_size_operator
3336
	cmp	al,'['
3337
	jne	invalid_operand
3338
	call	get_address
3339
	or	eax,eax
3340
	jnz	invalid_address
3341
	or	bl,ch
3342
	jnz	invalid_address
3343
	cmp	bh,26h
3344
	je	lods_address_16bit
3345
	cmp	bh,46h
3346
	je	lods_address_32bit
3347
	cmp	bh,86h
3348
	jne	invalid_address
3349
	cmp	[code_type],64
3350
	jne	invalid_address_size
3351
	jmp	lods_store
3352
      lods_address_32bit:
31 halyavin 3353
	call	address_32bit_prefix
157 heavyiron 3354
	jmp	lods_store
3355
      lods_address_16bit:
31 halyavin 3356
	cmp	[code_type],64
157 heavyiron 3357
	je	invalid_address_size
3358
	call	address_16bit_prefix
3359
      lods_store:
31 halyavin 3360
	xor	ebx,ebx
3010 dunkaist 3361
	call	store_segment_prefix_if_necessary
3362
	mov	al,0ACh
157 heavyiron 3363
	jmp	movs_check_size
1053 heavyiron 3364
stos_instruction:
31 halyavin 3365
	mov	[base_code],al
157 heavyiron 3366
	lods	byte [esi]
3367
	call	get_size_operator
3368
	cmp	al,'['
3369
	jne	invalid_operand
3370
	call	get_address
3371
	or	eax,eax
3372
	jnz	invalid_address
3373
	or	bl,ch
3374
	jnz	invalid_address
3375
	cmp	bh,27h
3376
	je	stos_address_16bit
3377
	cmp	bh,47h
3378
	je	stos_address_32bit
3379
	cmp	bh,87h
3380
	jne	invalid_address
3381
	cmp	[code_type],64
3382
	jne	invalid_address_size
3383
	jmp	stos_store
3384
      stos_address_32bit:
31 halyavin 3385
	call	address_32bit_prefix
157 heavyiron 3386
	jmp	stos_store
3387
      stos_address_16bit:
31 halyavin 3388
	cmp	[code_type],64
157 heavyiron 3389
	je	invalid_address_size
3390
	call	address_16bit_prefix
3391
      stos_store:
31 halyavin 3392
	cmp	[segment_register],1
157 heavyiron 3393
	ja	invalid_address
3394
	mov	al,[base_code]
3395
	jmp	movs_check_size
1053 heavyiron 3396
cmps_instruction:
31 halyavin 3397
	lods	byte [esi]
157 heavyiron 3398
	call	get_size_operator
3399
	cmp	al,'['
3400
	jne	invalid_operand
3401
	call	get_address
3402
	or	eax,eax
3403
	jnz	invalid_address
3404
	or	bl,ch
3405
	jnz	invalid_address
3406
	mov	al,[segment_register]
3407
	push	eax ebx
174 heavyiron 3408
	lods	byte [esi]
157 heavyiron 3409
	cmp	al,','
3410
	jne	invalid_operand
3411
	lods	byte [esi]
3412
	call	get_size_operator
3413
	cmp	al,'['
3414
	jne	invalid_operand
3415
	call	get_address
3416
	or	eax,eax
3417
	jnz	invalid_address
3418
	or	bl,ch
3419
	jnz	invalid_address
3420
	pop	edx eax
174 heavyiron 3421
	cmp	[segment_register],1
157 heavyiron 3422
	ja	invalid_address
3423
	mov	[segment_register],al
3424
	mov	al,dh
3425
	mov	ah,bh
3426
	shr	al,4
3427
	shr	ah,4
3428
	cmp	al,ah
3429
	jne	address_sizes_do_not_agree
3430
	and	bh,111b
3431
	and	dh,111b
3432
	cmp	bh,7
3433
	jne	invalid_address
3434
	cmp	dh,6
3435
	jne	invalid_address
3436
	cmp	al,2
3437
	je	cmps_address_16bit
3438
	cmp	al,4
3439
	je	cmps_address_32bit
3440
	cmp	[code_type],64
3441
	jne	invalid_address_size
3442
	jmp	cmps_store
3443
      cmps_address_32bit:
31 halyavin 3444
	call	address_32bit_prefix
157 heavyiron 3445
	jmp	cmps_store
3446
      cmps_address_16bit:
31 halyavin 3447
	cmp	[code_type],64
157 heavyiron 3448
	je	invalid_address_size
3449
	call	address_16bit_prefix
3450
      cmps_store:
31 halyavin 3451
	xor	ebx,ebx
3010 dunkaist 3452
	call	store_segment_prefix_if_necessary
3453
	mov	al,0A6h
157 heavyiron 3454
	jmp	movs_check_size
1053 heavyiron 3455
ins_instruction:
31 halyavin 3456
	lods	byte [esi]
157 heavyiron 3457
	call	get_size_operator
3458
	cmp	al,'['
3459
	jne	invalid_operand
3460
	call	get_address
3461
	or	eax,eax
3462
	jnz	invalid_address
3463
	or	bl,ch
3464
	jnz	invalid_address
3465
	cmp	bh,27h
3466
	je	ins_address_16bit
3467
	cmp	bh,47h
3468
	je	ins_address_32bit
3469
	cmp	bh,87h
3470
	jne	invalid_address
3471
	cmp	[code_type],64
3472
	jne	invalid_address_size
3473
	jmp	ins_store
3474
      ins_address_32bit:
31 halyavin 3475
	call	address_32bit_prefix
157 heavyiron 3476
	jmp	ins_store
3477
      ins_address_16bit:
31 halyavin 3478
	cmp	[code_type],64
157 heavyiron 3479
	je	invalid_address_size
3480
	call	address_16bit_prefix
3481
      ins_store:
31 halyavin 3482
	cmp	[segment_register],1
157 heavyiron 3483
	ja	invalid_address
3484
	lods	byte [esi]
3485
	cmp	al,','
3486
	jne	invalid_operand
3487
	lods	byte [esi]
3488
	cmp	al,10h
3489
	jne	invalid_operand
3490
	lods	byte [esi]
3491
	cmp	al,22h
3492
	jne	invalid_operand
3493
	mov	al,6Ch
3494
      ins_check_size:
1053 heavyiron 3495
	cmp	[operand_size],8
3496
	jne	movs_check_size
3497
	jmp	invalid_operand_size
157 heavyiron 3498
outs_instruction:
31 halyavin 3499
	lods	byte [esi]
157 heavyiron 3500
	cmp	al,10h
3501
	jne	invalid_operand
3502
	lods	byte [esi]
3503
	cmp	al,22h
3504
	jne	invalid_operand
3505
	lods	byte [esi]
3506
	cmp	al,','
3507
	jne	invalid_operand
3508
	lods	byte [esi]
3509
	call	get_size_operator
3510
	cmp	al,'['
3511
	jne	invalid_operand
3512
	call	get_address
3513
	or	eax,eax
3514
	jnz	invalid_address
3515
	or	bl,ch
3516
	jnz	invalid_address
3517
	cmp	bh,26h
3518
	je	outs_address_16bit
3519
	cmp	bh,46h
3520
	je	outs_address_32bit
3521
	cmp	bh,86h
3522
	jne	invalid_address
3523
	cmp	[code_type],64
3524
	jne	invalid_address_size
3525
	jmp	outs_store
3526
      outs_address_32bit:
31 halyavin 3527
	call	address_32bit_prefix
157 heavyiron 3528
	jmp	outs_store
3529
      outs_address_16bit:
31 halyavin 3530
	cmp	[code_type],64
157 heavyiron 3531
	je	invalid_address_size
3532
	call	address_16bit_prefix
3533
      outs_store:
31 halyavin 3534
	xor	ebx,ebx
3010 dunkaist 3535
	call	store_segment_prefix_if_necessary
3536
	mov	al,6Eh
157 heavyiron 3537
	jmp	ins_check_size
1053 heavyiron 3538
xlat_instruction:
31 halyavin 3539
	lods	byte [esi]
157 heavyiron 3540
	call	get_size_operator
3541
	cmp	al,'['
3542
	jne	invalid_operand
3543
	call	get_address
3544
	or	eax,eax
3545
	jnz	invalid_address
3546
	or	bl,ch
3547
	jnz	invalid_address
3548
	cmp	bh,23h
3549
	je	xlat_address_16bit
3550
	cmp	bh,43h
3551
	je	xlat_address_32bit
3552
	cmp	bh,83h
3553
	jne	invalid_address
3554
	cmp	[code_type],64
3555
	jne	invalid_address_size
3556
	jmp	xlat_store
3557
      xlat_address_32bit:
31 halyavin 3558
	call	address_32bit_prefix
157 heavyiron 3559
	jmp	xlat_store
3560
      xlat_address_16bit:
31 halyavin 3561
	cmp	[code_type],64
157 heavyiron 3562
	je	invalid_address_size
3563
	call	address_16bit_prefix
3564
      xlat_store:
31 halyavin 3565
	call	store_segment_prefix_if_necessary
157 heavyiron 3566
	mov	al,0D7h
3567
	cmp	[operand_size],1
3568
	jbe	simple_instruction
3569
	jmp	invalid_operand_size
3570
31 halyavin 3571
 
3572
	mov	ah,al
157 heavyiron 3573
	shr	ah,4
3574
	and	al,111b
3575
	mov	[base_code],0Fh
3576
	mov	[extended_code],ah
3577
	mov	[postbyte_register],al
3578
	lods	byte [esi]
3579
	call	get_size_operator
3580
	cmp	al,10h
3581
	je	pm_reg
3582
      pm_mem:
31 halyavin 3583
	cmp	al,'['
157 heavyiron 3584
	jne	invalid_operand
3585
	call	get_address
3586
	mov	al,[operand_size]
3587
	cmp	al,2
3588
	je	pm_mem_store
3589
	or	al,al
3590
	jnz	invalid_operand_size
3591
      pm_mem_store:
31 halyavin 3592
	jmp	instruction_ready
1053 heavyiron 3593
      pm_reg:
31 halyavin 3594
	lods	byte [esi]
157 heavyiron 3595
	call	convert_register
3596
	mov	bl,al
3597
	cmp	ah,2
3598
	jne	invalid_operand_size
3599
	jmp	nomem_instruction_ready
1053 heavyiron 3600
pm_store_word_instruction:
31 halyavin 3601
	mov	ah,al
157 heavyiron 3602
	shr	ah,4
3603
	and	al,111b
3604
	mov	[base_code],0Fh
3605
	mov	[extended_code],ah
3606
	mov	[postbyte_register],al
3607
	lods	byte [esi]
3608
	call	get_size_operator
3609
	cmp	al,10h
3610
	jne	pm_mem
3611
	lods	byte [esi]
3612
	call	convert_register
3613
	mov	bl,al
3614
	mov	al,ah
3615
	call	operand_autodetect
3616
	jmp	nomem_instruction_ready
1053 heavyiron 3617
lgdt_instruction:
31 halyavin 3618
	mov	[base_code],0Fh
157 heavyiron 3619
	mov	[extended_code],1
3620
	mov	[postbyte_register],al
3621
	lods	byte [esi]
3622
	call	get_size_operator
3623
	cmp	al,'['
3624
	jne	invalid_operand
3625
	call	get_address
3626
	mov	al,[operand_size]
3627
	cmp	al,6
3628
	je	lgdt_mem_48bit
3629
	cmp	al,10
3630
	je	lgdt_mem_80bit
3631
	or	al,al
3632
	jnz	invalid_operand_size
3633
	jmp	lgdt_mem_store
3634
      lgdt_mem_80bit:
109 heavyiron 3635
	cmp	[code_type],64
157 heavyiron 3636
	jne	illegal_instruction
3637
	jmp	lgdt_mem_store
3638
      lgdt_mem_48bit:
31 halyavin 3639
	cmp	[code_type],64
157 heavyiron 3640
	je	illegal_instruction
3641
	cmp	[postbyte_register],2
3642
	jb	lgdt_mem_store
3643
	call	operand_32bit
3644
      lgdt_mem_store:
109 heavyiron 3645
	jmp	instruction_ready
1053 heavyiron 3646
lar_instruction:
31 halyavin 3647
	mov	[extended_code],al
157 heavyiron 3648
	mov	[base_code],0Fh
3649
	lods	byte [esi]
3650
	call	get_size_operator
3651
	cmp	al,10h
3652
	jne	invalid_operand
3653
	lods	byte [esi]
3654
	call	convert_register
3655
	mov	[postbyte_register],al
3656
	lods	byte [esi]
3657
	cmp	al,','
3658
	jne	invalid_operand
3659
	xor	al,al
3660
	xchg	al,[operand_size]
3661
	call	operand_autodetect
3662
	lods	byte [esi]
3663
	call	get_size_operator
3664
	cmp	al,10h
3665
	je	lar_reg_reg
3666
	cmp	al,'['
3667
	jne	invalid_operand
3668
	call	get_address
3669
	mov	al,[operand_size]
3670
	or	al,al
3671
	jz	lar_reg_mem
3672
	cmp	al,2
3673
	jne	invalid_operand_size
3674
      lar_reg_mem:
31 halyavin 3675
	jmp	instruction_ready
1053 heavyiron 3676
      lar_reg_reg:
31 halyavin 3677
	lods	byte [esi]
157 heavyiron 3678
	call	convert_register
3679
	cmp	ah,2
3680
	jne	invalid_operand_size
3681
	mov	bl,al
3682
	jmp	nomem_instruction_ready
1053 heavyiron 3683
invlpg_instruction:
31 halyavin 3684
	mov	[base_code],0Fh
157 heavyiron 3685
	mov	[extended_code],1
3686
	mov	[postbyte_register],7
3687
	lods	byte [esi]
3688
	call	get_size_operator
3689
	cmp	al,'['
3690
	jne	invalid_operand
3691
	call	get_address
3692
	jmp	instruction_ready
1053 heavyiron 3693
swapgs_instruction:
31 halyavin 3694
	cmp	[code_type],64
2287 heavyiron 3695
	jne	illegal_instruction
3696
rdtscp_instruction:
3697
	mov	[base_code],0Fh
157 heavyiron 3698
	mov	[extended_code],1
3699
	mov	[postbyte_register],7
3700
	mov	bl,al
3701
	jmp	nomem_instruction_ready
1053 heavyiron 3702
31 halyavin 3703
 
3704
	mov	[base_code],0Fh
157 heavyiron 3705
	mov	[extended_code],al
3706
	lods	byte [esi]
3707
	call	get_size_operator
3708
	cmp	al,10h
3709
	je	basic_486_reg
3710
	cmp	al,'['
3711
	jne	invalid_operand
3712
	call	get_address
3713
	push	edx ebx ecx
174 heavyiron 3714
	lods	byte [esi]
157 heavyiron 3715
	cmp	al,','
3716
	jne	invalid_operand
3717
	lods	byte [esi]
3718
	call	get_size_operator
3719
	cmp	al,10h
3720
	jne	invalid_operand
3721
	lods	byte [esi]
3722
	call	convert_register
3723
	mov	[postbyte_register],al
3724
	pop	ecx ebx edx
174 heavyiron 3725
	mov	al,ah
157 heavyiron 3726
	cmp	al,1
3727
	je	basic_486_mem_reg_8bit
3728
	call	operand_autodetect
3729
	inc	[extended_code]
3730
      basic_486_mem_reg_8bit:
31 halyavin 3731
	jmp	instruction_ready
1053 heavyiron 3732
      basic_486_reg:
31 halyavin 3733
	lods	byte [esi]
157 heavyiron 3734
	call	convert_register
3735
	mov	[postbyte_register],al
3736
	lods	byte [esi]
3737
	cmp	al,','
3738
	jne	invalid_operand
3739
	lods	byte [esi]
3740
	call	get_size_operator
3741
	cmp	al,10h
3742
	jne	invalid_operand
3743
	lods	byte [esi]
3744
	call	convert_register
3745
	mov	bl,[postbyte_register]
3746
	mov	[postbyte_register],al
3747
	mov	al,ah
3748
	cmp	al,1
3749
	je	basic_486_reg_reg_8bit
3750
	call	operand_autodetect
3751
	inc	[extended_code]
3752
      basic_486_reg_reg_8bit:
31 halyavin 3753
	jmp	nomem_instruction_ready
1053 heavyiron 3754
bswap_instruction:
31 halyavin 3755
	lods	byte [esi]
157 heavyiron 3756
	call	get_size_operator
3757
	cmp	al,10h
3758
	jne	invalid_operand
3759
	lods	byte [esi]
3760
	call	convert_register
3761
	test	al,1000b
3762
	jz	bswap_reg_code_ok
3763
	or	[rex_prefix],41h
3764
	and	al,111b
3765
      bswap_reg_code_ok:
109 heavyiron 3766
	add	al,0C8h
157 heavyiron 3767
	mov	[extended_code],al
3768
	mov	[base_code],0Fh
3769
	cmp	ah,8
3770
	je	bswap_reg64
3771
	cmp	ah,4
3772
	jne	invalid_operand_size
3773
	call	operand_32bit
3774
	call	store_instruction_code
3775
	jmp	instruction_assembled
3776
      bswap_reg64:
31 halyavin 3777
	call	operand_64bit
157 heavyiron 3778
	call	store_instruction_code
3779
	jmp	instruction_assembled
3780
cmpxchgx_instruction:
31 halyavin 3781
	mov	[base_code],0Fh
157 heavyiron 3782
	mov	[extended_code],0C7h
3783
	mov	[postbyte_register],al
3784
	lods	byte [esi]
3785
	call	get_size_operator
3786
	cmp	al,'['
3787
	jne	invalid_operand
3788
	call	get_address
3789
	mov	ah,1
3790
	xchg	[postbyte_register],ah
3791
	mov	al,[operand_size]
3792
	or	al,al
3793
	jz	cmpxchgx_size_ok
3794
	cmp	al,ah
3795
	jne	invalid_operand_size
3796
      cmpxchgx_size_ok:
31 halyavin 3797
	cmp	ah,16
157 heavyiron 3798
	jne	cmpxchgx_store
3799
	call	operand_64bit
3800
      cmpxchgx_store:
31 halyavin 3801
	jmp	instruction_ready
1053 heavyiron 3802
nop_instruction:
174 heavyiron 3803
	mov	ah,[esi]
3804
	cmp	ah,10h
3805
	je	extended_nop
3806
	cmp	ah,11h
3807
	je	extended_nop
3808
	cmp	ah,'['
3809
	je	extended_nop
3810
	stos	byte [edi]
3811
	jmp	instruction_assembled
3812
      extended_nop:
3813
	mov	[base_code],0Fh
3814
	mov	[extended_code],1Fh
3815
	mov	[postbyte_register],0
3816
	lods	byte [esi]
3817
	call	get_size_operator
3818
	cmp	al,10h
3819
	je	extended_nop_reg
3820
	cmp	al,'['
3821
	jne	invalid_operand
3822
	call	get_address
3823
	mov	al,[operand_size]
3824
	or	al,al
3825
	jz	extended_nop_store
1039 heavyiron 3826
	call	operand_autodetect
174 heavyiron 3827
      extended_nop_store:
3828
	jmp	instruction_ready
1053 heavyiron 3829
      extended_nop_reg:
174 heavyiron 3830
	lods	byte [esi]
3831
	call	convert_register
3832
	mov	bl,al
3833
	mov	al,ah
3834
	call	operand_autodetect
3835
	jmp	nomem_instruction_ready
1053 heavyiron 3836
31 halyavin 3837
 
3838
	mov	[postbyte_register],al
157 heavyiron 3839
	mov	[base_code],0D8h
3840
	lods	byte [esi]
3841
	call	get_size_operator
3842
	cmp	al,10h
3843
	je	basic_fpu_streg
3844
	cmp	al,'['
3845
	je	basic_fpu_mem
3846
	dec	esi
3847
	mov	ah,[postbyte_register]
3848
	cmp	ah,2
3849
	jb	invalid_operand
3850
	cmp	ah,3
3851
	ja	invalid_operand
3852
	mov	bl,1
3853
	jmp	nomem_instruction_ready
1053 heavyiron 3854
      basic_fpu_mem:
31 halyavin 3855
	call	get_address
157 heavyiron 3856
	mov	al,[operand_size]
3857
	cmp	al,4
3858
	je	basic_fpu_mem_32bit
3859
	cmp	al,8
3860
	je	basic_fpu_mem_64bit
3861
	or	al,al
3862
	jnz	invalid_operand_size
3863
	call	recoverable_unknown_size
2665 dunkaist 3864
      basic_fpu_mem_32bit:
31 halyavin 3865
	jmp	instruction_ready
1053 heavyiron 3866
      basic_fpu_mem_64bit:
31 halyavin 3867
	mov	[base_code],0DCh
157 heavyiron 3868
	jmp	instruction_ready
1053 heavyiron 3869
      basic_fpu_streg:
31 halyavin 3870
	lods	byte [esi]
157 heavyiron 3871
	call	convert_fpu_register
3872
	mov	bl,al
3873
	mov	ah,[postbyte_register]
3874
	cmp	ah,2
3875
	je	basic_fpu_single_streg
3876
	cmp	ah,3
3877
	je	basic_fpu_single_streg
3878
	or	al,al
3879
	jz	basic_fpu_st0
3880
	test	ah,110b
3881
	jz	basic_fpu_streg_st0
3882
	xor	[postbyte_register],1
3883
      basic_fpu_streg_st0:
31 halyavin 3884
	lods	byte [esi]
157 heavyiron 3885
	cmp	al,','
3886
	jne	invalid_operand
3887
	lods	byte [esi]
3888
	call	get_size_operator
3889
	cmp	al,10h
3890
	jne	invalid_operand
3891
	lods	byte [esi]
3892
	call	convert_fpu_register
3893
	or	al,al
3894
	jnz	invalid_operand
3895
	mov	[base_code],0DCh
3896
	jmp	nomem_instruction_ready
1053 heavyiron 3897
      basic_fpu_st0:
31 halyavin 3898
	lods	byte [esi]
157 heavyiron 3899
	cmp	al,','
3900
	jne	invalid_operand
3901
	lods	byte [esi]
3902
	call	get_size_operator
3903
	cmp	al,10h
3904
	jne	invalid_operand
3905
	lods	byte [esi]
3906
	call	convert_fpu_register
3907
	mov	bl,al
3908
      basic_fpu_single_streg:
31 halyavin 3909
	mov	[base_code],0D8h
157 heavyiron 3910
	jmp	nomem_instruction_ready
1053 heavyiron 3911
simple_fpu_instruction:
31 halyavin 3912
	mov	ah,al
157 heavyiron 3913
	or	ah,11000000b
3914
	mov	al,0D9h
3915
	stos	word [edi]
3916
	jmp	instruction_assembled
3917
fi_instruction:
31 halyavin 3918
	mov	[postbyte_register],al
157 heavyiron 3919
	lods	byte [esi]
3920
	call	get_size_operator
3921
	cmp	al,'['
3922
	jne	invalid_operand
3923
	call	get_address
3924
	mov	al,[operand_size]
3925
	cmp	al,2
3926
	je	fi_mem_16bit
3927
	cmp	al,4
3928
	je	fi_mem_32bit
3929
	or	al,al
3930
	jnz	invalid_operand_size
3931
	call	recoverable_unknown_size
2665 dunkaist 3932
      fi_mem_32bit:
31 halyavin 3933
	mov	[base_code],0DAh
157 heavyiron 3934
	jmp	instruction_ready
1053 heavyiron 3935
      fi_mem_16bit:
31 halyavin 3936
	mov	[base_code],0DEh
157 heavyiron 3937
	jmp	instruction_ready
1053 heavyiron 3938
fld_instruction:
31 halyavin 3939
	mov	[postbyte_register],al
157 heavyiron 3940
	lods	byte [esi]
3941
	call	get_size_operator
3942
	cmp	al,10h
3943
	je	fld_streg
3944
	cmp	al,'['
3945
	jne	invalid_operand
3946
	call	get_address
3947
	mov	al,[operand_size]
3948
	cmp	al,4
3949
	je	fld_mem_32bit
3950
	cmp	al,8
3951
	je	fld_mem_64bit
3952
	cmp	al,10
3953
	je	fld_mem_80bit
3954
	or	al,al
3955
	jnz	invalid_operand_size
3956
	call	recoverable_unknown_size
2665 dunkaist 3957
      fld_mem_32bit:
31 halyavin 3958
	mov	[base_code],0D9h
157 heavyiron 3959
	jmp	instruction_ready
1053 heavyiron 3960
      fld_mem_64bit:
31 halyavin 3961
	mov	[base_code],0DDh
157 heavyiron 3962
	jmp	instruction_ready
1053 heavyiron 3963
      fld_mem_80bit:
31 halyavin 3964
	mov	al,[postbyte_register]
157 heavyiron 3965
	cmp	al,0
3966
	je	fld_mem_80bit_store
3967
	dec	[postbyte_register]
3968
	cmp	al,3
3969
	je	fld_mem_80bit_store
3970
	jmp	invalid_operand_size
3971
      fld_mem_80bit_store:
31 halyavin 3972
	add	[postbyte_register],5
157 heavyiron 3973
	mov	[base_code],0DBh
3974
	jmp	instruction_ready
1053 heavyiron 3975
      fld_streg:
31 halyavin 3976
	lods	byte [esi]
157 heavyiron 3977
	call	convert_fpu_register
3978
	mov	bl,al
3979
	cmp	[postbyte_register],2
3980
	jae	fst_streg
3981
	mov	[base_code],0D9h
3982
	jmp	nomem_instruction_ready
1053 heavyiron 3983
      fst_streg:
31 halyavin 3984
	mov	[base_code],0DDh
157 heavyiron 3985
	jmp	nomem_instruction_ready
1053 heavyiron 3986
fild_instruction:
31 halyavin 3987
	mov	[postbyte_register],al
157 heavyiron 3988
	lods	byte [esi]
3989
	call	get_size_operator
3990
	cmp	al,'['
3991
	jne	invalid_operand
3992
	call	get_address
3993
	mov	al,[operand_size]
3994
	cmp	al,2
3995
	je	fild_mem_16bit
3996
	cmp	al,4
3997
	je	fild_mem_32bit
3998
	cmp	al,8
3999
	je	fild_mem_64bit
4000
	or	al,al
4001
	jnz	invalid_operand_size
4002
	call	recoverable_unknown_size
2665 dunkaist 4003
      fild_mem_32bit:
31 halyavin 4004
	mov	[base_code],0DBh
157 heavyiron 4005
	jmp	instruction_ready
1053 heavyiron 4006
      fild_mem_16bit:
31 halyavin 4007
	mov	[base_code],0DFh
157 heavyiron 4008
	jmp	instruction_ready
1053 heavyiron 4009
      fild_mem_64bit:
31 halyavin 4010
	mov	al,[postbyte_register]
157 heavyiron 4011
	cmp	al,1
4012
	je	fisttp_64bit_store
4013
	jb	fild_mem_64bit_store
4014
	dec	[postbyte_register]
4015
	cmp	al,3
4016
	je	fild_mem_64bit_store
4017
	jmp	invalid_operand_size
4018
      fild_mem_64bit_store:
31 halyavin 4019
	add	[postbyte_register],5
157 heavyiron 4020
	mov	[base_code],0DFh
4021
	jmp	instruction_ready
1053 heavyiron 4022
      fisttp_64bit_store:
31 halyavin 4023
	mov	[base_code],0DDh
157 heavyiron 4024
	jmp	instruction_ready
1053 heavyiron 4025
fbld_instruction:
31 halyavin 4026
	mov	[postbyte_register],al
157 heavyiron 4027
	lods	byte [esi]
4028
	call	get_size_operator
4029
	cmp	al,'['
4030
	jne	invalid_operand
4031
	call	get_address
4032
	mov	al,[operand_size]
4033
	or	al,al
4034
	jz	fbld_mem_80bit
4035
	cmp	al,10
4036
	je	fbld_mem_80bit
4037
	jmp	invalid_operand_size
4038
      fbld_mem_80bit:
31 halyavin 4039
	mov	[base_code],0DFh
157 heavyiron 4040
	jmp	instruction_ready
1053 heavyiron 4041
faddp_instruction:
31 halyavin 4042
	mov	[postbyte_register],al
157 heavyiron 4043
	mov	[base_code],0DEh
4044
	mov	edx,esi
4045
	lods	byte [esi]
4046
	call	get_size_operator
4047
	cmp	al,10h
4048
	je	faddp_streg
4049
	mov	esi,edx
4050
	mov	bl,1
4051
	jmp	nomem_instruction_ready
1053 heavyiron 4052
      faddp_streg:
31 halyavin 4053
	lods	byte [esi]
157 heavyiron 4054
	call	convert_fpu_register
4055
	mov	bl,al
4056
	lods	byte [esi]
4057
	cmp	al,','
4058
	jne	invalid_operand
4059
	lods	byte [esi]
4060
	call	get_size_operator
4061
	cmp	al,10h
4062
	jne	invalid_operand
4063
	lods	byte [esi]
4064
	call	convert_fpu_register
4065
	or	al,al
4066
	jnz	invalid_operand
4067
	jmp	nomem_instruction_ready
1053 heavyiron 4068
fcompp_instruction:
31 halyavin 4069
	mov	ax,0D9DEh
157 heavyiron 4070
	stos	word [edi]
4071
	jmp	instruction_assembled
4072
fucompp_instruction:
31 halyavin 4073
	mov	ax,0E9DAh
157 heavyiron 4074
	stos	word [edi]
4075
	jmp	instruction_assembled
4076
fxch_instruction:
31 halyavin 4077
	mov	dx,01D9h
157 heavyiron 4078
	jmp	fpu_single_operand
4079
ffreep_instruction:
31 halyavin 4080
	mov	dx,00DFh
157 heavyiron 4081
	jmp	fpu_single_operand
4082
ffree_instruction:
31 halyavin 4083
	mov	dl,0DDh
157 heavyiron 4084
	mov	dh,al
4085
      fpu_single_operand:
31 halyavin 4086
	mov	ebx,esi
157 heavyiron 4087
	lods	byte [esi]
4088
	call	get_size_operator
4089
	cmp	al,10h
4090
	je	fpu_streg
4091
	or	dh,dh
4092
	jz	invalid_operand
4093
	mov	esi,ebx
4094
	shl	dh,3
4095
	or	dh,11000001b
4096
	mov	ax,dx
4097
	stos	word [edi]
4098
	jmp	instruction_assembled
4099
      fpu_streg:
31 halyavin 4100
	lods	byte [esi]
157 heavyiron 4101
	call	convert_fpu_register
4102
	shl	dh,3
4103
	or	dh,al
4104
	or	dh,11000000b
4105
	mov	ax,dx
4106
	stos	word [edi]
4107
	jmp	instruction_assembled
4108
1039 heavyiron 4109
 
31 halyavin 4110
	mov	byte [edi],9Bh
157 heavyiron 4111
	inc	edi
4112
fldenv_instruction:
31 halyavin 4113
	mov	[base_code],0D9h
157 heavyiron 4114
	jmp	fpu_mem
4115
fstenv_instruction_16bit:
1039 heavyiron 4116
	mov	byte [edi],9Bh
4117
	inc	edi
4118
fldenv_instruction_16bit:
4119
	call	operand_16bit
4120
	jmp	fldenv_instruction
4121
fstenv_instruction_32bit:
4122
	mov	byte [edi],9Bh
4123
	inc	edi
4124
fldenv_instruction_32bit:
4125
	call	operand_32bit
4126
	jmp	fldenv_instruction
4127
fsave_instruction_32bit:
4128
	mov	byte [edi],9Bh
4129
	inc	edi
4130
fnsave_instruction_32bit:
4131
	call	operand_32bit
4132
	jmp	fnsave_instruction
4133
fsave_instruction_16bit:
4134
	mov	byte [edi],9Bh
4135
	inc	edi
4136
fnsave_instruction_16bit:
4137
	call	operand_16bit
4138
	jmp	fnsave_instruction
4139
fsave_instruction:
31 halyavin 4140
	mov	byte [edi],9Bh
157 heavyiron 4141
	inc	edi
4142
fnsave_instruction:
31 halyavin 4143
	mov	[base_code],0DDh
157 heavyiron 4144
      fpu_mem:
31 halyavin 4145
	mov	[postbyte_register],al
157 heavyiron 4146
	lods	byte [esi]
4147
	call	get_size_operator
4148
	cmp	al,'['
4149
	jne	invalid_operand
4150
	call	get_address
4151
	cmp	[operand_size],0
4152
	jne	invalid_operand_size
4153
	jmp	instruction_ready
1053 heavyiron 4154
fstcw_instruction:
31 halyavin 4155
	mov	byte [edi],9Bh
157 heavyiron 4156
	inc	edi
4157
fldcw_instruction:
31 halyavin 4158
	mov	[postbyte_register],al
157 heavyiron 4159
	mov	[base_code],0D9h
4160
	lods	byte [esi]
4161
	call	get_size_operator
4162
	cmp	al,'['
4163
	jne	invalid_operand
4164
	call	get_address
4165
	mov	al,[operand_size]
4166
	or	al,al
4167
	jz	fldcw_mem_16bit
4168
	cmp	al,2
4169
	je	fldcw_mem_16bit
4170
	jmp	invalid_operand_size
4171
      fldcw_mem_16bit:
31 halyavin 4172
	jmp	instruction_ready
1053 heavyiron 4173
fstsw_instruction:
31 halyavin 4174
	mov	al,9Bh
157 heavyiron 4175
	stos	byte [edi]
4176
fnstsw_instruction:
31 halyavin 4177
	mov	[base_code],0DDh
157 heavyiron 4178
	mov	[postbyte_register],7
4179
	lods	byte [esi]
4180
	call	get_size_operator
4181
	cmp	al,10h
4182
	je	fstsw_reg
4183
	cmp	al,'['
4184
	jne	invalid_operand
4185
	call	get_address
4186
	mov	al,[operand_size]
4187
	or	al,al
4188
	jz	fstsw_mem_16bit
4189
	cmp	al,2
4190
	je	fstsw_mem_16bit
4191
	jmp	invalid_operand_size
4192
      fstsw_mem_16bit:
31 halyavin 4193
	jmp	instruction_ready
1053 heavyiron 4194
      fstsw_reg:
31 halyavin 4195
	lods	byte [esi]
157 heavyiron 4196
	call	convert_register
4197
	cmp	ax,0200h
4198
	jne	invalid_operand
4199
	mov	ax,0E0DFh
4200
	stos	word [edi]
4201
	jmp	instruction_assembled
4202
finit_instruction:
31 halyavin 4203
	mov	byte [edi],9Bh
157 heavyiron 4204
	inc	edi
4205
fninit_instruction:
31 halyavin 4206
	mov	ah,al
157 heavyiron 4207
	mov	al,0DBh
4208
	stos	word [edi]
4209
	jmp	instruction_assembled
4210
fcmov_instruction:
31 halyavin 4211
	mov	dh,0DAh
157 heavyiron 4212
	jmp	fcomi_streg
4213
fcomi_instruction:
31 halyavin 4214
	mov	dh,0DBh
157 heavyiron 4215
	jmp	fcomi_streg
4216
fcomip_instruction:
31 halyavin 4217
	mov	dh,0DFh
157 heavyiron 4218
      fcomi_streg:
31 halyavin 4219
	mov	dl,al
157 heavyiron 4220
	lods	byte [esi]
4221
	call	get_size_operator
4222
	cmp	al,10h
4223
	jne	invalid_operand
4224
	lods	byte [esi]
4225
	call	convert_fpu_register
4226
	mov	ah,al
4227
	cmp	byte [esi],','
4228
	je	fcomi_st0_streg
4229
	add	ah,dl
4230
	mov	al,dh
4231
	stos	word [edi]
4232
	jmp	instruction_assembled
4233
      fcomi_st0_streg:
31 halyavin 4234
	or	ah,ah
157 heavyiron 4235
	jnz	invalid_operand
4236
	inc	esi
4237
	lods	byte [esi]
4238
	call	get_size_operator
4239
	cmp	al,10h
4240
	jne	invalid_operand
4241
	lods	byte [esi]
4242
	call	convert_fpu_register
4243
	mov	ah,al
4244
	add	ah,dl
4245
	mov	al,dh
4246
	stos	word [edi]
4247
	jmp	instruction_assembled
4248
31 halyavin 4249
 
174 heavyiron 4250
	mov	[base_code],0Fh
157 heavyiron 4251
	mov	[extended_code],al
4252
      mmx_instruction:
174 heavyiron 4253
	lods	byte [esi]
157 heavyiron 4254
	call	get_size_operator
4255
	cmp	al,10h
4256
	jne	invalid_operand
4257
	lods	byte [esi]
4258
	call	convert_mmx_register
4259
	call	make_mmx_prefix
4260
	mov	[postbyte_register],al
4261
	lods	byte [esi]
4262
	cmp	al,','
4263
	jne	invalid_operand
4264
	lods	byte [esi]
4265
	call	get_size_operator
4266
	cmp	al,10h
4267
	je	mmx_mmreg_mmreg
4268
	cmp	al,'['
4269
	jne	invalid_operand
4270
      mmx_mmreg_mem:
31 halyavin 4271
	call	get_address
157 heavyiron 4272
	jmp	instruction_ready
1053 heavyiron 4273
      mmx_mmreg_mmreg:
31 halyavin 4274
	lods	byte [esi]
157 heavyiron 4275
	call	convert_mmx_register
4276
	mov	bl,al
4277
	jmp	nomem_instruction_ready
1053 heavyiron 4278
mmx_bit_shift_instruction:
2287 heavyiron 4279
	mov	[base_code],0Fh
157 heavyiron 4280
	mov	[extended_code],al
4281
	lods	byte [esi]
4282
	call	get_size_operator
4283
	cmp	al,10h
4284
	jne	invalid_operand
4285
	lods	byte [esi]
4286
	call	convert_mmx_register
4287
	call	make_mmx_prefix
4288
	mov	[postbyte_register],al
4289
	lods	byte [esi]
4290
	cmp	al,','
4291
	jne	invalid_operand
4292
	mov	[operand_size],0
4293
	lods	byte [esi]
4294
	call	get_size_operator
4295
	cmp	al,10h
4296
	je	mmx_mmreg_mmreg
4297
	cmp	al,'('
4298
	je	mmx_ps_mmreg_imm8
4299
	cmp	al,'['
4300
	je	mmx_mmreg_mem
4301
	jmp	invalid_operand
4302
      mmx_ps_mmreg_imm8:
31 halyavin 4303
	call	get_byte_value
157 heavyiron 4304
	mov	byte [value],al
4305
	test	[operand_size],not 1
4306
	jnz	invalid_value
4307
	mov	bl,[extended_code]
4308
	mov	al,bl
4309
	shr	bl,4
4310
	and	al,1111b
4311
	add	al,70h
4312
	mov	[extended_code],al
4313
	sub	bl,0Ch
4314
	shl	bl,1
4315
	xchg	bl,[postbyte_register]
4316
	call	store_nomem_instruction
4317
	mov	al,byte [value]
4318
	stos	byte [edi]
4319
	jmp	instruction_assembled
4320
pmovmskb_instruction:
1039 heavyiron 4321
	mov	[base_code],0Fh
157 heavyiron 4322
	mov	[extended_code],al
4323
	lods	byte [esi]
4324
	call	get_size_operator
4325
	cmp	al,10h
4326
	jne	invalid_operand
4327
	lods	byte [esi]
4328
	call	convert_register
4329
	cmp	ah,4
4330
	je	pmovmskb_reg_size_ok
1342 heavyiron 4331
	cmp	[code_type],64
4332
	jne	invalid_operand_size
4333
	cmp	ah,8
4334
	jnz	invalid_operand_size
157 heavyiron 4335
      pmovmskb_reg_size_ok:
1342 heavyiron 4336
	mov	[postbyte_register],al
157 heavyiron 4337
	mov	[operand_size],0
4338
	lods	byte [esi]
4339
	cmp	al,','
4340
	jne	invalid_operand
4341
	lods	byte [esi]
4342
	call	get_size_operator
4343
	cmp	al,10h
4344
	jne	invalid_operand
4345
	lods	byte [esi]
4346
	call	convert_mmx_register
4347
	mov	bl,al
4348
	call	make_mmx_prefix
4349
	cmp	[extended_code],0C5h
4350
	je	mmx_nomem_imm8
4351
	jmp	nomem_instruction_ready
1053 heavyiron 4352
      mmx_imm8:
31 halyavin 4353
	push	ebx ecx edx
174 heavyiron 4354
	xor	cl,cl
2287 heavyiron 4355
	xchg	cl,[operand_size]
4356
	lods	byte [esi]
157 heavyiron 4357
	cmp	al,','
4358
	jne	invalid_operand
4359
	lods	byte [esi]
4360
	call	get_size_operator
4361
	test	ah,not 1
4362
	jnz	invalid_operand_size
4363
	mov	[operand_size],cl
2287 heavyiron 4364
	cmp	al,'('
157 heavyiron 4365
	jne	invalid_operand
4366
	call	get_byte_value
4367
	mov	byte [value],al
4368
	pop	edx ecx ebx
174 heavyiron 4369
	call	store_instruction_with_imm8
157 heavyiron 4370
	jmp	instruction_assembled
4371
      mmx_nomem_imm8:
31 halyavin 4372
	call	store_nomem_instruction
157 heavyiron 4373
	call	append_imm8
1039 heavyiron 4374
	jmp	instruction_assembled
4375
      append_imm8:
4376
	mov	[operand_size],0
157 heavyiron 4377
	lods	byte [esi]
4378
	cmp	al,','
4379
	jne	invalid_operand
4380
	lods	byte [esi]
4381
	call	get_size_operator
4382
	test	ah,not 1
4383
	jnz	invalid_operand_size
4384
	cmp	al,'('
4385
	jne	invalid_operand
4386
	call	get_byte_value
4387
	stosb
4388
	ret
1039 heavyiron 4389
pinsrw_instruction:
31 halyavin 4390
	mov	[extended_code],al
157 heavyiron 4391
	mov	[base_code],0Fh
4392
	lods	byte [esi]
4393
	call	get_size_operator
4394
	cmp	al,10h
4395
	jne	invalid_operand
4396
	lods	byte [esi]
4397
	call	convert_mmx_register
4398
	call	make_mmx_prefix
4399
	mov	[postbyte_register],al
4400
	mov	[operand_size],0
4401
	lods	byte [esi]
4402
	cmp	al,','
4403
	jne	invalid_operand
4404
	lods	byte [esi]
4405
	call	get_size_operator
4406
	cmp	al,10h
4407
	je	pinsrw_mmreg_reg
4408
	cmp	al,'['
4409
	jne	invalid_operand
4410
	call	get_address
4411
	cmp	[operand_size],0
4412
	je	mmx_imm8
4413
	cmp	[operand_size],2
4414
	jne	invalid_operand_size
4415
	jmp	mmx_imm8
4416
      pinsrw_mmreg_reg:
31 halyavin 4417
	lods	byte [esi]
157 heavyiron 4418
	call	convert_register
4419
	cmp	ah,4
4420
	jne	invalid_operand_size
4421
	mov	bl,al
4422
	jmp	mmx_nomem_imm8
4423
pshufw_instruction:
31 halyavin 4424
	mov	[mmx_size],8
157 heavyiron 4425
	mov	[opcode_prefix],al
1039 heavyiron 4426
	jmp	pshuf_instruction
157 heavyiron 4427
pshufd_instruction:
31 halyavin 4428
	mov	[mmx_size],16
157 heavyiron 4429
	mov	[opcode_prefix],al
1039 heavyiron 4430
      pshuf_instruction:
31 halyavin 4431
	mov	[base_code],0Fh
157 heavyiron 4432
	mov	[extended_code],70h
4433
	lods	byte [esi]
4434
	call	get_size_operator
4435
	cmp	al,10h
4436
	jne	invalid_operand
4437
	lods	byte [esi]
4438
	call	convert_mmx_register
4439
	cmp	ah,[mmx_size]
4440
	jne	invalid_operand_size
4441
	mov	[postbyte_register],al
4442
	lods	byte [esi]
4443
	cmp	al,','
4444
	jne	invalid_operand
4445
	lods	byte [esi]
4446
	call	get_size_operator
4447
	cmp	al,10h
4448
	je	pshuf_mmreg_mmreg
4449
	cmp	al,'['
4450
	jne	invalid_operand
4451
	call	get_address
4452
	jmp	mmx_imm8
4453
      pshuf_mmreg_mmreg:
31 halyavin 4454
	lods	byte [esi]
157 heavyiron 4455
	call	convert_mmx_register
4456
	mov	bl,al
4457
	jmp	mmx_nomem_imm8
4458
movd_instruction:
31 halyavin 4459
	mov	[base_code],0Fh
157 heavyiron 4460
	mov	[extended_code],7Eh
4461
	lods	byte [esi]
4462
	call	get_size_operator
4463
	cmp	al,10h
4464
	je	movd_reg
4465
	cmp	al,'['
4466
	jne	invalid_operand
4467
	call	get_address
4468
	test	[operand_size],not 4
4469
	jnz	invalid_operand_size
4470
	mov	[operand_size],0
4471
	lods	byte [esi]
4472
	cmp	al,','
4473
	jne	invalid_operand
4474
	lods	byte [esi]
4475
	call	get_size_operator
4476
	cmp	al,10h
4477
	jne	invalid_operand
4478
	lods	byte [esi]
4479
	call	convert_mmx_register
4480
	call	make_mmx_prefix
4481
	mov	[postbyte_register],al
4482
	jmp	instruction_ready
1053 heavyiron 4483
      movd_reg:
31 halyavin 4484
	lods	byte [esi]
157 heavyiron 4485
	cmp	al,0B0h
4486
	jae	movd_mmreg
4487
	call	convert_register
4488
	cmp	ah,4
4489
	jne	invalid_operand_size
4490
	mov	[operand_size],0
4491
	mov	bl,al
4492
	lods	byte [esi]
4493
	cmp	al,','
4494
	jne	invalid_operand
4495
	lods	byte [esi]
4496
	call	get_size_operator
4497
	cmp	al,10h
4498
	jne	invalid_operand
4499
	lods	byte [esi]
4500
	call	convert_mmx_register
4501
	mov	[postbyte_register],al
4502
	call	make_mmx_prefix
4503
	jmp	nomem_instruction_ready
1053 heavyiron 4504
      movd_mmreg:
31 halyavin 4505
	mov	[extended_code],6Eh
157 heavyiron 4506
	call	convert_mmx_register
4507
	call	make_mmx_prefix
4508
	mov	[postbyte_register],al
4509
	mov	[operand_size],0
4510
	lods	byte [esi]
4511
	cmp	al,','
4512
	jne	invalid_operand
4513
	lods	byte [esi]
4514
	call	get_size_operator
4515
	cmp	al,10h
4516
	je	movd_mmreg_reg
4517
	cmp	al,'['
4518
	jne	invalid_operand
4519
	call	get_address
4520
	test	[operand_size],not 4
4521
	jnz	invalid_operand_size
4522
	jmp	instruction_ready
1053 heavyiron 4523
      movd_mmreg_reg:
31 halyavin 4524
	lods	byte [esi]
157 heavyiron 4525
	call	convert_register
4526
	cmp	ah,4
4527
	jne	invalid_operand_size
4528
	mov	bl,al
4529
	jmp	nomem_instruction_ready
1053 heavyiron 4530
      make_mmx_prefix:
31 halyavin 4531
	cmp	[vex_required],0
2287 heavyiron 4532
	jne	mmx_prefix_for_vex
4533
	cmp	[operand_size],16
157 heavyiron 4534
	jne	no_mmx_prefix
4535
	mov	[operand_prefix],66h
4536
      no_mmx_prefix:
31 halyavin 4537
	ret
157 heavyiron 4538
      mmx_prefix_for_vex:
2287 heavyiron 4539
	cmp	[operand_size],16
4540
	jne	invalid_operand
4541
	mov	[opcode_prefix],66h
4542
	ret
4543
movq_instruction:
31 halyavin 4544
	mov	[base_code],0Fh
157 heavyiron 4545
	lods	byte [esi]
4546
	call	get_size_operator
4547
	cmp	al,10h
4548
	je	movq_reg
4549
	cmp	al,'['
4550
	jne	invalid_operand
4551
	call	get_address
4552
	test	[operand_size],not 8
4553
	jnz	invalid_operand_size
4554
	mov	[operand_size],0
4555
	lods	byte [esi]
4556
	cmp	al,','
4557
	jne	invalid_operand
4558
	lods	byte [esi]
4559
	cmp	al,10h
4560
	jne	invalid_operand
4561
	lods	byte [esi]
4562
	call	convert_mmx_register
4563
	mov	[postbyte_register],al
4564
	cmp	ah,16
4565
	je	movq_mem_xmmreg
4566
	mov	[extended_code],7Fh
4567
	jmp	instruction_ready
1053 heavyiron 4568
     movq_mem_xmmreg:
31 halyavin 4569
	mov	[extended_code],0D6h
157 heavyiron 4570
	mov	[opcode_prefix],66h
1039 heavyiron 4571
	jmp	instruction_ready
1053 heavyiron 4572
     movq_reg:
31 halyavin 4573
	lods	byte [esi]
157 heavyiron 4574
	cmp	al,0B0h
4575
	jae	movq_mmreg
4576
	call	convert_register
4577
	cmp	ah,8
4578
	jne	invalid_operand_size
4579
	mov	bl,al
4580
	lods	byte [esi]
4581
	cmp	al,','
4582
	jne	invalid_operand
4583
	lods	byte [esi]
4584
	call	get_size_operator
4585
	cmp	al,10h
4586
	jne	invalid_operand
4587
	mov	[operand_size],0
992 heavyiron 4588
	lods	byte [esi]
157 heavyiron 4589
	call	convert_mmx_register
4590
	mov	[postbyte_register],al
4591
	call	make_mmx_prefix
4592
	mov	[extended_code],7Eh
4593
	call	operand_64bit
4594
	jmp	nomem_instruction_ready
1053 heavyiron 4595
     movq_mmreg:
31 halyavin 4596
	call	convert_mmx_register
157 heavyiron 4597
	mov	[postbyte_register],al
4598
	mov	[extended_code],6Fh
4599
	mov	[mmx_size],ah
4600
	cmp	ah,16
4601
	jne	movq_mmreg_
4602
	mov	[extended_code],7Eh
4603
	mov	[opcode_prefix],0F3h
1039 heavyiron 4604
      movq_mmreg_:
31 halyavin 4605
	lods	byte [esi]
157 heavyiron 4606
	cmp	al,','
4607
	jne	invalid_operand
4608
	mov	[operand_size],0
4609
	lods	byte [esi]
4610
	call	get_size_operator
4611
	cmp	al,10h
4612
	je	movq_mmreg_reg
4613
	call	get_address
4614
	test	[operand_size],not 8
4615
	jnz	invalid_operand_size
4616
	jmp	instruction_ready
1053 heavyiron 4617
      movq_mmreg_reg:
31 halyavin 4618
	lods	byte [esi]
157 heavyiron 4619
	cmp	al,0B0h
4620
	jae	movq_mmreg_mmreg
4621
	mov	[operand_size],0
4622
	call	convert_register
4623
	cmp	ah,8
4624
	jne	invalid_operand_size
4625
	mov	[extended_code],6Eh
4626
	mov	[opcode_prefix],0
1039 heavyiron 4627
	mov	bl,al
157 heavyiron 4628
	cmp	[mmx_size],16
4629
	jne	movq_mmreg_reg_store
4630
	mov	[opcode_prefix],66h
1039 heavyiron 4631
      movq_mmreg_reg_store:
109 heavyiron 4632
	call	operand_64bit
157 heavyiron 4633
	jmp	nomem_instruction_ready
1053 heavyiron 4634
      movq_mmreg_mmreg:
31 halyavin 4635
	call	convert_mmx_register
157 heavyiron 4636
	cmp	ah,[mmx_size]
872 heavyiron 4637
	jne	invalid_operand_size
4638
	mov	bl,al
157 heavyiron 4639
	jmp	nomem_instruction_ready
1053 heavyiron 4640
movdq_instruction:
31 halyavin 4641
	mov	[opcode_prefix],al
1039 heavyiron 4642
	mov	[base_code],0Fh
157 heavyiron 4643
	mov	[extended_code],6Fh
4644
	lods	byte [esi]
4645
	call	get_size_operator
4646
	cmp	al,10h
4647
	je	movdq_mmreg
4648
	cmp	al,'['
4649
	jne	invalid_operand
4650
	call	get_address
4651
	lods	byte [esi]
4652
	cmp	al,','
4653
	jne	invalid_operand
4654
	lods	byte [esi]
4655
	call	get_size_operator
4656
	cmp	al,10h
4657
	jne	invalid_operand
4658
	lods	byte [esi]
4659
	call	convert_xmm_register
2287 heavyiron 4660
	mov	[postbyte_register],al
157 heavyiron 4661
	mov	[extended_code],7Fh
4662
	jmp	instruction_ready
1053 heavyiron 4663
      movdq_mmreg:
31 halyavin 4664
	lods	byte [esi]
157 heavyiron 4665
	call	convert_xmm_register
2287 heavyiron 4666
	mov	[postbyte_register],al
157 heavyiron 4667
	lods	byte [esi]
4668
	cmp	al,','
4669
	jne	invalid_operand
4670
	lods	byte [esi]
4671
	call	get_size_operator
4672
	cmp	al,10h
4673
	je	movdq_mmreg_mmreg
4674
	cmp	al,'['
4675
	jne	invalid_operand
4676
	call	get_address
4677
	jmp	instruction_ready
1053 heavyiron 4678
      movdq_mmreg_mmreg:
31 halyavin 4679
	lods	byte [esi]
157 heavyiron 4680
	call	convert_xmm_register
2287 heavyiron 4681
	mov	bl,al
157 heavyiron 4682
	jmp	nomem_instruction_ready
1053 heavyiron 4683
lddqu_instruction:
31 halyavin 4684
	lods	byte [esi]
157 heavyiron 4685
	call	get_size_operator
4686
	cmp	al,10h
4687
	jne	invalid_operand
4688
	lods	byte [esi]
4689
	call	convert_xmm_register
2287 heavyiron 4690
	push	eax
157 heavyiron 4691
	lods	byte [esi]
4692
	cmp	al,','
4693
	jne	invalid_operand
4694
	lods	byte [esi]
4695
	call	get_size_operator
4696
	cmp	al,'['
4697
	jne	invalid_operand
4698
	call	get_address
4699
	pop	eax
4700
	mov	[postbyte_register],al
4701
	mov	[opcode_prefix],0F2h
1039 heavyiron 4702
	mov	[base_code],0Fh
157 heavyiron 4703
	mov	[extended_code],0F0h
4704
	jmp	instruction_ready
1053 heavyiron 4705
2287 heavyiron 4706
 
4707
	mov	[opcode_prefix],0F2h
4708
	mov	[mmx_size],8
4709
	jmp	movq2dq_
4710
movq2dq_instruction:
31 halyavin 4711
	mov	[opcode_prefix],0F3h
1039 heavyiron 4712
	mov	[mmx_size],16
2287 heavyiron 4713
      movq2dq_:
4714
	lods	byte [esi]
157 heavyiron 4715
	call	get_size_operator
4716
	cmp	al,10h
4717
	jne	invalid_operand
4718
	lods	byte [esi]
4719
	call	convert_mmx_register
4720
	cmp	ah,[mmx_size]
2287 heavyiron 4721
	jne	invalid_operand_size
157 heavyiron 4722
	mov	[postbyte_register],al
4723
	mov	[operand_size],0
4724
	lods	byte [esi]
4725
	cmp	al,','
4726
	jne	invalid_operand
4727
	lods	byte [esi]
4728
	call	get_size_operator
4729
	cmp	al,10h
4730
	jne	invalid_operand
4731
	lods	byte [esi]
4732
	call	convert_mmx_register
4733
	xor	[mmx_size],8+16
2287 heavyiron 4734
	cmp	ah,[mmx_size]
4735
	jne	invalid_operand_size
157 heavyiron 4736
	mov	bl,al
4737
	mov	[base_code],0Fh
4738
	mov	[extended_code],0D6h
4739
	jmp	nomem_instruction_ready
1053 heavyiron 4740
31 halyavin 4741
 
707 heavyiron 4742
	mov	[immediate_size],1
1062 heavyiron 4743
sse_ps_instruction:
31 halyavin 4744
	mov	[mmx_size],16
157 heavyiron 4745
	jmp	sse_instruction
4746
sse_pd_instruction_imm8:
707 heavyiron 4747
	mov	[immediate_size],1
1062 heavyiron 4748
sse_pd_instruction:
31 halyavin 4749
	mov	[mmx_size],16
157 heavyiron 4750
	mov	[opcode_prefix],66h
1039 heavyiron 4751
	jmp	sse_instruction
157 heavyiron 4752
sse_ss_instruction:
31 halyavin 4753
	mov	[mmx_size],4
157 heavyiron 4754
	mov	[opcode_prefix],0F3h
1039 heavyiron 4755
	jmp	sse_instruction
157 heavyiron 4756
sse_sd_instruction:
31 halyavin 4757
	mov	[mmx_size],8
157 heavyiron 4758
	mov	[opcode_prefix],0F2h
1039 heavyiron 4759
	jmp	sse_instruction
157 heavyiron 4760
cmp_pd_instruction:
2287 heavyiron 4761
	mov	[opcode_prefix],66h
4762
cmp_ps_instruction:
4763
	mov	[mmx_size],16
4764
	mov	byte [value],al
4765
	mov	al,0C2h
4766
	jmp	sse_instruction
4767
cmp_ss_instruction:
4768
	mov	[mmx_size],4
4769
	mov	[opcode_prefix],0F3h
4770
	jmp	cmp_sx_instruction
4771
cmpsd_instruction:
4772
	mov	al,0A7h
4773
	mov	ah,[esi]
4774
	or	ah,ah
4775
	jz	simple_instruction_32bit
4776
	cmp	ah,0Fh
4777
	je	simple_instruction_32bit
4778
	mov	al,-1
4779
cmp_sd_instruction:
4780
	mov	[mmx_size],8
4781
	mov	[opcode_prefix],0F2h
4782
      cmp_sx_instruction:
4783
	mov	byte [value],al
4784
	mov	al,0C2h
4785
	jmp	sse_instruction
4786
comiss_instruction:
31 halyavin 4787
	mov	[mmx_size],4
157 heavyiron 4788
	jmp	sse_instruction
4789
comisd_instruction:
31 halyavin 4790
	mov	[mmx_size],8
157 heavyiron 4791
	mov	[opcode_prefix],66h
1039 heavyiron 4792
	jmp	sse_instruction
157 heavyiron 4793
cvtdq2pd_instruction:
2287 heavyiron 4794
	mov	[opcode_prefix],0F3h
4795
cvtps2pd_instruction:
31 halyavin 4796
	mov	[mmx_size],8
157 heavyiron 4797
	jmp	sse_instruction
4798
cvtpd2dq_instruction:
31 halyavin 4799
	mov	[mmx_size],16
157 heavyiron 4800
	mov	[opcode_prefix],0F2h
1039 heavyiron 4801
	jmp	sse_instruction
157 heavyiron 4802
movshdup_instruction:
2287 heavyiron 4803
	mov	[mmx_size],16
157 heavyiron 4804
	mov	[opcode_prefix],0F3h
1039 heavyiron 4805
sse_instruction:
31 halyavin 4806
	mov	[base_code],0Fh
157 heavyiron 4807
	mov	[extended_code],al
4808
	lods	byte [esi]
4809
	call	get_size_operator
4810
	cmp	al,10h
4811
	jne	invalid_operand
4812
      sse_xmmreg:
31 halyavin 4813
	lods	byte [esi]
157 heavyiron 4814
	call	convert_xmm_register
2287 heavyiron 4815
      sse_reg:
31 halyavin 4816
	mov	[postbyte_register],al
157 heavyiron 4817
	mov	[operand_size],0
4818
	lods	byte [esi]
4819
	cmp	al,','
4820
	jne	invalid_operand
4821
	lods	byte [esi]
4822
	call	get_size_operator
4823
	cmp	al,10h
4824
	je	sse_xmmreg_xmmreg
4825
      sse_reg_mem:
31 halyavin 4826
	cmp	al,'['
157 heavyiron 4827
	jne	invalid_operand
4828
	call	get_address
4829
	cmp	[operand_size],0
4830
	je	sse_mem_size_ok
4831
	mov	al,[mmx_size]
4832
	cmp	[operand_size],al
4833
	jne	invalid_operand_size
4834
      sse_mem_size_ok:
31 halyavin 4835
	mov	al,[extended_code]
2287 heavyiron 4836
	mov	ah,[supplemental_code]
4837
	cmp	al,0C2h
4838
	je	sse_cmp_mem_ok
4839
	cmp	ax,443Ah
4840
	je	sse_cmp_mem_ok
4841
	cmp	[immediate_size],1
1062 heavyiron 4842
	je	mmx_imm8
157 heavyiron 4843
	cmp	[immediate_size],-1
707 heavyiron 4844
	jne	sse_ok
4845
	call	take_additional_xmm0
4846
	mov	[immediate_size],0
1189 heavyiron 4847
      sse_ok:
707 heavyiron 4848
	jmp	instruction_ready
1053 heavyiron 4849
      sse_cmp_mem_ok:
2287 heavyiron 4850
	cmp	byte [value],-1
4851
	je	mmx_imm8
4852
	call	store_instruction_with_imm8
4853
	jmp	instruction_assembled
4854
      sse_xmmreg_xmmreg:
31 halyavin 4855
	cmp	[operand_prefix],66h
157 heavyiron 4856
	jne	sse_xmmreg_xmmreg_ok
4857
	cmp	[extended_code],12h
4858
	je	invalid_operand
4859
	cmp	[extended_code],16h
4860
	je	invalid_operand
4861
      sse_xmmreg_xmmreg_ok:
31 halyavin 4862
	lods	byte [esi]
157 heavyiron 4863
	call	convert_xmm_register
2287 heavyiron 4864
	mov	bl,al
157 heavyiron 4865
	mov	al,[extended_code]
2287 heavyiron 4866
	mov	ah,[supplemental_code]
4867
	cmp	al,0C2h
4868
	je	sse_cmp_nomem_ok
4869
	cmp	ax,443Ah
4870
	je	sse_cmp_nomem_ok
4871
	cmp	[immediate_size],1
1062 heavyiron 4872
	je	mmx_nomem_imm8
157 heavyiron 4873
	cmp	[immediate_size],-1
707 heavyiron 4874
	jne	sse_nomem_ok
4875
	call	take_additional_xmm0
4876
	mov	[immediate_size],0
1189 heavyiron 4877
      sse_nomem_ok:
707 heavyiron 4878
	jmp	nomem_instruction_ready
1053 heavyiron 4879
      sse_cmp_nomem_ok:
2287 heavyiron 4880
	cmp	byte [value],-1
4881
	je	mmx_nomem_imm8
4882
	call	store_nomem_instruction
4883
	mov	al,byte [value]
4884
	stosb
4885
	jmp	instruction_assembled
4886
      take_additional_xmm0:
707 heavyiron 4887
	cmp	byte [esi],','
1189 heavyiron 4888
	jne	additional_xmm0_ok
4889
	inc	esi
4890
	lods	byte [esi]
707 heavyiron 4891
	cmp	al,10h
4892
	jne	invalid_operand
4893
	lods	byte [esi]
4894
	call	convert_xmm_register
2287 heavyiron 4895
	test	al,al
707 heavyiron 4896
	jnz	invalid_operand
4897
      additional_xmm0_ok:
1189 heavyiron 4898
	ret
707 heavyiron 4899
4900
 
2287 heavyiron 4901
	mov	[postbyte_register],al
157 heavyiron 4902
	mov	[opcode_prefix],66h
1039 heavyiron 4903
	mov	[base_code],0Fh
157 heavyiron 4904
	mov	[extended_code],73h
4905
	lods	byte [esi]
4906
	call	get_size_operator
4907
	cmp	al,10h
4908
	jne	invalid_operand
4909
	lods	byte [esi]
4910
	call	convert_xmm_register
2287 heavyiron 4911
	mov	bl,al
157 heavyiron 4912
	jmp	mmx_nomem_imm8
4913
movpd_instruction:
31 halyavin 4914
	mov	[opcode_prefix],66h
1039 heavyiron 4915
movps_instruction:
31 halyavin 4916
	mov	[base_code],0Fh
157 heavyiron 4917
	mov	[extended_code],al
4918
	mov	[mmx_size],16
4919
	jmp	sse_mov_instruction
4920
movss_instruction:
31 halyavin 4921
	mov	[mmx_size],4
157 heavyiron 4922
	mov	[opcode_prefix],0F3h
1039 heavyiron 4923
	jmp	sse_movs
157 heavyiron 4924
movsd_instruction:
31 halyavin 4925
	mov	al,0A5h
157 heavyiron 4926
	mov	ah,[esi]
4927
	or	ah,ah
4928
	jz	simple_instruction_32bit
4929
	cmp	ah,0Fh
4930
	je	simple_instruction_32bit
4931
	mov	[mmx_size],8
4932
	mov	[opcode_prefix],0F2h
1039 heavyiron 4933
      sse_movs:
31 halyavin 4934
	mov	[base_code],0Fh
157 heavyiron 4935
	mov	[extended_code],10h
4936
	jmp	sse_mov_instruction
4937
sse_mov_instruction:
31 halyavin 4938
	lods	byte [esi]
157 heavyiron 4939
	call	get_size_operator
4940
	cmp	al,10h
4941
	je	sse_xmmreg
4942
      sse_mem:
31 halyavin 4943
	cmp	al,'['
157 heavyiron 4944
	jne	invalid_operand
4945
	inc	[extended_code]
4946
	call	get_address
4947
	cmp	[operand_size],0
4948
	je	sse_mem_xmmreg
4949
	mov	al,[mmx_size]
4950
	cmp	[operand_size],al
4951
	jne	invalid_operand_size
4952
	mov	[operand_size],0
4953
      sse_mem_xmmreg:
31 halyavin 4954
	lods	byte [esi]
157 heavyiron 4955
	cmp	al,','
4956
	jne	invalid_operand
4957
	lods	byte [esi]
4958
	call	get_size_operator
4959
	cmp	al,10h
4960
	jne	invalid_operand
4961
	lods	byte [esi]
4962
	call	convert_xmm_register
2287 heavyiron 4963
	mov	[postbyte_register],al
157 heavyiron 4964
	jmp	instruction_ready
1053 heavyiron 4965
movlpd_instruction:
31 halyavin 4966
	mov	[opcode_prefix],66h
1039 heavyiron 4967
movlps_instruction:
31 halyavin 4968
	mov	[base_code],0Fh
157 heavyiron 4969
	mov	[extended_code],al
4970
	mov	[mmx_size],8
4971
	lods	byte [esi]
4972
	call	get_size_operator
4973
	cmp	al,10h
4974
	jne	sse_mem
4975
	lods	byte [esi]
4976
	call	convert_xmm_register
2287 heavyiron 4977
	mov	[postbyte_register],al
157 heavyiron 4978
	mov	[operand_size],0
4979
	lods	byte [esi]
4980
	cmp	al,','
4981
	jne	invalid_operand
4982
	lods	byte [esi]
4983
	call	get_size_operator
4984
	jmp	sse_reg_mem
4985
movhlps_instruction:
31 halyavin 4986
	mov	[base_code],0Fh
157 heavyiron 4987
	mov	[extended_code],al
4988
	mov	[mmx_size],0
4989
	lods	byte [esi]
4990
	call	get_size_operator
4991
	cmp	al,10h
4992
	jne	invalid_operand
4993
	lods	byte [esi]
4994
	call	convert_xmm_register
2287 heavyiron 4995
	mov	[postbyte_register],al
157 heavyiron 4996
	lods	byte [esi]
4997
	cmp	al,','
4998
	jne	invalid_operand
4999
	lods	byte [esi]
5000
	call	get_size_operator
5001
	cmp	al,10h
5002
	je	sse_xmmreg_xmmreg_ok
5003
	jmp	invalid_operand
5004
maskmovq_instruction:
31 halyavin 5005
	mov	cl,8
157 heavyiron 5006
	jmp	maskmov_instruction
5007
maskmovdqu_instruction:
31 halyavin 5008
	mov	cl,16
157 heavyiron 5009
	mov	[opcode_prefix],66h
1039 heavyiron 5010
      maskmov_instruction:
31 halyavin 5011
	mov	[base_code],0Fh
157 heavyiron 5012
	mov	[extended_code],0F7h
5013
	lods	byte [esi]
5014
	call	get_size_operator
5015
	cmp	al,10h
5016
	jne	invalid_operand
5017
	lods	byte [esi]
5018
	call	convert_mmx_register
5019
	cmp	ah,cl
5020
	jne	invalid_operand_size
5021
	mov	[postbyte_register],al
5022
	lods	byte [esi]
5023
	cmp	al,','
5024
	jne	invalid_operand
5025
	lods	byte [esi]
5026
	call	get_size_operator
5027
	cmp	al,10h
5028
	jne	invalid_operand
5029
	lods	byte [esi]
5030
	call	convert_mmx_register
5031
	mov	bl,al
5032
	jmp	nomem_instruction_ready
1053 heavyiron 5033
movmskpd_instruction:
31 halyavin 5034
	mov	[opcode_prefix],66h
1039 heavyiron 5035
movmskps_instruction:
31 halyavin 5036
	mov	[base_code],0Fh
157 heavyiron 5037
	mov	[extended_code],50h
5038
	lods	byte [esi]
5039
	call	get_size_operator
5040
	cmp	al,10h
5041
	jne	invalid_operand
5042
	lods	byte [esi]
5043
	call	convert_register
5044
	mov	[postbyte_register],al
2287 heavyiron 5045
	cmp	ah,4
157 heavyiron 5046
	je	movmskps_reg_ok
2287 heavyiron 5047
	cmp	ah,8
5048
	jne	invalid_operand_size
157 heavyiron 5049
	cmp	[code_type],64
2287 heavyiron 5050
	jne	invalid_operand
5051
      movmskps_reg_ok:
5052
	mov	[operand_size],0
157 heavyiron 5053
	lods	byte [esi]
5054
	cmp	al,','
5055
	jne	invalid_operand
5056
	lods	byte [esi]
5057
	call	get_size_operator
5058
	cmp	al,10h
5059
	je	sse_xmmreg_xmmreg_ok
2287 heavyiron 5060
	jmp	invalid_operand
5061
5062
 
31 halyavin 5063
	mov	[opcode_prefix],66h
1039 heavyiron 5064
cvtpi2ps_instruction:
31 halyavin 5065
	mov	[base_code],0Fh
157 heavyiron 5066
	mov	[extended_code],al
5067
	lods	byte [esi]
5068
	call	get_size_operator
5069
	cmp	al,10h
5070
	jne	invalid_operand
5071
	lods	byte [esi]
5072
	call	convert_xmm_register
2287 heavyiron 5073
	mov	[postbyte_register],al
157 heavyiron 5074
	mov	[operand_size],0
5075
	lods	byte [esi]
5076
	cmp	al,','
5077
	jne	invalid_operand
5078
	lods	byte [esi]
5079
	call	get_size_operator
5080
	cmp	al,10h
5081
	je	cvtpi_xmmreg_xmmreg
5082
	cmp	al,'['
5083
	jne	invalid_operand
5084
	call	get_address
5085
	cmp	[operand_size],0
5086
	je	cvtpi_size_ok
5087
	cmp	[operand_size],8
5088
	jne	invalid_operand_size
5089
      cvtpi_size_ok:
31 halyavin 5090
	jmp	instruction_ready
1053 heavyiron 5091
      cvtpi_xmmreg_xmmreg:
31 halyavin 5092
	lods	byte [esi]
157 heavyiron 5093
	call	convert_mmx_register
5094
	cmp	ah,8
5095
	jne	invalid_operand_size
5096
	mov	bl,al
5097
	jmp	nomem_instruction_ready
1053 heavyiron 5098
cvtsi2ss_instruction:
31 halyavin 5099
	mov	[opcode_prefix],0F3h
1039 heavyiron 5100
	jmp	cvtsi_instruction
157 heavyiron 5101
cvtsi2sd_instruction:
31 halyavin 5102
	mov	[opcode_prefix],0F2h
1039 heavyiron 5103
      cvtsi_instruction:
31 halyavin 5104
	mov	[base_code],0Fh
157 heavyiron 5105
	mov	[extended_code],al
5106
	lods	byte [esi]
5107
	call	get_size_operator
5108
	cmp	al,10h
5109
	jne	invalid_operand
5110
	lods	byte [esi]
5111
	call	convert_xmm_register
2287 heavyiron 5112
	mov	[postbyte_register],al
157 heavyiron 5113
      cvtsi_xmmreg:
2287 heavyiron 5114
	mov	[operand_size],0
157 heavyiron 5115
	lods	byte [esi]
5116
	cmp	al,','
5117
	jne	invalid_operand
5118
	lods	byte [esi]
5119
	call	get_size_operator
5120
	cmp	al,10h
5121
	je	cvtsi_xmmreg_reg
5122
	cmp	al,'['
5123
	jne	invalid_operand
5124
	call	get_address
5125
	cmp	[operand_size],0
5126
	je	cvtsi_size_ok
5127
	cmp	[operand_size],4
5128
	je	cvtsi_size_ok
2287 heavyiron 5129
	cmp	[operand_size],8
5130
	jne	invalid_operand_size
157 heavyiron 5131
	call	operand_64bit
2287 heavyiron 5132
      cvtsi_size_ok:
31 halyavin 5133
	jmp	instruction_ready
1053 heavyiron 5134
      cvtsi_xmmreg_reg:
31 halyavin 5135
	lods	byte [esi]
157 heavyiron 5136
	call	convert_register
5137
	cmp	ah,4
5138
	je	cvtsi_xmmreg_reg_store
5139
	cmp	ah,8
5140
	jne	invalid_operand_size
5141
	call	operand_64bit
5142
      cvtsi_xmmreg_reg_store:
31 halyavin 5143
	mov	bl,al
157 heavyiron 5144
	jmp	nomem_instruction_ready
1053 heavyiron 5145
cvtps2pi_instruction:
31 halyavin 5146
	mov	[mmx_size],8
157 heavyiron 5147
	jmp	cvtpd_instruction
5148
cvtpd2pi_instruction:
31 halyavin 5149
	mov	[opcode_prefix],66h
1039 heavyiron 5150
	mov	[mmx_size],16
157 heavyiron 5151
      cvtpd_instruction:
31 halyavin 5152
	mov	[base_code],0Fh
157 heavyiron 5153
	mov	[extended_code],al
5154
	lods	byte [esi]
5155
	call	get_size_operator
5156
	cmp	al,10h
5157
	jne	invalid_operand
5158
	lods	byte [esi]
5159
	call	convert_mmx_register
5160
	cmp	ah,8
5161
	jne	invalid_operand_size
5162
	mov	[operand_size],0
5163
	jmp	sse_reg
5164
cvtss2si_instruction:
31 halyavin 5165
	mov	[opcode_prefix],0F3h
1039 heavyiron 5166
	mov	[mmx_size],4
157 heavyiron 5167
	jmp	cvt2si_instruction
5168
cvtsd2si_instruction:
31 halyavin 5169
	mov	[opcode_prefix],0F2h
1039 heavyiron 5170
	mov	[mmx_size],8
157 heavyiron 5171
      cvt2si_instruction:
31 halyavin 5172
	mov	[extended_code],al
157 heavyiron 5173
	mov	[base_code],0Fh
5174
	lods	byte [esi]
5175
	call	get_size_operator
5176
	cmp	al,10h
5177
	jne	invalid_operand
5178
	lods	byte [esi]
5179
	call	convert_register
5180
	mov	[operand_size],0
5181
	cmp	ah,4
5182
	je	sse_reg
5183
	cmp	ah,8
5184
	jne	invalid_operand_size
5185
	call	operand_64bit
5186
	jmp	sse_reg
5187
174 heavyiron 5188
 
5189
	mov	[base_code],0Fh
5190
	mov	[extended_code],38h
5191
	mov	[supplemental_code],al
5192
	jmp	mmx_instruction
5193
palignr_instruction:
5194
	mov	[base_code],0Fh
5195
	mov	[extended_code],3Ah
5196
	mov	[supplemental_code],0Fh
5197
	lods	byte [esi]
5198
	call	get_size_operator
5199
	cmp	al,10h
5200
	jne	invalid_operand
5201
	lods	byte [esi]
5202
	call	convert_mmx_register
5203
	call	make_mmx_prefix
5204
	mov	[postbyte_register],al
5205
	lods	byte [esi]
5206
	cmp	al,','
5207
	jne	invalid_operand
5208
	lods	byte [esi]
5209
	call	get_size_operator
5210
	cmp	al,10h
5211
	je	palignr_mmreg_mmreg
5212
	cmp	al,'['
5213
	jne	invalid_operand
5214
	call	get_address
5215
	jmp	mmx_imm8
5216
      palignr_mmreg_mmreg:
5217
	lods	byte [esi]
5218
	call	convert_mmx_register
5219
	mov	bl,al
5220
	jmp	mmx_nomem_imm8
5221
amd3dnow_instruction:
31 halyavin 5222
	mov	[base_code],0Fh
157 heavyiron 5223
	mov	[extended_code],0Fh
5224
	mov	byte [value],al
5225
	lods	byte [esi]
5226
	call	get_size_operator
5227
	cmp	al,10h
5228
	jne	invalid_operand
5229
	lods	byte [esi]
5230
	call	convert_mmx_register
5231
	cmp	ah,8
5232
	jne	invalid_operand_size
5233
	mov	[postbyte_register],al
5234
	lods	byte [esi]
5235
	cmp	al,','
5236
	jne	invalid_operand
5237
	lods	byte [esi]
5238
	call	get_size_operator
5239
	cmp	al,10h
5240
	je	amd3dnow_mmreg_mmreg
5241
	cmp	al,'['
5242
	jne	invalid_operand
5243
	call	get_address
5244
	call	store_instruction_with_imm8
5245
	jmp	instruction_assembled
5246
      amd3dnow_mmreg_mmreg:
31 halyavin 5247
	lods	byte [esi]
157 heavyiron 5248
	call	convert_mmx_register
5249
	cmp	ah,8
5250
	jne	invalid_operand_size
5251
	mov	bl,al
5252
	call	store_nomem_instruction
5253
	mov	al,byte [value]
5254
	stos	byte [edi]
5255
	jmp	instruction_assembled
5256
31 halyavin 5257
 
707 heavyiron 5258
	mov	[immediate_size],-1
5259
sse4_instruction_38:
5260
	mov	[mmx_size],16
1062 heavyiron 5261
	mov	[opcode_prefix],66h
1039 heavyiron 5262
	mov	[supplemental_code],al
707 heavyiron 5263
	mov	al,38h
5264
	jmp	sse_instruction
5265
sse4_ss_instruction_3a_imm8:
1062 heavyiron 5266
	mov	[immediate_size],1
5267
	mov	[mmx_size],4
5268
	jmp	sse4_instruction_3a_setup
5269
sse4_sd_instruction_3a_imm8:
5270
	mov	[immediate_size],1
5271
	mov	[mmx_size],8
5272
	jmp	sse4_instruction_3a_setup
5273
sse4_instruction_3a_imm8:
707 heavyiron 5274
	mov	[immediate_size],1
1062 heavyiron 5275
	mov	[mmx_size],16
5276
      sse4_instruction_3a_setup:
5277
	mov	[opcode_prefix],66h
1039 heavyiron 5278
	mov	[supplemental_code],al
707 heavyiron 5279
	mov	al,3Ah
5280
	jmp	sse_instruction
5281
pclmulqdq_instruction:
2287 heavyiron 5282
	mov	byte [value],al
5283
	mov	[mmx_size],16
5284
	mov	al,44h
5285
	jmp	sse4_instruction_3a_setup
5286
extractps_instruction:
1039 heavyiron 5287
	mov	[opcode_prefix],66h
5288
	mov	[base_code],0Fh
5289
	mov	[extended_code],3Ah
5290
	mov	[supplemental_code],17h
5291
	lods	byte [esi]
5292
	call	get_size_operator
5293
	cmp	al,10h
5294
	je	extractps_reg
5295
	cmp	al,'['
5296
	jne	invalid_operand
5297
	call	get_address
5298
	cmp	[operand_size],4
5299
	je	extractps_size_ok
5300
	cmp	[operand_size],0
5301
	jne	invalid_operand_size
5302
      extractps_size_ok:
5303
	push	edx ebx ecx
5304
	mov	[operand_size],0
5305
	lods	byte [esi]
5306
	cmp	al,','
5307
	jne	invalid_operand
5308
	lods	byte [esi]
5309
	call	get_size_operator
5310
	cmp	al,10h
5311
	jne	invalid_operand
5312
	lods	byte [esi]
5313
	call	convert_xmm_register
2287 heavyiron 5314
	mov	[postbyte_register],al
1039 heavyiron 5315
	pop	ecx ebx edx
5316
	jmp	mmx_imm8
5317
      extractps_reg:
5318
	lods	byte [esi]
5319
	call	convert_register
5320
	push	eax
5321
	mov	[operand_size],0
5322
	lods	byte [esi]
5323
	cmp	al,','
5324
	jne	invalid_operand
5325
	lods	byte [esi]
5326
	call	get_size_operator
5327
	cmp	al,10h
5328
	jne	invalid_operand
5329
	lods	byte [esi]
5330
	call	convert_xmm_register
2287 heavyiron 5331
	mov	[postbyte_register],al
1039 heavyiron 5332
	pop	ebx
5333
	mov	al,bh
5334
	cmp	al,4
1189 heavyiron 5335
	je	mmx_nomem_imm8
5336
	cmp	al,8
1039 heavyiron 5337
	jne	invalid_operand_size
5338
	call	operand_64bit
1189 heavyiron 5339
	jmp	mmx_nomem_imm8
1039 heavyiron 5340
insertps_instruction:
5341
	lods	byte [esi]
5342
	call	get_size_operator
5343
	cmp	al,10h
5344
	jne	invalid_operand
5345
	lods	byte [esi]
5346
	call	convert_xmm_register
2287 heavyiron 5347
	mov	[postbyte_register],al
1039 heavyiron 5348
      insertps_xmmreg:
2287 heavyiron 5349
	mov	[opcode_prefix],66h
5350
	mov	[base_code],0Fh
5351
	mov	[extended_code],3Ah
5352
	mov	[supplemental_code],21h
5353
	mov	[operand_size],0
1039 heavyiron 5354
	lods	byte [esi]
5355
	cmp	al,','
5356
	jne	invalid_operand
5357
	lods	byte [esi]
5358
	call	get_size_operator
5359
	cmp	al,10h
5360
	je	insertps_xmmreg_reg
2287 heavyiron 5361
	cmp	al,'['
1039 heavyiron 5362
	jne	invalid_operand
5363
	call	get_address
5364
	cmp	[operand_size],4
5365
	je	insertps_size_ok
5366
	cmp	[operand_size],0
5367
	jne	invalid_operand_size
5368
      insertps_size_ok:
5369
	jmp	mmx_imm8
5370
      insertps_xmmreg_reg:
2287 heavyiron 5371
	lods	byte [esi]
1039 heavyiron 5372
	call	convert_mmx_register
5373
	mov	bl,al
5374
	jmp	mmx_nomem_imm8
5375
pextrq_instruction:
5376
	mov	[mmx_size],8
5377
	jmp	pextr_instruction
5378
pextrd_instruction:
5379
	mov	[mmx_size],4
5380
	jmp	pextr_instruction
5381
pextrw_instruction:
5382
	mov	[mmx_size],2
5383
	jmp	pextr_instruction
5384
pextrb_instruction:
5385
	mov	[mmx_size],1
5386
      pextr_instruction:
5387
	mov	[opcode_prefix],66h
5388
	mov	[base_code],0Fh
5389
	mov	[extended_code],3Ah
5390
	mov	[supplemental_code],al
5391
	lods	byte [esi]
5392
	call	get_size_operator
5393
	cmp	al,10h
5394
	je	pextr_reg
5395
	cmp	al,'['
5396
	jne	invalid_operand
5397
	call	get_address
5398
	mov	al,[mmx_size]
5399
	cmp	al,[operand_size]
5400
	je	pextr_size_ok
5401
	cmp	[operand_size],0
5402
	jne	invalid_operand_size
5403
      pextr_size_ok:
5404
	cmp	al,8
2287 heavyiron 5405
	jne	pextr_prefix_ok
5406
	call	operand_64bit
5407
      pextr_prefix_ok:
5408
	push	edx ebx ecx
1039 heavyiron 5409
	mov	[operand_size],0
5410
	lods	byte [esi]
5411
	cmp	al,','
5412
	jne	invalid_operand
5413
	lods	byte [esi]
5414
	call	get_size_operator
5415
	cmp	al,10h
5416
	jne	invalid_operand
5417
	lods	byte [esi]
5418
	call	convert_xmm_register
2287 heavyiron 5419
	mov	[postbyte_register],al
1039 heavyiron 5420
	pop	ecx ebx edx
5421
	jmp	mmx_imm8
5422
      pextr_reg:
5423
	lods	byte [esi]
5424
	call	convert_register
5425
	cmp	[mmx_size],4
5426
	ja	pextrq_reg
5427
	cmp	ah,4
5428
	je	pextr_reg_size_ok
5429
	cmp	[code_type],64
1342 heavyiron 5430
	jne	pextr_invalid_size
5431
	cmp	ah,8
1039 heavyiron 5432
	je	pextr_reg_size_ok
5433
      pextr_invalid_size:
5434
	jmp	invalid_operand_size
5435
      pextrq_reg:
5436
	cmp	ah,8
5437
	jne	pextr_invalid_size
5438
	call	operand_64bit
5439
      pextr_reg_size_ok:
5440
	mov	[operand_size],0
5441
	push	eax
5442
	lods	byte [esi]
5443
	cmp	al,','
5444
	jne	invalid_operand
5445
	lods	byte [esi]
5446
	call	get_size_operator
5447
	cmp	al,10h
5448
	jne	invalid_operand
5449
	lods	byte [esi]
5450
	call	convert_mmx_register
5451
	mov	ebx,eax
5452
	pop	eax
5453
	mov	[postbyte_register],al
5454
	mov	al,ah
5455
	cmp	[mmx_size],2
5456
	jne	pextr_reg_store
5457
	mov	[opcode_prefix],0
5458
	mov	[extended_code],0C5h
5459
	call	make_mmx_prefix
5460
	jmp	mmx_nomem_imm8
5461
      pextr_reg_store:
5462
	cmp	bh,16
5463
	jne	invalid_operand_size
5464
	xchg	bl,[postbyte_register]
5465
	call	operand_autodetect
5466
	jmp	mmx_nomem_imm8
5467
pinsrb_instruction:
5468
	mov	[mmx_size],1
5469
	jmp	pinsr_instruction
5470
pinsrd_instruction:
5471
	mov	[mmx_size],4
5472
	jmp	pinsr_instruction
5473
pinsrq_instruction:
5474
	mov	[mmx_size],8
5475
	call	operand_64bit
2287 heavyiron 5476
      pinsr_instruction:
1039 heavyiron 5477
	mov	[opcode_prefix],66h
5478
	mov	[base_code],0Fh
5479
	mov	[extended_code],3Ah
5480
	mov	[supplemental_code],al
5481
	lods	byte [esi]
5482
	call	get_size_operator
5483
	cmp	al,10h
5484
	jne	invalid_operand
5485
	lods	byte [esi]
5486
	call	convert_xmm_register
2287 heavyiron 5487
	mov	[postbyte_register],al
1039 heavyiron 5488
      pinsr_xmmreg:
2287 heavyiron 5489
	mov	[operand_size],0
1039 heavyiron 5490
	lods	byte [esi]
5491
	cmp	al,','
5492
	jne	invalid_operand
5493
	lods	byte [esi]
5494
	call	get_size_operator
5495
	cmp	al,10h
5496
	je	pinsr_xmmreg_reg
5497
	cmp	al,'['
5498
	jne	invalid_operand
5499
	call	get_address
5500
	cmp	[operand_size],0
5501
	je	mmx_imm8
5502
	mov	al,[mmx_size]
5503
	cmp	al,[operand_size]
5504
	je	mmx_imm8
5505
	jmp	invalid_operand_size
5506
      pinsr_xmmreg_reg:
5507
	lods	byte [esi]
5508
	call	convert_register
5509
	mov	bl,al
5510
	cmp	[mmx_size],8
5511
	je	pinsrq_xmmreg_reg
5512
	cmp	ah,4
5513
	je	mmx_nomem_imm8
5514
	jmp	invalid_operand_size
5515
      pinsrq_xmmreg_reg:
5516
	cmp	ah,8
5517
	je	mmx_nomem_imm8
5518
	jmp	invalid_operand_size
5519
pmovsxbw_instruction:
5520
	mov	[mmx_size],8
5521
	jmp	pmovsx_instruction
5522
pmovsxbd_instruction:
5523
	mov	[mmx_size],4
5524
	jmp	pmovsx_instruction
5525
pmovsxbq_instruction:
5526
	mov	[mmx_size],2
5527
	jmp	pmovsx_instruction
5528
pmovsxwd_instruction:
5529
	mov	[mmx_size],8
5530
	jmp	pmovsx_instruction
5531
pmovsxwq_instruction:
5532
	mov	[mmx_size],4
5533
	jmp	pmovsx_instruction
5534
pmovsxdq_instruction:
5535
	mov	[mmx_size],8
5536
      pmovsx_instruction:
5537
	mov	[opcode_prefix],66h
5538
	mov	[base_code],0Fh
5539
	mov	[extended_code],38h
5540
	mov	[supplemental_code],al
5541
	lods	byte [esi]
5542
	call	get_size_operator
5543
	cmp	al,10h
5544
	jne	invalid_operand
5545
	lods	byte [esi]
5546
	call	convert_xmm_register
2287 heavyiron 5547
	mov	[postbyte_register],al
1039 heavyiron 5548
	lods	byte [esi]
5549
	cmp	al,','
5550
	jne	invalid_operand
5551
	mov	[operand_size],0
5552
	lods	byte [esi]
5553
	call	get_size_operator
5554
	cmp	al,10h
5555
	je	pmovsx_xmmreg_reg
5556
	cmp	al,'['
5557
	jne	invalid_operand
5558
	call	get_address
5559
	cmp	[operand_size],0
5560
	je	instruction_ready
2665 dunkaist 5561
	mov	al,[mmx_size]
1039 heavyiron 5562
	cmp	al,[operand_size]
5563
	jne	invalid_operand_size
5564
	jmp	instruction_ready
1053 heavyiron 5565
      pmovsx_xmmreg_reg:
1039 heavyiron 5566
	lods	byte [esi]
5567
	call	convert_xmm_register
2287 heavyiron 5568
	mov	bl,al
1039 heavyiron 5569
	jmp	nomem_instruction_ready
1053 heavyiron 5570
707 heavyiron 5571
 
2287 heavyiron 5572
	call	operand_64bit
5573
fxsave_instruction:
31 halyavin 5574
	mov	[extended_code],0AEh
157 heavyiron 5575
	mov	[base_code],0Fh
5576
	mov	[postbyte_register],al
5577
	lods	byte [esi]
5578
	call	get_size_operator
5579
	cmp	al,'['
5580
	jne	invalid_operand
5581
	call	get_address
5582
	mov	ah,[operand_size]
5583
	or	ah,ah
5584
	jz	fxsave_size_ok
5585
	mov	al,[postbyte_register]
5586
	cmp	al,111b
5587
	je	clflush_size_check
5588
	cmp	al,10b
5589
	jb	invalid_operand_size
5590
	cmp	al,11b
5591
	ja	invalid_operand_size
5592
	cmp	ah,4
5593
	jne	invalid_operand_size
5594
	jmp	fxsave_size_ok
5595
      clflush_size_check:
31 halyavin 5596
	cmp	ah,1
157 heavyiron 5597
	jne	invalid_operand_size
5598
      fxsave_size_ok:
31 halyavin 5599
	jmp	instruction_ready
1053 heavyiron 5600
prefetch_instruction:
31 halyavin 5601
	mov	[extended_code],18h
157 heavyiron 5602
      prefetch_mem_8bit:
31 halyavin 5603
	mov	[base_code],0Fh
157 heavyiron 5604
	mov	[postbyte_register],al
5605
	lods	byte [esi]
5606
	call	get_size_operator
5607
	cmp	al,'['
5608
	jne	invalid_operand
5609
	or	ah,ah
5610
	jz	prefetch_size_ok
5611
	cmp	ah,1
5612
	jne	invalid_operand_size
5613
      prefetch_size_ok:
31 halyavin 5614
	call	get_address
157 heavyiron 5615
	jmp	instruction_ready
1053 heavyiron 5616
amd_prefetch_instruction:
31 halyavin 5617
	mov	[extended_code],0Dh
157 heavyiron 5618
	jmp	prefetch_mem_8bit
5619
fence_instruction:
31 halyavin 5620
	mov	bl,al
157 heavyiron 5621
	mov	ax,0AE0Fh
5622
	stos	word [edi]
5623
	mov	al,bl
5624
	stos	byte [edi]
5625
	jmp	instruction_assembled
5626
pause_instruction:
31 halyavin 5627
	mov	ax,90F3h
157 heavyiron 5628
	stos	word [edi]
5629
	jmp	instruction_assembled
5630
movntq_instruction:
31 halyavin 5631
	mov	[mmx_size],8
157 heavyiron 5632
	jmp	movnt_instruction
5633
movntpd_instruction:
2287 heavyiron 5634
	mov	[opcode_prefix],66h
5635
movntps_instruction:
31 halyavin 5636
	mov	[mmx_size],16
157 heavyiron 5637
      movnt_instruction:
31 halyavin 5638
	mov	[extended_code],al
157 heavyiron 5639
	mov	[base_code],0Fh
5640
	lods	byte [esi]
5641
	call	get_size_operator
5642
	cmp	al,'['
5643
	jne	invalid_operand
5644
	call	get_address
5645
	lods	byte [esi]
5646
	cmp	al,','
5647
	jne	invalid_operand
5648
	lods	byte [esi]
5649
	call	get_size_operator
5650
	cmp	al,10h
5651
	jne	invalid_operand
5652
	lods	byte [esi]
5653
	call	convert_mmx_register
5654
	cmp	ah,[mmx_size]
5655
	jne	invalid_operand_size
5656
	mov	[postbyte_register],al
5657
	jmp	instruction_ready
1053 heavyiron 5658
1039 heavyiron 5659
 
5660
	mov	[opcode_prefix],0F2h
5661
	mov	[mmx_size],8
5662
	jmp	movnts_instruction
5663
movntss_instruction:
5664
	mov	[opcode_prefix],0F3h
5665
	mov	[mmx_size],4
5666
      movnts_instruction:
5667
	mov	[extended_code],al
5668
	mov	[base_code],0Fh
5669
	lods	byte [esi]
5670
	call	get_size_operator
5671
	cmp	al,'['
5672
	jne	invalid_operand
5673
	call	get_address
5674
	mov	al,[operand_size]
5675
	cmp	al,[mmx_size]
5676
	je	movnts_size_ok
5677
	test	al,al
5678
	jnz	invalid_operand_size
5679
      movnts_size_ok:
5680
	lods	byte [esi]
5681
	cmp	al,','
5682
	jne	invalid_operand
5683
	mov	[operand_size],0
5684
	lods	byte [esi]
5685
	call	get_size_operator
5686
	cmp	al,10h
5687
	jne	invalid_operand
5688
	lods	byte [esi]
5689
	call	convert_xmm_register
2287 heavyiron 5690
	mov	[postbyte_register],al
1039 heavyiron 5691
	jmp	instruction_ready
1053 heavyiron 5692
1039 heavyiron 5693
 
31 halyavin 5694
	mov	[base_code],0Fh
157 heavyiron 5695
	mov	[extended_code],al
5696
	lods	byte [esi]
5697
	call	get_size_operator
5698
	cmp	al,'['
5699
	jne	invalid_operand
5700
	call	get_address
5701
	lods	byte [esi]
5702
	cmp	al,','
5703
	jne	invalid_operand
5704
	lods	byte [esi]
5705
	call	get_size_operator
5706
	cmp	al,10h
5707
	jne	invalid_operand
5708
	lods	byte [esi]
5709
	call	convert_register
5710
	cmp	ah,4
5711
	je	movnti_store
5712
	cmp	ah,8
5713
	jne	invalid_operand_size
5714
	call	operand_64bit
5715
      movnti_store:
31 halyavin 5716
	mov	[postbyte_register],al
157 heavyiron 5717
	jmp	instruction_ready
1053 heavyiron 5718
monitor_instruction:
31 halyavin 5719
	mov	[postbyte_register],al
157 heavyiron 5720
	cmp	byte [esi],0
1189 heavyiron 5721
	je	monitor_instruction_store
5722
	cmp	byte [esi],0Fh
5723
	je	monitor_instruction_store
5724
	lods	byte [esi]
157 heavyiron 5725
	call	get_size_operator
5726
	cmp	al,10h
5727
	jne	invalid_operand
5728
	lods	byte [esi]
5729
	call	convert_register
5730
	cmp	ax,0400h
5731
	jne	invalid_operand
5732
	lods	byte [esi]
5733
	cmp	al,','
5734
	jne	invalid_operand
5735
	lods	byte [esi]
5736
	call	get_size_operator
5737
	cmp	al,10h
5738
	jne	invalid_operand
5739
	lods	byte [esi]
5740
	call	convert_register
5741
	cmp	ax,0401h
5742
	jne	invalid_operand
5743
	cmp	[postbyte_register],0C8h
5744
	jne	monitor_instruction_store
5745
	lods	byte [esi]
5746
	cmp	al,','
5747
	jne	invalid_operand
5748
	lods	byte [esi]
5749
	call	get_size_operator
5750
	cmp	al,10h
5751
	jne	invalid_operand
5752
	lods	byte [esi]
5753
	call	convert_register
5754
	cmp	ax,0402h
5755
	jne	invalid_operand
5756
      monitor_instruction_store:
31 halyavin 5757
	mov	ax,010Fh
157 heavyiron 5758
	stos	word [edi]
5759
	mov	al,[postbyte_register]
5760
	stos	byte [edi]
5761
	jmp	instruction_assembled
5762
movntdqa_instruction:
1039 heavyiron 5763
	mov	[opcode_prefix],66h
5764
	mov	[base_code],0Fh
5765
	mov	[extended_code],38h
5766
	mov	[supplemental_code],al
2665 dunkaist 5767
	lods	byte [esi]
1039 heavyiron 5768
	call	get_size_operator
5769
	cmp	al,10h
5770
	jne	invalid_operand
5771
	lods	byte [esi]
5772
	call	convert_xmm_register
2287 heavyiron 5773
	mov	[postbyte_register],al
1039 heavyiron 5774
	lods	byte [esi]
5775
	cmp	al,','
5776
	jne	invalid_operand
5777
	lods	byte [esi]
5778
	call	get_size_operator
5779
	cmp	al,'['
5780
	jne	invalid_operand
5781
	call	get_address
5782
	jmp	instruction_ready
1053 heavyiron 5783
31 halyavin 5784
 
1039 heavyiron 5785
	mov	[opcode_prefix],66h
5786
	mov	[base_code],0Fh
5787
	mov	[extended_code],78h
5788
	lods	byte [esi]
5789
	call	get_size_operator
5790
	cmp	al,10h
5791
	jne	invalid_operand
5792
	lods	byte [esi]
5793
	call	convert_xmm_register
2287 heavyiron 5794
	mov	[postbyte_register],al
1039 heavyiron 5795
	mov	[operand_size],0
5796
	lods	byte [esi]
5797
	cmp	al,','
5798
	jne	invalid_operand
5799
	lods	byte [esi]
5800
	call	get_size_operator
5801
	cmp	al,10h
5802
	je	extrq_xmmreg_xmmreg
5803
	test	ah,not 1
5804
	jnz	invalid_operand_size
5805
	cmp	al,'('
5806
	jne	invalid_operand
5807
	xor	bl,bl
5808
	xchg	bl,[postbyte_register]
1242 heavyiron 5809
	call	store_nomem_instruction
1039 heavyiron 5810
	call	get_byte_value
5811
	stosb
5812
	call	append_imm8
5813
	jmp	instruction_assembled
5814
      extrq_xmmreg_xmmreg:
5815
	inc	[extended_code]
5816
	lods	byte [esi]
5817
	call	convert_xmm_register
2287 heavyiron 5818
	mov	bl,al
1039 heavyiron 5819
	jmp	nomem_instruction_ready
1053 heavyiron 5820
insertq_instruction:
1039 heavyiron 5821
	mov	[opcode_prefix],0F2h
5822
	mov	[base_code],0Fh
5823
	mov	[extended_code],78h
5824
	lods	byte [esi]
5825
	call	get_size_operator
5826
	cmp	al,10h
5827
	jne	invalid_operand
5828
	lods	byte [esi]
5829
	call	convert_xmm_register
2287 heavyiron 5830
	mov	[postbyte_register],al
1039 heavyiron 5831
	mov	[operand_size],0
5832
	lods	byte [esi]
5833
	cmp	al,','
5834
	jne	invalid_operand
5835
	lods	byte [esi]
5836
	call	get_size_operator
5837
	cmp	al,10h
5838
	jne	invalid_operand
5839
	lods	byte [esi]
5840
	call	convert_xmm_register
2287 heavyiron 5841
	mov	bl,al
1039 heavyiron 5842
	cmp	byte [esi],','
5843
	je	insertq_with_imm
5844
	inc	[extended_code]
5845
	jmp	nomem_instruction_ready
1053 heavyiron 5846
      insertq_with_imm:
1039 heavyiron 5847
	call	store_nomem_instruction
5848
	call	append_imm8
5849
	call	append_imm8
5850
	jmp	instruction_assembled
5851
5852
 
5853
	mov	[opcode_prefix],0F2h
5854
	mov	[base_code],0Fh
5855
	mov	[extended_code],38h
5856
	mov	[supplemental_code],0F0h
5857
	lods	byte [esi]
5858
	call	get_size_operator
5859
	cmp	al,10h
5860
	jne	invalid_operand
5861
	lods	byte [esi]
5862
	call	convert_register
5863
	mov	[postbyte_register],al
5864
	cmp	ah,8
5865
	je	crc32_reg64
5866
	cmp	ah,4
5867
	jne	invalid_operand
5868
	lods	byte [esi]
5869
	cmp	al,','
5870
	jne	invalid_operand
5871
	mov	[operand_size],0
5872
	lods	byte [esi]
5873
	call	get_size_operator
5874
	cmp	al,10h
5875
	je	crc32_reg32_reg
5876
	cmp	al,'['
5877
	jne	invalid_operand
5878
	call	get_address
5879
	mov	al,[operand_size]
5880
	test	al,al
5881
	jz	crc32_unknown_size
5882
	cmp	al,1
5883
	je	crc32_reg32_mem_store
5884
	cmp	al,4
5885
	ja	invalid_operand_size
5886
	inc	[supplemental_code]
5887
	call	operand_autodetect
5888
      crc32_reg32_mem_store:
5889
	jmp	instruction_ready
1053 heavyiron 5890
      crc32_unknown_size:
1039 heavyiron 5891
	call	recoverable_unknown_size
2665 dunkaist 5892
	jmp	crc32_reg32_mem_store
1039 heavyiron 5893
      crc32_reg32_reg:
5894
	lods	byte [esi]
5895
	call	convert_register
5896
	mov	bl,al
5897
	mov	al,ah
5898
	cmp	al,1
5899
	je	crc32_reg32_reg_store
5900
	cmp	al,4
5901
	ja	invalid_operand_size
5902
	inc	[supplemental_code]
5903
	call	operand_autodetect
5904
      crc32_reg32_reg_store:
5905
	jmp	nomem_instruction_ready
1053 heavyiron 5906
      crc32_reg64:
1039 heavyiron 5907
	lods	byte [esi]
5908
	cmp	al,','
5909
	jne	invalid_operand
5910
	mov	[operand_size],0
5911
	call	operand_64bit
1189 heavyiron 5912
	lods	byte [esi]
1039 heavyiron 5913
	call	get_size_operator
5914
	cmp	al,10h
5915
	je	crc32_reg64_reg
5916
	cmp	al,'['
5917
	jne	invalid_operand
5918
	call	get_address
5919
	mov	ah,[operand_size]
5920
	mov	al,8
5921
	test	ah,ah
5922
	jz	crc32_unknown_size
5923
	cmp	ah,1
5924
	je	crc32_reg32_mem_store
5925
	cmp	ah,al
5926
	jne	invalid_operand_size
5927
	inc	[supplemental_code]
5928
	jmp	crc32_reg32_mem_store
5929
      crc32_reg64_reg:
5930
	lods	byte [esi]
5931
	call	convert_register
5932
	mov	bl,al
5933
	mov	al,8
5934
	cmp	ah,1
5935
	je	crc32_reg32_reg_store
5936
	cmp	ah,al
5937
	jne	invalid_operand_size
5938
	inc	[supplemental_code]
5939
	jmp	crc32_reg32_reg_store
5940
popcnt_instruction:
5941
	mov	[opcode_prefix],0F3h
5942
	jmp	bs_instruction
5943
movbe_instruction:
1189 heavyiron 5944
	mov	[supplemental_code],al
5945
	mov	[extended_code],38h
5946
	mov	[base_code],0Fh
5947
	lods	byte [esi]
5948
	call	get_size_operator
5949
	cmp	al,'['
5950
	je	movbe_mem
5951
	cmp	al,10h
5952
	jne	invalid_operand
5953
	lods	byte [esi]
5954
	call	convert_register
5955
	mov	[postbyte_register],al
5956
	lods	byte [esi]
5957
	cmp	al,','
5958
	jne	invalid_operand
5959
	lods	byte [esi]
5960
	call	get_size_operator
5961
	cmp	al,'['
5962
	jne	invalid_argument
5963
	call	get_address
5964
	mov	al,[operand_size]
5965
	call	operand_autodetect
5966
	jmp	instruction_ready
5967
      movbe_mem:
5968
	inc	[supplemental_code]
5969
	call	get_address
5970
	push	edx ebx ecx
5971
	lods	byte [esi]
5972
	cmp	al,','
5973
	jne	invalid_operand
5974
	lods	byte [esi]
5975
	call	get_size_operator
5976
	cmp	al,10h
5977
	jne	invalid_operand
5978
	lods	byte [esi]
5979
	call	convert_register
5980
	mov	[postbyte_register],al
5981
	pop	ecx ebx edx
5982
	mov	al,[operand_size]
5983
	call	operand_autodetect
5984
	jmp	instruction_ready
5985
adx_instruction:
4039 heavyiron 5986
	mov	[base_code],0Fh
5987
	mov	[extended_code],38h
5988
	mov	[supplemental_code],0F6h
5989
	mov	[operand_prefix],al
5990
	call	get_reg_mem
5991
	jc	adx_reg_reg
5992
	mov	al,[operand_size]
5993
	cmp	al,4
5994
	je	instruction_ready
5995
	cmp	al,8
5996
	jne	invalid_operand_size
5997
	call	operand_64bit
5998
	jmp	instruction_ready
5999
      adx_reg_reg:
6000
	cmp	ah,4
6001
	je	nomem_instruction_ready
6002
	cmp	ah,8
6003
	jne	invalid_operand_size
6004
	call	operand_64bit
6005
	jmp	nomem_instruction_ready
6006
1039 heavyiron 6007
 
31 halyavin 6008
	mov	ah,al
157 heavyiron 6009
	mov	al,0Fh
6010
	stos	byte [edi]
6011
	mov	al,1
6012
	stos	word [edi]
6013
	jmp	instruction_assembled
6014
vmclear_instruction:
31 halyavin 6015
	mov	[opcode_prefix],66h
1039 heavyiron 6016
	jmp	vmx_instruction
157 heavyiron 6017
vmxon_instruction:
31 halyavin 6018
	mov	[opcode_prefix],0F3h
1039 heavyiron 6019
vmx_instruction:
31 halyavin 6020
	mov	[postbyte_register],al
157 heavyiron 6021
	mov	[extended_code],0C7h
6022
	lods	byte [esi]
6023
	call	get_size_operator
6024
	cmp	al,'['
6025
	jne	invalid_operand
6026
	call	get_address
6027
	mov	al,[operand_size]
6028
	or	al,al
6029
	jz	vmx_size_ok
6030
	cmp	al,8
6031
	jne	invalid_operand_size
6032
      vmx_size_ok:
31 halyavin 6033
	mov	[base_code],0Fh
157 heavyiron 6034
	jmp	instruction_ready
1053 heavyiron 6035
vmread_instruction:
31 halyavin 6036
	mov	[extended_code],78h
157 heavyiron 6037
	lods	byte [esi]
6038
	call	get_size_operator
6039
	cmp	al,10h
607 heavyiron 6040
	je	vmread_nomem
6041
	cmp	al,'['
157 heavyiron 6042
	jne	invalid_operand
6043
	call	get_address
6044
	lods	byte [esi]
6045
	cmp	al,','
6046
	jne	invalid_operand
6047
	lods	byte [esi]
6048
	call	get_size_operator
6049
	cmp	al,10h
6050
	jne	invalid_operand
6051
	lods	byte [esi]
6052
	call	convert_register
6053
	mov	[postbyte_register],al
6054
	call	vmread_check_size
872 heavyiron 6055
	jmp	vmx_size_ok
607 heavyiron 6056
      vmread_nomem:
6057
	lods	byte [esi]
6058
	call	convert_register
6059
	push	eax
6060
	call	vmread_check_size
6061
	lods	byte [esi]
6062
	cmp	al,','
6063
	jne	invalid_operand
6064
	lods	byte [esi]
6065
	call	get_size_operator
6066
	cmp	al,10h
6067
	jne	invalid_operand
6068
	lods	byte [esi]
6069
	call	convert_register
6070
	mov	[postbyte_register],al
6071
	call	vmread_check_size
872 heavyiron 6072
	pop	ebx
607 heavyiron 6073
	mov	[base_code],0Fh
6074
	jmp	nomem_instruction_ready
1053 heavyiron 6075
      vmread_check_size:
31 halyavin 6076
	cmp	[code_type],64
157 heavyiron 6077
	je	vmread_long
6078
	cmp	[operand_size],4
6079
	jne	invalid_operand_size
607 heavyiron 6080
	ret
6081
      vmread_long:
31 halyavin 6082
	cmp	[operand_size],8
157 heavyiron 6083
	jne	invalid_operand_size
607 heavyiron 6084
	ret
6085
vmwrite_instruction:
31 halyavin 6086
	mov	[extended_code],79h
157 heavyiron 6087
	lods	byte [esi]
6088
	call	get_size_operator
6089
	cmp	al,10h
6090
	jne	invalid_operand
6091
	lods	byte [esi]
6092
	call	convert_register
6093
	mov	[postbyte_register],al
6094
	lods	byte [esi]
6095
	cmp	al,','
6096
	jne	invalid_operand
6097
	lods	byte [esi]
6098
	call	get_size_operator
6099
	cmp	al,10h
607 heavyiron 6100
	je	vmwrite_nomem
6101
	cmp	al,'['
157 heavyiron 6102
	jne	invalid_operand
6103
	call	get_address
6104
	call	vmread_check_size
607 heavyiron 6105
	jmp	vmx_size_ok
6106
      vmwrite_nomem:
6107
	lods	byte [esi]
6108
	call	convert_register
6109
	mov	bl,al
6110
	mov	[base_code],0Fh
6111
	jmp	nomem_instruction_ready
1053 heavyiron 6112
vmx_inv_instruction:
1115 heavyiron 6113
	mov	[opcode_prefix],66h
6114
	mov	[extended_code],38h
6115
	mov	[supplemental_code],al
6116
	lods	byte [esi]
6117
	call	get_size_operator
6118
	cmp	al,10h
6119
	jne	invalid_operand
6120
	lods	byte [esi]
6121
	call	convert_register
6122
	mov	[postbyte_register],al
6123
	call	vmread_check_size
6124
	mov	[operand_size],0
6125
	lods	byte [esi]
6126
	cmp	al,','
6127
	jne	invalid_operand
6128
	lods	byte [esi]
6129
	call	get_size_operator
6130
	cmp	al,'['
6131
	jne	invalid_operand
6132
	call	get_address
6133
	mov	al,[operand_size]
6134
	or	al,al
6135
	jz	vmx_size_ok
6136
	cmp	al,16
6137
	jne	invalid_operand_size
6138
	jmp	vmx_size_ok
6139
simple_svm_instruction:
109 heavyiron 6140
	push	eax
157 heavyiron 6141
	mov	[base_code],0Fh
6142
	mov	[extended_code],1
6143
	lods	byte [esi]
6144
	call	get_size_operator
6145
	cmp	al,10h
6146
	jne	invalid_operand
6147
	lods	byte [esi]
6148
	call	convert_register
6149
	or	al,al
6150
	jnz	invalid_operand
6151
      simple_svm_detect_size:
109 heavyiron 6152
	cmp	ah,2
157 heavyiron 6153
	je	simple_svm_16bit
6154
	cmp	ah,4
6155
	je	simple_svm_32bit
6156
	cmp	[code_type],64
6157
	jne	invalid_operand_size
6158
	jmp	simple_svm_store
6159
      simple_svm_16bit:
109 heavyiron 6160
	cmp	[code_type],16
157 heavyiron 6161
	je	simple_svm_store
6162
	cmp	[code_type],64
6163
	je	invalid_operand_size
6164
	jmp	prefixed_svm_store
6165
      simple_svm_32bit:
109 heavyiron 6166
	cmp	[code_type],32
157 heavyiron 6167
	je	simple_svm_store
6168
      prefixed_svm_store:
109 heavyiron 6169
	mov	al,67h
157 heavyiron 6170
	stos	byte [edi]
6171
      simple_svm_store:
109 heavyiron 6172
	call	store_instruction_code
157 heavyiron 6173
	pop	eax
6174
	stos	byte [edi]
6175
	jmp	instruction_assembled
6176
skinit_instruction:
109 heavyiron 6177
	lods	byte [esi]
157 heavyiron 6178
	call	get_size_operator
6179
	cmp	al,10h
6180
	jne	invalid_operand
6181
	lods	byte [esi]
6182
	call	convert_register
6183
	cmp	ax,0400h
6184
	jne	invalid_operand
6185
	mov	al,0DEh
6186
	jmp	simple_vmx_instruction
6187
invlpga_instruction:
109 heavyiron 6188
	push	eax
157 heavyiron 6189
	mov	[base_code],0Fh
6190
	mov	[extended_code],1
6191
	lods	byte [esi]
6192
	call	get_size_operator
6193
	cmp	al,10h
6194
	jne	invalid_operand
6195
	lods	byte [esi]
6196
	call	convert_register
6197
	or	al,al
6198
	jnz	invalid_operand
6199
	mov	bl,ah
6200
	mov	[operand_size],0
6201
	lods	byte [esi]
6202
	cmp	al,','
6203
	jne	invalid_operand
6204
	lods	byte [esi]
6205
	call	get_size_operator
6206
	cmp	al,10h
6207
	jne	invalid_operand
6208
	lods	byte [esi]
6209
	call	convert_register
6210
	cmp	ax,0401h
6211
	jne	invalid_operand
6212
	mov	ah,bl
6213
	jmp	simple_svm_detect_size
6214
31 halyavin 6215
 
2287 heavyiron 6216
	mov	[base_code],0Fh
6217
	mov	[extended_code],0C7h
6218
	mov	[postbyte_register],al
6219
	lods	byte [esi]
6220
	call	get_size_operator
6221
	cmp	al,10h
6222
	jne	invalid_operand
6223
	lods	byte [esi]
6224
	call	convert_register
6225
	mov	bl,al
6226
	mov	al,ah
6227
	call	operand_autodetect
6228
	jmp	nomem_instruction_ready
6229
rdfsbase_instruction:
6230
	cmp	[code_type],64
2665 dunkaist 6231
	jne	illegal_instruction
6232
	mov	[opcode_prefix],0F3h
2287 heavyiron 6233
	mov	[base_code],0Fh
6234
	mov	[extended_code],0AEh
6235
	mov	[postbyte_register],al
6236
	lods	byte [esi]
6237
	call	get_size_operator
6238
	cmp	al,10h
6239
	jne	invalid_operand
6240
	lods	byte [esi]
6241
	call	convert_register
6242
	mov	bl,al
6243
	mov	al,ah
6244
	cmp	ah,2
6245
	je	invalid_operand_size
6246
	call	operand_autodetect
6247
	jmp	nomem_instruction_ready
6248
6249
 
2665 dunkaist 6250
	lods	byte [esi]
6251
	call	get_size_operator
6252
	cmp	ah,1
6253
	ja	invalid_operand_size
6254
	cmp	al,'('
6255
	jne	invalid_operand
6256
	call	get_byte_value
6257
	mov	dl,al
6258
	mov	ax,0F8C6h
6259
	stos	word [edi]
6260
	mov	al,dl
6261
	stos	byte [edi]
6262
	jmp	instruction_assembled
6263
xbegin_instruction:
6264
	lods	byte [esi]
6265
	cmp	al,'('
6266
	jne	invalid_operand
6267
	mov	al,[code_type]
6268
	cmp	al,64
6269
	je	xbegin_64bit
6270
	cmp	al,32
6271
	je	xbegin_32bit
6272
      xbegin_16bit:
6273
	call	get_address_word_value
6274
	add	edi,4
6275
	mov	ebp,[addressing_space]
4039 heavyiron 6276
	call	calculate_relative_offset
2665 dunkaist 6277
	sub	edi,4
6278
	shl	eax,16
6279
	mov	ax,0F8C7h
6280
	stos	dword [edi]
6281
	jmp	instruction_assembled
6282
      xbegin_32bit:
6283
	call	get_address_dword_value
6284
	jmp	xbegin_address_ok
6285
      xbegin_64bit:
6286
	call	get_address_qword_value
6287
      xbegin_address_ok:
6288
	add	edi,5
6289
	mov	ebp,[addressing_space]
4039 heavyiron 6290
	call	calculate_relative_offset
2665 dunkaist 6291
	sub	edi,5
6292
	mov	edx,eax
6293
	cwde
6294
	cmp	eax,edx
6295
	jne	xbegin_rel32
6296
	mov	al,66h
6297
	stos	byte [edi]
6298
	mov	eax,edx
6299
	shl	eax,16
6300
	mov	ax,0F8C7h
6301
	stos	dword [edi]
6302
	jmp	instruction_assembled
6303
      xbegin_rel32:
6304
	sub	edx,1
6305
	jno	xbegin_rel32_ok
6306
	cmp	[code_type],64
6307
	je	relative_jump_out_of_range
6308
      xbegin_rel32_ok:
6309
	mov	ax,0F8C7h
6310
	stos	word [edi]
6311
	mov	eax,edx
6312
	stos	dword [edi]
6313
	jmp	instruction_assembled
6314
6315
 
31 halyavin 6316
	mov	ah,al
157 heavyiron 6317
	shr	ah,4
6318
	and	al,0Fh
6319
	cmp	ah,8
6320
	je	match_register_size
6321
	cmp	ah,4
6322
	ja	invalid_operand
6323
	cmp	ah,1
6324
	ja	match_register_size
6325
	cmp	al,4
6326
	jb	match_register_size
6327
	or	ah,ah
6328
	jz	high_byte_register
6329
	or	[rex_prefix],40h
6330
      match_register_size:
31 halyavin 6331
	cmp	ah,[operand_size]
157 heavyiron 6332
	je	register_size_ok
6333
	cmp	[operand_size],0
6334
	jne	operand_sizes_do_not_match
6335
	mov	[operand_size],ah
6336
      register_size_ok:
31 halyavin 6337
	ret
157 heavyiron 6338
      high_byte_register:
31 halyavin 6339
	mov	ah,1
157 heavyiron 6340
	or	[rex_prefix],80h
6341
	jmp	match_register_size
6342
convert_fpu_register:
31 halyavin 6343
	mov	ah,al
157 heavyiron 6344
	shr	ah,4
6345
	and	al,111b
6346
	cmp	ah,10
6347
	jne	invalid_operand
6348
	jmp	match_register_size
6349
convert_mmx_register:
31 halyavin 6350
	mov	ah,al
157 heavyiron 6351
	shr	ah,4
6352
	cmp	ah,0Ch
6353
	je	xmm_register
6354
	ja	invalid_operand
6355
	and	al,111b
6356
	cmp	ah,0Bh
6357
	jne	invalid_operand
6358
	mov	ah,8
6359
	cmp	[vex_required],0
2287 heavyiron 6360
	jne	invalid_operand
6361
	jmp	match_register_size
157 heavyiron 6362
      xmm_register:
31 halyavin 6363
	and	al,0Fh
157 heavyiron 6364
	mov	ah,16
6365
	cmp	al,8
6366
	jb	match_register_size
6367
	cmp	[code_type],64
6368
	jne	invalid_operand
6369
	jmp	match_register_size
6370
convert_xmm_register:
2287 heavyiron 6371
	mov	ah,al
6372
	shr	ah,4
6373
	cmp	ah,0Ch
6374
	je	xmm_register
6375
	jmp	invalid_operand
6376
get_size_operator:
31 halyavin 6377
	xor	ah,ah
157 heavyiron 6378
	cmp	al,11h
6379
	jne	no_size_operator
6380
	mov	[size_declared],1
6381
	lods	word [esi]
6382
	xchg	al,ah
6383
	mov	[size_override],1
6384
	cmp	ah,[operand_size]
6385
	je	size_operator_ok
6386
	cmp	[operand_size],0
6387
	jne	operand_sizes_do_not_match
6388
	mov	[operand_size],ah
6389
      size_operator_ok:
31 halyavin 6390
	ret
157 heavyiron 6391
      no_size_operator:
31 halyavin 6392
	mov	[size_declared],0
157 heavyiron 6393
	cmp	al,'['
6394
	jne	size_operator_ok
6395
	mov	[size_override],0
6396
	ret
6397
get_jump_operator:
31 halyavin 6398
	mov	[jump_type],0
157 heavyiron 6399
	cmp	al,12h
6400
	jne	jump_operator_ok
6401
	lods	word [esi]
6402
	mov	[jump_type],al
6403
	mov	al,ah
6404
      jump_operator_ok:
31 halyavin 6405
	ret
157 heavyiron 6406
get_address:
31 halyavin 6407
	mov	[segment_register],0
157 heavyiron 6408
	mov	[address_size],0
6409
	mov	[free_address_range],0
4039 heavyiron 6410
	mov	al,[code_type]
157 heavyiron 6411
	shr	al,3
6412
	mov	[value_size],al
6413
	mov	al,[esi]
6414
	and	al,11110000b
6415
	cmp	al,60h
6416
	jne	get_size_prefix
6417
	lods	byte [esi]
6418
	sub	al,60h
6419
	mov	[segment_register],al
6420
	mov	al,[esi]
6421
	and	al,11110000b
6422
      get_size_prefix:
31 halyavin 6423
	cmp	al,70h
157 heavyiron 6424
	jne	address_size_prefix_ok
6425
	lods	byte [esi]
6426
	sub	al,70h
6427
	cmp	al,2
6428
	jb	invalid_address_size
6429
	cmp	al,8
6430
	ja	invalid_address_size
6431
	mov	[address_size],al
6432
	mov	[value_size],al
6433
      address_size_prefix_ok:
31 halyavin 6434
	call	calculate_address
157 heavyiron 6435
	cmp	byte [esi-1],']'
6436
	jne	invalid_address
6437
	mov	[address_high],edx
6438
	mov	edx,eax
6439
	cmp	[code_type],64
6440
	jne	address_ok
6441
	or	bx,bx
6442
	jnz	address_ok
6443
	test	ch,0Fh
6444
	jnz	address_ok
6445
      calculate_relative_address:
31 halyavin 6446
	mov	edx,[address_symbol]
196 heavyiron 6447
	mov	[symbol_identifier],edx
6448
	mov	edx,[address_high]
176 heavyiron 6449
	mov	ebp,[addressing_space]
4039 heavyiron 6450
	call	calculate_relative_offset
157 heavyiron 6451
	mov	[address_high],edx
6452
	cdq
176 heavyiron 6453
	cmp	edx,[address_high]
6454
	je	address_high_ok
707 heavyiron 6455
	call	recoverable_overflow
2665 dunkaist 6456
      address_high_ok:
707 heavyiron 6457
	mov	edx,eax
157 heavyiron 6458
	ror	ecx,16
205 heavyiron 6459
	mov	cl,[value_type]
6460
	rol	ecx,16
6461
	mov	bx,0FF00h
157 heavyiron 6462
      address_ok:
31 halyavin 6463
	ret
157 heavyiron 6464
operand_16bit:
31 halyavin 6465
	cmp	[code_type],16
157 heavyiron 6466
	je	size_prefix_ok
6467
	mov	[operand_prefix],66h
6468
	ret
6469
operand_32bit:
31 halyavin 6470
	cmp	[code_type],16
157 heavyiron 6471
	jne	size_prefix_ok
6472
	mov	[operand_prefix],66h
6473
      size_prefix_ok:
31 halyavin 6474
	ret
157 heavyiron 6475
operand_64bit:
31 halyavin 6476
	cmp	[code_type],64
157 heavyiron 6477
	jne	illegal_instruction
6478
	or	[rex_prefix],48h
6479
	ret
6480
operand_autodetect:
31 halyavin 6481
	cmp	al,2
157 heavyiron 6482
	je	operand_16bit
6483
	cmp	al,4
6484
	je	operand_32bit
6485
	cmp	al,8
6486
	je	operand_64bit
6487
	jmp	invalid_operand_size
6488
store_segment_prefix_if_necessary:
31 halyavin 6489
	mov	al,[segment_register]
157 heavyiron 6490
	or	al,al
6491
	jz	segment_prefix_ok
6492
	cmp	al,4
2287 heavyiron 6493
	ja	segment_prefix_386
6494
	cmp	[code_type],64
6495
	je	segment_prefix_ok
6496
	cmp	al,3
157 heavyiron 6497
	je	ss_prefix
6498
	jb	segment_prefix_86
6499
	cmp	bl,25h
6500
	je	segment_prefix_86
6501
	cmp	bh,25h
6502
	je	segment_prefix_86
6503
	cmp	bh,45h
6504
	je	segment_prefix_86
6505
	cmp	bh,44h
6506
	je	segment_prefix_86
6507
	ret
6508
      ss_prefix:
31 halyavin 6509
	cmp	bl,25h
157 heavyiron 6510
	je	segment_prefix_ok
6511
	cmp	bh,25h
6512
	je	segment_prefix_ok
6513
	cmp	bh,45h
6514
	je	segment_prefix_ok
6515
	cmp	bh,44h
6516
	je	segment_prefix_ok
6517
	jmp	segment_prefix_86
6518
store_segment_prefix:
31 halyavin 6519
	mov	al,[segment_register]
157 heavyiron 6520
	or	al,al
6521
	jz	segment_prefix_ok
6522
	cmp	al,5
6523
	jae	segment_prefix_386
6524
      segment_prefix_86:
31 halyavin 6525
	dec	al
157 heavyiron 6526
	shl	al,3
6527
	add	al,26h
6528
	stos	byte [edi]
6529
	jmp	segment_prefix_ok
6530
      segment_prefix_386:
31 halyavin 6531
	add	al,64h-5
157 heavyiron 6532
	stos	byte [edi]
6533
      segment_prefix_ok:
31 halyavin 6534
	ret
157 heavyiron 6535
store_instruction_code:
31 halyavin 6536
	cmp	[vex_required],0
2287 heavyiron 6537
	jne	store_vex_instruction_code
6538
	mov	al,[operand_prefix]
157 heavyiron 6539
	or	al,al
6540
	jz	operand_prefix_ok
6541
	stos	byte [edi]
6542
      operand_prefix_ok:
31 halyavin 6543
	mov	al,[opcode_prefix]
1039 heavyiron 6544
	or	al,al
6545
	jz	opcode_prefix_ok
6546
	stos	byte [edi]
6547
      opcode_prefix_ok:
6548
	mov	al,[rex_prefix]
157 heavyiron 6549
	test	al,40h
6550
	jz	rex_prefix_ok
6551
	cmp	[code_type],64
6552
	jne	invalid_operand
6553
	test	al,0B0h
6554
	jnz	disallowed_combination_of_registers
2665 dunkaist 6555
	stos	byte [edi]
157 heavyiron 6556
      rex_prefix_ok:
31 halyavin 6557
	mov	al,[base_code]
157 heavyiron 6558
	stos	byte [edi]
6559
	cmp	al,0Fh
6560
	jne	instruction_code_ok
6561
      store_extended_code:
31 halyavin 6562
	mov	al,[extended_code]
157 heavyiron 6563
	stos	byte [edi]
6564
	cmp	al,38h
174 heavyiron 6565
	je	store_supplemental_code
6566
	cmp	al,3Ah
6567
	je	store_supplemental_code
6568
      instruction_code_ok:
31 halyavin 6569
	ret
157 heavyiron 6570
      store_supplemental_code:
174 heavyiron 6571
	mov	al,[supplemental_code]
6572
	stos	byte [edi]
6573
	ret
6574
store_nomem_instruction:
31 halyavin 6575
	test	[postbyte_register],1000b
157 heavyiron 6576
	jz	nomem_reg_code_ok
6577
	or	[rex_prefix],44h
6578
	and	[postbyte_register],111b
6579
      nomem_reg_code_ok:
31 halyavin 6580
	test	bl,1000b
157 heavyiron 6581
	jz	nomem_rm_code_ok
6582
	or	[rex_prefix],41h
6583
	and	bl,111b
6584
      nomem_rm_code_ok:
31 halyavin 6585
	call	store_instruction_code
157 heavyiron 6586
	mov	al,[postbyte_register]
6587
	shl	al,3
6588
	or	al,bl
6589
	or	al,11000000b
6590
	stos	byte [edi]
6591
	ret
6592
store_instruction:
31 halyavin 6593
	mov	[current_offset],edi
157 heavyiron 6594
	test	[postbyte_register],1000b
6595
	jz	reg_code_ok
6596
	or	[rex_prefix],44h
6597
	and	[postbyte_register],111b
6598
      reg_code_ok:
31 halyavin 6599
	cmp	[code_type],64
2287 heavyiron 6600
	jne	address_value_ok
6601
	xor	eax,eax
6602
	bt	edx,31
6603
	sbb	eax,[address_high]
6604
	jz	address_value_ok
6605
	cmp	[address_high],0
6606
	jne	address_value_out_of_range
6607
	test	ch,44h
6608
	jnz	address_value_ok
6609
	test	bx,8080h
6610
	jz	address_value_ok
6611
      address_value_out_of_range:
6612
	call	recoverable_overflow
2665 dunkaist 6613
      address_value_ok:
2287 heavyiron 6614
	call	store_segment_prefix_if_necessary
157 heavyiron 6615
	test	[vex_required],4
2665 dunkaist 6616
	jnz	address_vsib
6617
	or	bx,bx
157 heavyiron 6618
	jz	address_immediate
6619
	cmp	bx,0F800h
176 heavyiron 6620
	je	address_rip_based
157 heavyiron 6621
	cmp	bx,0F400h
176 heavyiron 6622
	je	address_eip_based
6623
	cmp	bx,0FF00h
157 heavyiron 6624
	je	address_relative
6625
	mov	al,bl
6626
	or	al,bh
6627
	and	al,11110000b
6628
	cmp	al,80h
6629
	je	postbyte_64bit
6630
	cmp	al,40h
6631
	je	postbyte_32bit
6632
	cmp	al,20h
6633
	jne	invalid_address
6634
	cmp	[code_type],64
6635
	je	invalid_address_size
6636
	call	address_16bit_prefix
6637
	call	store_instruction_code
6638
	cmp	bl,bh
1053 heavyiron 6639
	jbe	determine_16bit_address
6640
	xchg	bl,bh
6641
      determine_16bit_address:
6642
	cmp	bx,2600h
157 heavyiron 6643
	je	address_si
6644
	cmp	bx,2700h
6645
	je	address_di
6646
	cmp	bx,2300h
6647
	je	address_bx
6648
	cmp	bx,2500h
6649
	je	address_bp
6650
	cmp	bx,2625h
1053 heavyiron 6651
	je	address_bp_si
6652
	cmp	bx,2725h
6653
	je	address_bp_di
6654
	cmp	bx,2723h
6655
	je	address_bx_di
6656
	cmp	bx,2623h
6657
	jne	invalid_address
6658
      address_bx_si:
31 halyavin 6659
	xor	al,al
157 heavyiron 6660
	jmp	postbyte_16bit
6661
      address_bx_di:
31 halyavin 6662
	mov	al,1
157 heavyiron 6663
	jmp	postbyte_16bit
6664
      address_bp_si:
31 halyavin 6665
	mov	al,10b
157 heavyiron 6666
	jmp	postbyte_16bit
6667
      address_bp_di:
31 halyavin 6668
	mov	al,11b
157 heavyiron 6669
	jmp	postbyte_16bit
6670
      address_si:
31 halyavin 6671
	mov	al,100b
157 heavyiron 6672
	jmp	postbyte_16bit
6673
      address_di:
31 halyavin 6674
	mov	al,101b
157 heavyiron 6675
	jmp	postbyte_16bit
6676
      address_bx:
31 halyavin 6677
	mov	al,111b
157 heavyiron 6678
	jmp	postbyte_16bit
6679
      address_bp:
31 halyavin 6680
	mov	al,110b
157 heavyiron 6681
      postbyte_16bit:
31 halyavin 6682
	test	ch,22h
157 heavyiron 6683
	jnz	address_16bit_value
6684
	or	ch,ch
6685
	jnz	address_sizes_do_not_agree
6686
	cmp	edx,10000h
6687
	jge	value_out_of_range
6688
	cmp	edx,-8000h
6689
	jl	value_out_of_range
6690
	or	dx,dx
6691
	jz	address
6692
	cmp	dx,80h
6693
	jb	address_8bit_value
6694
	cmp	dx,-80h
6695
	jae	address_8bit_value
6696
      address_16bit_value:
31 halyavin 6697
	or	al,10000000b
157 heavyiron 6698
	mov	cl,[postbyte_register]
6699
	shl	cl,3
6700
	or	al,cl
6701
	stos	byte [edi]
6702
	mov	eax,edx
6703
	stos	word [edi]
6704
	ret
6705
      address_8bit_value:
31 halyavin 6706
	or	al,01000000b
157 heavyiron 6707
	mov	cl,[postbyte_register]
6708
	shl	cl,3
6709
	or	al,cl
6710
	stos	byte [edi]
6711
	mov	al,dl
6712
	stos	byte [edi]
6713
	cmp	dx,80h
6714
	jge	value_out_of_range
6715
	cmp	dx,-80h
6716
	jl	value_out_of_range
6717
	ret
6718
      address:
31 halyavin 6719
	cmp	al,110b
157 heavyiron 6720
	je	address_8bit_value
6721
	mov	cl,[postbyte_register]
6722
	shl	cl,3
6723
	or	al,cl
6724
	stos	byte [edi]
6725
	ret
6726
      address_vsib:
2665 dunkaist 6727
	mov	al,bl
6728
	shr	al,4
6729
	cmp	al,0Ch
6730
	je	vector_index_ok
6731
	cmp	al,0Dh
6732
	jne	invalid_address
6733
      vector_index_ok:
6734
	mov	al,bh
6735
	shr	al,4
6736
	cmp	al,4
6737
	je	postbyte_32bit
6738
	cmp	[code_type],64
6739
	je	address_prefix_ok
6740
	test	al,al
6741
	jnz	invalid_address
6742
      postbyte_32bit:
31 halyavin 6743
	call	address_32bit_prefix
157 heavyiron 6744
	jmp	address_prefix_ok
6745
      postbyte_64bit:
31 halyavin 6746
	cmp	[code_type],64
157 heavyiron 6747
	jne	invalid_address_size
6748
      address_prefix_ok:
109 heavyiron 6749
	cmp	bl,44h
157 heavyiron 6750
	je	invalid_address
6751
	cmp	bl,84h
6752
	je	invalid_address
6753
	test	bh,1000b
1189 heavyiron 6754
	jz	base_code_ok
6755
	or	[rex_prefix],41h
6756
      base_code_ok:
6757
	test	bl,1000b
6758
	jz	index_code_ok
6759
	or	[rex_prefix],42h
6760
      index_code_ok:
6761
	call	store_instruction_code
6762
	or	cl,cl
157 heavyiron 6763
	jz	only_base_register
6764
      base_and_index:
31 halyavin 6765
	mov	al,100b
157 heavyiron 6766
	xor	ah,ah
6767
	cmp	cl,1
6768
	je	scale_ok
6769
	cmp	cl,2
6770
	je	scale_1
6771
	cmp	cl,4
6772
	je	scale_2
6773
	or	ah,11000000b
6774
	jmp	scale_ok
6775
      scale_2:
31 halyavin 6776
	or	ah,10000000b
157 heavyiron 6777
	jmp	scale_ok
6778
      scale_1:
31 halyavin 6779
	or	ah,01000000b
157 heavyiron 6780
      scale_ok:
31 halyavin 6781
	or	bh,bh
157 heavyiron 6782
	jz	only_index_register
6783
	and	bl,111b
6784
	shl	bl,3
6785
	or	ah,bl
6786
	and	bh,111b
6787
	or	ah,bh
6788
      sib_ready:
2665 dunkaist 6789
	test	ch,44h
157 heavyiron 6790
	jnz	sib_address_32bit_value
6791
	test	ch,88h
6792
	jnz	sib_address_32bit_value
6793
	or	ch,ch
6794
	jnz	address_sizes_do_not_agree
6795
	cmp	bh,5
6796
	je	address_value
6797
	or	edx,edx
6798
	jz	sib_address
6799
      address_value:
31 halyavin 6800
	cmp	edx,80h
157 heavyiron 6801
	jb	sib_address_8bit_value
6802
	cmp	edx,-80h
6803
	jae	sib_address_8bit_value
6804
      sib_address_32bit_value:
31 halyavin 6805
	or	al,10000000b
157 heavyiron 6806
	mov	cl,[postbyte_register]
6807
	shl	cl,3
6808
	or	al,cl
6809
	stos	word [edi]
6810
	jmp	store_address_32bit_value
6811
      sib_address_8bit_value:
31 halyavin 6812
	or	al,01000000b
157 heavyiron 6813
	mov	cl,[postbyte_register]
6814
	shl	cl,3
6815
	or	al,cl
6816
	stos	word [edi]
6817
	mov	al,dl
6818
	stos	byte [edi]
6819
	cmp	edx,80h
6820
	jge	value_out_of_range
6821
	cmp	edx,-80h
6822
	jl	value_out_of_range
6823
	ret
6824
      sib_address:
31 halyavin 6825
	mov	cl,[postbyte_register]
157 heavyiron 6826
	shl	cl,3
6827
	or	al,cl
6828
	stos	word [edi]
6829
	ret
6830
      only_index_register:
31 halyavin 6831
	or	ah,101b
157 heavyiron 6832
	and	bl,111b
6833
	shl	bl,3
6834
	or	ah,bl
6835
	mov	cl,[postbyte_register]
6836
	shl	cl,3
6837
	or	al,cl
6838
	stos	word [edi]
6839
	test	ch,44h
6840
	jnz	store_address_32bit_value
2287 heavyiron 6841
	test	ch,88h
340 heavyiron 6842
	jnz	store_address_32bit_value
2287 heavyiron 6843
	or	ch,ch
157 heavyiron 6844
	jnz	invalid_address_size
6845
	jmp	store_address_32bit_value
2287 heavyiron 6846
      zero_index_register:
31 halyavin 6847
	mov	bl,4
157 heavyiron 6848
	mov	cl,1
6849
	jmp	base_and_index
6850
      only_base_register:
31 halyavin 6851
	mov	al,bh
157 heavyiron 6852
	and	al,111b
6853
	cmp	al,4
6854
	je	zero_index_register
6855
	test	ch,44h
6856
	jnz	simple_address_32bit_value
6857
	test	ch,88h
6858
	jnz	simple_address_32bit_value
6859
	or	ch,ch
6860
	jnz	address_sizes_do_not_agree
6861
	or	edx,edx
6862
	jz	simple_address
6863
	cmp	edx,80h
6864
	jb	simple_address_8bit_value
6865
	cmp	edx,-80h
6866
	jae	simple_address_8bit_value
6867
      simple_address_32bit_value:
31 halyavin 6868
	or	al,10000000b
157 heavyiron 6869
	mov	cl,[postbyte_register]
6870
	shl	cl,3
6871
	or	al,cl
6872
	stos	byte [edi]
6873
	jmp	store_address_32bit_value
2287 heavyiron 6874
      simple_address_8bit_value:
31 halyavin 6875
	or	al,01000000b
157 heavyiron 6876
	mov	cl,[postbyte_register]
6877
	shl	cl,3
6878
	or	al,cl
6879
	stos	byte [edi]
6880
	mov	al,dl
6881
	stos	byte [edi]
6882
	cmp	edx,80h
6883
	jge	value_out_of_range
6884
	cmp	edx,-80h
6885
	jl	value_out_of_range
6886
	ret
6887
      simple_address:
31 halyavin 6888
	cmp	al,5
157 heavyiron 6889
	je	simple_address_8bit_value
6890
	mov	cl,[postbyte_register]
6891
	shl	cl,3
6892
	or	al,cl
6893
	stos	byte [edi]
6894
	ret
6895
      address_immediate:
31 halyavin 6896
	cmp	[code_type],64
157 heavyiron 6897
	je	address_immediate_sib
6898
	test	ch,44h
6899
	jnz	address_immediate_32bit
6900
	test	ch,88h
3010 dunkaist 6901
	jnz	address_immediate_32bit
6902
	test	ch,22h
157 heavyiron 6903
	jnz	address_immediate_16bit
6904
	or	ch,ch
6905
	jnz	invalid_address_size
6906
	cmp	[code_type],16
6907
	je	addressing_16bit
6908
      address_immediate_32bit:
31 halyavin 6909
	call	address_32bit_prefix
157 heavyiron 6910
	call	store_instruction_code
6911
      store_immediate_address:
31 halyavin 6912
	mov	al,101b
157 heavyiron 6913
	mov	cl,[postbyte_register]
6914
	shl	cl,3
6915
	or	al,cl
6916
	stos	byte [edi]
6917
      store_address_32bit_value:
31 halyavin 6918
	test	ch,0F0h
157 heavyiron 6919
	jz	address_32bit_relocation_ok
6920
	mov	eax,ecx
174 heavyiron 6921
	shr	eax,16
6922
	cmp	al,4
340 heavyiron 6923
	jne	address_32bit_relocation
6924
	mov	al,2
6925
      address_32bit_relocation:
6926
	xchg	[value_type],al
157 heavyiron 6927
	mov	ebx,[address_symbol]
6928
	xchg	ebx,[symbol_identifier]
6929
	call	mark_relocation
6930
	mov	[value_type],al
6931
	mov	[symbol_identifier],ebx
6932
      address_32bit_relocation_ok:
31 halyavin 6933
	mov	eax,edx
157 heavyiron 6934
	stos	dword [edi]
6935
	ret
6936
      store_address_64bit_value:
31 halyavin 6937
	test	ch,0F0h
157 heavyiron 6938
	jz	address_64bit_relocation_ok
6939
	mov	eax,ecx
174 heavyiron 6940
	shr	eax,16
6941
	xchg	[value_type],al
157 heavyiron 6942
	mov	ebx,[address_symbol]
6943
	xchg	ebx,[symbol_identifier]
6944
	call	mark_relocation
6945
	mov	[value_type],al
6946
	mov	[symbol_identifier],ebx
6947
      address_64bit_relocation_ok:
31 halyavin 6948
	mov	eax,edx
157 heavyiron 6949
	stos	dword [edi]
6950
	mov	eax,[address_high]
6951
	stos	dword [edi]
6952
	ret
6953
      address_immediate_sib:
31 halyavin 6954
	test	ch,44h
1242 heavyiron 6955
	jnz	address_immediate_sib_32bit
6956
	test	ch,not 88h
6957
	jnz	invalid_address_size
157 heavyiron 6958
      address_immediate_sib_store:
1242 heavyiron 6959
	call	store_instruction_code
157 heavyiron 6960
	mov	al,100b
6961
	mov	ah,100101b
6962
	mov	cl,[postbyte_register]
6963
	shl	cl,3
6964
	or	al,cl
6965
	stos	word [edi]
6966
	jmp	store_address_32bit_value
6967
      address_immediate_sib_32bit:
1242 heavyiron 6968
	test	ecx,0FF0000h
6969
	jnz	address_immediate_sib_nosignextend
6970
	test	edx,80000000h
6971
	jz	address_immediate_sib_store
6972
      address_immediate_sib_nosignextend:
6973
	call	address_32bit_prefix
6974
	jmp	address_immediate_sib_store
6975
      address_eip_based:
176 heavyiron 6976
	mov	al,67h
6977
	stos	byte [edi]
6978
      address_rip_based:
31 halyavin 6979
	cmp	[code_type],64
157 heavyiron 6980
	jne	invalid_address
6981
	call	store_instruction_code
6982
	jmp	store_immediate_address
6983
      address_relative:
31 halyavin 6984
	call	store_instruction_code
157 heavyiron 6985
	movzx	eax,[immediate_size]
6986
	add	eax,edi
6987
	sub	eax,[current_offset]
6988
	add	eax,5
6989
	sub	edx,eax
6990
	jo	value_out_of_range
6991
	mov	al,101b
6992
	mov	cl,[postbyte_register]
6993
	shl	cl,3
6994
	or	al,cl
6995
	stos	byte [edi]
6996
	shr	ecx,16
174 heavyiron 6997
	xchg	[value_type],cl
6998
	mov	ebx,[address_symbol]
157 heavyiron 6999
	xchg	ebx,[symbol_identifier]
7000
	mov	eax,edx
7001
	call	mark_relocation
7002
	mov	[value_type],cl
174 heavyiron 7003
	mov	[symbol_identifier],ebx
157 heavyiron 7004
	stos	dword [edi]
7005
	ret
7006
      addressing_16bit:
31 halyavin 7007
	cmp	edx,10000h
157 heavyiron 7008
	jge	address_immediate_32bit
7009
	cmp	edx,-8000h
7010
	jl	address_immediate_32bit
7011
	movzx	edx,dx
7012
      address_immediate_16bit:
31 halyavin 7013
	call	address_16bit_prefix
157 heavyiron 7014
	call	store_instruction_code
7015
	mov	al,110b
7016
	mov	cl,[postbyte_register]
7017
	shl	cl,3
7018
	or	al,cl
7019
	stos	byte [edi]
7020
	mov	eax,edx
7021
	stos	word [edi]
7022
	cmp	edx,10000h
7023
	jge	value_out_of_range
7024
	cmp	edx,-8000h
7025
	jl	value_out_of_range
7026
	ret
7027
      address_16bit_prefix:
31 halyavin 7028
	cmp	[code_type],16
157 heavyiron 7029
	je	instruction_prefix_ok
7030
	mov	al,67h
7031
	stos	byte [edi]
7032
	ret
7033
      address_32bit_prefix:
31 halyavin 7034
	cmp	[code_type],32
157 heavyiron 7035
	je	instruction_prefix_ok
7036
	mov	al,67h
7037
	stos	byte [edi]
7038
      instruction_prefix_ok:
31 halyavin 7039
	ret
157 heavyiron 7040
store_instruction_with_imm8:
31 halyavin 7041
	mov	[immediate_size],1
157 heavyiron 7042
	call	store_instruction
7043
	mov	al,byte [value]
7044
	stos	byte [edi]
7045
	ret
7046
store_instruction_with_imm16:
31 halyavin 7047
	mov	[immediate_size],2
157 heavyiron 7048
	call	store_instruction
7049
	mov	ax,word [value]
7050
	call	mark_relocation
7051
	stos	word [edi]
7052
	ret
7053
store_instruction_with_imm32:
31 halyavin 7054
	mov	[immediate_size],4
157 heavyiron 7055
	call	store_instruction
7056
	mov	eax,dword [value]
7057
	call	mark_relocation
7058
	stos	dword [edi]
7059
	ret
7060