Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2007, Tomasz Grysztar.
340 heavyiron 3
; All rights reserved.
31 halyavin 4
5
 
6
	xor	eax,eax
157 heavyiron 7
	mov	[stub_size],eax
8
	mov	[number_of_sections],eax
9
	mov	[current_pass],ax
10
	mov	[resolver_flags],eax
11
      assembler_loop:
31 halyavin 12
	mov	eax,[labels_list]
157 heavyiron 13
	mov	[display_buffer],eax
14
	mov	eax,[additional_memory]
15
	mov	[free_additional_memory],eax
16
	mov	eax,[additional_memory_end]
17
	mov	[structures_buffer],eax
18
	mov	esi,[source_start]
19
	mov	edi,[code_start]
20
	xor	eax,eax
21
	mov	dword [adjustment],eax
22
	mov	dword [adjustment+4],eax
23
	mov	dword [org_origin],edi
24
	mov	dword [org_origin+4],eax
25
	mov	[org_start],edi
26
	mov	[org_registers],eax
27
	mov	[org_symbol],eax
28
	mov	[error_line],eax
29
	mov	[counter],eax
30
	mov	[format_flags],eax
31
	mov	[number_of_relocations],eax
32
	mov	[undefined_data_end],eax
33
	mov	[file_extension],eax
607 heavyiron 34
	mov	[next_pass_needed],al
157 heavyiron 35
	mov	[output_format],al
36
	mov	[labels_type],al
37
	mov	[virtual_data],al
38
	mov	[code_type],16
39
      pass_loop:
31 halyavin 40
	call	assemble_line
157 heavyiron 41
	jnc	pass_loop
42
	mov	eax,[additional_memory_end]
43
	cmp	eax,[structures_buffer]
44
	je	pass_done
45
	sub	eax,20h
46
	mov	eax,[eax+4]
47
	mov	[current_line],eax
48
	jmp	missing_end_directive
49
      pass_done:
31 halyavin 50
	call	close_pass
157 heavyiron 51
	mov	eax,[labels_list]
52
      check_symbols:
31 halyavin 53
	cmp	eax,[memory_end]
157 heavyiron 54
	jae	symbols_checked
55
	test	byte [eax+8],8
56
	jz	symbol_defined_ok
57
	mov	cx,[current_pass]
58
	cmp	cx,[eax+18]
59
	jne	symbol_defined_ok
60
	test	byte [eax+8],1
61
	jz	symbol_defined_ok
62
	sub	cx,[eax+16]
63
	cmp	cx,1
64
	jne	symbol_defined_ok
65
	and	byte [eax+8],not 1
66
	or	[next_pass_needed],-1
67
      symbol_defined_ok:
31 halyavin 68
	test	byte [eax+8],10h
157 heavyiron 69
	jz	use_prediction_ok
70
	mov	cx,[current_pass]
71
	and	byte [eax+8],not 10h
72
	test	byte [eax+8],20h
73
	jnz	check_use_prediction
74
	cmp	cx,[eax+18]
75
	jne	use_prediction_ok
76
	test	byte [eax+8],8
77
	jz	use_prediction_ok
78
	jmp	use_misprediction
79
      check_use_prediction:
31 halyavin 80
	test	byte [eax+8],8
157 heavyiron 81
	jz	use_misprediction
82
	cmp	cx,[eax+18]
83
	je	use_prediction_ok
84
      use_misprediction:
31 halyavin 85
	or	[next_pass_needed],-1
157 heavyiron 86
      use_prediction_ok:
31 halyavin 87
	test	byte [eax+8],40h
157 heavyiron 88
	jz	check_next_symbol
89
	and	byte [eax+8],not 40h
90
	test	byte [eax+8],4
91
	jnz	define_misprediction
92
	mov	cx,[current_pass]
93
	test	byte [eax+8],80h
94
	jnz	check_define_prediction
95
	cmp	cx,[eax+16]
96
	jne	check_next_symbol
97
	test	byte [eax+8],1
98
	jz	check_next_symbol
99
	jmp	define_misprediction
100
      check_define_prediction:
31 halyavin 101
	test	byte [eax+8],1
157 heavyiron 102
	jz	define_misprediction
103
	cmp	cx,[eax+16]
104
	je	check_next_symbol
105
      define_misprediction:
31 halyavin 106
	or	[next_pass_needed],-1
157 heavyiron 107
      check_next_symbol:
31 halyavin 108
	add	eax,LABEL_STRUCTURE_SIZE
157 heavyiron 109
	jmp	check_symbols
110
      symbols_checked:
31 halyavin 111
	cmp	[next_pass_needed],0
157 heavyiron 112
	jne	next_pass
113
	mov	eax,[error_line]
114
	or	eax,eax
115
	jz	assemble_ok
116
	mov	[current_line],eax
117
	jmp	near [error]
118
      next_pass:
31 halyavin 119
	inc	[current_pass]
157 heavyiron 120
	mov	ax,[current_pass]
121
	cmp	ax,[passes_limit]
122
	je	code_cannot_be_generated
123
	jmp	assembler_loop
124
      assemble_ok:
31 halyavin 125
	ret
157 heavyiron 126
31 halyavin 127
 
128
	mov	eax,[display_buffer]
157 heavyiron 129
	sub	eax,100h
130
	cmp	edi,eax
131
	ja	out_of_memory
132
	lods	byte [esi]
133
	cmp	al,1
134
	je	assemble_instruction
135
	jb	source_end
136
	cmp	al,3
137
	jb	define_label
138
	je	define_constant
139
	cmp	al,0Fh
140
	je	new_line
141
	cmp	al,13h
142
	je	code_type_setting
143
	cmp	al,10h
144
	jne	illegal_instruction
145
	lods	byte [esi]
146
	jmp	segment_prefix
147
      code_type_setting:
31 halyavin 148
	lods	byte [esi]
157 heavyiron 149
	mov	[code_type],al
150
	jmp	line_assembled
151
      new_line:
31 halyavin 152
	lods	dword [esi]
157 heavyiron 153
	mov	[current_line],eax
154
	mov	[prefixed_instruction],0
155
      continue_line:
31 halyavin 156
	cmp	byte [esi],0Fh
157 heavyiron 157
	je	line_assembled
158
	jmp	assemble_line
159
      define_label:
31 halyavin 160
	lods	dword [esi]
157 heavyiron 161
	cmp	eax,0Fh
162
	jb	invalid_use_of_symbol
163
	je	reserved_word_used_as_symbol
164
	mov	ebx,eax
165
	lods	byte [esi]
166
	mov	cl,al
167
	mov	eax,edi
168
	xor	edx,edx
169
	sub	eax,dword [org_origin]
170
	sbb	edx,dword [org_origin+4]
171
	mov	ch,[labels_type]
172
	cmp	[virtual_data],0
173
	jne	make_virtual_label
174
	or	byte [ebx+9],1
175
	xchg	eax,[ebx]
176
	xchg	edx,[ebx+4]
177
	sub	eax,[ebx]
178
	sbb	edx,[ebx+4]
179
	mov	dword [adjustment],eax
180
	mov	dword [adjustment+4],edx
181
	or	eax,edx
182
	setnz	ah
183
	jmp	finish_label_symbol
184
      make_virtual_label:
31 halyavin 185
	and	byte [ebx+9],not 1
157 heavyiron 186
	cmp	eax,[ebx]
187
	mov	[ebx],eax
188
	setne	ah
189
	cmp	edx,[ebx+4]
190
	mov	[ebx+4],edx
191
	setne	al
192
	or	ah,al
193
      finish_label_symbol:
31 halyavin 194
	cmp	cl,[ebx+10]
157 heavyiron 195
	mov	[ebx+10],cl
196
	setne	al
197
	or	ah,al
198
	cmp	ch,[ebx+11]
199
	mov	[ebx+11],ch
200
	setne	al
201
	or	ah,al
202
	mov	edx,[org_registers]
203
	cmp	edx,[ebx+12]
204
	mov	[ebx+12],edx
205
	setne	al
206
	or	ah,al
207
	or	ch,ch
208
	jz	label_symbol_ok
209
	mov	edx,[org_symbol]
210
	cmp	edx,[ebx+20]
211
	mov	[ebx+20],edx
212
	setne	al
213
	or	ah,al
214
      label_symbol_ok:
31 halyavin 215
	mov	cx,[current_pass]
157 heavyiron 216
	xchg	[ebx+16],cx
217
	mov	edx,[current_line]
218
	mov	[ebx+28],edx
219
	and	byte [ebx+8],not 2
220
	test	byte [ebx+8],1
221
	jz	new_label
222
	cmp	cx,[ebx+16]
223
	je	symbol_already_defined
224
	inc	cx
225
	sub	cx,[ebx+16]
226
	setnz	al
227
	or	ah,al
228
	jz	continue_line
229
	test	byte [ebx+8],8
230
	jz	continue_line
231
	mov	cx,[current_pass]
232
	cmp	cx,[ebx+18]
233
	jne	continue_line
234
	or	[next_pass_needed],-1
235
	jmp	continue_line
236
      new_label:
31 halyavin 237
	or	byte [ebx+8],1
157 heavyiron 238
	jmp	continue_line
