Subversion Repositories Kolibri OS

Rev

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

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