Subversion Repositories Kolibri OS

Rev

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