Subversion Repositories Kolibri OS

Rev

Rev 992 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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