Subversion Repositories Kolibri OS

Rev

Rev 196 | 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-2006, Tomasz Grysztar.
109 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
	cmp	al,4
1405
	jae	push_sreg_386
1406
	shl	al,3
1407
	add	al,6
1408
	mov	[base_code],al
1409
	cmp	[code_type],64
1410
	je	illegal_instruction
1411
	jmp	push_reg_store
1412
      push_sreg_386:
31 halyavin 1413
	sub	al,4
157 heavyiron 1414
	shl	al,3
1415
	add	al,0A0h
1416
	mov	[extended_code],al
1417
	mov	[base_code],0Fh
1418
	jmp	push_reg_store
1419
      push_imm:
31 halyavin 1420
	mov	al,[operand_size]
157 heavyiron 1421
	mov	ah,[push_size]
1422
	or	al,al
1423
	je	push_imm_size_ok
1424
	or	ah,ah
1425
	je	push_imm_size_ok
1426
	cmp	al,ah
1427
	jne	invalid_operand_size
1428
      push_imm_size_ok:
31 halyavin 1429
	cmp	al,2
157 heavyiron 1430
	je	push_imm_16bit
1431
	cmp	al,4
1432
	je	push_imm_32bit
1433
	cmp	al,8
1434
	je	push_imm_64bit
1435
	cmp	ah,2
1436
	je	push_imm_optimized_16bit
1437
	cmp	ah,4
1438
	je	push_imm_optimized_32bit
1439
	cmp	ah,8
1440
	je	push_imm_optimized_64bit
1441
	or	al,al
1442
	jnz	invalid_operand_size
1443
	cmp	[code_type],16
1444
	je	push_imm_optimized_16bit
1445
	cmp	[code_type],32
1446
	je	push_imm_optimized_32bit
1447
      push_imm_optimized_64bit:
31 halyavin 1448
	cmp	[code_type],64
157 heavyiron 1449
	jne	illegal_instruction
1450
	call	get_simm32
1451
	mov	edx,eax
1452
	cmp	[value_type],0
1453
	jne	push_imm_32bit_store
1454
	cmp	eax,-80h
1455
	jl	push_imm_32bit_store
1456
	cmp	eax,80h
1457
	jge	push_imm_32bit_store
1458
	jmp	push_imm_8bit
1459
      push_imm_optimized_32bit:
31 halyavin 1460
	cmp	[code_type],64
157 heavyiron 1461
	je	illegal_instruction
1462
	call	get_dword_value
1463
	mov	edx,eax
1464
	call	operand_32bit
1465
	cmp	[value_type],0
1466
	jne	push_imm_32bit_store
1467
	cmp	eax,-80h
1468
	jl	push_imm_32bit_store
1469
	cmp	eax,80h
1470
	jge	push_imm_32bit_store
1471
	jmp	push_imm_8bit
1472
      push_imm_optimized_16bit:
31 halyavin 1473
	call	get_word_value
157 heavyiron 1474
	mov	dx,ax
1475
	call	operand_16bit
1476
	cmp	[value_type],0
1477
	jne	push_imm_16bit_store
1478
	cmp	ax,-80h
1479
	jl	push_imm_16bit_store
1480
	cmp	ax,80h
1481
	jge	push_imm_16bit_store
1482
      push_imm_8bit:
31 halyavin 1483
	mov	ah,al
157 heavyiron 1484
	mov	[base_code],6Ah
1485
	call	store_instruction_code
1486
	mov	al,ah
1487
	stos	byte [edi]
1488
	jmp	push_done
1489
      push_imm_16bit:
31 halyavin 1490
	call	get_word_value
157 heavyiron 1491
	mov	dx,ax
1492
	call	operand_16bit
1493
      push_imm_16bit_store:
31 halyavin 1494
	mov	[base_code],68h
157 heavyiron 1495
	call	store_instruction_code
1496
	mov	ax,dx
1497
	call	mark_relocation
1498
	stos	word [edi]
1499
	jmp	push_done
1500
      push_imm_64bit:
31 halyavin 1501
	cmp	[code_type],64
157 heavyiron 1502
	jne	illegal_instruction
1503
	call	get_simm32
1504
	mov	edx,eax
1505
	jmp	push_imm_32bit_store
1506
      push_imm_32bit:
31 halyavin 1507
	cmp	[code_type],64
157 heavyiron 1508
	je	illegal_instruction
1509
	call	get_dword_value
1510
	mov	edx,eax
1511
	call	operand_32bit
1512
      push_imm_32bit_store:
31 halyavin 1513
	mov	[base_code],68h
157 heavyiron 1514
	call	store_instruction_code
1515
	mov	eax,edx
1516
	call	mark_relocation
1517
	stos	dword [edi]
1518
      push_done:
31 halyavin 1519
	lods	byte [esi]
157 heavyiron 1520
	dec	esi
1521
	cmp	al,0Fh
1522
	je	instruction_assembled
1523
	or	al,al
1524
	jz	instruction_assembled
1525
	mov	[operand_size],0
1526
	mov	[size_override],0
1527
	mov	[operand_prefix],0
1528
	mov	[rex_prefix],0
1529
	jmp	push_next
1530
pop_instruction:
31 halyavin 1531
	mov	[push_size],al
157 heavyiron 1532
      pop_next:
31 halyavin 1533
	lods	byte [esi]
157 heavyiron 1534
	call	get_size_operator
1535
	cmp	al,10h
1536
	je	pop_reg
1537
	cmp	al,'['
1538
	jne	invalid_operand
1539
      pop_mem:
31 halyavin 1540
	call	get_address
157 heavyiron 1541
	mov	al,[operand_size]
1542
	mov	ah,[push_size]
1543
	cmp	al,2
1544
	je	pop_mem_16bit
1545
	cmp	al,4
1546
	je	pop_mem_32bit
1547
	cmp	al,8
1548
	je	pop_mem_64bit
1549
	or	al,al
1550
	jnz	invalid_operand_size
1551
	cmp	ah,2
1552
	je	pop_mem_16bit
1553
	cmp	ah,4
1554
	je	pop_mem_32bit
1555
	cmp	ah,8
1556
	je	pop_mem_64bit
1557
	cmp	[error_line],0
1558
	jne	pop_mem_store
1559
	mov	eax,[current_line]
1560
	mov	[error_line],eax
1561
	mov	[error],operand_size_not_specified
1562
	jmp	pop_mem_store
1563
      pop_mem_16bit:
31 halyavin 1564
	test	ah,not 2
157 heavyiron 1565
	jnz	invalid_operand_size
1566
	call	operand_16bit
1567
	jmp	pop_mem_store
1568
      pop_mem_32bit:
31 halyavin 1569
	test	ah,not 4
157 heavyiron 1570
	jnz	invalid_operand_size
1571
	cmp	[code_type],64
1572
	je	illegal_instruction
1573
	call	operand_32bit
1574
	jmp	pop_mem_store
1575
      pop_mem_64bit:
31 halyavin 1576
	test	ah,not 8
157 heavyiron 1577
	jnz	invalid_operand_size
1578
	cmp	[code_type],64
1579
	jne	illegal_instruction
1580
      pop_mem_store:
31 halyavin 1581
	mov	[base_code],08Fh
157 heavyiron 1582
	mov	[postbyte_register],0
1583
	call	store_instruction
1584
	jmp	pop_done
1585
      pop_reg:
31 halyavin 1586
	lods	byte [esi]
157 heavyiron 1587
	mov	ah,al
1588
	sub	ah,10h
1589
	and	ah,al
1590
	test	ah,0F0h
1591
	jnz	pop_sreg
1592
	call	convert_register
1593
	test	al,1000b
1594
	jz	pop_reg_ok
1595
	or	[rex_prefix],41h
1596
	and	al,111b
1597
      pop_reg_ok:
31 halyavin 1598
	add	al,58h
157 heavyiron 1599
	mov	[base_code],al
1600
	mov	al,ah
1601
	mov	ah,[push_size]
1602
	cmp	al,2
1603
	je	pop_reg_16bit
1604
	cmp	al,4
1605
	je	pop_reg_32bit
1606
	cmp	al,8
1607
	je	pop_reg_64bit
1608
	jmp	invalid_operand_size
1609
      pop_reg_64bit:
31 halyavin 1610
	test	ah,not 8
157 heavyiron 1611
	jnz	invalid_operand_size
1612
	cmp	[code_type],64
1613
	jne	illegal_instruction
1614
	jmp	pop_reg_store
1615
      pop_reg_32bit:
31 halyavin 1616
	test	ah,not 4
157 heavyiron 1617
	jnz	invalid_operand_size
1618
	cmp	[code_type],64
1619
	je	illegal_instruction
1620
	call	operand_32bit
1621
	jmp	pop_reg_store
1622
      pop_reg_16bit:
31 halyavin 1623
	test	ah,not 2
157 heavyiron 1624
	jnz	invalid_operand_size
1625
	call	operand_16bit
1626
      pop_reg_store:
31 halyavin 1627
	call	store_instruction_code
157 heavyiron 1628
      pop_done:
31 halyavin 1629
	lods	byte [esi]
157 heavyiron 1630
	dec	esi
1631
	cmp	al,0Fh
1632
	je	instruction_assembled
1633
	or	al,al
1634
	jz	instruction_assembled
1635
	mov	[operand_size],0
1636
	mov	[size_override],0
1637
	mov	[operand_prefix],0
1638
	mov	[rex_prefix],0
1639
	jmp	pop_next
1640
      pop_sreg:
31 halyavin 1641
	mov	dl,[operand_size]
157 heavyiron 1642
	mov	dh,[push_size]
1643
	cmp	al,62h
1644
	je	pop_cs
1645
	mov	bl,al
1646
	cmp	dl,2
1647
	je	pop_sreg16
1648
	cmp	dl,4
1649
	je	pop_sreg32
1650
	cmp	dl,8
1651
	je	pop_sreg64
1652
	or	dl,dl
1653
	jnz	invalid_operand_size
1654
	cmp	dh,2
1655
	je	pop_sreg16
1656
	cmp	dh,4
1657
	je	pop_sreg32
1658
	cmp	dh,8
1659
	je	pop_sreg64
1660
	jmp	pop_sreg_store
1661
      pop_sreg16:
31 halyavin 1662
	test	dh,not 2
157 heavyiron 1663
	jnz	invalid_operand_size
1664
	call	operand_16bit
1665
	jmp	pop_sreg_store
1666
      pop_sreg32:
31 halyavin 1667
	test	dh,not 4
157 heavyiron 1668
	jnz	invalid_operand_size
1669
	cmp	[code_type],64
1670
	je	illegal_instruction
1671
	call	operand_32bit
1672
	jmp	pop_sreg_store
1673
      pop_sreg64:
31 halyavin 1674
	test	dh,not 8
157 heavyiron 1675
	jnz	invalid_operand_size
1676
	cmp	[code_type],64
1677
	jne	illegal_instruction
1678
      pop_sreg_store:
31 halyavin 1679
	mov	al,bl
157 heavyiron 1680
	cmp	al,70h
1681
	jae	invalid_operand
1682
	sub	al,61h
1683
	cmp	al,4
1684
	jae	pop_sreg_386
1685
	shl	al,3
1686
	add	al,7
1687
	mov	[base_code],al
1688
	cmp	[code_type],64
1689
	je	illegal_instruction
1690
	jmp	pop_reg_store
1691
      pop_cs:
109 heavyiron 1692
	cmp	[code_type],16
157 heavyiron 1693
	jne	illegal_instruction
1694
	cmp	dl,2
1695
	je	pop_cs_store
1696
	or	dl,dl
1697
	jnz	invalid_operand_size
1698
	cmp	dh,2
1699
	je	pop_cs_store
1700
	or	dh,dh
1701
	jnz	illegal_instruction
1702
      pop_cs_store:
109 heavyiron 1703
	test	dh,not 2
157 heavyiron 1704
	jnz	invalid_operand_size
1705
	mov	al,0Fh
1706
	stos	byte [edi]
1707
	jmp	pop_done
1708
      pop_sreg_386:
31 halyavin 1709
	sub	al,4
157 heavyiron 1710
	shl	al,3
1711
	add	al,0A1h
1712
	mov	[extended_code],al
1713
	mov	[base_code],0Fh
1714
	jmp	pop_reg_store
1715
inc_instruction:
31 halyavin 1716
	mov	[base_code],al
157 heavyiron 1717
	lods	byte [esi]
1718
	call	get_size_operator
1719
	cmp	al,10h
1720
	je	inc_reg
1721
	cmp	al,'['
1722
	je	inc_mem
1723
	jne	invalid_operand
1724
      inc_mem:
31 halyavin 1725
	call	get_address
157 heavyiron 1726
	mov	al,[operand_size]
1727
	cmp	al,1
1728
	je	inc_mem_8bit
1729
	jb	inc_mem_nosize
1730
	call	operand_autodetect
1731
	mov	al,0FFh
1732
	xchg	al,[base_code]
1733
	mov	[postbyte_register],al
1734
	call	store_instruction
1735
	jmp	instruction_assembled
1736
      inc_mem_nosize:
31 halyavin 1737
	cmp	[error_line],0
157 heavyiron 1738
	jne	inc_mem_8bit
1739
	mov	eax,[current_line]
1740
	mov	[error_line],eax
1741
	mov	[error],operand_size_not_specified
1742
      inc_mem_8bit:
31 halyavin 1743
	mov	al,0FEh
157 heavyiron 1744
	xchg	al,[base_code]
1745
	mov	[postbyte_register],al
1746
	call	store_instruction
1747
	jmp	instruction_assembled
1748
      inc_reg:
31 halyavin 1749
	lods	byte [esi]
157 heavyiron 1750
	call	convert_register
1751
	mov	bl,al
1752
	mov	al,0FEh
1753
	xchg	al,[base_code]
1754
	mov	[postbyte_register],al
1755
	mov	al,ah
1756
	cmp	al,1
1757
	je	inc_reg_8bit
1758
	call	operand_autodetect
1759
	cmp	[code_type],64
1760
	je	inc_reg_long_form
1761
	mov	al,[postbyte_register]
1762
	shl	al,3
1763
	add	al,bl
1764
	add	al,40h
1765
	mov	[base_code],al
1766
	call	store_instruction_code
1767
	jmp	instruction_assembled
1768
      inc_reg_long_form:
31 halyavin 1769
	inc	[base_code]
157 heavyiron 1770
      inc_reg_8bit:
31 halyavin 1771
	call	store_nomem_instruction
157 heavyiron 1772
	jmp	instruction_assembled
1773
set_instruction:
31 halyavin 1774
	mov	[base_code],0Fh
157 heavyiron 1775
	mov	[extended_code],al
1776
	lods	byte [esi]
1777
	call	get_size_operator
1778
	cmp	al,10h
1779
	je	set_reg
1780
	cmp	al,'['
1781
	jne	invalid_operand
1782
      set_mem:
31 halyavin 1783
	call	get_address
157 heavyiron 1784
	cmp	[operand_size],1
1785
	ja	invalid_operand_size
1786
	mov	[postbyte_register],0
1787
	call	store_instruction
1788
	jmp	instruction_assembled
1789
      set_reg:
31 halyavin 1790
	lods	byte [esi]
157 heavyiron 1791
	call	convert_register
1792
	cmp	ah,1
1793
	jne	invalid_operand_size
1794
	mov	bl,al
1795
	mov	[postbyte_register],0
1796
	call	store_nomem_instruction
1797
	jmp	instruction_assembled
1798
arpl_instruction:
31 halyavin 1799
	cmp	[code_type],64
157 heavyiron 1800
	je	illegal_instruction
1801
	mov	[base_code],63h
1802
	lods	byte [esi]
1803
	call	get_size_operator
1804
	cmp	al,10h
1805
	je	arpl_reg
1806
	cmp	al,'['
1807
	jne	invalid_operand
1808
	call	get_address
1809
	lods	byte [esi]
1810
	cmp	al,','
1811
	jne	invalid_operand
1812
	lods	byte [esi]
1813
	cmp	al,10h
1814
	jne	invalid_operand
1815
	lods	byte [esi]
1816
	call	convert_register
1817
	mov	[postbyte_register],al
1818
	cmp	ah,2
1819
	jne	invalid_operand_size
1820
	call	store_instruction
1821
	jmp	instruction_assembled
1822
      arpl_reg:
31 halyavin 1823
	lods	byte [esi]
157 heavyiron 1824
	call	convert_register
1825
	cmp	ah,2
1826
	jne	invalid_operand_size
1827
	mov	bl,al
1828
	lods	byte [esi]
1829
	cmp	al,','
1830
	jne	invalid_operand
1831
	lods	byte [esi]
1832
	cmp	al,10h
1833
	jne	invalid_operand
1834
	lods	byte [esi]
1835
	call	convert_register
1836
	cmp	ah,2
1837
	jne	invalid_operand_size
1838
	mov	[postbyte_register],al
1839
	call	store_nomem_instruction
1840
	jmp	instruction_assembled
1841
bound_instruction:
31 halyavin 1842
	cmp	[code_type],64
157 heavyiron 1843
	je	illegal_instruction
1844
	lods	byte [esi]
1845
	call	get_size_operator
1846
	cmp	al,10h
1847
	jne	invalid_operand
1848
	lods	byte [esi]
1849
	call	convert_register
1850
	mov	[postbyte_register],al
1851
	lods	byte [esi]
1852
	cmp	al,','
1853
	jne	invalid_operand
1854
	lods	byte [esi]
1855
	call	get_size_operator
1856
	cmp	al,'['
1857
	jne	invalid_operand
1858
	call	get_address
1859
	mov	al,[operand_size]
1860
	cmp	al,2
1861
	je	bound_16bit
1862
	cmp	al,4
1863
	je	bound_32bit
1864
	jmp	invalid_operand_size
1865
      bound_32bit:
31 halyavin 1866
	call	operand_32bit
157 heavyiron 1867
	mov	[base_code],62h
1868
	call	store_instruction
1869
	jmp	instruction_assembled
1870
      bound_16bit:
31 halyavin 1871
	call	operand_16bit
157 heavyiron 1872
	mov	[base_code],62h
1873
	call	store_instruction
1874
	jmp	instruction_assembled
1875
enter_instruction:
31 halyavin 1876
	lods	byte [esi]
157 heavyiron 1877
	call	get_size_operator
1878
	cmp	ah,2
1879
	je	enter_imm16_size_ok
1880
	or	ah,ah
1881
	jnz	invalid_operand_size
1882
      enter_imm16_size_ok:
31 halyavin 1883
	cmp	al,'('
157 heavyiron 1884
	jne	invalid_operand
1885
	call	get_word_value
1886
	cmp	[next_pass_needed],0
1887
	jne	enter_imm16_ok
1888
	cmp	[value_type],0
1889
	jne	invalid_use_of_symbol
1890
      enter_imm16_ok:
31 halyavin 1891
	push	eax
157 heavyiron 1892
	mov	[operand_size],0
1893
	lods	byte [esi]
1894
	cmp	al,','
1895
	jne	invalid_operand
1896
	lods	byte [esi]
1897
	call	get_size_operator
1898
	cmp	ah,1
1899
	je	enter_imm8_size_ok
1900
	or	ah,ah
1901
	jnz	invalid_operand_size
1902
      enter_imm8_size_ok:
31 halyavin 1903
	cmp	al,'('
157 heavyiron 1904
	jne	invalid_operand
1905
	call	get_byte_value
1906
	mov	dl,al
1907
	pop	ebx
1908
	mov	al,0C8h
1909
	stos	byte [edi]
1910
	mov	ax,bx
1911
	stos	word [edi]
1912
	mov	al,dl
1913
	stos	byte [edi]
1914
	jmp	instruction_assembled
1915
ret_instruction_only64:
31 halyavin 1916
	cmp	[code_type],64
157 heavyiron 1917
	jne	illegal_instruction
1918
	jmp	ret_instruction
1919
ret_instruction_32bit_except64:
31 halyavin 1920
	cmp	[code_type],64
157 heavyiron 1921
	je	illegal_instruction
1922
ret_instruction_32bit:
31 halyavin 1923
	call	operand_32bit
157 heavyiron 1924
	jmp	ret_instruction
1925
ret_instruction_16bit:
31 halyavin 1926
	call	operand_16bit
157 heavyiron 1927
	jmp	ret_instruction
1928
retf_instruction:
31 halyavin 1929
	cmp	[code_type],64
157 heavyiron 1930
	jne	ret_instruction
1931
ret_instruction_64bit:
31 halyavin 1932
	call	operand_64bit
157 heavyiron 1933
ret_instruction:
31 halyavin 1934
	mov	[base_code],al
157 heavyiron 1935
	lods	byte [esi]
1936
	dec	esi
1937
	or	al,al
1938
	jz	simple_ret
1939
	cmp	al,0Fh
1940
	je	simple_ret
1941
	lods	byte [esi]
1942
	call	get_size_operator
1943
	or	ah,ah
1944
	jz	ret_imm
1945
	cmp	ah,2
1946
	je	ret_imm
1947
	jmp	invalid_operand_size
1948
      ret_imm:
31 halyavin 1949
	cmp	al,'('
157 heavyiron 1950
	jne	invalid_operand
1951
	call	get_word_value
1952
	cmp	[next_pass_needed],0
1953
	jne	ret_imm_ok
1954
	cmp	[value_type],0
1955
	jne	invalid_use_of_symbol
1956
      ret_imm_ok:
31 halyavin 1957
	cmp	[size_declared],0
157 heavyiron 1958
	jne	ret_imm_store
1959
	or	ax,ax
1960
	jz	simple_ret
1961
      ret_imm_store:
109 heavyiron 1962
	mov	dx,ax
157 heavyiron 1963
	call	store_instruction_code
1964
	mov	ax,dx
1965
	stos	word [edi]
1966
	jmp	instruction_assembled
1967
      simple_ret:
31 halyavin 1968
	inc	[base_code]
157 heavyiron 1969
	call	store_instruction_code
1970
	jmp	instruction_assembled
1971
lea_instruction:
31 halyavin 1972
	mov	[base_code],8Dh
157 heavyiron 1973
	lods	byte [esi]
1974
	call	get_size_operator
1975
	cmp	al,10h
1976
	jne	invalid_operand
1977
	lods	byte [esi]
1978
	call	convert_register
1979
	mov	[postbyte_register],al
1980
	lods	byte [esi]
1981
	cmp	al,','
1982
	jne	invalid_operand
1983
	xor	al,al
1984
	xchg	al,[operand_size]
1985
	push	eax
1986
	lods	byte [esi]
1987
	call	get_size_operator
1988
	cmp	al,'['
1989
	jne	invalid_operand
1990
	mov	[size_override],-1
1991
	call	get_address
1992
	pop	eax
1993
	mov	[operand_size],al
1994
	call	operand_autodetect
1995
	call	store_instruction
1996
	jmp	instruction_assembled
1997
ls_instruction:
31 halyavin 1998
	or	al,al
157 heavyiron 1999
	jz	les_instruction
2000
	cmp	al,3
2001
	jz	lds_instruction
2002
	add	al,0B0h
2003
	mov	[extended_code],al
2004
	mov	[base_code],0Fh
2005
	jmp	ls_code_ok
2006
      les_instruction:
31 halyavin 2007
	mov	[base_code],0C4h
157 heavyiron 2008
	jmp	ls_short_code
2009
      lds_instruction:
31 halyavin 2010
	mov	[base_code],0C5h
157 heavyiron 2011
      ls_short_code:
31 halyavin 2012
	cmp	[code_type],64
157 heavyiron 2013
	je	illegal_instruction
2014
      ls_code_ok:
31 halyavin 2015
	lods	byte [esi]
157 heavyiron 2016
	call	get_size_operator
2017
	cmp	al,10h
2018
	jne	invalid_operand
2019
	lods	byte [esi]
2020
	call	convert_register
2021
	mov	[postbyte_register],al
2022
	lods	byte [esi]
2023
	cmp	al,','
2024
	jne	invalid_operand
2025
	add	[operand_size],2
2026
	lods	byte [esi]
2027
	call	get_size_operator
2028
	cmp	al,'['
2029
	jne	invalid_operand
2030
	call	get_address
2031
	mov	al,[operand_size]
2032
	cmp	al,4
2033
	je	ls_16bit
2034
	cmp	al,6
2035
	je	ls_32bit
2036
	cmp	al,10
2037
	je	ls_64bit
2038
	jmp	invalid_operand_size
2039
      ls_16bit:
31 halyavin 2040
	call	operand_16bit
157 heavyiron 2041
	call	store_instruction
2042
	jmp	instruction_assembled
2043
      ls_32bit:
31 halyavin 2044
	call	operand_32bit
157 heavyiron 2045
	call	store_instruction
2046
	jmp	instruction_assembled
2047
      ls_64bit:
31 halyavin 2048
	call	operand_64bit
157 heavyiron 2049
	call	store_instruction
2050
	jmp	instruction_assembled
2051
sh_instruction:
31 halyavin 2052
	mov	[postbyte_register],al
157 heavyiron 2053
	lods	byte [esi]
2054
	call	get_size_operator
2055
	cmp	al,10h
2056
	je	sh_reg
2057
	cmp	al,'['
2058
	jne	invalid_operand
2059
      sh_mem:
31 halyavin 2060
	call	get_address
157 heavyiron 2061
	push	edx ebx ecx