239
      define_constant:
31 halyavin 240
	lods	dword [esi]
157 heavyiron 241
	inc	esi
242
	cmp	eax,0Fh
243
	jb	invalid_use_of_symbol
244
	je	reserved_word_used_as_symbol
245
	mov	edx,[eax+8]
246
	push	edx
247
	cmp	[current_pass],0
248
	je	get_constant_value
249
	test	dl,4
250
	jnz	get_constant_value
251
	mov	cx,[current_pass]
252
	cmp	cx,[eax+16]
253
	je	get_constant_value
254
	and	dl,not 1
255
	mov	[eax+8],dl
256
      get_constant_value:
31 halyavin 257
	push	eax
157 heavyiron 258
	mov	al,byte [esi-1]
259
	push	eax
260
	call	get_value
261
	pop	ebx
262
	mov	ch,bl
263
	pop	ebx
264
	pop	dword [ebx+8]
265
	cmp	ebx,0Fh
266
	jb	invalid_use_of_symbol
267
	je	reserved_word_used_as_symbol
268
	xor	cl,cl
269
	mov	ch,[value_type]
270
	cmp	ch,3
271
	je	invalid_use_of_symbol
272
      make_constant:
31 halyavin 273
	and	byte [ebx+9],not 1
157 heavyiron 274
	cmp	eax,[ebx]
275
	mov	[ebx],eax
276
	setne	ah
277
	cmp	edx,[ebx+4]
278
	mov	[ebx+4],edx
279
	setne	al
280
	or	ah,al
281
	cmp	cl,[ebx+10]
282
	mov	[ebx+10],cl
283
	setne	al
284
	or	ah,al
285
	cmp	ch,[ebx+11]
286
	mov	[ebx+11],ch
287
	setne	al
288
	or	ah,al
289
	xor	edx,edx
290
	cmp	edx,[ebx+12]
291
	mov	[ebx+12],edx
292
	setne	al
293
	or	ah,al
294
	or	ch,ch
295
	jz	constant_symbol_ok
296
	mov	edx,[symbol_identifier]
297
	cmp	edx,[ebx+20]
298
	mov	[ebx+20],edx
299
	setne	al
300
	or	ah,al
301
      constant_symbol_ok:
31 halyavin 302
	mov	cx,[current_pass]
157 heavyiron 303
	xchg	[ebx+16],cx
304
	mov	edx,[current_line]
305
	mov	[ebx+28],edx
306
	test	byte [ebx+8],1
307
	jz	new_constant
308
	cmp	cx,[ebx+16]
309
	jne	redeclare_constant
310
	test	byte [ebx+8],2
311
	jz	symbol_already_defined
312
	or	byte [ebx+8],4
313
	jmp	instruction_assembled
314
      redeclare_constant:
31 halyavin 315
	inc	cx
157 heavyiron 316
	sub	cx,[ebx+16]
317
	setnz	al
318
	or	ah,al
319
	jz	instruction_assembled
320
	test	byte [ebx+8],4
321
	jnz	instruction_assembled
322
	test	byte [ebx+8],8
323
	jz	instruction_assembled
324
	mov	cx,[current_pass]
325
	cmp	cx,[ebx+18]
326
	jne	instruction_assembled
327
	or	[next_pass_needed],-1
328
	jmp	instruction_assembled
329
      new_constant:
31 halyavin 330
	or	byte [ebx+8],1+2
157 heavyiron 331
	jmp	instruction_assembled
332
      assemble_instruction:
31 halyavin 333
;        mov     [operand_size],0
707 heavyiron 334
;        mov     [size_override],0
335
;        mov     [operand_prefix],0
336
;        mov     [rex_prefix],0
337
	mov	dword [operand_size],0
338
	mov	[immediate_size],0
157 heavyiron 339
	movzx	ebx,word [esi]
340
	mov	al,[esi+2]
341
	add	ebx,assembler
342
	add	esi,3
343
	jmp	near ebx
344
      instruction_assembled:
31 halyavin 345
	mov	al,[esi]
157 heavyiron 346
	cmp	al,0Fh
347
	je	line_assembled
348
	or	al,al
349
	jnz	extra_characters_on_line
350
      line_assembled:
31 halyavin 351
	clc
157 heavyiron 352
	ret
353
      source_end:
31 halyavin 354
	dec	esi
157 heavyiron 355
	stc
356
	ret
357
skip_line:
31 halyavin 358
	call	skip_symbol
157 heavyiron 359
	jnc	skip_line
360
	ret
361
skip_symbol:
31 halyavin 362
	lods	byte [esi]
157 heavyiron 363
	or	al,al
364
	jz	nothing_to_skip
365
	cmp	al,0Fh
366
	je	nothing_to_skip
367
	cmp	al,1
368
	je	skip_instruction
369
	cmp	al,2
370
	je	skip_label
371
	cmp	al,3
372
	je	skip_label
373
	cmp	al,20h
374
	jb	skip_assembler_symbol
375
	cmp	al,'('
376
	je	skip_expression
377
	cmp	al,'['
378
	je	skip_address
379
      skip_done:
31 halyavin 380
	clc
157 heavyiron 381
	ret
382
      skip_label:
31 halyavin 383
	add	esi,2
157 heavyiron 384
      skip_instruction:
31 halyavin 385
	add	esi,2
157 heavyiron 386
      skip_assembler_symbol:
31 halyavin 387
	inc	esi
157 heavyiron 388
	jmp	skip_done
389
      skip_address:
31 halyavin 390
	mov	al,[esi]
157 heavyiron 391
	and	al,11110000b
392
	cmp	al,60h
393
	jb	skip_expression
394
	cmp	al,70h
395
	ja	skip_expression
396
	inc	esi
397
	jmp	skip_address
398
      skip_expression:
31 halyavin 399
	lods	byte [esi]
157 heavyiron 400
	or	al,al
401
	jz	skip_string
402
	cmp	al,'.'
403
	je	skip_fp_value
404
	cmp	al,')'
405
	je	skip_done
406
	cmp	al,']'
407
	je	skip_done
408
	cmp	al,'!'
409
	je	skip_expression
410
	cmp	al,0Fh
411
	je	skip_expression
412
	cmp	al,10h
413
	je	skip_register
414
	cmp	al,11h
415
	je	skip_label_value
416
	cmp	al,80h
417
	jae	skip_expression
418
	movzx	eax,al
419
	add	esi,eax
420
	jmp	skip_expression
421
      skip_label_value:
31 halyavin 422
	add	esi,3
157 heavyiron 423
      skip_register:
31 halyavin 424
	inc	esi
157 heavyiron 425
	jmp	skip_expression
426
      skip_fp_value:
31 halyavin 427
	add	esi,12
157 heavyiron 428
	jmp	skip_done
429
      skip_string:
31 halyavin 430
	lods	dword [esi]
157 heavyiron 431
	add	esi,eax
432
	inc	esi
433
	jmp	skip_done
434
      nothing_to_skip:
31 halyavin 435
	dec	esi
157 heavyiron 436
	stc
437
	ret
438
31 halyavin 439
 
440
	lods	byte [esi]
157 heavyiron 441
	cmp	al,'('
442
	jne	invalid_argument
443
	cmp	byte [esi],'.'
444
	je	invalid_value
445
	call	get_qword_value
446
	mov	cl,[value_type]
447
	test	cl,1
448
	jnz	invalid_use_of_symbol
449
	mov	[labels_type],cl
450
	mov	ecx,edi
451
	sub	ecx,eax
452
	adc	edx,0
453
	neg	edx
454
	mov	dword [org_origin],ecx
455
	mov	dword [org_origin+4],edx
456
	mov	[org_registers],0
457
	mov	[org_start],edi
458
	mov	edx,[symbol_identifier]
459
	mov	[org_symbol],edx
460
	cmp	[output_format],1
461
	ja	instruction_assembled
462
	cmp	edi,[code_start]
463
	jne	instruction_assembled
464
	cmp	eax,100h
465
	jne	instruction_assembled
466
	bts	[format_flags],0
467
	jmp	instruction_assembled
468
label_directive:
31 halyavin 469
	lods	byte [esi]
157 heavyiron 470
	cmp	al,2
471
	jne	invalid_argument
472
	lods	dword [esi]
473
	cmp	eax,0Fh
474
	jb	invalid_use_of_symbol
475
	je	reserved_word_used_as_symbol
476
	inc	esi
477
	mov	ebx,eax
478
	xor	cl,cl
479
	lods	byte [esi]
480
	cmp	al,':'
481
	je	get_label_size
482
	dec	esi
483
	cmp	al,11h
484
	jne	label_size_ok
485
      get_label_size:
31 halyavin 486
	lods	word [esi]
157 heavyiron 487
	cmp	al,11h
488
	jne	invalid_argument
489
	mov	cl,ah
490
      label_size_ok:
31 halyavin 491
	mov	eax,edi
157 heavyiron 492
	xor	edx,edx
493
	sub	eax,dword [org_origin]
494
	sbb	edx,dword [org_origin+4]
495
	mov	ebp,[org_registers]
496
	cmp	byte [esi],80h
497
	je	get_free_label_value
498
	mov	ch,[labels_type]
