Subversion Repositories Kolibri OS

Rev

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