174 heavyiron 2062
	mov	al,[operand_size]
157 heavyiron 2063
	push	eax
2064
	mov	[operand_size],0
2065
	lods	byte [esi]
2066
	cmp	al,','
2067
	jne	invalid_operand
2068
	lods	byte [esi]
2069
	call	get_size_operator
2070
	cmp	al,'('
2071
	je	sh_mem_imm
2072
	cmp	al,10h
2073
	jne	invalid_operand
2074
      sh_mem_reg:
31 halyavin 2075
	lods	byte [esi]
157 heavyiron 2076
	cmp	al,11h
2077
	jne	invalid_operand
2078
	pop	eax ecx ebx edx
174 heavyiron 2079
	cmp	al,1
157 heavyiron 2080
	je	sh_mem_cl_8bit
2081
	jb	sh_mem_cl_nosize
2082
	call	operand_autodetect
2083
	mov	[base_code],0D3h
2084
	call	store_instruction
2085
	jmp	instruction_assembled
2086
      sh_mem_cl_nosize:
31 halyavin 2087
	cmp	[error_line],0
157 heavyiron 2088
	jne	sh_mem_cl_8bit
2089
	mov	eax,[current_line]
2090
	mov	[error_line],eax
2091
	mov	[error],operand_size_not_specified
2092
      sh_mem_cl_8bit:
31 halyavin 2093
	mov	[base_code],0D2h
157 heavyiron 2094
	call	store_instruction
2095
	jmp	instruction_assembled
2096
      sh_mem_imm:
31 halyavin 2097
	mov	al,[operand_size]
157 heavyiron 2098
	or	al,al
2099
	jz	sh_mem_imm_size_ok
2100
	cmp	al,1
2101
	jne	invalid_operand_size
2102
      sh_mem_imm_size_ok:
31 halyavin 2103
	call	get_byte_value
157 heavyiron 2104
	mov	byte [value],al
2105
	pop	eax ecx ebx edx
174 heavyiron 2106
	cmp	al,1
157 heavyiron 2107
	je	sh_mem_imm_8bit
2108
	jb	sh_mem_imm_nosize
2109
	call	operand_autodetect
2110
	cmp	byte [value],1
2111
	je	sh_mem_1
2112
	mov	[base_code],0C1h
2113
	call	store_instruction_with_imm8
2114
	jmp	instruction_assembled
2115
      sh_mem_1:
31 halyavin 2116
	mov	[base_code],0D1h
157 heavyiron 2117
	call	store_instruction
2118
	jmp	instruction_assembled
2119
      sh_mem_imm_nosize:
31 halyavin 2120
	cmp	[error_line],0
157 heavyiron 2121
	jne	sh_mem_imm_8bit
2122
	mov	eax,[current_line]
2123
	mov	[error_line],eax
2124
	mov	[error],operand_size_not_specified
2125
      sh_mem_imm_8bit:
31 halyavin 2126
	cmp	byte [value],1
157 heavyiron 2127
	je	sh_mem_1_8bit
2128
	mov	[base_code],0C0h
2129
	call	store_instruction_with_imm8
2130
	jmp	instruction_assembled
2131
      sh_mem_1_8bit:
31 halyavin 2132
	mov	[base_code],0D0h
157 heavyiron 2133
	call	store_instruction
2134
	jmp	instruction_assembled
2135
      sh_reg:
31 halyavin 2136
	lods	byte [esi]
157 heavyiron 2137
	call	convert_register
2138
	mov	bx,ax
2139
	mov	[operand_size],0
2140
	lods	byte [esi]
2141
	cmp	al,','
2142
	jne	invalid_operand
2143
	lods	byte [esi]
2144
	call	get_size_operator
2145
	cmp	al,'('
2146
	je	sh_reg_imm
2147
	cmp	al,10h
2148
	jne	invalid_operand
2149
      sh_reg_reg:
31 halyavin 2150
	lods	byte [esi]
157 heavyiron 2151
	cmp	al,11h
2152
	jne	invalid_operand
2153
	mov	al,bh
2154
	cmp	al,1
2155
	je	sh_reg_cl_8bit
2156
	call	operand_autodetect
2157
	mov	[base_code],0D3h
2158
	call	store_nomem_instruction
2159
	jmp	instruction_assembled
2160
      sh_reg_cl_8bit:
31 halyavin 2161
	mov	[base_code],0D2h
157 heavyiron 2162
	call	store_nomem_instruction
2163
	jmp	instruction_assembled
2164
      sh_reg_imm:
31 halyavin 2165
	mov	al,[operand_size]
157 heavyiron 2166
	or	al,al
2167
	jz	sh_reg_imm_size_ok
2168
	cmp	al,1
2169
	jne	invalid_operand_size
2170
      sh_reg_imm_size_ok:
31 halyavin 2171
	push	ebx
157 heavyiron 2172
	call	get_byte_value
2173
	mov	dl,al
2174
	pop	ebx
2175
	mov	al,bh
2176
	cmp	al,1
2177
	je	sh_reg_imm_8bit
2178
	call	operand_autodetect
2179
	cmp	dl,1
2180
	je	sh_reg_1
2181
	mov	[base_code],0C1h
2182
	call	store_nomem_instruction
2183
	mov	al,dl
2184
	stos	byte [edi]
2185
	jmp	instruction_assembled
2186
      sh_reg_1:
31 halyavin 2187
	mov	[base_code],0D1h
157 heavyiron 2188
	call	store_nomem_instruction
2189
	jmp	instruction_assembled
2190
      sh_reg_imm_8bit:
31 halyavin 2191
	cmp	dl,1
157 heavyiron 2192
	je	sh_reg_1_8bit
2193
	mov	[base_code],0C0h
2194
	call	store_nomem_instruction
2195
	mov	al,dl
2196
	stos	byte [edi]
2197
	jmp	instruction_assembled
2198
      sh_reg_1_8bit:
31 halyavin 2199
	mov	[base_code],0D0h
157 heavyiron 2200
	call	store_nomem_instruction
2201
	jmp	instruction_assembled
2202
shd_instruction:
31 halyavin 2203
	mov	[base_code],0Fh
157 heavyiron 2204
	mov	[extended_code],al
2205
	lods	byte [esi]
2206
	call	get_size_operator
2207
	cmp	al,10h
2208
	je	shd_reg
2209
	cmp	al,'['
2210
	jne	invalid_operand
2211
      shd_mem:
31 halyavin 2212
	call	get_address
157 heavyiron 2213
	push	edx ebx ecx
174 heavyiron 2214
	lods	byte [esi]
157 heavyiron 2215
	cmp	al,','
2216
	jne	invalid_operand
2217
	lods	byte [esi]
2218
	call	get_size_operator
2219
	cmp	al,10h
2220
	jne	invalid_operand
2221
	lods	byte [esi]
2222
	call	convert_register
2223
	mov	[postbyte_register],al
2224
	lods	byte [esi]
2225
	cmp	al,','
2226
	jne	invalid_operand
2227
	mov	al,ah
2228
	mov	[operand_size],0
2229
	push	eax
2230
	lods	byte [esi]
2231
	call	get_size_operator
2232
	cmp	al,'('
2233
	je	shd_mem_reg_imm
2234
	cmp	al,10h
2235
	jne	invalid_operand
2236
	lods	byte [esi]
2237
	cmp	al,11h
2238
	jne	invalid_operand
2239
	pop	eax ecx ebx edx
174 heavyiron 2240
	call	operand_autodetect
157 heavyiron 2241
	inc	[extended_code]
2242
	call	store_instruction
2243
	jmp	instruction_assembled
2244
      shd_mem_reg_imm:
31 halyavin 2245
	mov	al,[operand_size]
157 heavyiron 2246
	or	al,al
2247
	jz	shd_mem_reg_imm_size_ok
2248
	cmp	al,1
2249
	jne	invalid_operand_size
2250
      shd_mem_reg_imm_size_ok:
31 halyavin 2251
	call	get_byte_value
157 heavyiron 2252
	mov	byte [value],al
2253
	pop	eax ecx ebx edx
174 heavyiron 2254
	call	operand_autodetect
157 heavyiron 2255
	call	store_instruction_with_imm8
2256
	jmp	instruction_assembled
2257
      shd_reg:
31 halyavin 2258
	lods	byte [esi]
157 heavyiron 2259
	call	convert_register
2260
	mov	[postbyte_register],al
2261
	lods	byte [esi]
2262
	cmp	al,','
2263
	jne	invalid_operand
2264
	lods	byte [esi]
2265
	call	get_size_operator
2266
	cmp	al,10h
2267
	jne	invalid_operand
2268
	lods	byte [esi]
2269
	call	convert_register
2270
	mov	bl,[postbyte_register]
2271
	mov	[postbyte_register],al
2272
	mov	al,ah
2273
	push	eax ebx
2274
	lods	byte [esi]
2275
	cmp	al,','
2276
	jne	invalid_operand
2277
	mov	[operand_size],0
2278
	lods	byte [esi]
2279
	call	get_size_operator
2280
	cmp	al,'('
2281
	je	shd_reg_reg_imm
2282
	cmp	al,10h
2283
	jne	invalid_operand
2284
	lods	byte [esi]
2285
	cmp	al,11h
2286
	jne	invalid_operand
2287
	pop	ebx eax
2288
	call	operand_autodetect
2289
	inc	[extended_code]
2290
	call	store_nomem_instruction
2291
	jmp	instruction_assembled
2292
      shd_reg_reg_imm:
31 halyavin 2293
	mov	al,[operand_size]
157 heavyiron 2294
	or	al,al
2295
	jz	shd_reg_reg_imm_size_ok
2296
	cmp	al,1
2297
	jne	invalid_operand_size
2298
      shd_reg_reg_imm_size_ok:
31 halyavin 2299
	call	get_byte_value
157 heavyiron 2300
	mov	dl,al
2301
	pop	ebx eax
2302
	call	operand_autodetect
2303
	call	store_nomem_instruction
2304
	mov	al,dl
2305
	stos	byte [edi]
2306
	jmp	instruction_assembled
2307
movx_instruction:
31 halyavin 2308
	mov	[base_code],0Fh
157 heavyiron 2309
	mov	[extended_code],al
2310
	lods	byte [esi]
2311
	call	get_size_operator
2312
	cmp	al,10h
2313
	jne	invalid_operand
2314
	lods	byte [esi]
2315
	call	convert_register
2316
	mov	[postbyte_register],al
2317
	mov	al,ah
2318
	push	eax
2319
	lods	byte [esi]
2320
	cmp	al,','
2321
	jne	invalid_operand
2322
	mov	[operand_size],0
2323
	lods	byte [esi]
2324
	call	get_size_operator
2325
	cmp	al,10h
2326
	je	movx_reg
2327
	cmp	al,'['
2328
	jne	invalid_operand
2329
	call	get_address
2330
	pop	eax
2331
	mov	ah,[operand_size]
2332
	or	ah,ah
2333
	jz	movx_unknown_size
2334
	cmp	ah,al
2335
	jae	invalid_operand_size
2336
	cmp	ah,1
2337
	je	movx_mem_8bit
2338
	cmp	ah,2
2339
	jne	invalid_operand_size
2340
      movx_mem_16bit:
109 heavyiron 2341
	inc	[extended_code]
157 heavyiron 2342
	call	operand_autodetect
2343
	call	store_instruction
2344
	jmp	instruction_assembled
2345
      movx_unknown_size:
109 heavyiron 2346
	cmp	[error_line],0
157 heavyiron 2347
	jne	movx_mem_8bit
2348
	mov	eax,[current_line]
2349
	mov	[error_line],eax
2350
	mov	[error],operand_size_not_specified
2351
      movx_mem_8bit:
31 halyavin 2352
	call	operand_autodetect
157 heavyiron 2353
	call	store_instruction
2354
	jmp	instruction_assembled
2355
      movx_reg:
31 halyavin 2356
	lods	byte [esi]
157 heavyiron 2357
	call	convert_register
2358
	pop	ebx
2359
	xchg	bl,al
2360
	cmp	ah,al
2361
	jae	invalid_operand_size
2362
	cmp	ah,1
2363
	je	movx_reg_8bit
2364
	cmp	ah,2
2365
	je	movx_reg_16bit
2366
	jmp	invalid_operand_size
2367
      movx_reg_8bit:
31 halyavin 2368
	call	operand_autodetect
157 heavyiron 2369
	call	store_nomem_instruction
2370
	jmp	instruction_assembled
2371
      movx_reg_16bit:
31 halyavin 2372
	call	operand_autodetect
157 heavyiron 2373
	inc	[extended_code]
2374
	call	store_nomem_instruction
2375
	jmp	instruction_assembled
2376
movsxd_instruction:
31 halyavin 2377
	mov	[base_code],al
157 heavyiron 2378
	lods	byte [esi]
2379
	call	get_size_operator
2380
	cmp	al,10h
2381
	jne	invalid_operand
2382
	lods	byte [esi]
2383
	call	convert_register
2384
	mov	[postbyte_register],al
2385
	cmp	ah,8
2386
	jne	invalid_operand_size
2387
	lods	byte [esi]
2388
	cmp	al,','
2389
	jne	invalid_operand
2390
	mov	[operand_size],0
2391
	lods	byte [esi]
2392
	call	get_size_operator
2393
	cmp	al,10h
2394
	je	movsxd_reg
2395
	cmp	al,'['
2396
	jne	invalid_operand
2397
	call	get_address
2398
	cmp	[operand_size],4
2399
	je	movsxd_mem_store
2400
	cmp	[operand_size],0
2401
	jne	invalid_operand_size
2402
      movsxd_mem_store:
31 halyavin 2403
	call	operand_64bit
157 heavyiron 2404
	call	store_instruction
2405
	jmp	instruction_assembled
2406
      movsxd_reg:
31 halyavin 2407
	lods	byte [esi]
157 heavyiron 2408
	call	convert_register
2409
	cmp	ah,4
2410
	jne	invalid_operand_size
2411
	mov	bl,al
2412
	call	operand_64bit
2413
	call	store_nomem_instruction
2414
	jmp	instruction_assembled
2415
bt_instruction:
31 halyavin 2416
	mov	[postbyte_register],al
157 heavyiron 2417
	shl	al,3
2418
	add	al,83h
2419
	mov	[extended_code],al
2420
	mov	[base_code],0Fh
2421
	lods	byte [esi]
2422
	call	get_size_operator
2423
	cmp	al,10h
2424
	je	bt_reg
2425
	cmp	al,'['
2426
	jne	invalid_operand
2427
	call	get_address
2428
	push	eax ebx ecx
174 heavyiron 2429
	lods	byte [esi]
157 heavyiron 2430
	cmp	al,','
2431
	jne	invalid_operand
2432
	cmp	byte [esi],'('
2433
	je	bt_mem_imm
2434
	cmp	byte [esi],11h
2435
	jne	bt_mem_reg
2436
	cmp	byte [esi+2],'('
2437
	je	bt_mem_imm
2438
      bt_mem_reg:
31 halyavin 2439
	lods	byte [esi]
157 heavyiron 2440
	call	get_size_operator
2441
	cmp	al,10h
2442
	jne	invalid_operand
2443
	lods	byte [esi]
2444
	call	convert_register
2445
	mov	[postbyte_register],al
2446
	pop	ecx ebx edx
174 heavyiron 2447
	mov	al,ah
157 heavyiron 2448
	call	operand_autodetect
2449
	call	store_instruction
2450
	jmp	instruction_assembled
2451
      bt_mem_imm:
31 halyavin 2452
	xor	al,al
157 heavyiron 2453
	xchg	al,[operand_size]
2454
	push	eax
2455
	lods	byte [esi]
2456
	call	get_size_operator
2457
	cmp	al,'('
2458
	jne	invalid_operand
2459
	mov	al,[operand_size]
2460
	or	al,al
2461
	jz	bt_mem_imm_size_ok
2462
	cmp	al,1
2463
	jne	invalid_operand_size
2464
      bt_mem_imm_size_ok:
31 halyavin 2465
	call	get_byte_value
157 heavyiron 2466
	mov	byte [value],al
2467
	pop	eax
2468
	or	al,al
2469
	jz	bt_mem_imm_nosize
2470
	call	operand_autodetect
2471
      bt_mem_imm_store:
31 halyavin 2472
	pop	ecx ebx edx
174 heavyiron 2473
	mov	[extended_code],0BAh
157 heavyiron 2474
	call	store_instruction_with_imm8
2475
	jmp	instruction_assembled
2476
      bt_mem_imm_nosize:
31 halyavin 2477
	cmp	[error_line],0
157 heavyiron 2478
	jne	bt_mem_imm_store
2479
	mov	eax,[current_line]
2480
	mov	[error_line],eax
2481
	mov	[error],operand_size_not_specified
2482
	jmp	bt_mem_imm_store
2483
      bt_reg:
31 halyavin 2484
	lods	byte [esi]
157 heavyiron 2485
	call	convert_register
2486
	mov	bl,al
2487
	lods	byte [esi]
2488
	cmp	al,','
2489
	jne	invalid_operand
2490
	cmp	byte [esi],'('
2491
	je	bt_reg_imm
2492
	cmp	byte [esi],11h
2493
	jne	bt_reg_reg
2494
	cmp	byte [esi+2],'('
2495
	je	bt_reg_imm
2496
      bt_reg_reg:
31 halyavin 2497
	lods	byte [esi]
157 heavyiron 2498
	call	get_size_operator
2499
	cmp	al,10h
2500
	jne	invalid_operand
2501
	lods	byte [esi]
2502
	call	convert_register
2503
	mov	[postbyte_register],al
2504
	mov	al,ah
2505
	call	operand_autodetect
2506
	call	store_nomem_instruction
2507
	jmp	instruction_assembled
2508
      bt_reg_imm:
31 halyavin 2509
	xor	al,al
157 heavyiron 2510
	xchg	al,[operand_size]
2511
	push	eax ebx
2512
	lods	byte [esi]
2513
	call	get_size_operator
2514
	cmp	al,'('
2515
	jne	invalid_operand
2516
	mov	al,[operand_size]
2517
	or	al,al
2518
	jz	bt_reg_imm_size_ok
2519
	cmp	al,1
2520
	jne	invalid_operand_size
2521
      bt_reg_imm_size_ok:
31 halyavin 2522
	call	get_byte_value
157 heavyiron 2523
	mov	byte [value],al
2524
	pop	ebx eax
2525
	call	operand_autodetect
2526
      bt_reg_imm_store:
31 halyavin 2527
	mov	[extended_code],0BAh
157 heavyiron 2528
	call	store_nomem_instruction
2529
	mov	al,byte [value]
2530
	stos	byte [edi]
2531
	jmp	instruction_assembled
2532
bs_instruction:
31 halyavin 2533
	mov	[extended_code],al
157 heavyiron 2534
	mov	[base_code],0Fh
2535
	lods	byte [esi]
2536
	call	get_size_operator
2537
	cmp	al,10h
2538
	jne	invalid_operand
2539
	lods	byte [esi]
2540
	call	convert_register
2541
	mov	[postbyte_register],al
2542
	lods	byte [esi]
2543
	cmp	al,','
2544
	jne	invalid_operand
2545
	lods	byte [esi]
2546
	call	get_size_operator
2547
	cmp	al,10h
2548
	je	bs_reg_reg
2549
	cmp	al,'['
2550
	jne	invalid_argument
2551
	call	get_address
2552
	mov	al,[operand_size]
2553
	call	operand_autodetect
2554
	call	store_instruction
2555
	jmp	instruction_assembled
2556
      bs_reg_reg:
31 halyavin 2557
	lods	byte [esi]
157 heavyiron 2558
	call	convert_register
2559
	mov	bl,al
2560
	mov	al,ah
2561
	call	operand_autodetect
2562
	call	store_nomem_instruction
2563
	jmp	instruction_assembled
2564
imul_instruction:
31 halyavin 2565
	mov	[base_code],0F6h
157 heavyiron 2566
	mov	[postbyte_register],5
2567
	lods	byte [esi]
2568
	call	get_size_operator
2569
	cmp	al,10h
2570
	je	imul_reg
2571
	cmp	al,'['
2572
	jne	invalid_operand
2573
      imul_mem:
31 halyavin 2574
	call	get_address
157 heavyiron 2575
	mov	al,[operand_size]
2576
	cmp	al,1
2577
	je	imul_mem_8bit
2578
	jb	imul_mem_nosize
2579
	call	operand_autodetect
2580
	inc	[base_code]
2581
	call	store_instruction
2582
	jmp	instruction_assembled
2583
      imul_mem_nosize:
31 halyavin 2584
	cmp	[error_line],0
157 heavyiron 2585
	jne	imul_mem_8bit
2586
	mov	eax,[current_line]
2587
	mov	[error_line],eax
2588
	mov	[error],operand_size_not_specified
2589
      imul_mem_8bit:
31 halyavin 2590
	call	store_instruction
157 heavyiron 2591
	jmp	instruction_assembled
2592
      imul_reg:
31 halyavin 2593
	lods	byte [esi]
157 heavyiron 2594
	call	convert_register
2595
	cmp	byte [esi],','
2596
	je	imul_reg_
2597
	mov	bl,al
2598
	mov	al,ah
2599
	cmp	al,1
2600
	je	imul_reg_8bit
2601
	call	operand_autodetect
2602
	inc	[base_code]
2603
	call	store_nomem_instruction
2604
	jmp	instruction_assembled
2605
      imul_reg_8bit:
31 halyavin 2606
	call	store_nomem_instruction
157 heavyiron 2607
	jmp	instruction_assembled
2608
      imul_reg_:
31 halyavin 2609
	mov	[postbyte_register],al
157 heavyiron 2610
	inc	esi
2611
	cmp	byte [esi],'('
2612
	je	imul_reg_imm
2613
	cmp	byte [esi],11h
2614
	jne	imul_reg_noimm
2615
	cmp	byte [esi+2],'('
2616
	je	imul_reg_imm
2617
      imul_reg_noimm:
31 halyavin 2618
	lods	byte [esi]
157 heavyiron 2619
	call	get_size_operator
2620
	cmp	al,10h
2621
	je	imul_reg_reg
2622
	cmp	al,'['
2623
	jne	invalid_operand
2624
      imul_reg_mem:
31 halyavin 2625
	call	get_address
157 heavyiron 2626
	push	edx ebx ecx
174 heavyiron 2627
	cmp	byte [esi],','
157 heavyiron 2628
	je	imul_reg_mem_imm
2629
	mov	al,[operand_size]
2630
	call	operand_autodetect
2631
	pop	ecx ebx edx
174 heavyiron 2632
	mov	[base_code],0Fh
157 heavyiron 2633
	mov	[extended_code],0AFh
2634
	call	store_instruction
2635
	jmp	instruction_assembled
2636
      imul_reg_mem_imm:
31 halyavin 2637
	inc	esi
157 heavyiron 2638
	lods	byte [esi]
2639
	call	get_size_operator
2640
	cmp	al,'('
2641
	jne	invalid_operand
2642
	mov	al,[operand_size]
2643
	cmp	al,2
2644
	je	imul_reg_mem_imm_16bit
2645
	cmp	al,4
2646
	je	imul_reg_mem_imm_32bit
2647
	cmp	al,8
2648
	je	imul_reg_mem_imm_64bit
2649
	jmp	invalid_operand_size
2650
      imul_reg_mem_imm_16bit:
31 halyavin 2651
	call	operand_16bit
157 heavyiron 2652
	call	get_word_value
2653
	mov	word [value],ax
2654
	cmp	[value_type],0
2655
	jne	imul_reg_mem_imm_16bit_store
2656
	cmp	[size_declared],0
2657
	jne	imul_reg_mem_imm_16bit_store
2658
	cmp	ax,-80h
2659
	jl	imul_reg_mem_imm_16bit_store
2660
	cmp	ax,80h
2661
	jl	imul_reg_mem_imm_8bit_store
2662
      imul_reg_mem_imm_16bit_store:
31 halyavin 2663
	pop	ecx ebx edx
174 heavyiron 2664
	mov	[base_code],69h
157 heavyiron 2665
	call	store_instruction_with_imm16
2666
	jmp	instruction_assembled
2667
      imul_reg_mem_imm_32bit:
31 halyavin 2668
	call	operand_32bit
157 heavyiron 2669
	call	get_dword_value
2670
      imul_reg_mem_imm_32bit_ok:
31 halyavin 2671
	mov	dword [value],eax
157 heavyiron 2672
	cmp	[value_type],0
2673
	jne	imul_reg_mem_imm_32bit_store
2674
	cmp	[size_declared],0
2675
	jne	imul_reg_mem_imm_32bit_store
2676
	cmp	eax,-80h
2677
	jl	imul_reg_mem_imm_32bit_store
2678
	cmp	eax,80h
2679
	jl	imul_reg_mem_imm_8bit_store
2680
      imul_reg_mem_imm_32bit_store:
31 halyavin 2681
	pop	ecx ebx edx
174 heavyiron 2682
	mov	[base_code],69h
157 heavyiron 2683
	call	store_instruction_with_imm32
2684
	jmp	instruction_assembled
2685
      imul_reg_mem_imm_64bit:
31 halyavin 2686
	cmp	[size_declared],0
157 heavyiron 2687
	jne	long_immediate_not_encodable
2688
	call	operand_64bit
2689
	call	get_simm32
2690
	cmp	[value_type],4
2691
	jae	long_immediate_not_encodable