499
	push	[org_symbol]
500
	pop	[address_symbol]
501
	cmp	[virtual_data],0
502
	jne	make_free_label
503
	or	byte [ebx+9],1
504
	xchg	eax,[ebx]
505
	xchg	edx,[ebx+4]
506
	sub	eax,[ebx]
507
	sbb	edx,[ebx+4]
508
	mov	dword [adjustment],eax
509
	mov	dword [adjustment+4],edx
510
	or	eax,edx
511
	setne	ah
512
	jmp	finish_label
513
      get_free_label_value:
31 halyavin 514
	inc	esi
157 heavyiron 515
	lods	byte [esi]
516
	cmp	al,'('
517
	jne	invalid_argument
518
	push	dword [ebx+8]
519
	push	ebx ecx
520
	and	byte [ebx+8],not 1
521
	cmp	byte [esi],'.'
522
	je	invalid_value
523
	call	get_address_value
524
	or	bh,bh
525
	setnz	ch
526
	xchg	ch,cl
527
	mov	bp,cx
528
	shl	ebp,16
529
	xchg	bl,bh
530
	mov	bp,bx
531
	pop	ecx ebx
532
	pop	dword [ebx+8]
533
	mov	ch,[value_type]
534
	or	ch,ch
535
	jz	make_free_label
536
	cmp	ch,4
537
	je	make_free_label
538
	cmp	ch,2
539
	jne	invalid_use_of_symbol
540
      make_free_label:
31 halyavin 541
	and	byte [ebx+9],not 1
157 heavyiron 542
	cmp	eax,[ebx]
543
	mov	[ebx],eax
544
	setne	ah
545
	cmp	edx,[ebx+4]
546
	mov	[ebx+4],edx
547
	setne	al
548
	or	ah,al
549
	jmp	finish_label
550
      finish_label:
31 halyavin 551
	cmp	cl,[ebx+10]
157 heavyiron 552
	mov	[ebx+10],cl
553
	setne	al
554
	or	ah,al
555
	cmp	ch,[ebx+11]
556
	mov	[ebx+11],ch
557
	setne	al
558
	or	ah,al
559
	cmp	ebp,[ebx+12]
560
	mov	[ebx+12],ebp
561
	setne	al
562
	or	ah,al
563
	or	ch,ch
564
	jz	free_label_symbol_ok
565
	mov	edx,[address_symbol]
566
	cmp	edx,[ebx+20]
567
	mov	[ebx+20],edx
568
	setne	al
569
	or	ah,al
570
      free_label_symbol_ok:
31 halyavin 571
	mov	cx,[current_pass]
157 heavyiron 572
	xchg	[ebx+16],cx
573
	mov	edx,[current_line]
574
	mov	[ebx+28],edx
575
	and	byte [ebx+8],not 2
576
	test	byte [ebx+8],1
577
	jz	new_free_label
578
	cmp	cx,[ebx+16]
579
	je	symbol_already_defined
580
	inc	cx
581
	sub	cx,[ebx+16]
582
	setnz	al
583
	or	ah,al
584
	jz	instruction_assembled
585
	test	byte [ebx+8],8
586
	jz	instruction_assembled
587
	mov	cx,[current_pass]
588
	cmp	cx,[ebx+18]
589
	jne	instruction_assembled
590
	or	[next_pass_needed],-1
591
	jmp	instruction_assembled
592
      new_free_label:
31 halyavin 593
	or	byte [ebx+8],1
157 heavyiron 594
	jmp	instruction_assembled
595
load_directive:
31 halyavin 596
	lods	byte [esi]
157 heavyiron 597
	cmp	al,2
598
	jne	invalid_argument
599
	lods	dword [esi]
600
	cmp	eax,0Fh
601
	jb	invalid_use_of_symbol
602
	je	reserved_word_used_as_symbol
603
	inc	esi
604
	push	eax
605
	mov	al,1
606
	cmp	byte [esi],11h
607
	jne	load_size_ok
608
	lods	byte [esi]
609
	lods	byte [esi]
610
      load_size_ok:
31 halyavin 611
	cmp	al,8
157 heavyiron 612
	ja	invalid_value
613
	mov	[operand_size],al
614
	mov	dword [value],0
615
	mov	dword [value+4],0
616
	lods	word [esi]
617
	cmp	ax,82h+'(' shl 8
618
	jne	invalid_argument
619
      load_from_code:
31 halyavin 620
	cmp	byte [esi],'.'
157 heavyiron 621
	je	invalid_value
622
	or	[size_override],-1
242 heavyiron 623
	call	get_address_value
220 heavyiron 624
	call	calculate_relative_offset
174 heavyiron 625
	push	esi edi
626
	cmp	[next_pass_needed],0
157 heavyiron 627
	jne	load_address_type_ok
174 heavyiron 628
	cmp	[value_type],0
157 heavyiron 629
	jne	invalid_use_of_symbol
630
      load_address_type_ok:
174 heavyiron 631
	cmp	edx,-1
632
	jne	bad_load_address
633
	neg	eax
634
	mov	esi,edi
157 heavyiron 635
	sub	esi,eax
636
	jc	bad_load_address
637
	cmp	esi,[org_start]
638
	jb	bad_load_address
639
	mov	edi,value
640
	movzx	ecx,[operand_size]
641
	cmp	ecx,eax
642
	ja	bad_load_address
643
	rep	movs byte [edi],[esi]
644
	jmp	value_loaded
645
      bad_load_address:
31 halyavin 646
	cmp	[error_line],0
157 heavyiron 647
	jne	value_loaded
648
	mov	eax,[current_line]
649
	mov	[error_line],eax
650
	mov	[error],value_out_of_range
651
      value_loaded:
31 halyavin 652
	pop	edi esi
157 heavyiron 653
	mov	eax,dword [value]
654
	mov	edx,dword [value+4]
655
	pop	ebx
656
	xor	cx,cx
657
	jmp	make_constant
658
store_directive:
31 halyavin 659
	cmp	byte [esi],11h
157 heavyiron 660
	je	sized_store
661
	lods	byte [esi]
662
	cmp	al,'('
663
	jne	invalid_argument
664
	call	get_byte_value
665
	xor	edx,edx
666
	movzx	eax,al
667
	mov	[operand_size],1
668
	jmp	store_value_ok
669
      sized_store:
31 halyavin 670
	call	get_value
157 heavyiron 671
      store_value_ok:
31 halyavin 672
	cmp	[value_type],0
157 heavyiron 673
	jne	invalid_use_of_symbol
674
	mov	dword [value],eax
675
	mov	dword [value+4],edx
676
	lods	word [esi]
677
	cmp	ax,80h+'(' shl 8
678
	jne	invalid_argument
679
	cmp	byte [esi],'.'
680
	je	invalid_value
681
	or	[size_override],-1
242 heavyiron 682
	call	get_address_value
220 heavyiron 683
	call	calculate_relative_offset
174 heavyiron 684
	push	esi edi
685
	cmp	[next_pass_needed],0
157 heavyiron 686
	jne	store_address_type_ok
174 heavyiron 687
	cmp	[value_type],0
157 heavyiron 688
	jne	invalid_use_of_symbol
689
      store_address_type_ok:
174 heavyiron 690
	cmp	edx,-1
691
	jne	bad_store_address
692
	neg	eax
693
	sub	edi,eax
157 heavyiron 694
	jc	bad_store_address
695
	cmp	edi,[org_start]
696
	jb	bad_store_address
697
	mov	esi,value
698
	movzx	ecx,[operand_size]
699
	cmp	ecx,eax
700
	ja	bad_store_address
701
	rep	movs byte [edi],[esi]
702
	mov	eax,edi
703
	pop	edi esi
704
	cmp	edi,[undefined_data_end]
705
	jne	instruction_assembled
706
	cmp	eax,[undefined_data_start]
707
	jbe	instruction_assembled
708
	mov	[undefined_data_start],eax
709
	jmp	instruction_assembled
710
      bad_store_address:
31 halyavin 711
	pop	edi esi
157 heavyiron 712
	cmp	[error_line],0
713
	jne	instruction_assembled
714
	mov	eax,[current_line]
715
	mov	[error_line],eax
716
	mov	[error],value_out_of_range
717
	jmp	instruction_assembled
718
31 halyavin 719
 
720
	lods	byte [esi]
157 heavyiron 721
	cmp	al,'('
722
	jne	invalid_argument
723
	cmp	byte [esi],0
724
	jne	display_byte
725
	inc	esi
726
	lods	dword [esi]
727
	mov	ecx,eax
728
	push	edi
729
	mov	edi,[display_buffer]
730
	sub	edi,4
731
	sub	edi,eax
732
	mov	[display_buffer],edi
733
	rep	movs byte [edi],[esi]
734
	stos	dword [edi]
735
	pop	edi
736
	inc	esi
737
	jmp	display_next
738
      display_byte:
31 halyavin 739
	call	get_byte_value
157 heavyiron 740
	push	edi
741
	mov	edi,[display_buffer]
742
	sub	edi,4+1
743
	mov	[display_buffer],edi
744
	stos	byte [edi]
745
	mov	eax,1
746
	stos	dword [edi]
747
	pop	edi
748
      display_next:
31 halyavin 749
	cmp	edi,[display_buffer]
157 heavyiron 750
	ja	out_of_memory
751
	lods	byte [esi]
752
	cmp	al,','
753
	je	display_directive
754
	dec	esi
755
	jmp	instruction_assembled
756
flush_display_buffer:
31 halyavin 757
	mov	eax,[display_buffer]
157 heavyiron 758
	or	eax,eax
759
	jz	display_done
760
	mov	esi,[labels_list]
761
	cmp	esi,eax
762
	je	display_done
763
      display_messages:
31 halyavin 764
	sub	esi,4
157 heavyiron 765
	mov	ecx,[esi]
766
	sub	esi,ecx
767
	push	esi
768
	call	display_block
769
	pop	esi
770
	cmp	esi,[display_buffer]
771
	jne	display_messages
772
	mov	eax,[labels_list]
773
	mov	[display_buffer],eax
774
      display_done:
31 halyavin 775
	ret
157 heavyiron 776
times_directive:
31 halyavin 777
	lods	byte [esi]
157 heavyiron 778
	cmp	al,'('
779
	jne	invalid_argument
780
	cmp	byte [esi],'.'
781
	je	invalid_value
782
	call	get_dword_value
783
	cmp	[next_pass_needed],0
784
	jne	times_value_ok
785
	cmp	[value_type],0
786
	jne	invalid_use_of_symbol
787
      times_value_ok:
31 halyavin 788
	cmp	eax,0
157 heavyiron 789
	je	zero_times
790
	jl	negative_times
791
	cmp	byte [esi],':'
792
	jne	times_argument_ok
793
	inc	esi
794
      times_argument_ok:
31 halyavin 795
	push	[counter]
157 heavyiron 796
	push	[counter_limit]
797
	mov	[counter_limit],eax
798
	mov	[counter],1
799
      times_loop:
31 halyavin 800
	mov	eax,esp
157 heavyiron 801
	sub	eax,100h
802
	jc	stack_overflow
803
	cmp	eax,[stack_limit]
804
	jb	stack_overflow
805
	push	esi
806
	or	[prefixed_instruction],-1
807
	call	continue_line
808
	mov	eax,[counter_limit]
809
	cmp	[counter],eax
810
	je	times_done
811
	inc	[counter]
812
	pop	esi
813
	jmp	times_loop
814
      times_done:
31 halyavin 815
	pop	eax
157 heavyiron 816
	pop	[counter_limit]
817
	pop	[counter]
818
	jmp	instruction_assembled
819
      negative_times:
31 halyavin 820
	cmp	[error_line],0
157 heavyiron 821
	jne	zero_times
822
	mov	eax,[current_line]
823
	mov	[error_line],eax
824
	mov	[error],invalid_value
825
      zero_times:
31 halyavin 826
	call	skip_line
157 heavyiron 827
	jmp	instruction_assembled
828
31 halyavin 829
 
830
	lods	byte [esi]
157 heavyiron 831
	cmp	al,80h
832
	jne	virtual_at_current
833
	lods	byte [esi]
834
	cmp	al,'('
835
	jne	invalid_argument
836
	cmp	byte [esi],'.'
837
	je	invalid_value
838
	call	get_address_value
839
	mov	ebp,[address_symbol]
840
	xor	ch,ch
841
	or	bh,bh
842
	jz	set_virtual
843
	mov	ch,1
844
	jmp	set_virtual
845
      virtual_at_current:
31 halyavin 846
	dec	esi
157 heavyiron 847
	mov	al,[labels_type]
848
	mov	[value_type],al
849
	mov	ebp,[org_symbol]
850
	mov	eax,edi
851
	xor	edx,edx
852
	sub	eax,dword [org_origin]
853
	sbb	edx,dword [org_origin+4]
854
	mov	bx,word [org_registers]
855
	mov	cx,word [org_registers+2]
856
	xchg	bh,bl
857
	xchg	ch,cl
858
      set_virtual:
31 halyavin 859
	push	[org_registers]
157 heavyiron 860
	mov	byte [org_registers],bh
861
	mov	byte [org_registers+1],bl
862
	mov	byte [org_registers+2],ch
863
	mov	byte [org_registers+3],cl
864
	call	allocate_structure_data
865
	mov	word [ebx],virtual_directive-assembler
866
	not	eax
867
	not	edx
868
	add	eax,1
869
	adc	edx,0
870
	add	eax,edi
871
	adc	edx,0
872
	xchg	dword [org_origin],eax
873
	xchg	dword [org_origin+4],edx
874
	mov	[ebx+10h],eax
875
	mov	[ebx+14h],edx
876
	pop	eax
877
	mov	[ebx+18h],eax
878
	mov	al,[virtual_data]
879
	mov	[ebx+2],al
880
	mov	al,[labels_type]
881
	mov	[ebx+3],al
882
	mov	eax,edi
883
	xchg	eax,[org_start]
884
	mov	[ebx+0Ch],eax
885
	xchg	ebp,[org_symbol]
886
	mov	[ebx+1Ch],ebp
887
	mov	[ebx+8],edi
888
	mov	eax,[current_line]
889
	mov	[ebx+4],eax
890
	or	[virtual_data],-1
891
	mov	al,[value_type]
892
	test	al,1
893
	jnz	invalid_use_of_symbol
894
	mov	[labels_type],al
895
	jmp	instruction_assembled
896
      allocate_structure_data:
31 halyavin 897
	mov	ebx,[structures_buffer]
157 heavyiron 898
	sub	ebx,20h
899
	cmp	ebx,[free_additional_memory]
900
	jb	out_of_memory
901
	mov	[structures_buffer],ebx
902
	ret
903
      find_structure_data:
31 halyavin 904
	mov	ebx,[structures_buffer]
157 heavyiron 905
      scan_structures:
31 halyavin 906
	cmp	ebx,[additional_memory_end]
157 heavyiron 907
	je	no_such_structure
908
	cmp	ax,[ebx]
909
	je	structure_data_found
910
	add	ebx,20h
911
	jmp	scan_structures
912
      structure_data_found:
109 heavyiron 913
	ret
157 heavyiron 914
      no_such_structure:
31 halyavin 915
	stc
157 heavyiron 916
	ret
917
      end_virtual:
31 halyavin 918
	call	find_structure_data
157 heavyiron 919
	jc	unexpected_instruction
920
	mov	al,[ebx+2]
921
	mov	[virtual_data],al
922
	mov	al,[ebx+3]
923
	mov	[labels_type],al
924
	mov	eax,[ebx+10h]
925
	mov	dword [org_origin],eax
926
	mov	eax,[ebx+14h]
927
	mov	dword [org_origin+4],eax
928
	mov	eax,[ebx+18h]
929
	mov	[org_registers],eax
930
	mov	eax,[ebx+0Ch]
931
	mov	[org_start],eax
932
	mov	eax,[ebx+1Ch]
933
	mov	[org_symbol],eax
934
	mov	edi,[ebx+8]
935
      remove_structure_data:
31 halyavin 936
	push	esi edi
157 heavyiron 937
	mov	esi,[structures_buffer]
938
	mov	ecx,ebx
939
	sub	ecx,esi
940
	lea	edi,[esi+20h]
941
	mov	[structures_buffer],edi
942
	shr	ecx,2
943
	rep	movs dword [edi],[esi]
944
	pop	edi esi
945
	ret
946
repeat_directive:
31 halyavin 947
	cmp	[prefixed_instruction],0
157 heavyiron 948
	jne	unexpected_instruction
949
	lods	byte [esi]
950
	cmp	al,'('
951
	jne	invalid_argument
952
	cmp	byte [esi],'.'
953
	je	invalid_value
954
	call	get_dword_value
955
	cmp	[next_pass_needed],0
956
	jne	repeat_value_ok
957
	cmp	[value_type],0
958
	jne	invalid_use_of_symbol
959
      repeat_value_ok:
31 halyavin 960
	cmp	eax,0
157 heavyiron 961
	je	zero_repeat
962
	jl	negative_repeat
963
	call	allocate_structure_data
964
	mov	word [ebx],repeat_directive-assembler
965
	xchg	eax,[counter_limit]
966
	mov	[ebx+10h],eax
967
	mov	eax,1
968
	xchg	eax,[counter]
969
	mov	[ebx+14h],eax
970
	mov	[ebx+8],esi
971
	mov	eax,[current_line]
972
	mov	[ebx+4],eax
973
	jmp	instruction_assembled
974
      end_repeat:
31 halyavin 975
	cmp	[prefixed_instruction],0
157 heavyiron 976
	jne	unexpected_instruction
977
	call	find_structure_data
978
	jc	unexpected_instruction
979
	mov	eax,[counter_limit]
980
	inc	[counter]
981
	cmp	[counter],eax
982
	jbe	continue_repeating
983
      stop_repeat:
31 halyavin 984
	mov	eax,[ebx+10h]
157 heavyiron 985
	mov	[counter_limit],eax
986
	mov	eax,[ebx+14h]
987
	mov	[counter],eax
988
	call	remove_structure_data
989
	jmp	instruction_assembled
990
      continue_repeating:
31 halyavin 991
	mov	esi,[ebx+8]
