Subversion Repositories Kolibri OS

Rev

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