2692
	jmp	imul_reg_mem_imm_32bit_ok
2693
      imul_reg_mem_imm_8bit_store:
31 halyavin 2694
	pop	ecx ebx edx
174 heavyiron 2695
	mov	[base_code],6Bh
157 heavyiron 2696
	call	store_instruction_with_imm8
2697
	jmp	instruction_assembled
2698
      imul_reg_imm:
31 halyavin 2699
	mov	bl,[postbyte_register]
157 heavyiron 2700
	dec	esi
2701
	jmp	imul_reg_reg_imm
2702
      imul_reg_reg:
31 halyavin 2703
	lods	byte [esi]
157 heavyiron 2704
	call	convert_register
2705
	mov	bl,al
2706
	cmp	byte [esi],','
2707
	je	imul_reg_reg_imm
2708
	mov	al,ah
2709
	call	operand_autodetect
2710
	mov	[base_code],0Fh
2711
	mov	[extended_code],0AFh
2712
	call	store_nomem_instruction
2713
	jmp	instruction_assembled
2714
      imul_reg_reg_imm:
31 halyavin 2715
	inc	esi
157 heavyiron 2716
	lods	byte [esi]
2717
	call	get_size_operator
2718
	cmp	al,'('
2719
	jne	invalid_operand
2720
	mov	al,[operand_size]
2721
	cmp	al,2
2722
	je	imul_reg_reg_imm_16bit
2723
	cmp	al,4
2724
	je	imul_reg_reg_imm_32bit
2725
	cmp	al,8
2726
	je	imul_reg_reg_imm_64bit
2727
	jmp	invalid_operand_size
2728
      imul_reg_reg_imm_16bit:
31 halyavin 2729
	call	operand_16bit
157 heavyiron 2730
	push	ebx
2731
	call	get_word_value
2732
	pop	ebx
2733
	mov	dx,ax
2734
	cmp	[value_type],0
2735
	jne	imul_reg_reg_imm_16bit_store
2736
	cmp	[size_declared],0
2737
	jne	imul_reg_reg_imm_16bit_store
2738
	cmp	ax,-80h
2739
	jl	imul_reg_reg_imm_16bit_store
2740
	cmp	ax,80h
2741
	jl	imul_reg_reg_imm_8bit_store
2742
      imul_reg_reg_imm_16bit_store:
31 halyavin 2743
	mov	[base_code],69h
157 heavyiron 2744
	call	store_nomem_instruction
2745
	mov	ax,dx
2746
	call	mark_relocation
2747
	stos	word [edi]
2748
	jmp	instruction_assembled
2749
      imul_reg_reg_imm_32bit:
31 halyavin 2750
	call	operand_32bit
157 heavyiron 2751
	push	ebx
2752
	call	get_dword_value
2753
      imul_reg_reg_imm_32bit_ok:
31 halyavin 2754
	pop	ebx
157 heavyiron 2755
	mov	edx,eax
2756
	cmp	[value_type],0
2757
	jne	imul_reg_reg_imm_32bit_store
2758
	cmp	[size_declared],0
2759
	jne	imul_reg_reg_imm_32bit_store
2760
	cmp	eax,-80h
2761
	jl	imul_reg_reg_imm_32bit_store
2762
	cmp	eax,80h
2763
	jl	imul_reg_reg_imm_8bit_store
2764
      imul_reg_reg_imm_32bit_store:
31 halyavin 2765
	mov	[base_code],69h
157 heavyiron 2766
	call	store_nomem_instruction
2767
	mov	eax,edx
2768
	call	mark_relocation
2769
	stos	dword [edi]
2770
	jmp	instruction_assembled
2771
      imul_reg_reg_imm_64bit:
31 halyavin 2772
	cmp	[size_declared],0
157 heavyiron 2773
	jne	long_immediate_not_encodable
2774
	call	operand_64bit
2775
	push	ebx
2776
	call	get_simm32
2777
	cmp	[value_type],4
2778
	jae	long_immediate_not_encodable
2779
	jmp	imul_reg_reg_imm_32bit_ok
2780
      imul_reg_reg_imm_8bit_store:
31 halyavin 2781
	mov	[base_code],6Bh
157 heavyiron 2782
	call	store_nomem_instruction
2783
	mov	al,dl
2784
	stos	byte [edi]
2785
	jmp	instruction_assembled
2786
in_instruction:
31 halyavin 2787
	lods	byte [esi]
157 heavyiron 2788
	call	get_size_operator
2789
	cmp	al,10h
2790
	jne	invalid_operand
2791
	lods	byte [esi]
2792
	call	convert_register
2793
	or	al,al
2794
	jnz	invalid_operand
2795
	lods	byte [esi]
2796
	cmp	al,','
2797
	jne	invalid_operand
2798
	mov	al,ah
2799
	push	eax
2800
	mov	[operand_size],0
2801
	lods	byte [esi]
2802
	call	get_size_operator
2803
	cmp	al,'('
2804
	je	in_imm
2805
	cmp	al,10h
2806
	je	in_reg
2807
	jmp	invalid_operand
2808
      in_reg:
31 halyavin 2809
	lods	byte [esi]
157 heavyiron 2810
	cmp	al,22h
2811
	jne	invalid_operand
2812
	pop	eax
2813
	cmp	al,1
2814
	je	in_al_dx
2815
	cmp	al,2
2816
	je	in_ax_dx
2817
	cmp	al,4
2818
	je	in_eax_dx
2819
	jmp	invalid_operand_size
2820
      in_al_dx:
31 halyavin 2821
	mov	al,0ECh
157 heavyiron 2822
	stos	byte [edi]
2823
	jmp	instruction_assembled
2824
      in_ax_dx:
31 halyavin 2825
	call	operand_16bit
157 heavyiron 2826
	mov	[base_code],0EDh
2827
	call	store_instruction_code
2828
	jmp	instruction_assembled
2829
      in_eax_dx:
31 halyavin 2830
	call	operand_32bit
157 heavyiron 2831
	mov	[base_code],0EDh
2832
	call	store_instruction_code
2833
	jmp	instruction_assembled
2834
      in_imm:
31 halyavin 2835
	mov	al,[operand_size]
157 heavyiron 2836
	or	al,al
2837
	jz	in_imm_size_ok
2838
	cmp	al,1
2839
	jne	invalid_operand_size
2840
      in_imm_size_ok:
31 halyavin 2841
	call	get_byte_value
157 heavyiron 2842
	mov	dl,al
2843
	pop	eax
2844
	cmp	al,1
2845
	je	in_al_imm
2846
	cmp	al,2
2847
	je	in_ax_imm
2848
	cmp	al,4
2849
	je	in_eax_imm
2850
	jmp	invalid_operand_size
2851
      in_al_imm:
31 halyavin 2852
	mov	al,0E4h
157 heavyiron 2853
	stos	byte [edi]
2854
	mov	al,dl
2855
	stos	byte [edi]
2856
	jmp	instruction_assembled
2857
      in_ax_imm:
31 halyavin 2858
	call	operand_16bit
157 heavyiron 2859
	mov	[base_code],0E5h
2860
	call	store_instruction_code
2861
	mov	al,dl
2862
	stos	byte [edi]
2863
	jmp	instruction_assembled
2864
      in_eax_imm:
31 halyavin 2865
	call	operand_32bit
157 heavyiron 2866
	mov	[base_code],0E5h
2867
	call	store_instruction_code
2868
	mov	al,dl
2869
	stos	byte [edi]
2870
	jmp	instruction_assembled
2871
out_instruction:
31 halyavin 2872
	lods	byte [esi]
157 heavyiron 2873
	call	get_size_operator
2874
	cmp	al,'('
2875
	je	out_imm
2876
	cmp	al,10h
2877
	jne	invalid_operand
2878
	lods	byte [esi]
2879
	cmp	al,22h
2880
	jne	invalid_operand
2881
	lods	byte [esi]
2882
	cmp	al,','
2883
	jne	invalid_operand
2884
	mov	[operand_size],0
2885
	lods	byte [esi]
2886
	call	get_size_operator
2887
	cmp	al,10h
2888
	jne	invalid_operand
2889
	lods	byte [esi]
2890
	call	convert_register
2891
	or	al,al
2892
	jnz	invalid_operand
2893
	mov	al,ah
2894
	cmp	al,1
2895
	je	out_dx_al
2896
	cmp	al,2
2897
	je	out_dx_ax
2898
	cmp	al,4
2899
	je	out_dx_eax
2900
	jmp	invalid_operand_size
2901
      out_dx_al:
31 halyavin 2902
	mov	al,0EEh
157 heavyiron 2903
	stos	byte [edi]
2904
	jmp	instruction_assembled
2905
      out_dx_ax:
31 halyavin 2906
	call	operand_16bit
157 heavyiron 2907
	mov	[base_code],0EFh
2908
	call	store_instruction_code
2909
	jmp	instruction_assembled
2910
      out_dx_eax:
31 halyavin 2911
	call	operand_32bit
157 heavyiron 2912
	mov	[base_code],0EFh
2913
	call	store_instruction_code
2914
	jmp	instruction_assembled
2915
      out_imm:
31 halyavin 2916
	mov	al,[operand_size]
157 heavyiron 2917
	or	al,al
2918
	jz	out_imm_size_ok
2919
	cmp	al,1
2920
	jne	invalid_operand_size
2921
      out_imm_size_ok:
31 halyavin 2922
	call	get_byte_value
157 heavyiron 2923
	mov	dl,al
2924
	lods	byte [esi]
2925
	cmp	al,','
2926
	jne	invalid_operand
2927
	mov	[operand_size],0
2928
	lods	byte [esi]
2929
	call	get_size_operator
2930
	cmp	al,10h
2931
	jne	invalid_operand
2932
	lods	byte [esi]
2933
	call	convert_register
2934
	or	al,al
2935
	jnz	invalid_operand
2936
	mov	al,ah
2937
	cmp	al,1
2938
	je	out_imm_al
2939
	cmp	al,2
2940
	je	out_imm_ax
2941
	cmp	al,4
2942
	je	out_imm_eax
2943
	jmp	invalid_operand_size
2944
      out_imm_al:
31 halyavin 2945
	mov	al,0E6h
157 heavyiron 2946
	stos	byte [edi]
2947
	mov	al,dl
2948
	stos	byte [edi]
2949
	jmp	instruction_assembled
2950
      out_imm_ax:
31 halyavin 2951
	call	operand_16bit
157 heavyiron 2952
	mov	[base_code],0E7h
2953
	call	store_instruction_code
2954
	mov	al,dl
2955
	stos	byte [edi]
2956
	jmp	instruction_assembled
2957
      out_imm_eax:
31 halyavin 2958
	call	operand_32bit
157 heavyiron 2959
	mov	[base_code],0E7h
2960
	call	store_instruction_code
2961
	mov	al,dl
2962
	stos	byte [edi]
2963
	jmp	instruction_assembled
2964
31 halyavin 2965
 
2966
	mov	[postbyte_register],10b
157 heavyiron 2967
	mov	[base_code],0E8h
2968
	mov	[extended_code],9Ah
2969
	jmp	process_jmp
2970
jmp_instruction:
31 halyavin 2971
	mov	[postbyte_register],100b
157 heavyiron 2972
	mov	[base_code],0E9h
2973
	mov	[extended_code],0EAh
2974
      process_jmp:
31 halyavin 2975
	lods	byte [esi]
157 heavyiron 2976
	call	get_jump_operator
2977
	call	get_size_operator
2978
	cmp	al,'('
2979
	je	jmp_imm
2980
	mov	[base_code],0FFh
2981
	cmp	al,10h
2982
	je	jmp_reg
2983
	cmp	al,'['
2984
	jne	invalid_operand
2985
      jmp_mem:
31 halyavin 2986
	cmp	[jump_type],1
157 heavyiron 2987
	je	illegal_instruction
2988
	call	get_address
2989
	mov	edx,eax
2990
	mov	al,[operand_size]
2991
	or	al,al
2992
	jz	jmp_mem_size_not_specified
2993
	cmp	al,2
2994
	je	jmp_mem_16bit
2995
	cmp	al,4
2996
	je	jmp_mem_32bit
2997
	cmp	al,6
2998
	je	jmp_mem_48bit
2999
	cmp	al,8
3000
	je	jmp_mem_64bit
3001
	cmp	al,10
3002
	je	jmp_mem_80bit
3003
	jmp	invalid_operand_size
3004
      jmp_mem_size_not_specified:
31 halyavin 3005
	cmp	[jump_type],3
157 heavyiron 3006
	je	jmp_mem_far
3007
	cmp	[jump_type],2
3008
	je	jmp_mem_near
3009
	cmp	[error_line],0
3010
	jne	jmp_mem_near
3011
	mov	eax,[current_line]
3012
	mov	[error_line],eax
3013
	mov	[error],operand_size_not_specified
3014
      jmp_mem_near:
31 halyavin 3015
	cmp	[code_type],16
157 heavyiron 3016
	je	jmp_mem_16bit
3017
	cmp	[code_type],32
3018
	je	jmp_mem_near_32bit
3019
      jmp_mem_64bit:
31 halyavin 3020
	cmp	[jump_type],3
157 heavyiron 3021
	je	invalid_operand_size
3022
	cmp	[code_type],64
3023
	jne	illegal_instruction
3024
	call	store_instruction
3025
	jmp	instruction_assembled
3026
      jmp_mem_far:
31 halyavin 3027
	cmp	[code_type],16
157 heavyiron 3028
	je	jmp_mem_far_32bit
3029
      jmp_mem_48bit:
31 halyavin 3030
	call	operand_32bit
157 heavyiron 3031
      jmp_mem_far_store:
31 halyavin 3032
	cmp	[jump_type],2
157 heavyiron 3033
	je	invalid_operand_size
3034
	inc	[postbyte_register]
3035
	call	store_instruction
3036
	jmp	instruction_assembled
3037
      jmp_mem_80bit:
31 halyavin 3038
	call	operand_64bit
157 heavyiron 3039
	jmp	jmp_mem_far_store
3040
      jmp_mem_far_32bit:
31 halyavin 3041
	call	operand_16bit
157 heavyiron 3042
	jmp	jmp_mem_far_store
3043
      jmp_mem_32bit:
31 halyavin 3044
	cmp	[jump_type],3
157 heavyiron 3045
	je	jmp_mem_far_32bit
3046
	cmp	[jump_type],2
3047
	je	jmp_mem_near_32bit
3048
	cmp	[code_type],16
3049
	je	jmp_mem_far_32bit
3050
      jmp_mem_near_32bit:
31 halyavin 3051
	cmp	[code_type],64
157 heavyiron 3052
	je	illegal_instruction
3053
	call	operand_32bit
3054
	call	store_instruction
3055
	jmp	instruction_assembled
3056
      jmp_mem_16bit:
31 halyavin 3057
	cmp	[jump_type],3
157 heavyiron 3058
	je	invalid_operand_size
3059
	call	operand_16bit
3060
	call	store_instruction
3061
	jmp	instruction_assembled
3062
      jmp_reg:
31 halyavin 3063
	test	[jump_type],1
157 heavyiron 3064
	jnz	invalid_operand
3065
	lods	byte [esi]
3066
	call	convert_register
3067
	mov	bl,al
3068
	mov	al,ah
3069
	cmp	al,2
3070
	je	jmp_reg_16bit
3071
	cmp	al,4
3072
	je	jmp_reg_32bit
3073
	cmp	al,8
3074
	jne	invalid_operand_size
3075
      jmp_reg_64bit:
31 halyavin 3076
	cmp	[code_type],64
157 heavyiron 3077
	jne	illegal_instruction
3078
	call	store_nomem_instruction
3079
	jmp	instruction_assembled
3080
      jmp_reg_32bit:
31 halyavin 3081
	cmp	[code_type],64
157 heavyiron 3082
	je	illegal_instruction
3083
	call	store_nomem_instruction
3084
	jmp	instruction_assembled
3085
      jmp_reg_16bit:
31 halyavin 3086
	call	operand_16bit
157 heavyiron 3087
	call	store_nomem_instruction
3088
	jmp	instruction_assembled
3089
      jmp_imm:
31 halyavin 3090
	cmp	byte [esi],'.'
157 heavyiron 3091
	je	invalid_value
3092
	mov	ebx,esi
3093
	dec	esi
3094
	call	skip_symbol
3095
	xchg	esi,ebx
3096
	cmp	byte [ebx],':'
3097
	je	jmp_far
3098
	cmp	[jump_type],3
3099
	je	invalid_operand
3100
      jmp_near:
109 heavyiron 3101
	mov	al,[operand_size]
157 heavyiron 3102
	cmp	al,2
3103
	je	jmp_imm_16bit
3104
	cmp	al,4
3105
	je	jmp_imm_32bit
3106
	cmp	al,8
3107
	je	jmp_imm_64bit
3108
	or	al,al
3109
	jnz	invalid_operand_size
3110
	cmp	[code_type],16
3111
	je	jmp_imm_16bit
3112
	cmp	[code_type],64
3113
	je	jmp_imm_64bit
3114
      jmp_imm_32bit:
109 heavyiron 3115
	cmp	[code_type],64
157 heavyiron 3116
	je	invalid_operand_size
3117
	call	get_dword_value
3118
	cmp	[code_type],16
3119
	jne	jmp_imm_32bit_prefix_ok
3120
	mov	byte [edi],66h
3121
	inc	edi
3122
      jmp_imm_32bit_prefix_ok:
109 heavyiron 3123
	call	calculate_jump_offset
157 heavyiron 3124
	cdq
3125
	call	check_for_short_jump
3126
	jc	jmp_short
3127
      jmp_imm_32bit_store:
109 heavyiron 3128
	mov	edx,eax
157 heavyiron 3129
	sub	edx,3
3130
	mov	al,[base_code]
3131
	stos	byte [edi]
3132
	mov	eax,edx
3133
	call	mark_relocation
3134
	stos	dword [edi]
3135
	jmp	instruction_assembled
3136
      jmp_imm_64bit:
109 heavyiron 3137
	cmp	[code_type],64
157 heavyiron 3138
	jne	invalid_operand_size
3139
	call	get_qword_value
3140
	call	calculate_jump_offset
3141
	mov	ecx,edx
3142
	cdq
3143
	cmp	edx,ecx
3144
	jne	value_out_of_range
3145
	call	check_for_short_jump
3146
	jnc	jmp_imm_32bit_store
3147
      jmp_short:
109 heavyiron 3148
	mov	ah,al
157 heavyiron 3149
	mov	al,0EBh
3150
	stos	word [edi]
3151
	jmp	instruction_assembled
3152
      jmp_imm_16bit:
109 heavyiron 3153
	call	get_word_value
157 heavyiron 3154
	cmp	[code_type],16
3155
	je	jmp_imm_16bit_prefix_ok
3156
	mov	byte [edi],66h
3157
	inc	edi
3158
      jmp_imm_16bit_prefix_ok:
109 heavyiron 3159
	call	calculate_jump_offset
157 heavyiron 3160
	cwde
3161
	cdq
3162
	call	check_for_short_jump
3163
	jc	jmp_short
3164
	cmp	[value_type],0
3165
	jne	invalid_use_of_symbol
3166
	mov	edx,eax
3167
	dec	edx
3168
	mov	al,[base_code]
3169
	stos	byte [edi]
3170
	mov	eax,edx
3171
	stos	word [edi]
3172
	jmp	instruction_assembled
3173
      calculate_jump_offset:
109 heavyiron 3174
	add	edi,2
174 heavyiron 3175
	call	calculate_relative_offset
3176
	sub	edi,2
3177
	ret
157 heavyiron 3178
      check_for_short_jump:
109 heavyiron 3179
	cmp	[jump_type],1
157 heavyiron 3180
	je	forced_short
3181
	ja	no_short_jump
3182
	cmp	[base_code],0E8h
3183
	je	no_short_jump
3184
	cmp	[value_type],0
3185
	jne	no_short_jump
3186
	cmp	eax,80h
3187
	jb	short_jump
3188
	cmp	eax,-80h
3189
	jae	short_jump
3190
      no_short_jump:
109 heavyiron 3191
	clc
157 heavyiron 3192
	ret
3193
      forced_short:
109 heavyiron 3194
	cmp	[base_code],0E8h
157 heavyiron 3195
	je	illegal_instruction
3196
	cmp	[next_pass_needed],0
3197
	jne	jmp_short_value_type_ok
3198
	cmp	[value_type],0
3199
	jne	invalid_use_of_symbol
3200
      jmp_short_value_type_ok:
109 heavyiron 3201
	cmp	eax,-80h
157 heavyiron 3202
	jae	short_jump
3203
	cmp	eax,80h
3204
	jae	jump_out_of_range
3205
      short_jump:
109 heavyiron 3206
	stc
157 heavyiron 3207
	ret
3208
      jump_out_of_range:
109 heavyiron 3209
	cmp	[error_line],0
157 heavyiron 3210
	jne	instruction_assembled
3211
	mov	eax,[current_line]
3212
	mov	[error_line],eax
3213
	mov	[error],relative_jump_out_of_range
3214
	jmp	instruction_assembled
3215
      jmp_far:
31 halyavin 3216
	cmp	[jump_type],2
157 heavyiron 3217
	je	invalid_operand
3218
	cmp	[code_type],64
3219
	je	illegal_instruction
3220
	mov	al,[extended_code]
3221
	mov	[base_code],al
3222
	call	get_word_value
3223
	push	eax
3224
	inc	esi
3225
	lods	byte [esi]
3226
	cmp	al,'('
3227
	jne	invalid_operand
3228
	mov	al,[value_type]
3229
	push	eax [symbol_identifier]
3230
	cmp	byte [esi],'.'
3231
	je	invalid_value
3232
	mov	al,[operand_size]
3233
	cmp	al,4
3234
	je	jmp_far_16bit
3235
	cmp	al,6
3236
	je	jmp_far_32bit
3237
	or	al,al
3238
	jnz	invalid_operand_size
3239
	cmp	[code_type],16
3240
	jne	jmp_far_32bit
3241
      jmp_far_16bit:
31 halyavin 3242
	call	get_word_value
157 heavyiron 3243
	mov	ebx,eax
3244
	call	operand_16bit
3245
	call	store_instruction_code
3246
	mov	ax,bx
3247
	call	mark_relocation
3248
	stos	word [edi]
3249
      jmp_far_segment:
31 halyavin 3250
	pop	[symbol_identifier] eax
157 heavyiron 3251
	mov	[value_type],al
3252
	pop	eax
3253
	call	mark_relocation
3254
	stos	word [edi]
3255
	jmp	instruction_assembled
3256
      jmp_far_32bit:
31 halyavin 3257
	call	get_dword_value
157 heavyiron 3258
	mov	ebx,eax
3259
	call	operand_32bit
3260
	call	store_instruction_code
3261
	mov	eax,ebx
3262
	call	mark_relocation
3263
	stos	dword [edi]
3264
	jmp	jmp_far_segment
3265
conditional_jump:
109 heavyiron 3266
	mov	[base_code],al
157 heavyiron 3267
	lods	byte [esi]
3268
	call	get_jump_operator
3269
	cmp	[jump_type],3
3270
	je	invalid_operand
3271
	call	get_size_operator
3272
	cmp	al,'('
3273
	jne	invalid_operand
3274
	cmp	byte [esi],'.'
3275
	je	invalid_value
3276
	mov	al,[operand_size]
3277
	cmp	al,2
3278
	je	conditional_jump_16bit
3279
	cmp	al,4
3280
	je	conditional_jump_32bit
3281
	cmp	al,8
3282
	je	conditional_jump_64bit
3283
	or	al,al
3284
	jnz	invalid_operand_size
3285
	cmp	[code_type],16
3286
	je	conditional_jump_16bit
3287
	cmp	[code_type],64
3288
	je	conditional_jump_64bit
3289
      conditional_jump_32bit:
109 heavyiron 3290
	cmp	[code_type],64
157 heavyiron 3291
	je	invalid_operand_size
3292
	call	get_dword_value
3293
	cmp	[code_type],16
3294
	jne	conditional_jump_32bit_prefix_ok
3295
	mov	byte [edi],66h
3296
	inc	edi
3297
      conditional_jump_32bit_prefix_ok:
109 heavyiron 3298
	call	calculate_jump_offset
157 heavyiron 3299
	cdq
3300
	call	check_for_short_jump
3301
	jc	conditional_jump_short
3302
      conditional_jump_32bit_store:
109 heavyiron 3303
	mov	edx,eax
157 heavyiron 3304
	sub	edx,4
3305
	mov	ah,[base_code]
3306
	add	ah,10h
3307
	mov	al,0Fh
3308
	stos	word [edi]
3309
	mov	eax,edx
3310
	call	mark_relocation
3311
	stos	dword [edi]
3312
	jmp	instruction_assembled
3313
      conditional_jump_64bit:
109 heavyiron 3314
	cmp	[code_type],64
157 heavyiron 3315
	jne	invalid_operand_size
3316
	call	get_qword_value
3317
	call	calculate_jump_offset
3318
	mov	ecx,edx
3319
	cdq
3320
	cmp	edx,ecx
3321
	jne	value_out_of_range
3322
	call	check_for_short_jump
3323
	jnc	conditional_jump_32bit_store
3324
      conditional_jump_short:
109 heavyiron 3325
	mov	ah,al
157 heavyiron 3326
	mov	al,[base_code]