157 heavyiron 992
	jmp	instruction_assembled
993
      negative_repeat:
31 halyavin 994
	cmp	[error_line],0
157 heavyiron 995
	jne	zero_repeat
996
	mov	eax,[current_line]
997
	mov	[error_line],eax
998
	mov	[error],invalid_value
999
      zero_repeat:
31 halyavin 1000
	mov	al,[esi]
157 heavyiron 1001
	or	al,al
1002
	jz	missing_end_directive
1003
	cmp	al,0Fh
1004
	jne	extra_characters_on_line
1005
	call	find_end_repeat
1006
	jmp	instruction_assembled
1007
      find_end_repeat:
31 halyavin 1008
	call	find_structure_end
157 heavyiron 1009
	cmp	ax,repeat_directive-assembler
1010
	jne	unexpected_instruction
1011
	ret
1012
while_directive:
31 halyavin 1013
	cmp	[prefixed_instruction],0
157 heavyiron 1014
	jne	unexpected_instruction
1015
	call	allocate_structure_data
1016
	mov	word [ebx],while_directive-assembler
1017
	mov	eax,1
1018
	xchg	eax,[counter]
1019
	mov	[ebx+10h],eax
1020
	mov	[ebx+8],esi
1021
	mov	eax,[current_line]
1022
	mov	[ebx+4],eax
1023
      do_while:
31 halyavin 1024
	push	ebx
157 heavyiron 1025
	call	calculate_logical_expression
1026
	or	al,al
1027
	jnz	while_true
1028
	mov	al,[esi]
1029
	or	al,al
1030
	jz	missing_end_directive
1031
	cmp	al,0Fh
1032
	jne	extra_characters_on_line
1033
      stop_while:
31 halyavin 1034
	call	find_end_while
157 heavyiron 1035
	pop	ebx
1036
	mov	eax,[ebx+10h]
1037
	mov	[counter],eax
1038
	call	remove_structure_data
1039
	jmp	instruction_assembled
1040
      while_true:
31 halyavin 1041
	pop	ebx
157 heavyiron 1042
	jmp	instruction_assembled
1043
      end_while:
31 halyavin 1044
	cmp	[prefixed_instruction],0
157 heavyiron 1045
	jne	unexpected_instruction
1046
	call	find_structure_data
1047
	jc	unexpected_instruction
1048
	mov	eax,[ebx+4]
1049
	mov	[current_line],eax
1050
	inc	[counter]
1051
	jz	too_many_repeats
1052
	mov	esi,[ebx+8]
1053
	jmp	do_while
1054
      find_end_while:
31 halyavin 1055
	call	find_structure_end
157 heavyiron 1056
	cmp	ax,while_directive-assembler
1057
	jne	unexpected_instruction
1058
	ret
1059
if_directive:
31 halyavin 1060
	cmp	[prefixed_instruction],0
157 heavyiron 1061
	jne	unexpected_instruction
1062
	call	calculate_logical_expression
1063
	mov	dl,al
1064
	mov	al,[esi]
1065
	or	al,al
1066
	jz	missing_end_directive
1067
	cmp	al,0Fh
1068
	jne	extra_characters_on_line
1069
	or	dl,dl
1070
	jnz	if_true
1071
	call	find_else
1072
	jc	instruction_assembled
1073
	mov	al,[esi]
1074
	cmp	al,1
1075
	jne	else_true
1076
	cmp	word [esi+1],if_directive-assembler
1077
	jne	else_true
1078
	add	esi,4
1079
	jmp	if_directive
1080
      if_true:
31 halyavin 1081
	xor	al,al
157 heavyiron 1082
      make_if_structure:
31 halyavin 1083
	call	allocate_structure_data
157 heavyiron 1084
	mov	word [ebx],if_directive-assembler
1085
	mov	byte [ebx+2],al
1086
	mov	eax,[current_line]
1087
	mov	[ebx+4],eax
1088
	jmp	instruction_assembled
1089
      else_true:
31 halyavin 1090
	or	al,al
157 heavyiron 1091
	jz	missing_end_directive
1092
	cmp	al,0Fh
1093
	jne	extra_characters_on_line
1094
	or	al,-1
1095
	jmp	make_if_structure
1096
      else_directive:
31 halyavin 1097
	cmp	[prefixed_instruction],0
157 heavyiron 1098
	jne	unexpected_instruction
1099
	mov	ax,if_directive-assembler
1100
	call	find_structure_data
1101
	jc	unexpected_instruction
1102
	cmp	byte [ebx+2],0
1103
	jne	unexpected_instruction
1104
      found_else:
31 halyavin 1105
	mov	al,[esi]
157 heavyiron 1106
	cmp	al,1
1107
	jne	skip_else
1108
	cmp	word [esi+1],if_directive-assembler
1109
	jne	skip_else
1110
	add	esi,4
1111
	call	find_else
1112
	jnc	found_else
1113
	call	remove_structure_data
1114
	jmp	instruction_assembled
1115
      skip_else:
31 halyavin 1116
	or	al,al
157 heavyiron 1117
	jz	missing_end_directive
1118
	cmp	al,0Fh
1119
	jne	extra_characters_on_line
1120
	call	find_end_if
1121
	call	remove_structure_data
1122
	jmp	instruction_assembled
1123
      end_if:
31 halyavin 1124
	cmp	[prefixed_instruction],0
157 heavyiron 1125
	jne	unexpected_instruction
1126
	call	find_structure_data
1127
	jc	unexpected_instruction
1128
	call	remove_structure_data
1129
	jmp	instruction_assembled
1130
      find_else:
31 halyavin 1131
	call	find_structure_end
157 heavyiron 1132
	cmp	ax,else_directive-assembler
1133
	je	else_found
1134
	cmp	ax,if_directive-assembler
1135
	jne	unexpected_instruction
1136
	stc
1137
	ret
1138
      else_found:
31 halyavin 1139
	clc
157 heavyiron 1140
	ret
1141
      find_end_if:
31 halyavin 1142
	call	find_structure_end
157 heavyiron 1143
	cmp	ax,if_directive-assembler
1144
	jne	unexpected_instruction
1145
	ret
1146
      find_structure_end:
31 halyavin 1147
	push	[error_line]
157 heavyiron 1148
	mov	eax,[current_line]
1149
	mov	[error_line],eax
1150
      find_end_directive:
31 halyavin 1151
	call	skip_line
157 heavyiron 1152
	lods	byte [esi]
1153
	cmp	al,0Fh
1154
	jne	no_end_directive
1155
	lods	dword [esi]
1156
	mov	[current_line],eax
1157
      skip_labels:
31 halyavin 1158
	cmp	byte [esi],2
157 heavyiron 1159
	jne	labels_ok
1160
	add	esi,6
1161
	jmp	skip_labels
1162
      labels_ok:
31 halyavin 1163
	cmp	byte [esi],1
157 heavyiron 1164
	jne	find_end_directive
1165
	mov	ax,[esi+1]
1166
	cmp	ax,prefix_instruction-assembler
1167
	je	find_end_directive
1168
	add	esi,4
1169
	cmp	ax,repeat_directive-assembler
1170
	je	skip_repeat
1171
	cmp	ax,while_directive-assembler
1172
	je	skip_while
1173
	cmp	ax,if_directive-assembler
1174
	je	skip_if
1175
	cmp	ax,else_directive-assembler
1176
	je	structure_end
1177
	cmp	ax,end_directive-assembler
1178
	jne	find_end_directive
1179
	cmp	byte [esi],1
1180
	jne	find_end_directive
1181
	mov	ax,[esi+1]
1182
	add	esi,4
1183
	cmp	ax,repeat_directive-assembler
1184
	je	structure_end
1185
	cmp	ax,while_directive-assembler
1186
	je	structure_end
1187
	cmp	ax,if_directive-assembler
1188
	jne	find_end_directive
1189
      structure_end:
31 halyavin 1190
	pop	[error_line]
157 heavyiron 1191
	ret
1192
      no_end_directive:
31 halyavin 1193
	mov	eax,[error_line]
157 heavyiron 1194
	mov	[current_line],eax
1195
	jmp	missing_end_directive
1196
      skip_repeat:
31 halyavin 1197
	call	find_end_repeat
157 heavyiron 1198
	jmp	find_end_directive
1199
      skip_while:
31 halyavin 1200
	call	find_end_while
157 heavyiron 1201
	jmp	find_end_directive
1202
      skip_if:
31 halyavin 1203
	call	skip_if_block
157 heavyiron 1204
	jmp	find_end_directive
1205
      skip_if_block:
31 halyavin 1206
	call	find_else
157 heavyiron 1207
	jc	if_block_skipped
1208
	cmp	byte [esi],1
1209
	jne	skip_after_else
1210
	cmp	word [esi+1],if_directive-assembler
1211
	jne	skip_after_else
1212
	add	esi,4
1213
	jmp	skip_if_block
1214
      skip_after_else:
31 halyavin 1215
	call	find_end_if
157 heavyiron 1216
      if_block_skipped:
31 halyavin 1217
	ret
157 heavyiron 1218
end_directive:
31 halyavin 1219
	lods	byte [esi]
157 heavyiron 1220
	cmp	al,1
