Subversion Repositories Kolibri OS

Rev

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