3327
	stos	word [edi]
3328
	jmp	instruction_assembled
3329
      conditional_jump_16bit:
109 heavyiron 3330
	call	get_word_value
157 heavyiron 3331
	cmp	[code_type],16
3332
	je	conditional_jump_16bit_prefix_ok
3333
	mov	byte [edi],66h
3334
	inc	edi
3335
      conditional_jump_16bit_prefix_ok:
109 heavyiron 3336
	call	calculate_jump_offset
157 heavyiron 3337
	cwde
3338
	cdq
3339
	call	check_for_short_jump
3340
	jc	conditional_jump_short
3341
	cmp	[value_type],0
3342
	jne	invalid_use_of_symbol
3343
	mov	edx,eax
3344
	sub	edx,2
3345
	mov	ah,[base_code]
3346
	add	ah,10h
3347
	mov	al,0Fh
3348
	stos	word [edi]
3349
	mov	eax,edx
3350
	stos	word [edi]
3351
	jmp	instruction_assembled
3352
loop_instruction_16bit:
109 heavyiron 3353
	cmp	[code_type],64
157 heavyiron 3354
	je	illegal_instruction
3355
	mov	dl,al
3356
	call	address_16bit_prefix
3357
	mov	al,dl
3358
	jmp	loop_instruction
3359
loop_instruction_32bit:
109 heavyiron 3360
	mov	dl,al
157 heavyiron 3361
	call	address_32bit_prefix
3362
	mov	al,dl
3363
	jmp	loop_instruction
3364
loop_instruction_64bit:
109 heavyiron 3365
	cmp	[code_type],64
157 heavyiron 3366
	jne	illegal_instruction
3367
loop_instruction:
109 heavyiron 3368
	mov	[base_code],al
157 heavyiron 3369
	lods	byte [esi]
3370
	call	get_jump_operator
3371
	cmp	[jump_type],1
3372
	ja	invalid_operand
3373
	call	get_size_operator
3374
	cmp	al,'('
3375
	jne	invalid_operand
3376
	cmp	byte [esi],'.'
3377
	je	invalid_value
3378
	mov	al,[operand_size]
3379
	cmp	al,2
3380
	je	loop_jump_16bit
3381
	cmp	al,4
3382
	je	loop_jump_32bit
3383
	cmp	al,8
3384
	je	loop_jump_64bit
3385
	or	al,al
3386
	jnz	invalid_operand_size
3387
	cmp	[code_type],16
3388
	je	loop_jump_16bit
3389
	cmp	[code_type],64
3390
	je	loop_jump_64bit
3391
      loop_jump_32bit:
109 heavyiron 3392
	cmp	[code_type],64
157 heavyiron 3393
	je	invalid_operand_size
3394
	call	get_dword_value
3395
	cmp	[code_type],16
3396
	jne	loop_jump_32bit_prefix_ok
3397
	mov	byte [edi],66h
3398
	inc	edi
3399
      loop_jump_32bit_prefix_ok:
109 heavyiron 3400
	call	calculate_jump_offset
157 heavyiron 3401
	cdq
3402
      make_loop_jump:
109 heavyiron 3403
	call	check_for_short_jump
157 heavyiron 3404
	jc	conditional_jump_short
3405
	jmp	jump_out_of_range
3406
      loop_jump_64bit:
109 heavyiron 3407
	cmp	[code_type],64
157 heavyiron 3408
	jne	invalid_operand_size
3409
	call	get_qword_value
3410
	call	calculate_jump_offset
3411
	mov	ecx,edx
3412
	cdq
3413
	cmp	edx,ecx
3414
	jne	value_out_of_range
3415
	jmp	make_loop_jump
3416
      loop_jump_16bit:
109 heavyiron 3417
	call	get_word_value
157 heavyiron 3418
	cmp	[code_type],16
3419
	je	loop_jump_16bit_prefix_ok
3420
	mov	byte [edi],66h
3421
	inc	edi
3422
      loop_jump_16bit_prefix_ok:
109 heavyiron 3423
	call	calculate_jump_offset
157 heavyiron 3424
	cwde
3425
	cdq
3426
	jmp	make_loop_jump
3427
31 halyavin 3428
 
3429
	lods	byte [esi]
157 heavyiron 3430
	call	get_size_operator
3431
	cmp	al,'['
3432
	jne	invalid_operand
3433
	call	get_address
3434
	or	eax,eax
3435
	jnz	invalid_address
3436
	or	bl,ch
3437
	jnz	invalid_address
3438
	cmp	[segment_register],1
3439
	ja	invalid_address
3440
	push	ebx
3441
	lods	byte [esi]
3442
	cmp	al,','
3443
	jne	invalid_operand
3444
	lods	byte [esi]
3445
	call	get_size_operator
3446
	cmp	al,'['
3447
	jne	invalid_operand
3448
	call	get_address
3449
	pop	edx
3450
	or	eax,eax
3451
	jnz	invalid_address
3452
	or	bl,ch
3453
	jnz	invalid_address
3454
	mov	al,dh
3455
	mov	ah,bh
3456
	shr	al,4
3457
	shr	ah,4
3458
	cmp	al,ah
3459
	jne	address_sizes_do_not_agree
3460
	and	bh,111b
3461
	and	dh,111b
3462
	cmp	bh,6
3463
	jne	invalid_address
3464
	cmp	dh,7
3465
	jne	invalid_address
3466
	cmp	al,2
3467
	je	movs_address_16bit
3468
	cmp	al,4
3469
	je	movs_address_32bit
3470
	cmp	[code_type],64
3471
	jne	invalid_address_size
3472
	jmp	movs_store
3473
      movs_address_32bit:
31 halyavin 3474
	call	address_32bit_prefix
157 heavyiron 3475
	jmp	movs_store
3476
      movs_address_16bit:
31 halyavin 3477
	cmp	[code_type],64
157 heavyiron 3478
	je	invalid_address_size
3479
	call	address_16bit_prefix
3480
      movs_store:
31 halyavin 3481
	cmp	[segment_register],4
157 heavyiron 3482
	je	movs_segment_ok
3483
	call	store_segment_prefix
3484
      movs_segment_ok:
31 halyavin 3485
	mov	al,0A4h
157 heavyiron 3486
	mov	bl,[operand_size]
3487
	cmp	bl,1
3488
	je	simple_instruction
3489
	inc	al
3490
	cmp	bl,2
3491
	je	simple_instruction_16bit
3492
	cmp	bl,4
3493
	je	simple_instruction_32bit
3494
	cmp	bl,8
3495
	je	simple_instruction_64bit
3496
	or	bl,bl
3497
	jz	operand_size_not_specified
3498
	jmp	invalid_operand_size
3499
lods_instruction:
31 halyavin 3500
	lods	byte [esi]
157 heavyiron 3501
	call	get_size_operator
3502
	cmp	al,'['
3503
	jne	invalid_operand
3504
	call	get_address
3505
	or	eax,eax
3506
	jnz	invalid_address
3507
	or	bl,ch
3508
	jnz	invalid_address
3509
	cmp	bh,26h
3510
	je	lods_address_16bit
3511
	cmp	bh,46h
3512
	je	lods_address_32bit
3513
	cmp	bh,86h
3514
	jne	invalid_address
3515
	cmp	[code_type],64
3516
	jne	invalid_address_size
3517
	jmp	lods_store
3518
      lods_address_32bit:
31 halyavin 3519
	call	address_32bit_prefix
157 heavyiron 3520
	jmp	lods_store
3521
      lods_address_16bit:
31 halyavin 3522
	cmp	[code_type],64
157 heavyiron 3523
	je	invalid_address_size
3524
	call	address_16bit_prefix
3525
      lods_store:
31 halyavin 3526
	cmp	[segment_register],4
157 heavyiron 3527
	je	lods_segment_ok
3528
	call	store_segment_prefix
3529
      lods_segment_ok:
31 halyavin 3530
	mov	al,0ACh
157 heavyiron 3531
	mov	bl,[operand_size]
3532
	cmp	bl,1
3533
	je	simple_instruction
3534
	inc	al
3535
	cmp	bl,2
3536
	je	simple_instruction_16bit
3537
	cmp	bl,4
3538
	je	simple_instruction_32bit
3539
	cmp	bl,8
3540
	je	simple_instruction_64bit
3541
	or	bl,bl
3542
	jz	operand_size_not_specified
3543
	jmp	invalid_operand_size
3544
stos_instruction:
31 halyavin 3545
	mov	[base_code],al
157 heavyiron 3546
	lods	byte [esi]
3547
	call	get_size_operator
3548
	cmp	al,'['
3549
	jne	invalid_operand
3550
	call	get_address
3551
	or	eax,eax
3552
	jnz	invalid_address
3553
	or	bl,ch
3554
	jnz	invalid_address
3555
	cmp	bh,27h
3556
	je	stos_address_16bit
3557
	cmp	bh,47h
3558
	je	stos_address_32bit
3559
	cmp	bh,87h
3560
	jne	invalid_address
3561
	cmp	[code_type],64
3562
	jne	invalid_address_size
3563
	jmp	stos_store
3564
      stos_address_32bit:
31 halyavin 3565
	call	address_32bit_prefix
157 heavyiron 3566
	jmp	stos_store
3567
      stos_address_16bit:
31 halyavin 3568
	cmp	[code_type],64
157 heavyiron 3569
	je	invalid_address_size
3570
	call	address_16bit_prefix
3571
      stos_store:
31 halyavin 3572
	cmp	[segment_register],1
157 heavyiron 3573
	ja	invalid_address
3574
	mov	al,[base_code]
3575
	mov	bl,[operand_size]
3576
	cmp	bl,1
3577
	je	simple_instruction
3578
	inc	al
3579
	cmp	bl,2
3580
	je	simple_instruction_16bit
3581
	cmp	bl,4
3582
	je	simple_instruction_32bit
3583
	cmp	bl,8
3584
	je	simple_instruction_64bit
3585
	or	bl,bl
3586
	jz	operand_size_not_specified
3587
	jmp	invalid_operand_size
3588
cmps_instruction:
31 halyavin 3589
	lods	byte [esi]
157 heavyiron 3590
	call	get_size_operator
3591
	cmp	al,'['
3592
	jne	invalid_operand
3593
	call	get_address
3594
	or	eax,eax
3595
	jnz	invalid_address
3596
	or	bl,ch
3597
	jnz	invalid_address
3598
	mov	al,[segment_register]
3599
	push	eax ebx
174 heavyiron 3600
	lods	byte [esi]
157 heavyiron 3601
	cmp	al,','
3602
	jne	invalid_operand
3603
	lods	byte [esi]
3604
	call	get_size_operator
3605
	cmp	al,'['
3606
	jne	invalid_operand
3607
	call	get_address
3608
	or	eax,eax
3609
	jnz	invalid_address
3610
	or	bl,ch
3611
	jnz	invalid_address
3612
	pop	edx eax
174 heavyiron 3613
	cmp	[segment_register],1
157 heavyiron 3614
	ja	invalid_address
3615
	mov	[segment_register],al
3616
	mov	al,dh
3617
	mov	ah,bh
3618
	shr	al,4
3619
	shr	ah,4
3620
	cmp	al,ah
3621
	jne	address_sizes_do_not_agree
3622
	and	bh,111b
3623
	and	dh,111b
3624
	cmp	bh,7
3625
	jne	invalid_address
3626
	cmp	dh,6
3627
	jne	invalid_address
3628
	cmp	al,2
3629
	je	cmps_address_16bit
3630
	cmp	al,4
3631
	je	cmps_address_32bit
3632
	cmp	[code_type],64
3633
	jne	invalid_address_size
3634
	jmp	cmps_store
3635
      cmps_address_32bit:
31 halyavin 3636
	call	address_32bit_prefix
157 heavyiron 3637
	jmp	cmps_store
3638
      cmps_address_16bit:
31 halyavin 3639
	cmp	[code_type],64
157 heavyiron 3640
	je	invalid_address_size
3641
	call	address_16bit_prefix
3642
      cmps_store:
31 halyavin 3643
	cmp	[segment_register],4
157 heavyiron 3644
	je	cmps_segment_ok
3645
	call	store_segment_prefix
3646
      cmps_segment_ok:
31 halyavin 3647
	mov	al,0A6h
157 heavyiron 3648
	mov	bl,[operand_size]
3649
	cmp	bl,1
3650
	je	simple_instruction
3651
	inc	al
3652
	cmp	bl,2
3653
	je	simple_instruction_16bit
3654
	cmp	bl,4
3655
	je	simple_instruction_32bit
3656
	cmp	bl,8
3657
	je	simple_instruction_64bit
3658
	or	bl,bl
3659
	jz	operand_size_not_specified
3660
	jmp	invalid_operand_size
3661
ins_instruction:
31 halyavin 3662
	lods	byte [esi]
157 heavyiron 3663
	call	get_size_operator
3664
	cmp	al,'['
3665
	jne	invalid_operand
3666
	call	get_address
3667
	or	eax,eax
3668
	jnz	invalid_address
3669
	or	bl,ch
3670
	jnz	invalid_address
3671
	cmp	bh,27h
3672
	je	ins_address_16bit
3673
	cmp	bh,47h
3674
	je	ins_address_32bit
3675
	cmp	bh,87h
3676
	jne	invalid_address
3677
	cmp	[code_type],64
3678
	jne	invalid_address_size
3679
	jmp	ins_store
3680
      ins_address_32bit:
31 halyavin 3681
	call	address_32bit_prefix
157 heavyiron 3682
	jmp	ins_store
3683
      ins_address_16bit:
31 halyavin 3684
	cmp	[code_type],64
157 heavyiron 3685
	je	invalid_address_size
3686
	call	address_16bit_prefix
3687
      ins_store:
31 halyavin 3688
	cmp	[segment_register],1
157 heavyiron 3689
	ja	invalid_address
3690
	lods	byte [esi]
3691
	cmp	al,','
3692
	jne	invalid_operand
3693
	lods	byte [esi]
3694
	cmp	al,10h
3695
	jne	invalid_operand
3696
	lods	byte [esi]
3697
	cmp	al,22h
3698
	jne	invalid_operand
3699
	mov	al,6Ch
3700
	mov	bl,[operand_size]
3701
	cmp	bl,1
3702
	je	simple_instruction
3703
	inc	al
3704
	cmp	bl,2
3705
	je	simple_instruction_16bit
3706
	cmp	bl,4
3707
	je	simple_instruction_32bit
3708
	or	bl,bl
3709
	jz	operand_size_not_specified
3710
	jmp	invalid_operand_size
3711
outs_instruction:
31 halyavin 3712
	lods	byte [esi]
157 heavyiron 3713
	cmp	al,10h
3714
	jne	invalid_operand
3715
	lods	byte [esi]
3716
	cmp	al,22h
3717
	jne	invalid_operand
3718
	lods	byte [esi]
3719
	cmp	al,','
3720
	jne	invalid_operand
3721
	lods	byte [esi]
3722
	call	get_size_operator
3723
	cmp	al,'['
3724
	jne	invalid_operand
3725
	call	get_address
3726
	or	eax,eax
3727
	jnz	invalid_address
3728
	or	bl,ch
3729
	jnz	invalid_address
3730
	cmp	bh,26h
3731
	je	outs_address_16bit
3732
	cmp	bh,46h
3733
	je	outs_address_32bit
3734
	cmp	bh,86h
3735
	jne	invalid_address
3736
	cmp	[code_type],64
3737
	jne	invalid_address_size
3738
	jmp	outs_store
3739
      outs_address_32bit:
31 halyavin 3740
	call	address_32bit_prefix
157 heavyiron 3741
	jmp	outs_store
3742
      outs_address_16bit:
31 halyavin 3743
	cmp	[code_type],64
157 heavyiron 3744
	je	invalid_address_size
3745
	call	address_16bit_prefix
3746
      outs_store:
31 halyavin 3747
	cmp	[segment_register],4
157 heavyiron 3748
	je	outs_segment_ok
3749
	call	store_segment_prefix
3750
      outs_segment_ok:
31 halyavin 3751
	mov	al,6Eh
157 heavyiron 3752
	mov	bl,[operand_size]
3753
	cmp	bl,1
3754
	je	simple_instruction
3755
	inc	al
3756
	cmp	bl,2
3757
	je	simple_instruction_16bit
3758
	cmp	bl,4
3759
	je	simple_instruction_32bit
3760
	or	bl,bl
3761
	jz	operand_size_not_specified
3762
	jmp	invalid_operand_size
3763
xlat_instruction:
31 halyavin 3764
	lods	byte [esi]
157 heavyiron 3765
	call	get_size_operator
3766
	cmp	al,'['
3767
	jne	invalid_operand
3768
	call	get_address
3769
	or	eax,eax
3770
	jnz	invalid_address
3771
	or	bl,ch
3772
	jnz	invalid_address
3773
	cmp	bh,23h
3774
	je	xlat_address_16bit
3775
	cmp	bh,43h
3776
	je	xlat_address_32bit
3777
	cmp	bh,83h
3778
	jne	invalid_address
3779
	cmp	[code_type],64
3780
	jne	invalid_address_size
3781
	jmp	xlat_store
3782
      xlat_address_32bit:
31 halyavin 3783
	call	address_32bit_prefix
157 heavyiron 3784
	jmp	xlat_store
3785
      xlat_address_16bit:
31 halyavin 3786
	cmp	[code_type],64
157 heavyiron 3787
	je	invalid_address_size
3788
	call	address_16bit_prefix
3789
      xlat_store:
31 halyavin 3790
	call	store_segment_prefix_if_necessary
157 heavyiron 3791
	mov	al,0D7h
3792
	cmp	[operand_size],1
3793
	jbe	simple_instruction
3794
	jmp	invalid_operand_size
3795
31 halyavin 3796
 
3797
	mov	ah,al
157 heavyiron 3798
	shr	ah,4
3799
	and	al,111b
3800
	mov	[base_code],0Fh
3801
	mov	[extended_code],ah
3802
	mov	[postbyte_register],al
3803
	lods	byte [esi]
3804
	call	get_size_operator
3805
	cmp	al,10h
3806
	je	pm_reg
3807
      pm_mem:
31 halyavin 3808
	cmp	al,'['
157 heavyiron 3809
	jne	invalid_operand
3810
	call	get_address
3811
	mov	al,[operand_size]
3812
	cmp	al,2
3813
	je	pm_mem_store
3814
	or	al,al
3815
	jnz	invalid_operand_size
3816
      pm_mem_store:
31 halyavin 3817
	call	store_instruction
157 heavyiron 3818
	jmp	instruction_assembled
3819
      pm_reg:
31 halyavin 3820
	lods	byte [esi]
157 heavyiron 3821
	call	convert_register
3822
	mov	bl,al
3823
	cmp	ah,2
3824
	jne	invalid_operand_size
3825
	call	store_nomem_instruction
3826
	jmp	instruction_assembled
3827
pm_store_word_instruction:
31 halyavin 3828
	mov	ah,al
157 heavyiron 3829
	shr	ah,4
3830
	and	al,111b
3831
	mov	[base_code],0Fh
3832
	mov	[extended_code],ah
3833
	mov	[postbyte_register],al
3834
	lods	byte [esi]
3835
	call	get_size_operator
3836
	cmp	al,10h
3837
	jne	pm_mem
3838
	lods	byte [esi]
3839
	call	convert_register
3840
	mov	bl,al
3841
	mov	al,ah
3842
	call	operand_autodetect
3843
	call	store_nomem_instruction
3844
	jmp	instruction_assembled
3845
lgdt_instruction:
31 halyavin 3846
	mov	[base_code],0Fh
157 heavyiron 3847
	mov	[extended_code],1
3848
	mov	[postbyte_register],al
3849
	lods	byte [esi]
3850
	call	get_size_operator
3851
	cmp	al,'['
3852
	jne	invalid_operand
3853
	call	get_address
3854
	mov	al,[operand_size]
3855
	cmp	al,6
3856
	je	lgdt_mem_48bit
3857
	cmp	al,10
3858
	je	lgdt_mem_80bit
3859
	or	al,al
3860
	jnz	invalid_operand_size
3861
	jmp	lgdt_mem_store
3862
      lgdt_mem_80bit:
109 heavyiron 3863
	cmp	[code_type],64
157 heavyiron 3864
	jne	illegal_instruction
3865
	jmp	lgdt_mem_store
3866
      lgdt_mem_48bit:
31 halyavin 3867
	cmp	[code_type],64
157 heavyiron 3868
	je	illegal_instruction
3869
	cmp	[postbyte_register],2
3870
	jb	lgdt_mem_store
3871
	call	operand_32bit
3872
      lgdt_mem_store:
109 heavyiron 3873
	call	store_instruction
157 heavyiron 3874
	jmp	instruction_assembled
3875
lar_instruction:
31 halyavin 3876
	mov	[extended_code],al
157 heavyiron 3877
	mov	[base_code],0Fh
3878
	lods	byte [esi]
3879
	call	get_size_operator
3880
	cmp	al,10h
3881
	jne	invalid_operand
3882
	lods	byte [esi]
3883
	call	convert_register
3884
	mov	[postbyte_register],al
3885
	lods	byte [esi]
3886
	cmp	al,','
3887
	jne	invalid_operand
3888
	xor	al,al
3889
	xchg	al,[operand_size]
3890
	call	operand_autodetect
3891
	lods	byte [esi]
3892
	call	get_size_operator
3893
	cmp	al,10h
3894
	je	lar_reg_reg
3895
	cmp	al,'['
3896
	jne	invalid_operand
3897
	call	get_address
3898
	mov	al,[operand_size]
3899
	or	al,al
3900
	jz	lar_reg_mem
3901
	cmp	al,2
3902
	jne	invalid_operand_size
3903
      lar_reg_mem:
31 halyavin 3904
	call	store_instruction
157 heavyiron 3905
	jmp	instruction_assembled
3906
      lar_reg_reg:
31 halyavin 3907
	lods	byte [esi]
157 heavyiron 3908
	call	convert_register
3909
	cmp	ah,2
3910
	jne	invalid_operand_size
3911
	mov	bl,al
3912
	call	store_nomem_instruction
3913
	jmp	instruction_assembled
3914
invlpg_instruction:
31 halyavin 3915
	mov	[base_code],0Fh
157 heavyiron 3916
	mov	[extended_code],1
3917
	mov	[postbyte_register],7
3918
	lods	byte [esi]
3919
	call	get_size_operator
3920
	cmp	al,'['
3921
	jne	invalid_operand
3922
	call	get_address
3923
	call	store_instruction
3924
	jmp	instruction_assembled
3925
swapgs_instruction:
31 halyavin 3926
	mov	[base_code],0Fh
157 heavyiron 3927
	mov	[extended_code],1
3928
	mov	[postbyte_register],7
3929
	mov	bl,al
3930
	call	store_nomem_instruction
3931
	jmp	instruction_assembled
3932
31 halyavin 3933
 
3934
	mov	[base_code],0Fh
157 heavyiron 3935
	mov	[extended_code],al
3936
	lods	byte [esi]
3937
	call	get_size_operator
3938
	cmp	al,10h
3939
	je	basic_486_reg
3940
	cmp	al,'['
3941
	jne	invalid_operand
3942
	call	get_address
3943
	push	edx ebx ecx
174 heavyiron 3944
	lods	byte [esi]
157 heavyiron 3945
	cmp	al,','
3946
	jne	invalid_operand
3947
	lods	byte [esi]
3948
	call	get_size_operator
3949
	cmp	al,10h
3950
	jne	invalid_operand
3951
	lods	byte [esi]
3952
	call	convert_register
3953
	mov	[postbyte_register],al
3954
	pop	ecx ebx edx
174 heavyiron 3955
	mov	al,ah
157 heavyiron 3956
	cmp	al,1
3957
	je	basic_486_mem_reg_8bit
3958
	call	operand_autodetect
3959
	inc	[extended_code]
3960
      basic_486_mem_reg_8bit:
31 halyavin 3961
	call	store_instruction
157 heavyiron 3962
	jmp	instruction_assembled
3963
      basic_486_reg:
31 halyavin 3964
	lods	byte [esi]
157 heavyiron 3965
	call	convert_register
3966
	mov	[postbyte_register],al
3967
	lods	byte [esi]
3968
	cmp	al,','
3969
	jne	invalid_operand
3970
	lods	byte [esi]
3971
	call	get_size_operator
3972
	cmp	al,10h
3973
	jne	invalid_operand
3974
	lods	byte [esi]
3975
	call	convert_register
3976
	mov	bl,[postbyte_register]
3977
	mov	[postbyte_register],al
3978
	mov	al,ah
3979
	cmp	al,1
3980
	je	basic_486_reg_reg_8bit
3981
	call	operand_autodetect
3982
	inc	[extended_code]
3983
      basic_486_reg_reg_8bit:
31 halyavin 3984
	call	store_nomem_instruction
157 heavyiron 3985
	jmp	instruction_assembled
3986
bswap_instruction:
31 halyavin 3987
	lods	byte [esi]
157 heavyiron 3988
	call	get_size_operator
3989
	cmp	al,10h
3990
	jne	invalid_operand
3991
	lods	byte [esi]
3992
	call	convert_register
3993
	test	al,1000b
3994
	jz	bswap_reg_code_ok
3995
	or	[rex_prefix],41h
3996
	and	al,111b
3997
      bswap_reg_code_ok:
109 heavyiron 3998
	add	al,0C8h
157 heavyiron 3999
	mov	[extended_code],al
4000
	mov	[base_code],0Fh
4001
	cmp	ah,8
4002
	je	bswap_reg64
4003
	cmp	ah,4
4004
	jne	invalid_operand_size
4005
	call	operand_32bit
4006
	call	store_instruction_code
4007
	jmp	instruction_assembled
4008
      bswap_reg64:
31 halyavin 4009
	call	operand_64bit
157 heavyiron 4010
	call	store_instruction_code
4011
	jmp	instruction_assembled
4012
cmpxchgx_instruction:
31 halyavin 4013
	mov	[base_code],0Fh
157 heavyiron 4014
	mov	[extended_code],0C7h
4015
	mov	[postbyte_register],al
4016
	lods	byte [esi]
4017
	call	get_size_operator
4018
	cmp	al,'['
4019
	jne	invalid_operand
4020
	call	get_address
4021
	mov	ah,1
4022
	xchg	[postbyte_register],ah
4023
	mov	al,[operand_size]
4024
	or	al,al
4025
	jz	cmpxchgx_size_ok
4026
	cmp	al,ah
4027
	jne	invalid_operand_size
4028
      cmpxchgx_size_ok:
31 halyavin 4029
	cmp	ah,16
157 heavyiron 4030
	jne	cmpxchgx_store
4031
	call	operand_64bit
4032
      cmpxchgx_store:
31 halyavin 4033
	call	store_instruction
157 heavyiron 4034
	jmp	instruction_assembled
4035
nop_instruction:
174 heavyiron 4036
	mov	ah,[esi]
4037
	cmp	ah,10h
4038
	je	extended_nop
4039
	cmp	ah,11h
4040
	je	extended_nop
4041
	cmp	ah,'['
4042
	je	extended_nop
4043
	stos	byte [edi]
4044
	jmp	instruction_assembled
4045
      extended_nop:
4046
	mov	[base_code],0Fh
4047
	mov	[extended_code],1Fh
4048
	mov	[postbyte_register],0
4049
	lods	byte [esi]
4050
	call	get_size_operator
4051
	cmp	al,10h
4052
	je	extended_nop_reg
4053
	cmp	al,'['
4054
	jne	invalid_operand
4055
	call	get_address
4056
	mov	al,[operand_size]
4057
	or	al,al
4058
	jz	extended_nop_nosize
4059
	call	operand_autodetect
4060
      extended_nop_store:
4061
	call	store_instruction
4062
	jmp	instruction_assembled
4063
      extended_nop_nosize:
4064
	cmp	[error_line],0
4065
	jne	extended_nop_store
4066
	mov	eax,[current_line]
4067
	mov	[error_line],eax
4068
	mov	[error],operand_size_not_specified
4069
	jmp	extended_nop_store
4070
      extended_nop_reg:
4071
	lods	byte [esi]
4072
	call	convert_register
4073
	mov	bl,al
4074
	mov	al,ah
4075
	call	operand_autodetect
4076
	call	store_nomem_instruction
4077
	jmp	instruction_assembled
4078
31 halyavin 4079
 
4080
	mov	[postbyte_register],al
157 heavyiron 4081
	mov	[base_code],0D8h
4082
	lods	byte [esi]
4083
	call	get_size_operator
4084
	cmp	al,10h
4085
	je	basic_fpu_streg
4086
	cmp	al,'['
4087
	je	basic_fpu_mem
4088
	dec	esi
4089
	mov	ah,[postbyte_register]
4090
	cmp	ah,2
4091
	jb	invalid_operand
4092
	cmp	ah,3
4093
	ja	invalid_operand
4094
	mov	bl,1
4095
	call	store_nomem_instruction
4096
	jmp	instruction_assembled
4097
      basic_fpu_mem:
31 halyavin 4098
	call	get_address
157 heavyiron 4099
	mov	al,[operand_size]
4100
	cmp	al,4
4101
	je	basic_fpu_mem_32bit
4102
	cmp	al,8
4103
	je	basic_fpu_mem_64bit
4104
	or	al,al
4105
	jnz	invalid_operand_size
4106
	cmp	[error_line],0
4107
	jne	basic_fpu_mem_32bit
4108
	mov	eax,[current_line]
4109
	mov	[error_line],eax
4110
	mov	[error],operand_size_not_specified
4111
      basic_fpu_mem_32bit:
31 halyavin 4112
	call	store_instruction
157 heavyiron 4113
	jmp	instruction_assembled
4114
      basic_fpu_mem_64bit:
31 halyavin 4115
	mov	[base_code],0DCh
157 heavyiron 4116
	call	store_instruction
4117
	jmp	instruction_assembled
4118
      basic_fpu_streg:
31 halyavin 4119
	lods	byte [esi]
157 heavyiron 4120
	call	convert_fpu_register
4121
	mov	bl,al
4122
	mov	ah,[postbyte_register]
4123
	cmp	ah,2
4124
	je	basic_fpu_single_streg
4125
	cmp	ah,3
4126
	je	basic_fpu_single_streg
4127
	or	al,al
4128
	jz	basic_fpu_st0
4129
	test	ah,110b
4130
	jz	basic_fpu_streg_st0
4131
	xor	[postbyte_register],1
4132
      basic_fpu_streg_st0:
31 halyavin 4133
	lods	byte [esi]
157 heavyiron 4134
	cmp	al,','
4135
	jne	invalid_operand
4136
	lods	byte [esi]
4137
	call	get_size_operator
4138
	cmp	al,10h
4139
	jne	invalid_operand
4140
	lods	byte [esi]
4141
	call	convert_fpu_register
4142
	or	al,al
4143
	jnz	invalid_operand
4144
	mov	[base_code],0DCh
4145
	call	store_nomem_instruction
4146
	jmp	instruction_assembled
4147
      basic_fpu_st0:
31 halyavin 4148
	lods	byte [esi]
157 heavyiron 4149
	cmp	al,','
4150
	jne	invalid_operand
4151
	lods	byte [esi]
4152
	call	get_size_operator
4153
	cmp	al,10h
4154
	jne	invalid_operand
4155
	lods	byte [esi]
4156
	call	convert_fpu_register
4157
	mov	bl,al
4158
      basic_fpu_single_streg:
31 halyavin 4159
	mov	[base_code],0D8h
157 heavyiron 4160
	call	store_nomem_instruction
4161
	jmp	instruction_assembled
4162
simple_fpu_instruction:
31 halyavin 4163
	mov	ah,al
157 heavyiron 4164
	or	ah,11000000b
4165
	mov	al,0D9h
4166
	stos	word [edi]
4167
	jmp	instruction_assembled
4168
fi_instruction:
31 halyavin 4169
	mov	[postbyte_register],al
157 heavyiron 4170
	lods	byte [esi]
4171
	call	get_size_operator
4172
	cmp	al,'['
4173
	jne	invalid_operand
4174
	call	get_address
4175
	mov	al,[operand_size]
4176
	cmp	al,2
4177
	je	fi_mem_16bit
4178
	cmp	al,4
4179
	je	fi_mem_32bit
4180
	or	al,al
4181
	jnz	invalid_operand_size
4182
	cmp	[error_line],0
4183
	jne	fi_mem_32bit
4184
	mov	eax,[current_line]
4185
	mov	[error_line],eax
4186
	mov	[error],operand_size_not_specified
4187
      fi_mem_32bit:
31 halyavin 4188
	mov	[base_code],0DAh
157 heavyiron 4189
	call	store_instruction
4190
	jmp	instruction_assembled
4191
      fi_mem_16bit:
31 halyavin 4192
	mov	[base_code],0DEh
157 heavyiron 4193
	call	store_instruction
4194
	jmp	instruction_assembled
4195
fld_instruction:
31 halyavin 4196
	mov	[postbyte_register],al
157 heavyiron 4197
	lods	byte [esi]
4198
	call	get_size_operator
4199
	cmp	al,10h
4200
	je	fld_streg
4201
	cmp	al,'['
4202
	jne	invalid_operand
4203
	call	get_address
4204
	mov	al,[operand_size]
4205
	cmp	al,4
4206
	je	fld_mem_32bit
4207
	cmp	al,8
4208
	je	fld_mem_64bit
4209
	cmp	al,10
4210
	je	fld_mem_80bit
4211
	or	al,al
4212
	jnz	invalid_operand_size
4213
	cmp	[error_line],0
4214
	jne	fld_mem_32bit
4215
	mov	eax,[current_line]
4216
	mov	[error_line],eax
4217
	mov	[error],operand_size_not_specified
4218
      fld_mem_32bit:
31 halyavin 4219
	mov	[base_code],0D9h
157 heavyiron 4220
	call	store_instruction
4221
	jmp	instruction_assembled
4222
      fld_mem_64bit:
31 halyavin 4223
	mov	[base_code],0DDh
157 heavyiron 4224
	call	store_instruction
4225
	jmp	instruction_assembled
4226
      fld_mem_80bit:
31 halyavin 4227
	mov	al,[postbyte_register]
157 heavyiron 4228
	cmp	al,0
4229
	je	fld_mem_80bit_store
4230
	dec	[postbyte_register]
4231
	cmp	al,3
4232
	je	fld_mem_80bit_store
4233
	jmp	invalid_operand_size
4234
      fld_mem_80bit_store:
31 halyavin 4235
	add	[postbyte_register],5
157 heavyiron 4236
	mov	[base_code],0DBh
4237
	call	store_instruction
4238
	jmp	instruction_assembled
4239
      fld_streg:
31 halyavin 4240
	lods	byte [esi]
157 heavyiron 4241
	call	convert_fpu_register
4242
	mov	bl,al
4243
	cmp	[postbyte_register],2
4244
	jae	fst_streg
4245
	mov	[base_code],0D9h
4246
	call	store_nomem_instruction
4247
	jmp	instruction_assembled
4248
      fst_streg:
31 halyavin 4249
	mov	[base_code],0DDh
157 heavyiron 4250
	call	store_nomem_instruction
4251
	jmp	instruction_assembled
4252
fild_instruction:
31 halyavin 4253
	mov	[postbyte_register],al
157 heavyiron 4254
	lods	byte [esi]
4255
	call	get_size_operator
4256
	cmp	al,'['
4257
	jne	invalid_operand
4258
	call	get_address
4259
	mov	al,[operand_size]
4260
	cmp	al,2
4261
	je	fild_mem_16bit
4262
	cmp	al,4
4263
	je	fild_mem_32bit
4264
	cmp	al,8
4265
	je	fild_mem_64bit
4266
	or	al,al
4267
	jnz	invalid_operand_size
4268
	cmp	[error_line],0
4269
	jne	fild_mem_32bit
4270
	mov	eax,[current_line]
4271
	mov	[error_line],eax
4272
	mov	[error],operand_size_not_specified
4273
      fild_mem_32bit:
31 halyavin 4274
	mov	[base_code],0DBh
157 heavyiron 4275
	call	store_instruction
4276
	jmp	instruction_assembled
4277
      fild_mem_16bit:
31 halyavin 4278
	mov	[base_code],0DFh
157 heavyiron 4279
	call	store_instruction
4280
	jmp	instruction_assembled
4281
      fild_mem_64bit:
31 halyavin 4282
	mov	al,[postbyte_register]
157 heavyiron 4283
	cmp	al,1
4284
	je	fisttp_64bit_store
4285
	jb	fild_mem_64bit_store
4286
	dec	[postbyte_register]
4287
	cmp	al,3
4288
	je	fild_mem_64bit_store
4289
	jmp	invalid_operand_size
4290
      fild_mem_64bit_store:
31 halyavin 4291
	add	[postbyte_register],5
157 heavyiron 4292
	mov	[base_code],0DFh
4293
	call	store_instruction
4294
	jmp	instruction_assembled
4295
      fisttp_64bit_store:
31 halyavin 4296
	mov	[base_code],0DDh
157 heavyiron 4297
	call	store_instruction
4298
	jmp	instruction_assembled
4299
fbld_instruction:
31 halyavin 4300
	mov	[postbyte_register],al
157 heavyiron 4301
	lods	byte [esi]
4302
	call	get_size_operator
4303
	cmp	al,'['
4304
	jne	invalid_operand
4305
	call	get_address
4306
	mov	al,[operand_size]
4307
	or	al,al
4308
	jz	fbld_mem_80bit
4309
	cmp	al,10
4310
	je	fbld_mem_80bit
4311
	jmp	invalid_operand_size
4312
      fbld_mem_80bit:
31 halyavin 4313
	mov	[base_code],0DFh
157 heavyiron 4314
	call	store_instruction
4315
	jmp	instruction_assembled
4316
faddp_instruction:
31 halyavin 4317
	mov	[postbyte_register],al
157 heavyiron 4318
	mov	[base_code],0DEh
4319
	mov	edx,esi
4320
	lods	byte [esi]
4321
	call	get_size_operator
4322
	cmp	al,10h
4323
	je	faddp_streg
4324
	mov	esi,edx
4325
	mov	bl,1
4326
	call	store_nomem_instruction
4327
	jmp	instruction_assembled
4328
      faddp_streg:
31 halyavin 4329
	lods	byte [esi]
157 heavyiron 4330
	call	convert_fpu_register
4331
	mov	bl,al
4332
	lods	byte [esi]
4333
	cmp	al,','
4334
	jne	invalid_operand
4335
	lods	byte [esi]
4336
	call	get_size_operator
4337
	cmp	al,10h
4338
	jne	invalid_operand
4339
	lods	byte [esi]
4340
	call	convert_fpu_register
4341
	or	al,al
4342
	jnz	invalid_operand
4343
	call	store_nomem_instruction
4344
	jmp	instruction_assembled
4345
fcompp_instruction:
31 halyavin 4346
	mov	ax,0D9DEh
157 heavyiron 4347
	stos	word [edi]
4348
	jmp	instruction_assembled
4349
fucompp_instruction:
31 halyavin 4350
	mov	ax,0E9DAh
157 heavyiron 4351
	stos	word [edi]
4352
	jmp	instruction_assembled
4353
fxch_instruction:
31 halyavin 4354
	mov	dx,01D9h
157 heavyiron 4355
	jmp	fpu_single_operand
4356
ffreep_instruction:
31 halyavin 4357
	mov	dx,00DFh
157 heavyiron 4358
	jmp	fpu_single_operand
4359
ffree_instruction:
31 halyavin 4360
	mov	dl,0DDh
157 heavyiron 4361
	mov	dh,al
4362
      fpu_single_operand:
31 halyavin 4363
	mov	ebx,esi
157 heavyiron 4364
	lods	byte [esi]
4365
	call	get_size_operator
4366
	cmp	al,10h
4367
	je	fpu_streg
4368
	or	dh,dh
4369
	jz	invalid_operand
4370
	mov	esi,ebx
4371
	shl	dh,3
4372
	or	dh,11000001b
4373
	mov	ax,dx
4374
	stos	word [edi]
4375
	jmp	instruction_assembled
4376
      fpu_streg:
31 halyavin 4377
	lods	byte [esi]
157 heavyiron 4378
	call	convert_fpu_register
4379
	shl	dh,3
4380
	or	dh,al
4381
	or	dh,11000000b
4382
	mov	ax,dx
4383
	stos	word [edi]
4384
	jmp	instruction_assembled
4385
fstenv_instruction:
31 halyavin 4386
	mov	byte [edi],9Bh
157 heavyiron 4387
	inc	edi
4388
fldenv_instruction:
31 halyavin 4389
	mov	[base_code],0D9h
157 heavyiron 4390
	jmp	fpu_mem
4391
fsave_instruction:
31 halyavin 4392
	mov	byte [edi],9Bh
157 heavyiron 4393
	inc	edi
4394
fnsave_instruction:
31 halyavin 4395
	mov	[base_code],0DDh
157 heavyiron 4396
      fpu_mem:
31 halyavin 4397
	mov	[postbyte_register],al
157 heavyiron 4398
	lods	byte [esi]
4399
	call	get_size_operator
4400
	cmp	al,'['
4401
	jne	invalid_operand
4402
	call	get_address
4403
	cmp	[operand_size],0
4404
	jne	invalid_operand_size
4405
	call	store_instruction
4406
	jmp	instruction_assembled
4407
fstcw_instruction:
31 halyavin 4408
	mov	byte [edi],9Bh
157 heavyiron 4409
	inc	edi
4410
fldcw_instruction:
31 halyavin 4411
	mov	[postbyte_register],al
157 heavyiron 4412
	mov	[base_code],0D9h
4413
	lods	byte [esi]
4414
	call	get_size_operator
4415
	cmp	al,'['
4416
	jne	invalid_operand
4417
	call	get_address
4418
	mov	al,[operand_size]
4419
	or	al,al
4420
	jz	fldcw_mem_16bit
4421
	cmp	al,2
4422
	je	fldcw_mem_16bit
4423
	jmp	invalid_operand_size
4424
      fldcw_mem_16bit:
31 halyavin 4425
	call	store_instruction
157 heavyiron 4426
	jmp	instruction_assembled
4427
fstsw_instruction:
31 halyavin 4428
	mov	al,9Bh
157 heavyiron 4429
	stos	byte [edi]
4430
fnstsw_instruction:
31 halyavin 4431
	mov	[base_code],0DDh
157 heavyiron 4432
	mov	[postbyte_register],7
4433
	lods	byte [esi]
4434
	call	get_size_operator
4435
	cmp	al,10h
4436
	je	fstsw_reg
4437
	cmp	al,'['
4438
	jne	invalid_operand
4439
	call	get_address
4440
	mov	al,[operand_size]
4441
	or	al,al
4442
	jz	fstsw_mem_16bit
4443
	cmp	al,2
4444
	je	fstsw_mem_16bit
4445
	jmp	invalid_operand_size
4446
      fstsw_mem_16bit:
31 halyavin 4447
	call	store_instruction
157 heavyiron 4448
	jmp	instruction_assembled
4449
      fstsw_reg:
31 halyavin 4450
	lods	byte [esi]
157 heavyiron 4451
	call	convert_register
4452
	cmp	ax,0200h
4453
	jne	invalid_operand
4454
	mov	ax,0E0DFh
4455
	stos	word [edi]
4456
	jmp	instruction_assembled
4457
finit_instruction:
31 halyavin 4458
	mov	byte [edi],9Bh
157 heavyiron 4459
	inc	edi
4460
fninit_instruction:
31 halyavin 4461
	mov	ah,al
157 heavyiron 4462
	mov	al,0DBh
4463
	stos	word [edi]
4464
	jmp	instruction_assembled
4465
fcmov_instruction:
31 halyavin 4466
	mov	dh,0DAh
157 heavyiron 4467
	jmp	fcomi_streg
4468
fcomi_instruction:
31 halyavin 4469
	mov	dh,0DBh
157 heavyiron 4470
	jmp	fcomi_streg
4471
fcomip_instruction:
31 halyavin 4472
	mov	dh,0DFh
157 heavyiron 4473
      fcomi_streg:
31 halyavin 4474
	mov	dl,al
157 heavyiron 4475
	lods	byte [esi]
4476
	call	get_size_operator
4477
	cmp	al,10h
4478
	jne	invalid_operand
4479
	lods	byte [esi]
4480
	call	convert_fpu_register
4481
	mov	ah,al
4482
	cmp	byte [esi],','
4483
	je	fcomi_st0_streg
4484
	add	ah,dl
4485
	mov	al,dh
4486
	stos	word [edi]
4487
	jmp	instruction_assembled
4488
      fcomi_st0_streg:
31 halyavin 4489
	or	ah,ah
157 heavyiron 4490
	jnz	invalid_operand
4491
	inc	esi
4492
	lods	byte [esi]
4493
	call	get_size_operator
4494
	cmp	al,10h
4495
	jne	invalid_operand
4496
	lods	byte [esi]
4497
	call	convert_fpu_register
4498
	mov	ah,al
4499
	add	ah,dl
4500
	mov	al,dh
4501
	stos	word [edi]
4502
	jmp	instruction_assembled
4503
31 halyavin 4504
 
174 heavyiron 4505
	mov	[base_code],0Fh
157 heavyiron 4506
	mov	[extended_code],al
4507
      mmx_instruction:
174 heavyiron 4508
	lods	byte [esi]
157 heavyiron 4509
	call	get_size_operator
4510
	cmp	al,10h
4511
	jne	invalid_operand
4512
	lods	byte [esi]
4513
	call	convert_mmx_register
4514
	call	make_mmx_prefix
4515
	mov	[postbyte_register],al
4516
	lods	byte [esi]
4517
	cmp	al,','
4518
	jne	invalid_operand
4519
	lods	byte [esi]
4520
	call	get_size_operator
4521
	cmp	al,10h
4522
	je	mmx_mmreg_mmreg
4523
	cmp	al,'['
4524
	jne	invalid_operand
4525
      mmx_mmreg_mem:
31 halyavin 4526
	call	get_address
157 heavyiron 4527
	call	store_instruction
4528
	jmp	instruction_assembled
4529
      mmx_mmreg_mmreg:
31 halyavin 4530
	lods	byte [esi]
157 heavyiron 4531
	call	convert_mmx_register
4532
	mov	bl,al
4533
	call	store_nomem_instruction
4534
	jmp	instruction_assembled
4535
mmx_ps_instruction:
31 halyavin 4536
	mov	[base_code],0Fh
157 heavyiron 4537
	mov	[extended_code],al
4538
	lods	byte [esi]
4539
	call	get_size_operator
4540
	cmp	al,10h
4541
	jne	invalid_operand
4542
	lods	byte [esi]
4543
	call	convert_mmx_register
4544
	call	make_mmx_prefix
4545
	mov	[postbyte_register],al
4546
	lods	byte [esi]
4547
	cmp	al,','
4548
	jne	invalid_operand
4549
	mov	[operand_size],0
4550
	lods	byte [esi]
4551
	call	get_size_operator
4552
	cmp	al,10h
4553
	je	mmx_mmreg_mmreg
4554
	cmp	al,'('
4555
	je	mmx_ps_mmreg_imm8
4556
	cmp	al,'['
4557
	je	mmx_mmreg_mem
4558
	jmp	invalid_operand
4559
      mmx_ps_mmreg_imm8:
31 halyavin 4560
	call	get_byte_value
157 heavyiron 4561
	mov	byte [value],al
4562
	test	[operand_size],not 1
4563
	jnz	invalid_value
4564
	mov	bl,[extended_code]
4565
	mov	al,bl
4566
	shr	bl,4
4567
	and	al,1111b
4568
	add	al,70h
4569
	mov	[extended_code],al
4570
	sub	bl,0Ch
4571
	shl	bl,1
4572
	xchg	bl,[postbyte_register]
4573
	call	store_nomem_instruction
4574
	mov	al,byte [value]
4575
	stos	byte [edi]
4576
	jmp	instruction_assembled
4577
pextrw_instruction:
31 halyavin 4578
	mov	[base_code],0Fh
157 heavyiron 4579
	mov	[extended_code],al
4580
	lods	byte [esi]
4581
	call	get_size_operator
4582
	cmp	al,10h
4583
	jne	invalid_operand
4584
	lods	byte [esi]
4585
	call	convert_register
4586
	cmp	ah,4
4587
	jnz	invalid_operand_size
4588
	mov	[postbyte_register],al
4589
	mov	[operand_size],0
4590
	lods	byte [esi]
4591
	cmp	al,','
4592
	jne	invalid_operand
4593
	lods	byte [esi]
4594
	call	get_size_operator
4595
	cmp	al,10h
4596
	jne	invalid_operand
4597
	lods	byte [esi]
4598
	call	convert_mmx_register
4599
	mov	bl,al
4600
	call	make_mmx_prefix
4601
	cmp	[extended_code],0C5h
4602
	je	mmx_nomem_imm8
4603
	call	store_nomem_instruction
4604
	jmp	instruction_assembled
4605
      mmx_imm8:
31 halyavin 4606
	push	ebx ecx edx
174 heavyiron 4607
	mov	[operand_size],0
157 heavyiron 4608
	lods	byte [esi]
4609
	cmp	al,','
4610
	jne	invalid_operand
4611
	lods	byte [esi]
4612
	call	get_size_operator
4613
	test	ah,not 1
4614
	jnz	invalid_operand_size
4615
	cmp	al,'('
4616
	jne	invalid_operand
4617
	call	get_byte_value
4618
	mov	byte [value],al
4619
	pop	edx ecx ebx
174 heavyiron 4620
	call	store_instruction_with_imm8
157 heavyiron 4621
	jmp	instruction_assembled
4622
      mmx_nomem_imm8:
31 halyavin 4623
	call	store_nomem_instruction
157 heavyiron 4624
	mov	[operand_size],0
4625
	lods	byte [esi]
4626
	cmp	al,','
4627
	jne	invalid_operand
4628
	lods	byte [esi]
4629
	call	get_size_operator
4630
	test	ah,not 1
4631
	jnz	invalid_operand_size
4632
	cmp	al,'('
4633
	jne	invalid_operand
4634
	call	get_byte_value
4635
	stosb
4636
	jmp	instruction_assembled
4637
pinsrw_instruction:
31 halyavin 4638
	mov	[extended_code],al
157 heavyiron 4639
	mov	[base_code],0Fh
4640
	lods	byte [esi]
4641
	call	get_size_operator
4642
	cmp	al,10h
4643
	jne	invalid_operand
4644
	lods	byte [esi]