1221
	jne	invalid_argument
1222
	lods	word [esi]
1223
	inc	esi
1224
	cmp	ax,virtual_directive-assembler
1225
	je	end_virtual
1226
	cmp	ax,repeat_directive-assembler
1227
	je	end_repeat
1228
	cmp	ax,while_directive-assembler
1229
	je	end_while
1230
	cmp	ax,if_directive-assembler
1231
	je	end_if
1232
	cmp	ax,data_directive-assembler
1233
	je	end_data
1234
	jmp	invalid_argument
1235
break_directive:
31 halyavin 1236
	mov	ebx,[structures_buffer]
157 heavyiron 1237
	mov	al,[esi]
1238
	or	al,al
1239
	jz	find_breakable_structure
1240
	cmp	al,0Fh
1241
	jne	extra_characters_on_line
1242
      find_breakable_structure:
31 halyavin 1243
	cmp	ebx,[additional_memory_end]
157 heavyiron 1244
	je	unexpected_instruction
1245
	mov	ax,[ebx]
1246
	cmp	ax,repeat_directive-assembler
1247
	je	break_repeat
1248
	cmp	ax,while_directive-assembler
1249
	je	break_while
1250
	cmp	ax,if_directive-assembler
1251
	je	break_if
1252
	add	ebx,20h
1253
	jmp	find_breakable_structure
1254
      break_if:
31 halyavin 1255
	push	[current_line]
157 heavyiron 1256
	mov	eax,[ebx+4]
1257
	mov	[current_line],eax
1258
	call	remove_structure_data
1259
	call	skip_if_block
1260
	pop	[current_line]
1261
	mov	ebx,[structures_buffer]
1262
	jmp	find_breakable_structure
1263
      break_repeat:
31 halyavin 1264
	push	ebx
157 heavyiron 1265
	call	find_end_repeat
1266
	pop	ebx
1267
	jmp	stop_repeat
1268
      break_while:
31 halyavin 1269
	push	ebx
157 heavyiron 1270
	jmp	stop_while
1271
31 halyavin 1272
 
1273
	call	define_data
157 heavyiron 1274
	lods	byte [esi]
1275
	cmp	al,'('
1276
	je	get_byte
1277
	cmp	al,'?'
1278
	jne	invalid_argument
1279
	mov	eax,edi
1280
	mov	byte [edi],0
1281
	inc	edi
1282
	jmp	undefined_data
1283
      get_byte:
31 halyavin 1284
	cmp	byte [esi],0
157 heavyiron 1285
	je	get_string
1286
	call	get_byte_value
1287
	stos	byte [edi]
1288
	ret
1289
      get_string:
31 halyavin 1290
	inc	esi
157 heavyiron 1291
	lods	dword [esi]
1292
	mov	ecx,eax
1293
	lea	eax,[edi+ecx]
1294
	cmp	eax,[display_buffer]
1295
	ja	out_of_memory
1296
	rep	movs byte [edi],[esi]
1297
	inc	esi
1298
	ret
1299
      undefined_data:
31 halyavin 1300
	cmp	[virtual_data],0
157 heavyiron 1301
	je	mark_undefined_data
1302
	ret
1303
      mark_undefined_data:
31 halyavin 1304
	cmp	eax,[undefined_data_end]
157 heavyiron 1305
	je	undefined_data_ok
1306
	mov	[undefined_data_start],eax
1307
      undefined_data_ok:
31 halyavin 1308
	mov	[undefined_data_end],edi
157 heavyiron 1309
	ret
1310
      define_data:
31 halyavin 1311
	cmp	edi,[display_buffer]
157 heavyiron 1312
	jae	out_of_memory
1313
	cmp	byte [esi],'('
1314
	jne	simple_data_value
1315
	mov	ebx,esi
1316
	inc	esi
1317
	call	skip_expression
1318
	xchg	esi,ebx
1319
	cmp	byte [ebx],81h
1320
	jne	simple_data_value
1321
	inc	esi
1322
	call	get_dword_value
1323
	cmp	[next_pass_needed],0
1324
	jne	dup_value_ok
1325
	cmp	[value_type],0
1326
	jne	invalid_use_of_symbol
1327
      dup_value_ok:
31 halyavin 1328
	inc	esi
157 heavyiron 1329
	cmp	eax,0
1330
	jg	dup_positive
1331
	cmp	[error_line],0
1332
	jne	dup_invalid
1333
	mov	eax,[current_line]
1334
	mov	[error_line],eax
1335
	mov	[error],invalid_value
1336
      dup_invalid:
31 halyavin 1337
	mov	eax,1
157 heavyiron 1338
      dup_positive:
31 halyavin 1339
	cmp	byte [esi],'{'
157 heavyiron 1340
	jne	duplicate_single_data_value
1341
	inc	esi
1342
      duplicate_data:
31 halyavin 1343
	push	eax esi
157 heavyiron 1344
      duplicated_values:
31 halyavin 1345
	cmp	edi,[display_buffer]
157 heavyiron 1346
	jae	out_of_memory
1347
	call	near dword [esp+8]
1348
	lods	byte [esi]
1349
	cmp	al,','
1350
	je	duplicated_values
1351
	cmp	al,'}'
1352
	jne	invalid_argument
1353
	pop	ebx eax
1354
	dec	eax
1355
	jz	data_defined
1356
	mov	esi,ebx
1357
	jmp	duplicate_data
1358
      duplicate_single_data_value:
31 halyavin 1359
	cmp	edi,[display_buffer]
157 heavyiron 1360
	jae	out_of_memory
1361
	push	eax esi
1362
	call	near dword [esp+8]
1363
	pop	ebx eax
1364
	dec	eax
1365
	jz	data_defined
1366
	mov	esi,ebx
1367
	jmp	duplicate_single_data_value
1368
      simple_data_value:
31 halyavin 1369
	cmp	edi,[display_buffer]
157 heavyiron 1370
	jae	out_of_memory
1371
	call	near dword [esp]
1372
      data_defined:
31 halyavin 1373
	lods	byte [esi]
157 heavyiron 1374
	cmp	al,','
1375
	je	define_data
1376
	dec	esi
1377
	add	esp,4
1378
	jmp	instruction_assembled
1379
data_unicode:
31 halyavin 1380
	or	[base_code],-1
157 heavyiron 1381
	jmp	define_words
1382
data_words:
31 halyavin 1383
	mov	[base_code],0
157 heavyiron 1384
      define_words:
31 halyavin 1385
	call	define_data
157 heavyiron 1386
	lods	byte [esi]
1387
	cmp	al,'('
1388
	je	get_word
1389
	cmp	al,'?'
1390
	jne	invalid_argument
1391
	mov	eax,edi
1392
	mov	word [edi],0
1393
	scas	word [edi]
1394
	jmp	undefined_data
1395
	ret
1396
      get_word:
31 halyavin 1397
	cmp	[base_code],0
157 heavyiron 1398
	je	word_data_value
1399
	cmp	byte [esi],0
1400
	je	word_string
1401
      word_data_value:
31 halyavin 1402
	call	get_word_value
157 heavyiron 1403
	call	mark_relocation
1404
	stos	word [edi]
1405
	ret
1406
      word_string:
31 halyavin 1407
	inc	esi
157 heavyiron 1408
	lods	dword [esi]
1409
	mov	ecx,eax
1410
	jecxz	word_string_ok
1411
	lea	eax,[edi+ecx*2]
1412
	cmp	eax,[display_buffer]
1413
	ja	out_of_memory
1414
	xor	ah,ah
1415
      copy_word_string:
31 halyavin 1416
	lods	byte [esi]
157 heavyiron 1417
	stos	word [edi]
1418
	loop	copy_word_string
1419
      word_string_ok:
31 halyavin 1420
	inc	esi
157 heavyiron 1421
	ret
1422
data_dwords:
31 halyavin 1423
	call	define_data
157 heavyiron 1424
	lods	byte [esi]
1425
	cmp	al,'('
1426
	je	get_dword
1427
	cmp	al,'?'
1428
	jne	invalid_argument
1429
	mov	eax,edi
1430
	mov	dword [edi],0
1431
	scas	dword [edi]
1432
	jmp	undefined_data
1433
      get_dword:
31 halyavin 1434
	push	esi
157 heavyiron 1435
	call	get_dword_value
1436
	pop	ebx
1437
	cmp	byte [esi],':'
1438
	je	complex_dword
1439
	call	mark_relocation
1440
	stos	dword [edi]
1441
	ret
1442
      complex_dword:
31 halyavin 1443
	mov	esi,ebx
157 heavyiron 1444
	cmp	byte [esi],'.'
1445
	je	invalid_value
1446
	call	get_word_value
1447
	push	eax
1448
	inc	esi
1449
	lods	byte [esi]
1450
	cmp	al,'('
1451
	jne	invalid_operand
1452
	mov	al,[value_type]
1453
	push	eax
1454
	cmp	byte [esi],'.'
1455
	je	invalid_value
1456
	call	get_word_value
1457
	call	mark_relocation
1458
	stos	word [edi]
1459
	pop	eax
1460
	mov	[value_type],al
1461
	pop	eax
1462
	call	mark_relocation
