Subversion Repositories Kolibri OS

Rev

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