4645
	call	convert_mmx_register
4646
	call	make_mmx_prefix
4647
	mov	[postbyte_register],al
4648
	mov	[operand_size],0
4649
	lods	byte [esi]
4650
	cmp	al,','
4651
	jne	invalid_operand
4652
	lods	byte [esi]
4653
	call	get_size_operator
4654
	cmp	al,10h
4655
	je	pinsrw_mmreg_reg
4656
	cmp	al,'['
4657
	jne	invalid_operand
4658
	call	get_address
4659
	cmp	[operand_size],0
4660
	je	mmx_imm8
4661
	cmp	[operand_size],2
4662
	jne	invalid_operand_size
4663
	jmp	mmx_imm8
4664
      pinsrw_mmreg_reg:
31 halyavin 4665
	lods	byte [esi]
157 heavyiron 4666
	call	convert_register
4667
	cmp	ah,4
4668
	jne	invalid_operand_size
4669
	mov	bl,al
4670
	jmp	mmx_nomem_imm8
4671
pshufw_instruction:
31 halyavin 4672
	mov	[mmx_size],8
157 heavyiron 4673
	mov	[operand_prefix],al
4674
	jmp	pshuf_instruction
4675
pshufd_instruction:
31 halyavin 4676
	mov	[mmx_size],16
157 heavyiron 4677
	mov	[operand_prefix],al
4678
      pshuf_instruction:
31 halyavin 4679
	mov	[base_code],0Fh
157 heavyiron 4680
	mov	[extended_code],70h
4681
	lods	byte [esi]
4682
	call	get_size_operator
4683
	cmp	al,10h
4684
	jne	invalid_operand
4685
	lods	byte [esi]
4686
	call	convert_mmx_register
4687
	cmp	ah,[mmx_size]
4688
	jne	invalid_operand_size
4689
	mov	[postbyte_register],al
4690
	lods	byte [esi]
4691
	cmp	al,','
4692
	jne	invalid_operand
4693
	lods	byte [esi]
4694
	call	get_size_operator
4695
	cmp	al,10h
4696
	je	pshuf_mmreg_mmreg
4697
	cmp	al,'['
4698
	jne	invalid_operand
4699
	call	get_address
4700
	jmp	mmx_imm8
4701
      pshuf_mmreg_mmreg:
31 halyavin 4702
	lods	byte [esi]
157 heavyiron 4703
	call	convert_mmx_register
4704
	mov	bl,al
4705
	jmp	mmx_nomem_imm8
4706
movd_instruction:
31 halyavin 4707
	mov	[base_code],0Fh
157 heavyiron 4708
	mov	[extended_code],7Eh
4709
	lods	byte [esi]
4710
	call	get_size_operator
4711
	cmp	al,10h
4712
	je	movd_reg
4713
	cmp	al,'['
4714
	jne	invalid_operand
4715
	call	get_address
4716
	test	[operand_size],not 4
4717
	jnz	invalid_operand_size
4718
	mov	[operand_size],0
4719
	lods	byte [esi]
4720
	cmp	al,','
4721
	jne	invalid_operand
4722
	lods	byte [esi]
4723
	call	get_size_operator
4724
	cmp	al,10h
4725
	jne	invalid_operand
4726
	lods	byte [esi]
4727
	call	convert_mmx_register
4728
	call	make_mmx_prefix
4729
	mov	[postbyte_register],al
4730
	call	store_instruction
4731
	jmp	instruction_assembled
4732
      movd_reg:
31 halyavin 4733
	lods	byte [esi]
157 heavyiron 4734
	cmp	al,0B0h
4735
	jae	movd_mmreg
4736
	call	convert_register
4737
	cmp	ah,4
4738
	jne	invalid_operand_size
4739
	mov	[operand_size],0
4740
	mov	bl,al
4741
	lods	byte [esi]
4742
	cmp	al,','
4743
	jne	invalid_operand
4744
	lods	byte [esi]
4745
	call	get_size_operator
4746
	cmp	al,10h
4747
	jne	invalid_operand
4748
	lods	byte [esi]
4749
	call	convert_mmx_register
4750
	mov	[postbyte_register],al
4751
	call	make_mmx_prefix
4752
	call	store_nomem_instruction
4753
	jmp	instruction_assembled
4754
      movd_mmreg:
31 halyavin 4755
	mov	[extended_code],6Eh
157 heavyiron 4756
	call	convert_mmx_register
4757
	call	make_mmx_prefix
4758
	mov	[postbyte_register],al
4759
	mov	[operand_size],0
4760
	lods	byte [esi]
4761
	cmp	al,','
4762
	jne	invalid_operand
4763
	lods	byte [esi]
4764
	call	get_size_operator
4765
	cmp	al,10h
4766
	je	movd_mmreg_reg
4767
	cmp	al,'['
4768
	jne	invalid_operand
4769
	call	get_address
4770
	test	[operand_size],not 4
4771
	jnz	invalid_operand_size
4772
	call	store_instruction
4773
	jmp	instruction_assembled
4774
      movd_mmreg_reg:
31 halyavin 4775
	lods	byte [esi]
157 heavyiron 4776
	call	convert_register
4777
	cmp	ah,4
4778
	jne	invalid_operand_size
4779
	mov	bl,al
4780
	call	store_nomem_instruction
4781
	jmp	instruction_assembled
4782
      make_mmx_prefix:
31 halyavin 4783
	cmp	[operand_size],16
157 heavyiron 4784
	jne	no_mmx_prefix
4785
	mov	[operand_prefix],66h
4786
      no_mmx_prefix:
31 halyavin 4787
	ret
157 heavyiron 4788
movq_instruction:
31 halyavin 4789
	mov	[base_code],0Fh
157 heavyiron 4790
	lods	byte [esi]
4791
	call	get_size_operator
4792
	cmp	al,10h
4793
	je	movq_reg
4794
	cmp	al,'['
4795
	jne	invalid_operand
4796
	call	get_address
4797
	test	[operand_size],not 8
4798
	jnz	invalid_operand_size
4799
	mov	[operand_size],0
4800
	lods	byte [esi]
4801
	cmp	al,','
4802
	jne	invalid_operand
4803
	lods	byte [esi]
4804
	cmp	al,10h
4805
	jne	invalid_operand
4806
	lods	byte [esi]
4807
	call	convert_mmx_register
4808
	mov	[postbyte_register],al
4809
	cmp	ah,16
4810
	je	movq_mem_xmmreg
4811
	mov	[extended_code],7Fh
4812
	call	store_instruction
4813
	jmp	instruction_assembled
4814
     movq_mem_xmmreg:
31 halyavin 4815
	mov	[extended_code],0D6h
157 heavyiron 4816
	mov	[operand_prefix],66h
4817
	call	store_instruction
4818
	jmp	instruction_assembled
4819
     movq_reg:
31 halyavin 4820
	lods	byte [esi]
157 heavyiron 4821
	cmp	al,0B0h
4822
	jae	movq_mmreg
4823
	call	convert_register
4824
	cmp	ah,8
4825
	jne	invalid_operand_size
4826
	mov	bl,al
4827
	lods	byte [esi]
4828
	cmp	al,','
4829
	jne	invalid_operand
4830
	lods	byte [esi]
4831
	call	get_size_operator
4832
	cmp	al,10h
4833
	jne	invalid_operand
4834
	lods	byte [esi]
4835
	call	convert_mmx_register
4836
	mov	[postbyte_register],al
4837
	call	make_mmx_prefix
4838
	mov	[extended_code],7Eh
4839
	call	operand_64bit
4840
	call	store_nomem_instruction
4841
	jmp	instruction_assembled
4842
     movq_mmreg:
31 halyavin 4843
	call	convert_mmx_register
157 heavyiron 4844
	mov	[postbyte_register],al
4845
	mov	[extended_code],6Fh
4846
	mov	[mmx_size],ah
4847
	cmp	ah,16
4848
	jne	movq_mmreg_
4849
	mov	[extended_code],7Eh
4850
	mov	[operand_prefix],0F3h
4851
      movq_mmreg_:
31 halyavin 4852
	lods	byte [esi]
157 heavyiron 4853
	cmp	al,','
4854
	jne	invalid_operand
4855
	mov	[operand_size],0
4856
	lods	byte [esi]
4857
	call	get_size_operator
4858
	cmp	al,10h
4859
	je	movq_mmreg_reg
4860
	call	get_address
4861
	test	[operand_size],not 8
4862
	jnz	invalid_operand_size
4863
	call	store_instruction
4864
	jmp	instruction_assembled
4865
      movq_mmreg_reg:
31 halyavin 4866
	lods	byte [esi]
157 heavyiron 4867
	cmp	al,0B0h
4868
	jae	movq_mmreg_mmreg
4869
	mov	[operand_size],0
4870
	call	convert_register
4871
	cmp	ah,8
4872
	jne	invalid_operand_size
4873
	mov	[extended_code],6Eh
4874
	mov	[operand_prefix],0
4875
	mov	bl,al
4876
	cmp	[mmx_size],16
4877
	jne	movq_mmreg_reg_store
4878
	mov	[operand_prefix],66h
4879
      movq_mmreg_reg_store:
109 heavyiron 4880
	call	operand_64bit
157 heavyiron 4881
	call	store_nomem_instruction
4882
	jmp	instruction_assembled
4883
      movq_mmreg_mmreg:
31 halyavin 4884
	call	convert_mmx_register
157 heavyiron 4885
	mov	bl,al
4886
	call	store_nomem_instruction
4887
	jmp	instruction_assembled
4888
movdq_instruction:
31 halyavin 4889
	mov	[operand_prefix],al
157 heavyiron 4890
	mov	[base_code],0Fh
4891
	mov	[extended_code],6Fh
4892
	lods	byte [esi]
4893
	call	get_size_operator
4894
	cmp	al,10h
4895
	je	movdq_mmreg
4896
	cmp	al,'['
4897
	jne	invalid_operand
4898
	call	get_address
4899
	lods	byte [esi]
4900
	cmp	al,','
4901
	jne	invalid_operand
4902
	lods	byte [esi]
4903
	call	get_size_operator
4904
	cmp	al,10h
4905
	jne	invalid_operand
4906
	lods	byte [esi]
4907
	call	convert_mmx_register
4908
	cmp	ah,16
4909
	jne	invalid_operand_size
4910
	mov	[postbyte_register],al
4911
	mov	[extended_code],7Fh
4912
	call	store_instruction
4913
	jmp	instruction_assembled
4914
      movdq_mmreg:
31 halyavin 4915
	lods	byte [esi]
157 heavyiron 4916
	call	convert_mmx_register
4917
	cmp	ah,16
4918
	jne	invalid_operand_size
4919
	mov	[postbyte_register],al
4920
	lods	byte [esi]
4921
	cmp	al,','
4922
	jne	invalid_operand
4923
	lods	byte [esi]
4924
	call	get_size_operator
4925
	cmp	al,10h
4926
	je	movdq_mmreg_mmreg
4927
	cmp	al,'['
4928
	jne	invalid_operand
4929
	call	get_address
4930
	call	store_instruction
4931
	jmp	instruction_assembled
4932
      movdq_mmreg_mmreg:
31 halyavin 4933
	lods	byte [esi]
157 heavyiron 4934
	call	convert_mmx_register
4935
	cmp	ah,16
4936
	jne	invalid_operand_size
4937
	mov	bl,al
4938
	call	store_nomem_instruction
4939
	jmp	instruction_assembled
4940
lddqu_instruction:
31 halyavin 4941
	lods	byte [esi]
157 heavyiron 4942
	call	get_size_operator
4943
	cmp	al,10h
4944
	jne	invalid_operand
4945
	lods	byte [esi]
4946
	call	convert_mmx_register
4947
	cmp	ah,16
4948
	jne	invalid_operand_size
4949
	push	eax
4950
	lods	byte [esi]
4951
	cmp	al,','
4952
	jne	invalid_operand
4953
	lods	byte [esi]
4954
	call	get_size_operator
4955
	cmp	al,'['
4956
	jne	invalid_operand
4957
	call	get_address
4958
	pop	eax
4959
	mov	[postbyte_register],al
4960
	mov	[operand_prefix],0F2h
4961
	mov	[base_code],0Fh
4962
	mov	[extended_code],0F0h
4963
	call	store_instruction
4964
	jmp	instruction_assembled
4965
movq2dq_instruction:
31 halyavin 4966
	lods	byte [esi]
157 heavyiron 4967
	call	get_size_operator
4968
	cmp	al,10h
4969
	jne	invalid_operand
4970
	lods	byte [esi]
4971
	call	convert_mmx_register
4972
	cmp	ah,16
4973
	jne	invalid_operand_size
4974
	mov	[postbyte_register],al
4975
	mov	[operand_size],0
4976
	lods	byte [esi]
4977
	cmp	al,','
4978
	jne	invalid_operand
4979
	lods	byte [esi]
4980
	call	get_size_operator
4981
	cmp	al,10h
4982
	jne	invalid_operand
4983
	lods	byte [esi]
4984
	call	convert_mmx_register
4985
	cmp	ah,8
4986
	jne	invalid_operand_size
4987
	mov	bl,al
4988
	mov	[operand_prefix],0F3h
4989
	mov	[base_code],0Fh
4990
	mov	[extended_code],0D6h
4991
	call	store_nomem_instruction
4992
	jmp	instruction_assembled
4993
movdq2q_instruction:
31 halyavin 4994
	lods	byte [esi]
157 heavyiron 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	[postbyte_register],al
5003
	mov	[operand_size],0
5004
	lods	byte [esi]
5005
	cmp	al,','
5006
	jne	invalid_operand
5007
	lods	byte [esi]
5008
	call	get_size_operator
5009
	cmp	al,10h
5010
	jne	invalid_operand
5011
	lods	byte [esi]
5012
	call	convert_mmx_register
5013
	cmp	ah,16
5014
	jne	invalid_operand_size
5015
	mov	bl,al
5016
	mov	[operand_prefix],0F2h
5017
	mov	[base_code],0Fh
5018
	mov	[extended_code],0D6h
5019
	call	store_nomem_instruction
5020
	jmp	instruction_assembled
5021
31 halyavin 5022
 
5023
	mov	[mmx_size],16
157 heavyiron 5024
	jmp	sse_instruction
5025
sse_pd_instruction:
31 halyavin 5026
	mov	[mmx_size],16
157 heavyiron 5027
	mov	[operand_prefix],66h
5028
	jmp	sse_instruction
5029
sse_ss_instruction:
31 halyavin 5030
	mov	[mmx_size],4
157 heavyiron 5031
	mov	[operand_prefix],0F3h
5032
	jmp	sse_instruction
5033
sse_sd_instruction:
31 halyavin 5034
	mov	[mmx_size],8
157 heavyiron 5035
	mov	[operand_prefix],0F2h
5036
	jmp	sse_instruction
5037
comiss_instruction:
31 halyavin 5038
	mov	[mmx_size],4
157 heavyiron 5039
	jmp	sse_instruction
5040
comisd_instruction:
31 halyavin 5041
	mov	[mmx_size],8
157 heavyiron 5042
	mov	[operand_prefix],66h
5043
	jmp	sse_instruction
5044
cvtps2pd_instruction:
31 halyavin 5045
	mov	[mmx_size],8
157 heavyiron 5046
	jmp	sse_instruction
5047
cvtpd2dq_instruction:
31 halyavin 5048
	mov	[mmx_size],16
157 heavyiron 5049
	mov	[operand_prefix],0F2h
5050
	jmp	sse_instruction
5051
cvtdq2pd_instruction:
31 halyavin 5052
	mov	[mmx_size],16
157 heavyiron 5053
	mov	[operand_prefix],0F3h
5054
sse_instruction:
31 halyavin 5055
	mov	[base_code],0Fh
157 heavyiron 5056
	mov	[extended_code],al
5057
	lods	byte [esi]
5058
	call	get_size_operator
5059
	cmp	al,10h
5060
	jne	invalid_operand
5061
      sse_xmmreg:
31 halyavin 5062
	lods	byte [esi]
157 heavyiron 5063
	call	convert_mmx_register
5064
	cmp	ah,16
5065
	jne	invalid_operand_size
5066
      sse_reg:
31 halyavin 5067
	mov	[postbyte_register],al
157 heavyiron 5068
	mov	[operand_size],0
5069
	lods	byte [esi]
5070
	cmp	al,','
5071
	jne	invalid_operand
5072
	lods	byte [esi]
5073
	call	get_size_operator
5074
	cmp	al,10h
5075
	je	sse_xmmreg_xmmreg
5076
      sse_reg_mem:
31 halyavin 5077
	cmp	al,'['
157 heavyiron 5078
	jne	invalid_operand
5079
	call	get_address
5080
	cmp	[operand_size],0
5081
	je	sse_mem_size_ok
5082
	mov	al,[mmx_size]
5083
	cmp	[operand_size],al
5084
	jne	invalid_operand_size
5085
      sse_mem_size_ok:
31 halyavin 5086
	cmp	[extended_code],0C6h
157 heavyiron 5087
	je	mmx_imm8
5088
	call	store_instruction
5089
	jmp	instruction_assembled
5090
      sse_xmmreg_xmmreg:
31 halyavin 5091
	cmp	[operand_prefix],66h
157 heavyiron 5092
	jne	sse_xmmreg_xmmreg_ok
5093
	cmp	[extended_code],12h
5094
	je	invalid_operand
5095
	cmp	[extended_code],16h
5096
	je	invalid_operand
5097
      sse_xmmreg_xmmreg_ok:
31 halyavin 5098
	lods	byte [esi]
157 heavyiron 5099
	call	convert_mmx_register
5100
	cmp	ah,16
5101
	jne	invalid_operand_size
5102
	mov	bl,al
5103
	cmp	[extended_code],0C6h
5104
	je	mmx_nomem_imm8
5105
	call	store_nomem_instruction
5106
	jmp	instruction_assembled
5107
ps_dq_instruction:
31 halyavin 5108
	mov	[postbyte_register],al
157 heavyiron 5109
	mov	[operand_prefix],66h
5110
	mov	[base_code],0Fh
5111
	mov	[extended_code],73h
5112
	lods	byte [esi]
5113
	call	get_size_operator
5114
	cmp	al,10h
5115
	jne	invalid_operand
5116
	lods	byte [esi]
5117
	call	convert_mmx_register
5118
	cmp	ah,16
5119
	jne	invalid_operand_size
5120
	mov	bl,al
5121
	jmp	mmx_nomem_imm8
5122
movpd_instruction:
31 halyavin 5123
	mov	[operand_prefix],66h
157 heavyiron 5124
movps_instruction:
31 halyavin 5125
	mov	[base_code],0Fh
157 heavyiron 5126
	mov	[extended_code],al
5127
	mov	[mmx_size],16
5128
	jmp	sse_mov_instruction
5129
movss_instruction:
31 halyavin 5130
	mov	[mmx_size],4
157 heavyiron 5131
	mov	[operand_prefix],0F3h
5132
	jmp	sse_movs
5133
movsd_instruction:
31 halyavin 5134
	mov	al,0A5h
157 heavyiron 5135
	mov	ah,[esi]
5136
	or	ah,ah
5137
	jz	simple_instruction_32bit
5138
	cmp	ah,0Fh
5139
	je	simple_instruction_32bit
5140
	mov	[mmx_size],8
5141
	mov	[operand_prefix],0F2h
5142
      sse_movs:
31 halyavin 5143
	mov	[base_code],0Fh
157 heavyiron 5144
	mov	[extended_code],10h
5145
	jmp	sse_mov_instruction
5146
sse_mov_instruction:
31 halyavin 5147
	lods	byte [esi]
157 heavyiron 5148
	call	get_size_operator
5149
	cmp	al,10h
5150
	je	sse_xmmreg
5151
      sse_mem:
31 halyavin 5152
	cmp	al,'['
157 heavyiron 5153
	jne	invalid_operand
5154
	inc	[extended_code]
5155
	call	get_address
5156
	cmp	[operand_size],0
5157
	je	sse_mem_xmmreg
5158
	mov	al,[mmx_size]
5159
	cmp	[operand_size],al
5160
	jne	invalid_operand_size
5161
	mov	[operand_size],0
5162
      sse_mem_xmmreg:
31 halyavin 5163
	lods	byte [esi]
157 heavyiron 5164
	cmp	al,','
5165
	jne	invalid_operand
5166
	lods	byte [esi]
5167
	call	get_size_operator
5168
	cmp	al,10h
5169
	jne	invalid_operand
5170
	lods	byte [esi]
5171
	call	convert_mmx_register
5172
	cmp	ah,16
5173
	jne	invalid_operand_size
5174
	mov	[postbyte_register],al
5175
	call	store_instruction
5176
	jmp	instruction_assembled
5177
movlpd_instruction:
31 halyavin 5178
	mov	[operand_prefix],66h
157 heavyiron 5179
movlps_instruction:
31 halyavin 5180
	mov	[base_code],0Fh
157 heavyiron 5181
	mov	[extended_code],al
5182
	mov	[mmx_size],8
5183
	lods	byte [esi]
5184
	call	get_size_operator
5185
	cmp	al,10h
5186
	jne	sse_mem
5187
	lods	byte [esi]
5188
	call	convert_mmx_register
5189
	cmp	ah,16
5190
	jne	invalid_operand_size
5191
	mov	[postbyte_register],al
5192
	mov	[operand_size],0
5193
	lods	byte [esi]
5194
	cmp	al,','
5195
	jne	invalid_operand
5196
	lods	byte [esi]
5197
	call	get_size_operator
5198
	jmp	sse_reg_mem
5199
movhlps_instruction:
31 halyavin 5200
	mov	[base_code],0Fh
157 heavyiron 5201
	mov	[extended_code],al
5202
	mov	[mmx_size],0
5203
	lods	byte [esi]
5204
	call	get_size_operator
5205
	cmp	al,10h
5206
	jne	invalid_operand
5207
	lods	byte [esi]
5208
	call	convert_mmx_register
5209
	cmp	ah,16
5210
	jne	invalid_operand_size
5211
	mov	[postbyte_register],al
5212
	lods	byte [esi]
5213
	cmp	al,','
5214
	jne	invalid_operand
5215
	lods	byte [esi]
5216
	call	get_size_operator
5217
	cmp	al,10h
5218
	je	sse_xmmreg_xmmreg_ok
5219
	jmp	invalid_operand
5220
maskmovq_instruction:
31 halyavin 5221
	mov	cl,8
157 heavyiron 5222
	jmp	maskmov_instruction
5223
maskmovdqu_instruction:
31 halyavin 5224
	mov	cl,16
157 heavyiron 5225
	mov	[operand_prefix],66h
5226
      maskmov_instruction:
31 halyavin 5227
	mov	[base_code],0Fh
157 heavyiron 5228
	mov	[extended_code],0F7h
5229
	lods	byte [esi]
5230
	call	get_size_operator
5231
	cmp	al,10h
5232
	jne	invalid_operand
5233
	lods	byte [esi]
5234
	call	convert_mmx_register
5235
	cmp	ah,cl
5236
	jne	invalid_operand_size
5237
	mov	[postbyte_register],al
5238
	lods	byte [esi]
5239
	cmp	al,','
5240
	jne	invalid_operand
5241
	lods	byte [esi]
5242
	call	get_size_operator
5243
	cmp	al,10h
5244
	jne	invalid_operand
5245
	lods	byte [esi]
5246
	call	convert_mmx_register
5247
	mov	bl,al
5248
	call	store_nomem_instruction
5249
	jmp	instruction_assembled
5250
movmskpd_instruction:
31 halyavin 5251
	mov	[operand_prefix],66h
157 heavyiron 5252
movmskps_instruction:
31 halyavin 5253
	mov	[base_code],0Fh
157 heavyiron 5254
	mov	[extended_code],50h
5255
	lods	byte [esi]
5256
	call	get_size_operator
5257
	cmp	al,10h
5258
	jne	invalid_operand
5259
	lods	byte [esi]
5260
	call	convert_register
5261
	cmp	ah,4
5262
	jne	invalid_operand_size
5263
	mov	[operand_size],0
5264
	mov	[postbyte_register],al
5265
	lods	byte [esi]
5266
	cmp	al,','
5267
	jne	invalid_operand
5268
	lods	byte [esi]
5269
	call	get_size_operator
5270
	cmp	al,10h
5271
	jne	invalid_operand
5272
	lods	byte [esi]
5273
	call	convert_mmx_register
5274
	cmp	ah,16
5275
	jne	invalid_operand_size
5276
	mov	bl,al
5277
	call	store_nomem_instruction
5278
	jmp	instruction_assembled
5279
cmppd_instruction:
31 halyavin 5280
	mov	[operand_prefix],66h
157 heavyiron 5281
cmpps_instruction:
31 halyavin 5282
	mov	[base_code],0Fh
157 heavyiron 5283
	mov	[extended_code],0C2h
5284
	mov	[mmx_size],16
5285
	mov	byte [value],-1
5286
	jmp	sse_cmp_instruction
5287
cmp_pd_instruction:
31 halyavin 5288
	mov	[operand_prefix],66h
157 heavyiron 5289
cmp_ps_instruction:
31 halyavin 5290
	mov	[base_code],0Fh
157 heavyiron 5291
	mov	[extended_code],0C2h
5292
	mov	[mmx_size],16
5293
	mov	byte [value],al
5294
	jmp	sse_cmp_instruction