1463
	stos	word [edi]
1464
	ret
1465
data_pwords:
31 halyavin 1466
	call	define_data
157 heavyiron 1467
	lods	byte [esi]
1468
	cmp	al,'('
1469
	je	get_pword
1470
	cmp	al,'?'
1471
	jne	invalid_argument
1472
	mov	eax,edi
1473
	mov	dword [edi],0
1474
	scas	dword [edi]
1475
	mov	word [edi],0
1476
	scas	word [edi]
1477
	jmp	undefined_data
1478
      get_pword:
31 halyavin 1479
	push	esi
157 heavyiron 1480
	call	get_pword_value
1481
	pop	ebx
1482
	cmp	byte [esi],':'
1483
	je	complex_pword
1484
	call	mark_relocation
1485
	stos	dword [edi]
1486
	mov	ax,dx
1487
	stos	word [edi]
1488
	ret
1489
      complex_pword:
31 halyavin 1490
	mov	esi,ebx
157 heavyiron 1491
	cmp	byte [esi],'.'
1492
	je	invalid_value
1493
	call	get_word_value
1494
	push	eax
1495
	inc	esi
1496
	lods	byte [esi]
1497
	cmp	al,'('
1498
	jne	invalid_operand
1499
	mov	al,[value_type]
1500
	push	eax
1501
	cmp	byte [esi],'.'
1502
	je	invalid_value
1503
	call	get_dword_value
1504
	call	mark_relocation
1505
	stos	dword [edi]
1506
	pop	eax
1507
	mov	[value_type],al
1508
	pop	eax
1509
	call	mark_relocation
1510
	stos	word [edi]
1511
	ret
1512
data_qwords:
31 halyavin 1513
	call	define_data
157 heavyiron 1514
	lods	byte [esi]
1515
	cmp	al,'('
1516
	je	get_qword
1517
	cmp	al,'?'
1518
	jne	invalid_argument
1519
	mov	eax,edi
1520
	mov	dword [edi],0
1521
	scas	dword [edi]
1522
	mov	dword [edi],0
1523
	scas	dword [edi]
1524
	jmp	undefined_data
1525
      get_qword:
31 halyavin 1526
	call	get_qword_value
157 heavyiron 1527
	call	mark_relocation
1528
	stos	dword [edi]
1529
	mov	eax,edx
1530
	stos	dword [edi]
1531
	ret
1532
data_twords:
31 halyavin 1533
	call	define_data
157 heavyiron 1534
	lods	byte [esi]
1535
	cmp	al,'('
1536
	je	get_tword
1537
	cmp	al,'?'
1538
	jne	invalid_argument
1539
	mov	eax,edi
1540
	mov	dword [edi],0
1541
	scas	dword [edi]
1542
	mov	dword [edi],0
1543
	scas	dword [edi]
1544
	mov	word [edi],0
1545
	scas	word [edi]
1546
	jmp	undefined_data
1547
      get_tword:
31 halyavin 1548
	cmp	byte [esi],'.'
157 heavyiron 1549
	jne	complex_tword
1550
	inc	esi
1551
	cmp	word [esi+8],8000h
1552
	je	fp_zero_tword
1553
	mov	eax,[esi]
1554
	stos	dword [edi]
1555
	mov	eax,[esi+4]
1556
	stos	dword [edi]
1557
	mov	ax,[esi+8]
1558
	add	ax,3FFFh
1559
	cmp	ax,8000h
1560
	jae	value_out_of_range
1561
	mov	bl,[esi+11]
1562
	shl	bx,15
1563
	or	ax,bx
1564
	stos	word [edi]
1565
	add	esi,13
1566
	ret
1567
      fp_zero_tword:
31 halyavin 1568
	xor	eax,eax
157 heavyiron 1569
	stos	dword [edi]
1570
	stos	dword [edi]
1571
	mov	al,[esi+11]
1572
	shl	ax,15
1573
	stos	word [edi]
1574
	add	esi,13
1575
	ret
1576
      complex_tword:
31 halyavin 1577
	call	get_word_value
157 heavyiron 1578
	push	eax
1579
	inc	esi
1580
	lods	byte [esi]
1581
	cmp	al,'('
1582
	jne	invalid_operand
1583
	mov	al,[value_type]
1584
	push	eax
1585
	cmp	byte [esi],'.'
1586
	je	invalid_value
1587
	call	get_qword_value
1588
	call	mark_relocation
1589
	stos	dword [edi]
1590
	mov	eax,edx
1591
	stos	dword [edi]
1592
	pop	eax
1593
	mov	[value_type],al
1594
	pop	eax
1595
	call	mark_relocation
1596
	stos	word [edi]
1597
	ret
1598
data_file:
31 halyavin 1599
	lods	word [esi]
157 heavyiron 1600
	cmp	ax,'('
1601
	jne	invalid_argument
1602
	add	esi,4
1603
	call	open_binary_file
1604
	mov	eax,[esi-4]
1605
	lea	esi,[esi+eax+1]
1606
	mov	al,2
1607
	xor	edx,edx
1608
	call	lseek
1609
	push	eax
1610
	xor	edx,edx
1611
	cmp	byte [esi],':'
1612
	jne	position_ok
1613
	inc	esi
1614
	cmp	byte [esi],'('
1615
	jne	invalid_argument
1616
	inc	esi
1617
	cmp	byte [esi],'.'
1618
	je	invalid_value
1619
	push	ebx
1620
	call	get_dword_value
1621
	pop	ebx
1622
	mov	edx,eax
1623
	sub	[esp],edx
1624
      position_ok:
31 halyavin 1625
	cmp	byte [esi],','
157 heavyiron 1626
	jne	size_ok
1627
	inc	esi
1628
	cmp	byte [esi],'('
1629
	jne	invalid_argument
1630
	inc	esi
1631
	cmp	byte [esi],'.'
1632
	je	invalid_value
1633
	push	ebx edx
1634
	call	get_dword_value
1635
	pop	edx ebx
1636
	mov	[esp],eax
1637
      size_ok:
31 halyavin 1638
	xor	al,al
157 heavyiron 1639
	call	lseek
1640
	pop	ecx
1641
	mov	edx,edi
1642
	add	edi,ecx
1643
	jc	out_of_memory
1644
	cmp	edi,[display_buffer]
1645
	ja	out_of_memory
1646
	call	read
1647
	jc	error_reading_file
1648
	call	close
1649
	lods	byte [esi]
1650
	cmp	al,','
1651
	je	data_file
1652
	dec	esi
1653
	jmp	instruction_assembled
1654
      open_binary_file:
31 halyavin 1655
	push	esi
157 heavyiron 1656
	push	edi
1657
	mov	esi,[current_line]
1658
	mov	esi,[esi]
1659
      get_current_path:
31 halyavin 1660
	lodsb
157 heavyiron 1661
	stosb
1662
	or	al,al
1663
	jnz	get_current_path
1664
      cut_current_path:
31 halyavin 1665
	cmp	edi,[esp]
157 heavyiron 1666
	je	current_path_ok
1667
	cmp	byte [edi-1],'\'
1668
	je	current_path_ok
1669
	cmp	byte [edi-1],'/'
1670
	je	current_path_ok
1671
	dec	edi
1672
	jmp	cut_current_path
1673
      current_path_ok:
31 halyavin 1674
	mov	esi,[esp+4]
157 heavyiron 1675
	call	preprocess_path
1676
	pop	edx
1677
	mov	esi,edx
1678
	call	open
1679
	jnc	file_opened
1680
	mov	edi,esi
1681
	mov	esi,[esp]
1682
	push	edi
1683
	call	preprocess_path
1684
	pop	edx
1685
	mov	esi,edx
1686
	call	open
1687
	jc	file_not_found
1688
      file_opened:
31 halyavin 1689
	mov	edi,esi
157 heavyiron 1690
	pop	esi
1691
	ret
1692
reserve_bytes:
31 halyavin 1693
	lods	byte [esi]
157 heavyiron 1694
	cmp	al,'('
1695
	jne	invalid_argument
1696
	cmp	byte [esi],'.'
1697
	je	invalid_value
1698
	call	get_dword_value
1699
	cmp	[next_pass_needed],0
1700
	jne	rb_value_ok
1701
	cmp	[value_type],0
1702
	jne	invalid_use_of_symbol
1703
      rb_value_ok:
31 halyavin 1704
	cmp	eax,0
157 heavyiron 1705
	jl	reserve_negative
1706
	mov	ecx,eax
1707
	mov	edx,ecx
1708
	add	edx,edi
1709
	jc	out_of_memory
1710
	cmp	edx,[display_buffer]
1711
	ja	out_of_memory
1712
	push	edi
1713
	cmp	[next_pass_needed],0
1714
	je	zero_bytes
1715
	add	edi,ecx
1716
	jmp	reserved_data
1717
      zero_bytes:
31 halyavin 1718
	xor	eax,eax
157 heavyiron 1719
	shr	ecx,1
1720
	jnc	bytes_stosb_ok
1721
	stos	byte [edi]
1722
      bytes_stosb_ok:
31 halyavin 1723
	shr	ecx,1
157 heavyiron 1724
	jnc	bytes_stosw_ok
