Subversion Repositories Kolibri OS

Rev

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