5295
cmpss_instruction:
31 halyavin 5296
	mov	[mmx_size],4
157 heavyiron 5297
	mov	[operand_prefix],0F3h
5298
	jmp	cmpsx_instruction
5299
cmpsd_instruction:
31 halyavin 5300
	mov	al,0A7h
157 heavyiron 5301
	mov	ah,[esi]
5302
	or	ah,ah
5303
	jz	simple_instruction_32bit
5304
	cmp	ah,0Fh
5305
	je	simple_instruction_32bit
5306
	mov	[mmx_size],8
5307
	mov	[operand_prefix],0F2h
5308
      cmpsx_instruction:
31 halyavin 5309
	mov	[base_code],0Fh
157 heavyiron 5310
	mov	[extended_code],0C2h
5311
	mov	byte [value],-1
5312
	jmp	sse_cmp_instruction
5313
cmp_ss_instruction:
31 halyavin 5314
	mov	[mmx_size],4
157 heavyiron 5315
	mov	[operand_prefix],0F3h
5316
	jmp	cmp_sx_instruction
5317
cmp_sd_instruction:
31 halyavin 5318
	mov	[mmx_size],8
157 heavyiron 5319
	mov	[operand_prefix],0F2h
5320
      cmp_sx_instruction:
31 halyavin 5321
	mov	[base_code],0Fh
157 heavyiron 5322
	mov	[extended_code],0C2h
5323
	mov	byte [value],al
5324
sse_cmp_instruction:
31 halyavin 5325
	lods	byte [esi]
157 heavyiron 5326
	call	get_size_operator
5327
	cmp	al,10h
5328
	jne	invalid_operand
5329
	lods	byte [esi]
5330
	call	convert_mmx_register
5331
	cmp	ah,16
5332
	jne	invalid_operand_size
5333
	mov	[postbyte_register],al
5334
	lods	byte [esi]
5335
	cmp	al,','
5336
	jne	invalid_operand
5337
	mov	[operand_size],0
5338
	lods	byte [esi]
5339
	call	get_size_operator
5340
	cmp	al,10h
5341
	je	sse_cmp_xmmreg_xmmreg
5342
	cmp	al,'['
5343
	jne	invalid_operand
5344
	call	get_address
5345
	mov	al,[operand_size]
5346
	or	al,al
5347
	jz	sse_cmp_size_ok
5348
	cmp	al,[mmx_size]
5349
	jne	invalid_operand_size
5350
      sse_cmp_size_ok:
31 halyavin 5351
	push	ebx ecx edx
174 heavyiron 5352
	call	get_nextbyte
157 heavyiron 5353
	pop	edx ecx ebx
174 heavyiron 5354
	call	store_instruction_with_imm8
157 heavyiron 5355
	jmp	instruction_assembled
5356
      sse_cmp_xmmreg_xmmreg:
31 halyavin 5357
	lods	byte [esi]
157 heavyiron 5358
	call	convert_mmx_register
5359
	cmp	ah,16
5360
	jne	invalid_operand_size
5361
	mov	bl,al
5362
	call	store_nomem_instruction
5363
	call	get_nextbyte
5364
	mov	al,byte [value]
5365
	stos	byte [edi]
5366
	jmp	instruction_assembled
5367
      get_nextbyte:
31 halyavin 5368
	cmp	byte [value],-1
157 heavyiron 5369
	jne	nextbyte_ok
5370
	mov	[operand_size],0
5371
	lods	byte [esi]
5372
	cmp	al,','
5373
	jne	invalid_operand
5374
	lods	byte [esi]
5375
	call	get_size_operator
5376
	test	[operand_size],not 1
5377
	jnz	invalid_value
5378
	cmp	al,'('
5379
	jne	invalid_operand
5380
	call	get_byte_value
5381
	cmp	al,7
5382
	ja	invalid_value
5383
	mov	byte [value],al
5384
      nextbyte_ok:
31 halyavin 5385
	ret
157 heavyiron 5386
cvtpi2pd_instruction:
31 halyavin 5387
	mov	[operand_prefix],66h
157 heavyiron 5388
cvtpi2ps_instruction:
31 halyavin 5389
	mov	[base_code],0Fh
157 heavyiron 5390
	mov	[extended_code],al
5391
	lods	byte [esi]
5392
	call	get_size_operator
5393
	cmp	al,10h
5394
	jne	invalid_operand
5395
	lods	byte [esi]
5396
	call	convert_mmx_register
5397
	cmp	ah,16
5398
	jne	invalid_operand_size
5399
	mov	[postbyte_register],al
5400
	mov	[operand_size],0
5401
	lods	byte [esi]
5402
	cmp	al,','
5403
	jne	invalid_operand
5404
	lods	byte [esi]
5405
	call	get_size_operator
5406
	cmp	al,10h
5407
	je	cvtpi_xmmreg_xmmreg
5408
	cmp	al,'['
5409
	jne	invalid_operand
5410
	call	get_address
5411
	cmp	[operand_size],0
5412
	je	cvtpi_size_ok
5413
	cmp	[operand_size],8
5414
	jne	invalid_operand_size
5415
      cvtpi_size_ok:
31 halyavin 5416
	call	store_instruction
157 heavyiron 5417
	jmp	instruction_assembled
5418
      cvtpi_xmmreg_xmmreg:
31 halyavin 5419
	lods	byte [esi]
157 heavyiron 5420
	call	convert_mmx_register
5421
	cmp	ah,8
5422
	jne	invalid_operand_size
5423
	mov	bl,al
5424
	call	store_nomem_instruction
5425
	jmp	instruction_assembled
5426
cvtsi2ss_instruction:
31 halyavin 5427
	mov	[operand_prefix],0F3h
157 heavyiron 5428
	jmp	cvtsi_instruction
5429
cvtsi2sd_instruction:
31 halyavin 5430
	mov	[operand_prefix],0F2h
157 heavyiron 5431
      cvtsi_instruction:
31 halyavin 5432
	mov	[base_code],0Fh
157 heavyiron 5433
	mov	[extended_code],al
5434
	lods	byte [esi]
5435
	call	get_size_operator
5436
	cmp	al,10h
5437
	jne	invalid_operand
5438
	lods	byte [esi]
5439
	call	convert_mmx_register
5440
	cmp	ah,16
5441
	jne	invalid_operand_size
5442
	mov	[postbyte_register],al
5443
	mov	[operand_size],0
5444
	lods	byte [esi]
5445
	cmp	al,','
5446
	jne	invalid_operand
5447
	lods	byte [esi]
5448
	call	get_size_operator
5449
	cmp	al,10h
5450
	je	cvtsi_xmmreg_reg
5451
	cmp	al,'['
5452
	jne	invalid_operand
5453
	call	get_address
5454
	cmp	[operand_size],0
5455
	je	cvtsi_size_ok
5456
	cmp	[operand_size],4
5457
	jne	invalid_operand_size
5458
      cvtsi_size_ok:
31 halyavin 5459
	call	store_instruction
157 heavyiron 5460
	jmp	instruction_assembled
5461
      cvtsi_xmmreg_reg:
31 halyavin 5462
	lods	byte [esi]
157 heavyiron 5463
	call	convert_register
5464
	cmp	ah,4
5465
	je	cvtsi_xmmreg_reg_store
5466
	cmp	ah,8
5467
	jne	invalid_operand_size
5468
	call	operand_64bit
5469
      cvtsi_xmmreg_reg_store:
31 halyavin 5470
	mov	bl,al
157 heavyiron 5471
	call	store_nomem_instruction
5472
	jmp	instruction_assembled
5473
cvtps2pi_instruction:
31 halyavin 5474
	mov	[mmx_size],8
157 heavyiron 5475
	jmp	cvtpd_instruction
5476
cvtpd2pi_instruction:
31 halyavin 5477
	mov	[operand_prefix],66h
157 heavyiron 5478
	mov	[mmx_size],16
5479
      cvtpd_instruction:
31 halyavin 5480
	mov	[base_code],0Fh
157 heavyiron 5481
	mov	[extended_code],al
5482
	lods	byte [esi]
5483
	call	get_size_operator
5484
	cmp	al,10h
5485
	jne	invalid_operand
5486
	lods	byte [esi]
5487
	call	convert_mmx_register
5488
	cmp	ah,8
5489
	jne	invalid_operand_size
5490
	mov	[operand_size],0
5491
	jmp	sse_reg
5492
cvtss2si_instruction:
31 halyavin 5493
	mov	[operand_prefix],0F3h
157 heavyiron 5494
	mov	[mmx_size],4
5495
	jmp	cvt2si_instruction
5496
cvtsd2si_instruction:
31 halyavin 5497
	mov	[operand_prefix],0F2h
157 heavyiron 5498
	mov	[mmx_size],8
5499
      cvt2si_instruction:
31 halyavin 5500
	mov	[extended_code],al
157 heavyiron 5501
	mov	[base_code],0Fh
5502
	lods	byte [esi]
5503
	call	get_size_operator
5504
	cmp	al,10h
5505
	jne	invalid_operand
5506
	lods	byte [esi]
5507
	call	convert_register
5508
	mov	[operand_size],0
5509
	cmp	ah,4
5510
	je	sse_reg
5511
	cmp	ah,8
5512
	jne	invalid_operand_size
5513
	call	operand_64bit
5514
	jmp	sse_reg
5515
174 heavyiron 5516
 
5517
	mov	[base_code],0Fh
5518
	mov	[extended_code],38h
5519
	mov	[supplemental_code],al
5520
	jmp	mmx_instruction
5521
palignr_instruction:
5522
	mov	[base_code],0Fh
5523
	mov	[extended_code],3Ah
5524
	mov	[supplemental_code],0Fh
5525
	lods	byte [esi]
5526
	call	get_size_operator
5527
	cmp	al,10h
5528
	jne	invalid_operand
5529
	lods	byte [esi]
5530
	call	convert_mmx_register
5531
	call	make_mmx_prefix
5532
	mov	[postbyte_register],al
5533
	lods	byte [esi]
5534
	cmp	al,','
5535
	jne	invalid_operand
5536
	lods	byte [esi]
5537
	call	get_size_operator
5538
	cmp	al,10h
5539
	je	palignr_mmreg_mmreg
5540
	cmp	al,'['
5541
	jne	invalid_operand
5542
	call	get_address
5543
	jmp	mmx_imm8
5544
      palignr_mmreg_mmreg:
5545
	lods	byte [esi]
5546
	call	convert_mmx_register
5547
	mov	bl,al
5548
	jmp	mmx_nomem_imm8
5549
amd3dnow_instruction:
31 halyavin 5550
	mov	[base_code],0Fh
157 heavyiron 5551
	mov	[extended_code],0Fh
5552
	mov	byte [value],al
5553
	lods	byte [esi]
5554
	call	get_size_operator
5555
	cmp	al,10h
5556
	jne	invalid_operand
5557
	lods	byte [esi]
5558
	call	convert_mmx_register
5559
	cmp	ah,8
5560
	jne	invalid_operand_size
5561
	mov	[postbyte_register],al
5562
	lods	byte [esi]
5563
	cmp	al,','
5564
	jne	invalid_operand
5565
	lods	byte [esi]
5566
	call	get_size_operator
5567
	cmp	al,10h
5568
	je	amd3dnow_mmreg_mmreg
5569
	cmp	al,'['
5570
	jne	invalid_operand
5571
	call	get_address
5572
	call	store_instruction_with_imm8
5573
	jmp	instruction_assembled
5574
      amd3dnow_mmreg_mmreg:
31 halyavin 5575
	lods	byte [esi]
157 heavyiron 5576
	call	convert_mmx_register
5577
	cmp	ah,8
5578
	jne	invalid_operand_size
5579
	mov	bl,al
5580
	call	store_nomem_instruction
5581
	mov	al,byte [value]
5582
	stos	byte [edi]
5583
	jmp	instruction_assembled
5584
31 halyavin 5585
 
5586
	mov	[extended_code],0AEh
157 heavyiron 5587
	mov	[base_code],0Fh
5588
	mov	[postbyte_register],al
5589
	lods	byte [esi]
5590
	call	get_size_operator
5591
	cmp	al,'['
5592
	jne	invalid_operand
5593
	call	get_address
5594
	mov	ah,[operand_size]
5595
	or	ah,ah
5596
	jz	fxsave_size_ok
5597
	mov	al,[postbyte_register]
5598
	cmp	al,111b
5599
	je	clflush_size_check
5600
	cmp	al,10b
5601
	jb	invalid_operand_size
5602
	cmp	al,11b
5603
	ja	invalid_operand_size
5604
	cmp	ah,4
5605
	jne	invalid_operand_size
5606
	jmp	fxsave_size_ok
5607
      clflush_size_check:
31 halyavin 5608
	cmp	ah,1
157 heavyiron 5609
	jne	invalid_operand_size
5610
      fxsave_size_ok:
31 halyavin 5611
	call	store_instruction
157 heavyiron 5612
	jmp	instruction_assembled
5613
prefetch_instruction:
31 halyavin 5614
	mov	[extended_code],18h
157 heavyiron 5615
      prefetch_mem_8bit:
31 halyavin 5616
	mov	[base_code],0Fh
157 heavyiron 5617
	mov	[postbyte_register],al
5618
	lods	byte [esi]
5619
	call	get_size_operator
5620
	cmp	al,'['
5621
	jne	invalid_operand
5622
	or	ah,ah
5623
	jz	prefetch_size_ok
5624
	cmp	ah,1
5625
	jne	invalid_operand_size
5626
      prefetch_size_ok:
31 halyavin 5627
	call	get_address
157 heavyiron 5628
	call	store_instruction
5629
	jmp	instruction_assembled
5630
amd_prefetch_instruction:
31 halyavin 5631
	mov	[extended_code],0Dh
157 heavyiron 5632
	jmp	prefetch_mem_8bit
5633
fence_instruction:
31 halyavin 5634
	mov	bl,al
157 heavyiron 5635
	mov	ax,0AE0Fh
5636
	stos	word [edi]
5637
	mov	al,bl
5638
	stos	byte [edi]
5639
	jmp	instruction_assembled
5640
pause_instruction:
31 halyavin 5641
	mov	ax,90F3h
157 heavyiron 5642
	stos	word [edi]
5643
	jmp	instruction_assembled
5644
movntq_instruction:
31 halyavin 5645
	mov	[mmx_size],8
157 heavyiron 5646
	jmp	movnt_instruction
5647
movntps_instruction:
31 halyavin 5648
	mov	[mmx_size],16
157 heavyiron 5649
	jmp	movnt_instruction
5650
movntdq_instruction:
31 halyavin 5651
	mov	[operand_prefix],66h
157 heavyiron 5652
	mov	[mmx_size],16
5653
      movnt_instruction:
31 halyavin 5654
	mov	[extended_code],al
157 heavyiron 5655
	mov	[base_code],0Fh
5656
	lods	byte [esi]
5657
	call	get_size_operator
5658
	cmp	al,'['
5659
	jne	invalid_operand
5660
	call	get_address
5661
	lods	byte [esi]
5662
	cmp	al,','
5663
	jne	invalid_operand
5664
	lods	byte [esi]
5665
	call	get_size_operator
5666
	cmp	al,10h
5667
	jne	invalid_operand
5668
	lods	byte [esi]
5669
	call	convert_mmx_register
5670
	cmp	ah,[mmx_size]
5671
	jne	invalid_operand_size
5672
	mov	[postbyte_register],al
5673
	call	store_instruction
5674
	jmp	instruction_assembled
5675
movnti_instruction:
31 halyavin 5676
	mov	[base_code],0Fh
157 heavyiron 5677
	mov	[extended_code],al
5678
	lods	byte [esi]
5679
	call	get_size_operator
5680
	cmp	al,'['
5681
	jne	invalid_operand
5682
	call	get_address
5683
	lods	byte [esi]
5684
	cmp	al,','
5685
	jne	invalid_operand
5686
	lods	byte [esi]
5687
	call	get_size_operator
5688
	cmp	al,10h
5689
	jne	invalid_operand
5690
	lods	byte [esi]
5691
	call	convert_register
5692
	cmp	ah,4
5693
	je	movnti_store
5694
	cmp	ah,8
5695
	jne	invalid_operand_size
5696
	call	operand_64bit
5697
      movnti_store:
31 halyavin 5698
	mov	[postbyte_register],al
157 heavyiron 5699
	call	store_instruction
5700
	jmp	instruction_assembled
5701
monitor_instruction:
31 halyavin 5702
	mov	[postbyte_register],al
157 heavyiron 5703
	lods	byte [esi]
5704
	call	get_size_operator
5705
	cmp	al,10h
5706
	jne	invalid_operand
5707
	lods	byte [esi]
5708
	call	convert_register
5709
	cmp	ax,0400h
5710
	jne	invalid_operand
5711
	lods	byte [esi]
5712
	cmp	al,','
5713
	jne	invalid_operand
5714
	lods	byte [esi]
5715
	call	get_size_operator
5716
	cmp	al,10h
5717
	jne	invalid_operand
5718
	lods	byte [esi]
5719
	call	convert_register
5720
	cmp	ax,0401h
5721
	jne	invalid_operand
5722
	cmp	[postbyte_register],0C8h
5723
	jne	monitor_instruction_store
5724
	lods	byte [esi]
5725
	cmp	al,','
5726
	jne	invalid_operand
5727
	lods	byte [esi]
5728
	call	get_size_operator
5729
	cmp	al,10h
5730
	jne	invalid_operand
5731
	lods	byte [esi]
5732
	call	convert_register
5733
	cmp	ax,0402h
5734
	jne	invalid_operand
5735
      monitor_instruction_store:
31 halyavin 5736
	mov	ax,010Fh
157 heavyiron 5737
	stos	word [edi]
5738
	mov	al,[postbyte_register]
5739
	stos	byte [edi]
5740
	jmp	instruction_assembled
5741
31 halyavin 5742
 
5743
	mov	ah,al
157 heavyiron 5744
	mov	al,0Fh
5745
	stos	byte [edi]
5746
	mov	al,1
5747
	stos	word [edi]
5748
	jmp	instruction_assembled
5749
vmclear_instruction:
31 halyavin 5750
	mov	[operand_prefix],66h
157 heavyiron 5751
	jmp	vmx_instruction
5752
vmxon_instruction:
31 halyavin 5753
	mov	[operand_prefix],0F3h
157 heavyiron 5754
vmx_instruction:
31 halyavin 5755
	mov	[postbyte_register],al
157 heavyiron 5756
	mov	[extended_code],0C7h
5757
	lods	byte [esi]
5758
	call	get_size_operator
5759
	cmp	al,'['
5760
	jne	invalid_operand
5761
	call	get_address
5762
	mov	al,[operand_size]
5763
	or	al,al
5764
	jz	vmx_size_ok
5765
	cmp	al,8
5766
	jne	invalid_operand_size
5767
      vmx_size_ok:
31 halyavin 5768
	mov	[base_code],0Fh
157 heavyiron 5769
	call	store_instruction
5770
	jmp	instruction_assembled
5771
vmread_instruction:
31 halyavin 5772
	mov	[extended_code],78h
157 heavyiron 5773
	lods	byte [esi]
5774
	call	get_size_operator
5775
	cmp	al,'['
5776
	jne	invalid_operand
5777
	call	get_address
5778
	lods	byte [esi]
5779
	cmp	al,','
5780
	jne	invalid_operand
5781
	lods	byte [esi]
5782
	call	get_size_operator
5783
	cmp	al,10h
5784
	jne	invalid_operand
5785
	lods	byte [esi]
5786
	call	convert_register
5787
	mov	[postbyte_register],al
5788
      vmread_check_size:
31 halyavin 5789
	cmp	[code_type],64
157 heavyiron 5790
	je	vmread_long
5791
	cmp	[operand_size],4
5792
	je	vmx_size_ok
5793
	jmp	invalid_operand_size
5794
      vmread_long:
31 halyavin 5795
	cmp	[operand_size],8
157 heavyiron 5796
	je	vmx_size_ok
5797
	jmp	invalid_operand_size
5798
vmwrite_instruction:
31 halyavin 5799
	mov	[extended_code],79h
157 heavyiron 5800
	lods	byte [esi]
5801
	call	get_size_operator
5802
	cmp	al,10h
5803
	jne	invalid_operand
5804
	lods	byte [esi]
5805
	call	convert_register
5806
	mov	[postbyte_register],al
5807
	lods	byte [esi]
5808
	cmp	al,','
5809
	jne	invalid_operand
5810
	lods	byte [esi]
5811
	call	get_size_operator
5812
	cmp	al,'['
5813
	jne	invalid_operand
5814
	call	get_address
5815
	jmp	vmread_check_size
5816
simple_svm_instruction:
109 heavyiron 5817
	push	eax
157 heavyiron 5818
	mov	[base_code],0Fh
5819
	mov	[extended_code],1
5820
	lods	byte [esi]
5821
	call	get_size_operator
5822
	cmp	al,10h
5823
	jne	invalid_operand
5824
	lods	byte [esi]
5825
	call	convert_register
5826
	or	al,al
5827
	jnz	invalid_operand
5828
      simple_svm_detect_size:
109 heavyiron 5829
	cmp	ah,2
157 heavyiron 5830
	je	simple_svm_16bit
5831
	cmp	ah,4
5832
	je	simple_svm_32bit
5833
	cmp	[code_type],64
5834
	jne	invalid_operand_size
5835
	jmp	simple_svm_store
5836
      simple_svm_16bit:
109 heavyiron 5837
	cmp	[code_type],16
157 heavyiron 5838
	je	simple_svm_store
5839
	cmp	[code_type],64
5840
	je	invalid_operand_size
5841
	jmp	prefixed_svm_store
5842
      simple_svm_32bit:
109 heavyiron 5843
	cmp	[code_type],32
157 heavyiron 5844
	je	simple_svm_store
5845
      prefixed_svm_store:
109 heavyiron 5846
	mov	al,67h
157 heavyiron 5847
	stos	byte [edi]
5848
      simple_svm_store:
109 heavyiron 5849
	call	store_instruction_code
157 heavyiron 5850
	pop	eax
5851
	stos	byte [edi]
5852
	jmp	instruction_assembled
5853
skinit_instruction:
109 heavyiron 5854
	lods	byte [esi]
157 heavyiron 5855
	call	get_size_operator
5856
	cmp	al,10h
5857
	jne	invalid_operand
5858
	lods	byte [esi]
5859
	call	convert_register
5860
	cmp	ax,0400h
5861
	jne	invalid_operand
5862
	mov	al,0DEh
5863
	jmp	simple_vmx_instruction
5864
invlpga_instruction:
109 heavyiron 5865
	push	eax
157 heavyiron 5866
	mov	[base_code],0Fh
5867
	mov	[extended_code],1
5868
	lods	byte [esi]
5869
	call	get_size_operator
5870
	cmp	al,10h
5871
	jne	invalid_operand
5872
	lods	byte [esi]
5873
	call	convert_register
5874
	or	al,al
5875
	jnz	invalid_operand
5876
	mov	bl,ah
5877
	mov	[operand_size],0
5878
	lods	byte [esi]
5879
	cmp	al,','
5880
	jne	invalid_operand
5881
	lods	byte [esi]
5882
	call	get_size_operator
5883
	cmp	al,10h
5884
	jne	invalid_operand
5885
	lods	byte [esi]
5886
	call	convert_register
5887
	cmp	ax,0401h
5888
	jne	invalid_operand
5889
	mov	ah,bl
5890
	jmp	simple_svm_detect_size
5891
31 halyavin 5892
 
5893
	mov	ah,al
157 heavyiron 5894
	shr	ah,4
5895
	and	al,0Fh
5896
	cmp	ah,8
5897
	je	match_register_size
5898
	cmp	ah,4
5899
	ja	invalid_operand
5900
	cmp	ah,1
5901
	ja	match_register_size
5902
	cmp	al,4
5903
	jb	match_register_size
5904
	or	ah,ah
5905
	jz	high_byte_register
5906
	or	[rex_prefix],40h
5907
      match_register_size:
31 halyavin 5908
	cmp	ah,[operand_size]
157 heavyiron 5909
	je	register_size_ok
5910
	cmp	[operand_size],0
5911
	jne	operand_sizes_do_not_match
5912
	mov	[operand_size],ah
5913
      register_size_ok:
31 halyavin 5914
	ret
157 heavyiron 5915
      high_byte_register:
31 halyavin 5916
	mov	ah,1
157 heavyiron 5917
	or	[rex_prefix],80h
5918
	jmp	match_register_size
5919
convert_fpu_register:
31 halyavin 5920
	mov	ah,al
157 heavyiron 5921
	shr	ah,4
5922
	and	al,111b
5923
	cmp	ah,10
5924
	jne	invalid_operand
5925
	jmp	match_register_size
5926
convert_mmx_register:
31 halyavin 5927
	mov	ah,al
157 heavyiron 5928
	shr	ah,4
5929
	cmp	ah,0Ch
5930
	je	xmm_register
5931
	ja	invalid_operand
5932
	and	al,111b
5933
	cmp	ah,0Bh
5934
	jne	invalid_operand
5935
	mov	ah,8
5936
	jmp	match_register_size
5937
      xmm_register:
31 halyavin 5938
	and	al,0Fh
157 heavyiron 5939
	mov	ah,16
5940
	cmp	al,8
5941
	jb	match_register_size
5942
	cmp	[code_type],64