1725
	stos	word [edi]
1726
      bytes_stosw_ok:
31 halyavin 1727
	rep	stos dword [edi]
157 heavyiron 1728
      reserved_data:
31 halyavin 1729
	pop	eax
157 heavyiron 1730
	call	undefined_data
1731
	jmp	instruction_assembled
1732
      reserve_negative:
31 halyavin 1733
	cmp	[error_line],0
157 heavyiron 1734
	jne	instruction_assembled
1735
	mov	eax,[current_line]
1736
	mov	[error_line],eax
1737
	mov	[error],invalid_value
1738
	jmp	instruction_assembled
1739
reserve_words:
31 halyavin 1740
	lods	byte [esi]
157 heavyiron 1741
	cmp	al,'('
1742
	jne	invalid_argument
1743
	cmp	byte [esi],'.'
1744
	je	invalid_value
1745
	call	get_dword_value
1746
	cmp	[next_pass_needed],0
1747
	jne	rw_value_ok
1748
	cmp	[value_type],0
1749
	jne	invalid_use_of_symbol
1750
      rw_value_ok:
31 halyavin 1751
	cmp	eax,0
157 heavyiron 1752
	jl	reserve_negative
1753
	mov	ecx,eax
1754
	mov	edx,ecx
1755
	shl	edx,1
1756
	jc	out_of_memory
1757
	add	edx,edi
1758
	jc	out_of_memory
1759
	cmp	edx,[display_buffer]
1760
	ja	out_of_memory
1761
	push	edi
1762
	cmp	[next_pass_needed],0
1763
	je	zero_words
1764
	lea	edi,[edi+ecx*2]
1765
	jmp	reserved_data
1766
      zero_words:
31 halyavin 1767
	xor	eax,eax
157 heavyiron 1768
	shr	ecx,1
1769
	jnc	words_stosw_ok
1770
	stos	word [edi]
1771
      words_stosw_ok:
31 halyavin 1772
	rep	stos dword [edi]
157 heavyiron 1773
	jmp	reserved_data
1774
reserve_dwords:
31 halyavin 1775
	lods	byte [esi]
157 heavyiron 1776
	cmp	al,'('
1777
	jne	invalid_argument
1778
	cmp	byte [esi],'.'
1779
	je	invalid_value
1780
	call	get_dword_value
1781
	cmp	[next_pass_needed],0
1782
	jne	rd_value_ok
1783
	cmp	[value_type],0
1784
	jne	invalid_use_of_symbol
1785
      rd_value_ok:
31 halyavin 1786
	cmp	eax,0
157 heavyiron 1787
	jl	reserve_negative
1788
	mov	ecx,eax
1789
	mov	edx,ecx
1790
	shl	edx,1
1791
	jc	out_of_memory
1792
	shl	edx,1
1793
	jc	out_of_memory
1794
	add	edx,edi
1795
	jc	out_of_memory
1796
	cmp	edx,[display_buffer]
1797
	ja	out_of_memory
1798
	push	edi
1799
	cmp	[next_pass_needed],0
1800
	je	zero_dwords
1801
	lea	edi,[edi+ecx*4]
1802
	jmp	reserved_data
1803
      zero_dwords:
31 halyavin 1804
	xor	eax,eax
157 heavyiron 1805
	rep	stos dword [edi]
1806
	jmp	reserved_data
1807
reserve_pwords:
31 halyavin 1808
	lods	byte [esi]
157 heavyiron 1809
	cmp	al,'('
1810
	jne	invalid_argument
1811
	cmp	byte [esi],'.'
1812
	je	invalid_value
1813
	call	get_dword_value
1814
	cmp	[next_pass_needed],0
1815
	jne	rp_value_ok
1816
	cmp	[value_type],0
1817
	jne	invalid_use_of_symbol
1818
      rp_value_ok:
31 halyavin 1819
	cmp	eax,0
157 heavyiron 1820
	jl	reserve_negative
1821
	mov	ecx,eax
1822
	shl	ecx,1
1823
	jc	out_of_memory
1824
	add	ecx,eax
1825
	mov	edx,ecx
1826
	shl	edx,1
1827
	jc	out_of_memory
1828
	add	edx,edi
1829
	jc	out_of_memory
1830
	cmp	edx,[display_buffer]
1831
	ja	out_of_memory
1832
	push	edi
1833
	cmp	[next_pass_needed],0
1834
	je	zero_words
1835
	lea	edi,[edi+ecx*2]
1836
	jmp	reserved_data
1837
reserve_qwords:
31 halyavin 1838
	lods	byte [esi]
157 heavyiron 1839
	cmp	al,'('
1840
	jne	invalid_argument
1841
	cmp	byte [esi],'.'
1842
	je	invalid_value
1843
	call	get_dword_value
1844
	cmp	[next_pass_needed],0
1845
	jne	rq_value_ok
1846
	cmp	[value_type],0
1847
	jne	invalid_use_of_symbol
1848
      rq_value_ok:
31 halyavin 1849
	cmp	eax,0
157 heavyiron 1850
	jl	reserve_negative
1851
	mov	ecx,eax
1852
	shl	ecx,1
1853
	jc	out_of_memory
1854
	mov	edx,ecx
1855
	shl	edx,1
1856
	jc	out_of_memory
1857
	shl	edx,1
1858
	jc	out_of_memory
1859
	add	edx,edi
1860
	jc	out_of_memory
1861
	cmp	edx,[display_buffer]
1862
	ja	out_of_memory
1863
	push	edi
1864
	cmp	[next_pass_needed],0
1865
	je	zero_dwords
1866
	lea	edi,[edi+ecx*4]
1867
	jmp	reserved_data
1868
reserve_twords:
31 halyavin 1869
	lods	byte [esi]
157 heavyiron 1870
	cmp	al,'('
1871
	jne	invalid_argument
1872
	cmp	byte [esi],'.'
1873
	je	invalid_value
1874
	call	get_dword_value
1875
	cmp	[next_pass_needed],0
1876
	jne	rt_value_ok
1877
	cmp	[value_type],0
1878
	jne	invalid_use_of_symbol
1879
      rt_value_ok:
31 halyavin 1880
	cmp	eax,0
157 heavyiron 1881
	jl	reserve_negative
1882
	mov	ecx,eax
1883
	shl	ecx,2
1884
	jc	out_of_memory
1885
	add	ecx,eax
1886
	mov	edx,ecx
1887
	shl	edx,1
1888
	jc	out_of_memory
1889
	add	edx,edi
1890
	jc	out_of_memory
1891
	cmp	edx,[display_buffer]
1892
	ja	out_of_memory
1893
	push	edi
1894
	cmp	[next_pass_needed],0
1895
	je	zero_words
1896
	lea	edi,[edi+ecx*2]
1897
	jmp	reserved_data
1898
align_directive:
31 halyavin 1899
	lods	byte [esi]
157 heavyiron 1900
	cmp	al,'('
1901
	jne	invalid_argument
1902
	cmp	byte [esi],'.'
1903
	je	invalid_value
1904
	call	get_dword_value
1905
	cmp	[value_type],0
1906
	jne	invalid_use_of_symbol
1907
	mov	edx,eax
1908
	dec	edx
1909
	test	eax,edx
1910
	jnz	negative_times
1911
	or	eax,eax
1912
	jz	negative_times
1913
	cmp	eax,1
1914
	je	instruction_assembled
1915
	mov	ecx,edi
1916
	sub	ecx,dword [org_origin]
1917
	cmp	[org_registers],0
1918
	jne	section_not_aligned_enough
1919
	cmp	[labels_type],0
1920
	je	make_alignment
1921
	cmp	[output_format],3
1922
	je	pe_alignment
1923
	mov	ebx,[org_symbol]
1924
	cmp	byte [ebx],0
1925
	jne	section_not_aligned_enough
1926
	cmp	eax,[ebx+10h]
1927
	jbe	make_alignment
1928
	jmp	section_not_aligned_enough
1929
      pe_alignment:
31 halyavin 1930
	cmp	eax,1000h
157 heavyiron 1931
	ja	section_not_aligned_enough
1932
      make_alignment:
31 halyavin 1933
	dec	eax
157 heavyiron 1934
	and	ecx,eax
1935
	jz	instruction_assembled
1936
	neg	ecx
1937
	add	ecx,eax
1938
	inc	ecx
1939
	mov	edx,ecx
1940
	add	edx,edi
1941
	jc	out_of_memory
1942
	cmp	edx,[display_buffer]
1943
	ja	out_of_memory
1944
	push	edi
1945
	cmp	[next_pass_needed],0
1946
	je	nops
1947
	add	edi,ecx
1948
	jmp	reserved_data
1949
      nops:
31 halyavin 1950
	mov	eax,90909090h
157 heavyiron 1951
	shr	ecx,1
1952
	jnc	nops_stosb_ok
1953
	stos	byte [edi]
1954
      nops_stosb_ok:
31 halyavin 1955
	shr	ecx,1
157 heavyiron 1956
	jnc	nops_stosw_ok
1957
	stos	word [edi]
1958
      nops_stosw_ok:
31 halyavin 1959
	rep	stos dword [edi]
157 heavyiron 1960
	jmp	reserved_data
1961