5943
	jne	invalid_operand
5944
	jmp	match_register_size
5945
get_size_operator:
31 halyavin 5946
	xor	ah,ah
157 heavyiron 5947
	cmp	al,11h
5948
	jne	no_size_operator
5949
	mov	[size_declared],1
5950
	lods	word [esi]
5951
	xchg	al,ah
5952
	mov	[size_override],1
5953
	cmp	ah,[operand_size]
5954
	je	size_operator_ok
5955
	cmp	[operand_size],0
5956
	jne	operand_sizes_do_not_match
5957
	mov	[operand_size],ah
5958
      size_operator_ok:
31 halyavin 5959
	ret
157 heavyiron 5960
      no_size_operator:
31 halyavin 5961
	mov	[size_declared],0
157 heavyiron 5962
	cmp	al,'['
5963
	jne	size_operator_ok
5964
	mov	[size_override],0
5965
	ret
5966
get_jump_operator:
31 halyavin 5967
	mov	[jump_type],0
157 heavyiron 5968
	cmp	al,12h
5969
	jne	jump_operator_ok
5970
	lods	word [esi]
5971
	mov	[jump_type],al
5972
	mov	al,ah
5973
      jump_operator_ok:
31 halyavin 5974
	ret
157 heavyiron 5975
get_address:
31 halyavin 5976
	mov	[segment_register],0
157 heavyiron 5977
	mov	[address_size],0
5978
	mov	al,[code_type]
5979
	shr	al,3
5980
	mov	[value_size],al
5981
	mov	al,[esi]
5982
	and	al,11110000b
5983
	cmp	al,60h
5984
	jne	get_size_prefix
5985
	lods	byte [esi]
5986
	sub	al,60h
5987
	mov	[segment_register],al
5988
	mov	al,[esi]
5989
	and	al,11110000b
5990
      get_size_prefix:
31 halyavin 5991
	cmp	al,70h
157 heavyiron 5992
	jne	address_size_prefix_ok
5993
	lods	byte [esi]
5994
	sub	al,70h
5995
	cmp	al,2
5996
	jb	invalid_address_size
5997
	cmp	al,8
5998
	ja	invalid_address_size
5999
	mov	[address_size],al
6000
	mov	[value_size],al
6001
      address_size_prefix_ok:
31 halyavin 6002
	call	calculate_address
157 heavyiron 6003
	cmp	byte [esi-1],']'
6004
	jne	invalid_address
6005
	mov	[address_high],edx
6006
	mov	edx,eax
6007
	cmp	[code_type],64
6008
	jne	address_ok
6009
	or	bx,bx
6010
	jnz	address_ok
6011
	test	ch,0Fh
6012
	jnz	address_ok
6013
      calculate_relative_address:
31 halyavin 6014
	mov	edx,[address_symbol]
196 heavyiron 6015
	mov	[symbol_identifier],edx
6016
	mov	edx,[address_high]
176 heavyiron 6017
	call	calculate_relative_offset
157 heavyiron 6018
	mov	[address_high],edx
6019
	cdq
176 heavyiron 6020
	cmp	edx,[address_high]
6021
	jne	value_out_of_range
6022
	mov	edx,[symbol_identifier]
157 heavyiron 6023
	mov	[address_symbol],edx
6024
	mov	edx,eax
6025
	ror	ecx,16
205 heavyiron 6026
	mov	cl,[value_type]
6027
	rol	ecx,16
6028
	mov	bx,0FF00h
157 heavyiron 6029
      address_ok:
31 halyavin 6030
	ret
157 heavyiron 6031
operand_16bit:
31 halyavin 6032
	cmp	[code_type],16
157 heavyiron 6033
	je	size_prefix_ok
6034
	mov	[operand_prefix],66h
6035
	ret
6036
operand_32bit:
31 halyavin 6037
	cmp	[code_type],16
157 heavyiron 6038
	jne	size_prefix_ok
6039
	mov	[operand_prefix],66h
6040
      size_prefix_ok:
31 halyavin 6041
	ret
157 heavyiron 6042
operand_64bit:
31 halyavin 6043
	cmp	[code_type],64
157 heavyiron 6044
	jne	illegal_instruction
6045
	or	[rex_prefix],48h
6046
	ret
6047
operand_autodetect:
31 halyavin 6048
	cmp	al,2
157 heavyiron 6049
	je	operand_16bit
6050
	cmp	al,4
6051
	je	operand_32bit
6052
	cmp	al,8
6053
	je	operand_64bit
6054
	jmp	invalid_operand_size
6055
store_segment_prefix_if_necessary:
31 halyavin 6056
	mov	al,[segment_register]
157 heavyiron 6057
	or	al,al
6058
	jz	segment_prefix_ok
6059
	cmp	al,3
6060
	je	ss_prefix
6061
	cmp	al,4
6062
	ja	segment_prefix_386
6063
	jb	segment_prefix_86
6064
	cmp	bl,25h
6065
	je	segment_prefix_86
6066
	cmp	bh,25h
6067
	je	segment_prefix_86
6068
	cmp	bh,45h
6069
	je	segment_prefix_86
6070
	cmp	bh,44h
6071
	je	segment_prefix_86
6072
	ret
6073
      ss_prefix:
31 halyavin 6074
	cmp	bl,25h
157 heavyiron 6075
	je	segment_prefix_ok
6076
	cmp	bh,25h
6077
	je	segment_prefix_ok
6078
	cmp	bh,45h
6079
	je	segment_prefix_ok
6080
	cmp	bh,44h
6081
	je	segment_prefix_ok
6082
	jmp	segment_prefix_86
6083
store_segment_prefix:
31 halyavin 6084
	mov	al,[segment_register]
157 heavyiron 6085
	or	al,al
6086
	jz	segment_prefix_ok
6087
	cmp	al,5
6088
	jae	segment_prefix_386
6089
      segment_prefix_86:
31 halyavin 6090
	dec	al
157 heavyiron 6091
	shl	al,3
6092
	add	al,26h
6093
	stos	byte [edi]
6094
	jmp	segment_prefix_ok
6095
      segment_prefix_386:
31 halyavin 6096
	add	al,64h-5
157 heavyiron 6097
	stos	byte [edi]
6098
      segment_prefix_ok:
31 halyavin 6099
	ret
157 heavyiron 6100
store_instruction_code:
31 halyavin 6101
	mov	al,[operand_prefix]
157 heavyiron 6102
	or	al,al
6103
	jz	operand_prefix_ok
6104
	stos	byte [edi]
6105
      operand_prefix_ok:
31 halyavin 6106
	mov	al,[rex_prefix]
157 heavyiron 6107
	test	al,40h
6108
	jz	rex_prefix_ok
6109
	cmp	[code_type],64
6110
	jne	invalid_operand
6111
	test	al,0B0h
6112
	jnz	prefix_conflict
6113
	stos	byte [edi]
6114
      rex_prefix_ok:
31 halyavin 6115
	mov	al,[base_code]
157 heavyiron 6116
	stos	byte [edi]
6117
	cmp	al,0Fh
6118
	jne	instruction_code_ok
6119
      store_extended_code:
31 halyavin 6120
	mov	al,[extended_code]
157 heavyiron 6121
	stos	byte [edi]
6122
	cmp	al,38h
174 heavyiron 6123
	je	store_supplemental_code
6124
	cmp	al,3Ah
6125
	je	store_supplemental_code
6126
      instruction_code_ok:
31 halyavin 6127
	ret
157 heavyiron 6128
      store_supplemental_code:
174 heavyiron 6129
	mov	al,[supplemental_code]
6130
	stos	byte [edi]
6131
	ret
6132
store_nomem_instruction:
31 halyavin 6133
	test	[postbyte_register],1000b
157 heavyiron 6134
	jz	nomem_reg_code_ok
6135
	or	[rex_prefix],44h
6136
	and	[postbyte_register],111b
6137
      nomem_reg_code_ok:
31 halyavin 6138
	test	bl,1000b
157 heavyiron 6139
	jz	nomem_rm_code_ok
6140
	or	[rex_prefix],41h
6141
	and	bl,111b
6142
      nomem_rm_code_ok:
31 halyavin 6143
	call	store_instruction_code
157 heavyiron 6144
	mov	al,[postbyte_register]
6145
	shl	al,3
6146
	or	al,bl
6147
	or	al,11000000b
6148
	stos	byte [edi]
6149
	ret
6150
store_instruction:
31 halyavin 6151
	mov	[current_offset],edi
157 heavyiron 6152
	test	[postbyte_register],1000b
6153
	jz	reg_code_ok
6154
	or	[rex_prefix],44h
6155
	and	[postbyte_register],111b
6156
      reg_code_ok:
31 halyavin 6157
	call	store_segment_prefix_if_necessary
157 heavyiron 6158
	or	bx,bx
6159
	jz	address_immediate
6160
	cmp	bx,0F800h
176 heavyiron 6161
	je	address_rip_based
157 heavyiron 6162
	cmp	bx,0F400h
176 heavyiron 6163
	je	address_eip_based
6164
	cmp	bx,0FF00h
157 heavyiron 6165
	je	address_relative
6166
	mov	al,bl
6167
	or	al,bh
6168
	and	al,11110000b
6169
	cmp	al,80h
6170
	je	postbyte_64bit
6171
	cmp	al,40h
6172
	je	postbyte_32bit
6173
	cmp	al,20h
6174
	jne	invalid_address
6175
	cmp	[code_type],64
6176
	je	invalid_address_size
6177
	call	address_16bit_prefix
6178
	call	store_instruction_code
6179
	cmp	bx,2326h
6180
	je	address_bx_si
6181
	cmp	bx,2623h
6182
	je	address_bx_si
6183
	cmp	bx,2327h
6184
	je	address_bx_di
6185
	cmp	bx,2723h
6186
	je	address_bx_di
6187
	cmp	bx,2526h
6188
	je	address_bp_si
6189
	cmp	bx,2625h
6190
	je	address_bp_si
6191
	cmp	bx,2527h
6192
	je	address_bp_di
6193
	cmp	bx,2725h
6194
	je	address_bp_di
6195
	cmp	bx,2600h
6196
	je	address_si
6197
	cmp	bx,2700h
6198
	je	address_di
6199
	cmp	bx,2300h
6200
	je	address_bx
6201
	cmp	bx,2500h
6202
	je	address_bp
6203
	jmp	invalid_address
6204
      address_bx_si:
31 halyavin 6205
	xor	al,al
157 heavyiron 6206
	jmp	postbyte_16bit
6207
      address_bx_di:
31 halyavin 6208
	mov	al,1
157 heavyiron 6209
	jmp	postbyte_16bit
6210
      address_bp_si:
31 halyavin 6211
	mov	al,10b
157 heavyiron 6212
	jmp	postbyte_16bit
6213
      address_bp_di:
31 halyavin 6214
	mov	al,11b
157 heavyiron 6215
	jmp	postbyte_16bit
6216
      address_si:
31 halyavin 6217
	mov	al,100b
157 heavyiron 6218
	jmp	postbyte_16bit
6219
      address_di:
31 halyavin 6220
	mov	al,101b
157 heavyiron 6221
	jmp	postbyte_16bit
6222
      address_bx:
31 halyavin 6223
	mov	al,111b
157 heavyiron 6224
	jmp	postbyte_16bit
6225
      address_bp:
31 halyavin 6226
	mov	al,110b
157 heavyiron 6227
      postbyte_16bit:
31 halyavin 6228
	test	ch,22h
157 heavyiron 6229
	jnz	address_16bit_value
6230
	or	ch,ch
6231
	jnz	address_sizes_do_not_agree
6232
	cmp	edx,10000h
6233
	jge	value_out_of_range
6234
	cmp	edx,-8000h
6235
	jl	value_out_of_range
6236
	or	dx,dx
6237
	jz	address
6238
	cmp	dx,80h
6239
	jb	address_8bit_value
6240
	cmp	dx,-80h
6241
	jae	address_8bit_value
6242
      address_16bit_value:
31 halyavin 6243
	or	al,10000000b
157 heavyiron 6244
	mov	cl,[postbyte_register]
6245
	shl	cl,3
6246
	or	al,cl
6247
	stos	byte [edi]
6248
	mov	eax,edx
6249
	stos	word [edi]
6250
	ret
6251
      address_8bit_value:
31 halyavin 6252
	or	al,01000000b
157 heavyiron 6253
	mov	cl,[postbyte_register]
6254
	shl	cl,3
6255
	or	al,cl
6256
	stos	byte [edi]
6257
	mov	al,dl
6258
	stos	byte [edi]
6259
	cmp	dx,80h
6260
	jge	value_out_of_range
6261
	cmp	dx,-80h
6262
	jl	value_out_of_range
6263
	ret
6264
      address:
31 halyavin 6265
	cmp	al,110b
157 heavyiron 6266
	je	address_8bit_value
6267
	mov	cl,[postbyte_register]
6268
	shl	cl,3
6269
	or	al,cl
6270
	stos	byte [edi]
6271
	ret
6272
      postbyte_32bit:
31 halyavin 6273
	call	address_32bit_prefix
157 heavyiron 6274
	jmp	address_prefix_ok
6275
      postbyte_64bit:
31 halyavin 6276
	cmp	[code_type],64
157 heavyiron 6277
	jne	invalid_address_size
6278
      address_prefix_ok:
109 heavyiron 6279
	test	bh,1000b
157 heavyiron 6280
	jz	base_code_ok
6281
	or	[rex_prefix],41h
6282
      base_code_ok:
31 halyavin 6283
	test	bl,1000b
157 heavyiron 6284
	jz	index_code_ok
6285
	or	[rex_prefix],42h
6286
      index_code_ok:
31 halyavin 6287
	call	store_instruction_code
157 heavyiron 6288
	cmp	bl,44h
6289
	je	swap_base_with_index
6290
	cmp	bl,84h
6291
	jne	base_register_ok
6292
      swap_base_with_index:
109 heavyiron 6293
	cmp	cl,1
157 heavyiron 6294
	jne	invalid_address
6295
	xchg	bl,bh
6296
	cmp	bl,44h
6297
	je	invalid_address
6298
	cmp	bl,84h
6299
	je	invalid_address
6300
      base_register_ok:
109 heavyiron 6301
	or	cl,cl
157 heavyiron 6302
	jz	only_base_register
6303
      base_and_index:
31 halyavin 6304
	mov	al,100b
157 heavyiron 6305
	xor	ah,ah
6306
	cmp	cl,1
6307
	je	scale_ok
6308
	cmp	cl,2
6309
	je	scale_1
6310
	cmp	cl,4
6311
	je	scale_2
6312
	or	ah,11000000b
6313
	jmp	scale_ok
6314
      scale_2:
31 halyavin 6315
	or	ah,10000000b
157 heavyiron 6316
	jmp	scale_ok
6317
      scale_1:
31 halyavin 6318
	or	ah,01000000b
157 heavyiron 6319
      scale_ok:
31 halyavin 6320
	or	bh,bh
157 heavyiron 6321
	jz	only_index_register
6322
	and	bl,111b
6323
	shl	bl,3
6324
	or	ah,bl
6325
	and	bh,111b
6326
	or	ah,bh
6327
	test	ch,44h
6328
	jnz	sib_address_32bit_value
6329
	test	ch,88h
6330
	jnz	sib_address_32bit_value
6331
	or	ch,ch
6332
	jnz	address_sizes_do_not_agree
6333
	cmp	bh,5
6334
	je	address_value
6335
	or	edx,edx
6336
	jz	sib_address
6337
      address_value:
31 halyavin 6338
	cmp	edx,80h
157 heavyiron 6339
	jb	sib_address_8bit_value
6340
	cmp	edx,-80h
6341
	jae	sib_address_8bit_value
6342
      sib_address_32bit_value:
31 halyavin 6343
	or	al,10000000b
157 heavyiron 6344
	mov	cl,[postbyte_register]
6345
	shl	cl,3
6346
	or	al,cl
6347
	stos	word [edi]
6348
	jmp	store_address_32bit_value
6349
      sib_address_8bit_value:
31 halyavin 6350
	or	al,01000000b
157 heavyiron 6351
	mov	cl,[postbyte_register]
6352
	shl	cl,3
6353
	or	al,cl
6354
	stos	word [edi]
6355
	mov	al,dl
6356
	stos	byte [edi]
6357
	cmp	edx,80h
6358
	jge	value_out_of_range
6359
	cmp	edx,-80h
6360
	jl	value_out_of_range
6361
	ret
6362
      sib_address:
31 halyavin 6363
	mov	cl,[postbyte_register]
157 heavyiron 6364
	shl	cl,3
6365
	or	al,cl
6366
	stos	word [edi]
6367
	ret
6368
      only_index_register:
31 halyavin 6369
	or	ah,101b
157 heavyiron 6370
	and	bl,111b
6371
	shl	bl,3
6372
	or	ah,bl
6373
	mov	cl,[postbyte_register]
6374
	shl	cl,3
6375
	or	al,cl
6376
	stos	word [edi]
6377
	test	ch,44h
6378
	jnz	store_address_32bit_value
6379
	or	ch,ch
6380
	jnz	invalid_address_size
6381
	jmp	store_address_32bit_value
6382
      zero_index_register:
31 halyavin 6383
	mov	bl,4
157 heavyiron 6384
	mov	cl,1
6385
	jmp	base_and_index
6386
      only_base_register:
31 halyavin 6387
	mov	al,bh
157 heavyiron 6388
	and	al,111b
6389
	cmp	al,4
6390
	je	zero_index_register
6391
	test	ch,44h
6392
	jnz	simple_address_32bit_value
6393
	test	ch,88h
6394
	jnz	simple_address_32bit_value
6395
	or	ch,ch
6396
	jnz	address_sizes_do_not_agree
6397
	or	edx,edx
6398
	jz	simple_address
6399
	cmp	edx,80h
6400
	jb	simple_address_8bit_value
6401
	cmp	edx,-80h
6402
	jae	simple_address_8bit_value
6403
      simple_address_32bit_value:
31 halyavin 6404
	or	al,10000000b
157 heavyiron 6405
	mov	cl,[postbyte_register]
6406
	shl	cl,3
6407
	or	al,cl
6408
	stos	byte [edi]
6409
	jmp	store_address_32bit_value
6410
      simple_address_8bit_value:
31 halyavin 6411
	or	al,01000000b
157 heavyiron 6412
	mov	cl,[postbyte_register]
6413
	shl	cl,3
6414
	or	al,cl
6415
	stos	byte [edi]
6416
	mov	al,dl
6417
	stos	byte [edi]
6418
	cmp	edx,80h
6419
	jge	value_out_of_range
6420
	cmp	edx,-80h
6421
	jl	value_out_of_range
6422
	ret
6423
      simple_address:
31 halyavin 6424
	cmp	al,5
157 heavyiron 6425
	je	simple_address_8bit_value
6426
	mov	cl,[postbyte_register]
6427
	shl	cl,3
6428
	or	al,cl
6429
	stos	byte [edi]
6430
	ret
6431
      address_immediate:
31 halyavin 6432
	cmp	[code_type],64
157 heavyiron 6433
	je	address_immediate_sib
6434
	test	ch,44h
6435
	jnz	address_immediate_32bit
6436
	test	ch,22h
6437
	jnz	address_immediate_16bit
6438
	or	ch,ch
6439
	jnz	invalid_address_size
6440
	cmp	[code_type],16
6441
	je	addressing_16bit
6442
      address_immediate_32bit:
31 halyavin 6443
	call	address_32bit_prefix
157 heavyiron 6444
	call	store_instruction_code
6445
      store_immediate_address:
31 halyavin 6446
	mov	al,101b
157 heavyiron 6447
	mov	cl,[postbyte_register]
6448
	shl	cl,3
6449
	or	al,cl
6450
	stos	byte [edi]
6451
      store_address_32bit_value:
31 halyavin 6452
	test	ch,0F0h
157 heavyiron 6453
	jz	address_32bit_relocation_ok
6454
	mov	eax,ecx
174 heavyiron 6455
	shr	eax,16
6456
	xchg	[value_type],al
157 heavyiron 6457
	mov	ebx,[address_symbol]
6458
	xchg	ebx,[symbol_identifier]
6459
	call	mark_relocation
6460
	mov	[value_type],al
6461
	mov	[symbol_identifier],ebx
6462
      address_32bit_relocation_ok:
31 halyavin 6463
	mov	eax,edx
157 heavyiron 6464
	stos	dword [edi]
6465
	ret
6466
      store_address_64bit_value:
31 halyavin 6467
	test	ch,0F0h
157 heavyiron 6468
	jz	address_64bit_relocation_ok
6469
	mov	eax,ecx
174 heavyiron 6470
	shr	eax,16
6471
	xchg	[value_type],al
157 heavyiron 6472
	mov	ebx,[address_symbol]
6473
	xchg	ebx,[symbol_identifier]
6474
	call	mark_relocation
6475
	mov	[value_type],al
6476
	mov	[symbol_identifier],ebx
6477
      address_64bit_relocation_ok:
31 halyavin 6478
	mov	eax,edx
157 heavyiron 6479
	stos	dword [edi]
6480
	mov	eax,[address_high]
6481
	stos	dword [edi]
6482
	ret
6483
      address_immediate_sib:
31 halyavin 6484
	test	ch,not 44h
157 heavyiron 6485
	jnz	invalid_address_size
6486
	test	ecx,0FF0000h
174 heavyiron 6487
	jnz	address_immediate_sib_nosignextend
6488
	test	edx,80000000h
157 heavyiron 6489
	jz	address_immediate_sib_prefix_ok
6490
      address_immediate_sib_nosignextend:
109 heavyiron 6491
	call	address_32bit_prefix
157 heavyiron 6492
      address_immediate_sib_prefix_ok:
109 heavyiron 6493
	call	store_instruction_code
157 heavyiron 6494
	mov	al,100b
6495
	mov	ah,100101b
6496
	mov	cl,[postbyte_register]
6497
	shl	cl,3
6498
	or	al,cl
6499
	stos	word [edi]
6500
	jmp	store_address_32bit_value
6501
      address_eip_based:
176 heavyiron 6502
	mov	al,67h
6503
	stos	byte [edi]
6504
      address_rip_based:
31 halyavin 6505
	cmp	[code_type],64
157 heavyiron 6506
	jne	invalid_address
6507
	call	store_instruction_code
6508
	jmp	store_immediate_address
6509
      address_relative:
31 halyavin 6510
	call	store_instruction_code
157 heavyiron 6511
	movzx	eax,[immediate_size]
6512
	add	eax,edi
6513
	sub	eax,[current_offset]
6514
	add	eax,5
6515
	sub	edx,eax
6516
	jo	value_out_of_range
6517
	mov	al,101b
6518
	mov	cl,[postbyte_register]
6519
	shl	cl,3
6520
	or	al,cl
6521
	stos	byte [edi]
6522
	shr	ecx,16
174 heavyiron 6523
	xchg	[value_type],cl
6524
	mov	ebx,[address_symbol]
157 heavyiron 6525
	xchg	ebx,[symbol_identifier]
6526
	mov	eax,edx
6527
	call	mark_relocation
6528
	mov	[value_type],cl
174 heavyiron 6529
	mov	[symbol_identifier],ebx
157 heavyiron 6530
	stos	dword [edi]
6531
	ret
6532
      addressing_16bit:
31 halyavin 6533
	cmp	edx,10000h
157 heavyiron 6534
	jge	address_immediate_32bit
6535
	cmp	edx,-8000h
6536
	jl	address_immediate_32bit
6537
	movzx	edx,dx
6538
      address_immediate_16bit:
31 halyavin 6539
	call	address_16bit_prefix
157 heavyiron 6540
	call	store_instruction_code
6541
	mov	al,110b
6542
	mov	cl,[postbyte_register]
6543
	shl	cl,3
6544
	or	al,cl
6545
	stos	byte [edi]
6546
	mov	eax,edx
6547
	stos	word [edi]
6548
	cmp	edx,10000h
6549
	jge	value_out_of_range
6550
	cmp	edx,-8000h
6551
	jl	value_out_of_range
6552
	ret
6553
      address_16bit_prefix:
31 halyavin 6554
	cmp	[code_type],16
157 heavyiron 6555
	je	instruction_prefix_ok
6556
	mov	al,67h
6557
	stos	byte [edi]
6558
	ret
6559
      address_32bit_prefix:
31 halyavin 6560
	cmp	[code_type],32
157 heavyiron 6561
	je	instruction_prefix_ok
6562
	mov	al,67h
6563
	stos	byte [edi]
6564
      instruction_prefix_ok:
31 halyavin 6565
	ret
157 heavyiron 6566
store_instruction_with_imm8:
31 halyavin 6567
	mov	[immediate_size],1
157 heavyiron 6568
	call	store_instruction
6569
	mov	al,byte [value]
6570
	stos	byte [edi]
6571
	ret
6572
store_instruction_with_imm16:
31 halyavin 6573
	mov	[immediate_size],2
157 heavyiron 6574
	call	store_instruction
6575
	mov	ax,word [value]
6576
	call	mark_relocation
6577
	stos	word [edi]
6578
	ret
6579
store_instruction_with_imm32:
31 halyavin 6580
	mov	[immediate_size],4
157 heavyiron 6581
	call	store_instruction
6582
	mov	eax,dword [value]
6583
	call	mark_relocation
6584
	stos	dword [edi]
6585
	ret
6586