-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisasm.asm
1467 lines (1035 loc) · 24.3 KB
/
disasm.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.MODEL small
.STACK 100h
.DATA
LAST_COMMAND equ LIST_41
poslinkisORG dw 100h
ok db 13, 10, 'File written successfully.', 13, 10, '$'
noFileMsg db 13, 10, 'No such file: ', '$'
InvalidParameters db 13, 10, 'Invalid arguments', 13, 10, '$'
Info db 13, 10, 'Made by Justas Glodenis', 13, 10, 'Arguments to use in order: ', 13, 10, 'arg 1: sourceFile - file to disassemble', 13, 10, 'arg 2: destinationFile - output for disassembled code', 13, 10, 'example: ', 96, 'disasm sourceFile.com destinationFile.txt', 96, '$'
file1 db 20 dup(0), '$'
rezFile db 20 dup(0)
duom1 db 255 dup(0)
rez db 60 dup(32), '$'
nl db 10, 13, '$'
IsReg16 db 0
IsRegSEGMENT db 0
IsPoslinkis db 0
IsComJump db 0
safeDX dw 0
sx db 16
nr dw 9
byteNumber dw 0
fileHandler dw 0
; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
komandos db 'MOV PUSHPOP ADD INC SUB DEC CMP MUL DIV CALLRET JMP LOOPINT : '
jump db 'JO JNO JB JNB JE JNE JNA JA JS JNS JP JNP JL JGE JLE JG '
allRegs db 'ALCLDLBLAHCHDHBHAXCXDXBXSPBPSIDI'
segRegs db 'ESCSSSDS'
; 0 1 2 3 4 5 6 7
regMemory db '[BX+SI] [BX+DI] [BP+SI] [BP+DI] [SI] [DI] [BP] [BX] '
; 0 1 2 3 4 5 6 7 8 9
; HAS or IS: comBytes MOD d w s XCM comNR reg p/bop
LIST_01 db 00000000b, 11111100b, 01, 01, 01, 00, 000b, 03, 00000000b, 00
LIST_02 db 00000100b, 11111110b, 00, 00, 01, 00, 000b, 03, 00000000b, 01
LIST_03 db 00101000b, 11111100b, 01, 01, 01, 00, 000b, 05, 00000000b, 00
LIST_04 db 00101100b, 11111110b, 00, 00, 01, 00, 000b, 05, 00000000b, 01
LIST_05 db 00111000b, 11111100b, 01, 01, 01, 00, 000b, 07, 00000000b, 00
LIST_06 db 00111100b, 11111110b, 00, 00, 01, 00, 000b, 07, 00000000b, 01
LIST_07 db 01000000b, 11111000b, 00, 00, 03, 00, 000b, 04, 00000111b, 00
LIST_08 db 01001000b, 11111000b, 00, 00, 03, 00, 000b, 06, 00000111b, 00
LIST_09 db 01010000b, 11111000b, 00, 00, 03, 00, 000b, 01, 00000111b, 00
LIST_10 db 01011000b, 11111000b, 00, 00, 03, 00, 000b, 02, 00000111b, 00
LIST_11 db 00000110b, 11100111b, 00, 00, 00, 00, 000b, 01, 00011000b, 00
LIST_12 db 00000111b, 11100111b, 00, 00, 00, 00, 000b, 02, 00011000b, 00
LIST_13 db 00100110b, 11100111b, 00, 00, 00, 00, 000b, 15, 00011000b, 00
LIST_14 db 10001000b, 11111100b, 01, 01, 01, 00, 000b, 00, 00000000b, 00
LIST_15 db 10001100b, 11111101b, 01, 01, 03, 00, 000b, 00, 00011000b, 00
LIST_16 db 10110000b, 11110000b, 00, 00, 00, 00, 000b, 00, 00001111b, 01
LIST_17 db 10100000b, 11111100b, 00, 01, 01, 00, 000b, 00, 00100000b, 00
LIST_18 db 11001101b, 11111111b, 00, 00, 00, 00, 000b, 14, 10000000b, 01
LIST_19 db 11000011b, 11111111b, 00, 00, 00, 00, 000b, 11, 10000000b, 00
LIST_20 db 11000010b, 11111111b, 00, 00, 00, 00, 000b, 11, 10000000b, 02
LIST_21 db 10011010b, 11111111b, 00, 00, 00, 00, 000b, 10, 10000000b, 04
LIST_22 db 11101010b, 11111111b, 00, 00, 00, 00, 000b, 12, 10000000b, 04
LIST_23 db 01110000b, 11110000b, 00, 00, 00, 00, 000b, 16, 10000000b, 00 ;isimtis
LIST_24 db 11101000b, 11111111b, 00, 00, 00, 00, 000b, 10, 10000000b, 20h
LIST_25 db 11101001b, 11111111b, 00, 00, 00, 00, 000b, 12, 10000000b, 20h
LIST_26 db 11101011b, 11111111b, 00, 00, 00, 00, 000b, 12, 10000000b, 10h
LIST_27 db 11100010b, 11111111b, 00, 00, 00, 00, 000b, 13, 10000000b, 10h
LIST_28 db 11111110b, 11111110b, 02, 00, 01, 00, 000b, 04, 00000000b, 00
LIST_29 db 11111110b, 11111110b, 02, 00, 01, 00, 001b, 06, 00000000b, 00
LIST_30 db 11111111b, 11111111b, 02, 00, 03, 00, 010b, 10, 00000000b, 00
LIST_31 db 11111111b, 11111111b, 02, 00, 04, 00, 011b, 10, 00000000b, 00
LIST_32 db 11111111b, 11111111b, 02, 00, 02, 00, 100b, 12, 00000000b, 00
LIST_33 db 11111111b, 11111111b, 02, 00, 03, 00, 101b, 12, 00000000b, 00
LIST_34 db 11111111b, 11111111b, 02, 00, 03, 00, 110b, 01, 00000000b, 00
LIST_35 db 11110110b, 11111110b, 02, 00, 01, 00, 100b, 08, 00000000b, 00
LIST_36 db 11110110b, 11111110b, 02, 00, 01, 00, 110b, 09, 00000000b, 00
LIST_37 db 10001111b, 11111111b, 02, 00, 03, 00, 000b, 02, 00000000b, 00
LIST_38 db 10000000b, 11111100b, 02, 00, 01, 01, 000b, 03, 00000000b, 00
LIST_39 db 10000000b, 11111100b, 02, 00, 01, 01, 101b, 05, 00000000b, 00
LIST_40 db 10000000b, 11111100b, 02, 00, 01, 01, 111b, 07, 00000000b, 00
LIST_41 db 11000110b, 11111110b, 02, 00, 01, 02, 000b, 00, 00000000b, 00
.code
mov ax, @data
mov ds, ax
mov bx, 81h ; pirmas simbolio parametre adresas
cmp byte ptr es:[bx], 13
je skip
mov dl, es:[bx + 1]
cmp dl, 13
je skip
cmp dl, '/'
jne testi
mov dl, es:[bx + 2]
cmp dl, '?'
jne wrongParams
skip:
jmp WriteInfo
testi:
; Nuskaito dvieju failu vardus
inc bx
mov di, offset file1
call ReadFileName
cmp cl, 'E'
je wrongParams
inc bx
mov di, offset rezFile
call ReadFileName
cmp cl, 'E'
je wrongParams
; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Nuskaito duomenis is failo
mov dx, offset file1
mov cx, offset duom1
call ReadFile
push cx
cmp cl, 'F'
je noFile
; Atlieka skaiciavimus
mov bx, byteNumber
call OpenFile
CiklasDisasm:
mov bx, byteNumber
pop cx
cmp bx, cx
jge endDisasm
push cx
mov si, offset duom1
mov di, offset rez
mov dh, 0
mov dl, [si][bx]
; nulina reikesmes ir padeda \N zenkla
push bx
mov bx, 0
nulinaReiksmes:
mov byte ptr [di][bx], 32
inc bx
cmp bx, 62
jge poNulinaReiksmes
jmp nulinaReiksmes
poNulinaReiksmes:
;--
mov byte ptr [di][60], 10
pop bx
mov nr, 9
call CheckCommandByte
call WriteLine
inc byteNumber
inc bx
jmp CiklasDisasm
endDisasm:
call CloseFile
; Iraso i faila
mov dx, offset ok
mov ah, 09h
int 21h
jmp exit
wrongParams:
mov dx, offset InvalidParameters
mov ah, 09h
int 21h
jmp exit
WriteInfo:
mov dx, offset Info
mov ah, 09h
int 21h
jmp exit
noFile:
push dx
mov dx, offset noFileMsg
mov ah, 09h
int 21h
pop dx
mov ah, 09h
int 21h
mov dx, offset nl
mov ah, 09h
int 21h
Exit:
mov ax, 4c00h
int 21h
ReadFileName PROC ;------------------------------------------
mov cl, 'F'
mov dx, 0
Reallocate:
mov al, es:bx
cmp al, 32
je Allocated
cmp al, 0
je Allocated
cmp al, 13
je Allocated
push bx
mov bx, dx
mov [di][bx], al
pop bx
inc bx
inc dx
jmp Reallocate
Allocated:
cmp dx, 1
jle FileError
mov cl, 'T'
jmp return2
FileError:
mov cl, 'E'
return2:
ret
ReadFileName ENDP ;-------------------------------------------
ReadFile PROC ;------------------------------------------
mov ah, 3Dh ;open
mov al, 02h
int 21h
jnc read ; CF = 0 (no error)
mov cl, 'F'
jmp readReturn
read:
mov bx, ax ; File Handler
mov dx, cx
mov cx, 255
mov ah, 3Fh ;read
int 21h
mov cx, ax
mov ah, 3Eh ;close
int 21h
readReturn:
ret
ReadFile ENDP ;-------------------------------------------
OpenFile PROC ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
push ax
push dx
mov cx, 01000000b
mov dx, offset rezFile
mov ah, 3Ch ;Create
int 21h
mov fileHandler, ax
pop dx
pop ax
ret
OpenFile ENDP
WriteLine PROC
push bx
push dx
mov bx, fileHandler ; FileHandler
mov dx, offset rez
mov cx, 61
mov ah, 40h ;Write
int 21h
mov dx, offset rez
mov ah, 09h
int 21h
pop dx
pop bx
ret
WriteLine ENDP
CloseFile PROC
push bx
push ax
mov bx, fileHandler
mov ah, 3Eh ;close
int 21h
pop ax
pop bx
ret
CloseFile ENDP ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;###################################################################
CheckCommandByte PROC ;------------------------------------------
; args: dl - byte, bx - byte address
call WriteAddress
mov dh, dl
mov safeDX, dx
mov si, offset LIST_01
CheckCiklas:
mov dx, safeDX
mov al, [si + 1]
and dl, al
mov al, [si]
cmp dl, al
jne skipComPletinys
cmp byte ptr [si + 2], 2
jne CommandFound
call ReadOneMoreByte
mov safeDX, dx
and dl, 00111000b
shr dl, 3
sub si, 10
CheckCiklas2:
add si, 10
cmp [si + 6], dl
je CommandFound
jmp CheckCiklas2
skipComPletinys:
mov ax, offset LAST_COMMAND
cmp si, ax
jge NoCommand1
add si, 10
jmp CheckCiklas
NoCommand1:
jmp NoCommand
CommandFound:
mov al, [si + 7]
call WriteCommand
and dl, 11110000b
cmp dl, 01110000b
jne skipConditionalJMP
; CONDITIONAL JUMPS
mov IsComJump, 1
mov al, dh
and al, 00001111b
call WriteCommand
mov ax, 30
mov IsPoslinkis, 1
call WriteJumpPoslinkis
jmp RetOfCheck
skipConditionalJMP:
mov dl, dh
mov al, [si + 8]
cmp al, 10000000b
jne skipNoReg
; Command with no reg
mov al, [si + 9]
cmp al, 0
je endNoReg
cmp al, 4
je callException
cmp al, 0Fh
jg skipFreeOpernad
; Free Operand
mov IsPoslinkis, al
mov ax, 30
call WriteFreeOperand
jmp endNoReg
skipFreeOpernad:
; Poslinkis
and al, 11110000b
shr al, 4
mov IsPoslinkis, al
mov ax, 30
call WriteJumpPoslinkis
jmp endNoReg
callException:
mov IsPoslinkis, 2
mov ax, 37
call WriteFreeOperand
mov IsPoslinkis, 2
mov ax, 30
call WriteFreeOperand
mov byte ptr [di + 36], ':'
endNoReg:
jmp RetOfCheck
skipNoReg:
mov IsRegSEGMENT, 0
mov al, [si + 8] ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cmp al, 00011000b
jne skipAddRegSeg
; Has seg reg here
mov IsRegSEGMENT, 1
mov al, [si + 2]
cmp al, 1 ; if it has MOD, skip adding segment now
je skipAddRegSeg ; MOD will do it
mov al, [si + 7]
cmp al, 15
jne skipSegmentoKeitimas
;segmento keitimo komanda
mov ax, 24
call WriteSegReg
jmp RetOfCheck
skipSegmentoKeitimas:
;eiline komanda su segmento registru
mov ax, 30
call WriteSegReg
jmp RetOfCheck
skipAddRegSeg:
mov al, [si + 8] ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cmp al, 00100000b
jne SkipAtmintisAX
mov IsReg16, 0
call Check8or16Reg
mov al, [si + 3]
cmp al, 1
jne AtmintisAXReverse
and dl, 00000010b
cmp dl, 00000000b
je AtmintisAXReverse
;NOrmal
mov ax, 30
call WriteDirectAddress
mov [di + 38], ' ,'
mov dl, dh
mov al, [si + 8]
and dl, al
and dl, 00001111b
or dl, IsReg16
mov ax, 40
call WriteReg
jmp skip01
AtmintisAXReverse:
;Reverse
mov ax, 34
call WriteDirectAddress
mov [di + 32], ' ,'
mov dl, dh
mov al, [si + 8]
and dl, al
and dl, 00001111b
or dl, IsReg16
mov ax, 30
call WriteReg
skip01:
jmp RetOfCheck
SkipAtmintisAX:
mov al, [si + 2]
cmp al, 0
je NoMod
Jmp HasMOD
NoMod:
;no MOD here..............................................
; word or byte
mov al, [si + 4]
cmp al, 2
je Reg8
cmp al, 3
je Reg16
cmp al, 1
jne skip02
and dl, 00000001b
cmp dl, 1
je Reg16
jmp Reg8
skip02:
mov dl, dh
mov al, [si + 8]
and dl, al
cmp dl, 00000111b
jg Reg16
Reg8:
mov dl, dh
mov al, [si + 8]
and dl, al
mov ax, 30
call WriteReg
mov al, [si + 9]
cmp al, 1
jne skip2
; has free operand
call ReadOneMoreByte
mov [di + 35], ax
mov [di + 32], ' ,'
mov byte ptr[di + 34], '0'
mov byte ptr[di + 37], 'h'
jmp skip2
Reg16:
mov dl, dh
mov al, [si + 8]
and dl, al
or dl, 00001000b
mov ax, 30
call WriteReg
mov al, [si + 9]
cmp al, 1
jne skip2
; has two free operands
call ReadOneMoreByte
mov [di + 37], ax
call ReadOneMoreByte
mov [di + 35], ax
mov [di + 32], ' ,'
mov byte ptr[di + 34], '0'
mov byte ptr[di + 39], 'h'
skip2:
jmp RetOfCheck
HasMOD:
; has MOD here............................................
cmp byte ptr [si + 2], 2
jne skipMOD2
call checkMOD2
jmp RetOfCheck
skipMOD2:
call ReadOneMoreByte
call checkMOD
jmp RetOfCheck
NoCommand:
RetOfCheck:
ret
CheckCommandByte ENDP ;-------------------------------------------
;###################################################################
ValueToHex PROC ;------------------------------------------
;arguments: dl - 1byte value to change
mov ah, 0
mov al, dl
div sx
cmp al, 9
jg raide
add al, 48
jmp antrasSimbolis
raide:
add al, 55
antrasSimbolis:
cmp ah, 9
jg raide2
add ah, 48
jmp hexEnd
raide2:
add ah, 55
jmp hexEnd
hexEnd:
ret
ValueToHex ENDP ;-------------------------------------------
WriteAddress PROC ;------------------------------------------
;arguments: bx - address
push bx
push dx
mov bx, byteNumber
add bx, poslinkisORG
mov dl, bh
call ValueToHex
mov [di + 0], ax
mov dl, bl
call ValueToHex
mov [di + 2], ax
mov byte ptr [di + 4], ':'
pop dx ; also writes the first byte
pop bx
call ValueToHex
mov [di + 6], ax
ret
WriteAddress ENDP ;-------------------------------------------
WriteCommand PROC
; arguments: al - command num
push si
push bx
mov si, offset komandos
cmp IsComJump, 1
jne skipComJump
mov si, offset jump
mov IsComJump, 0
skipComJump:
mov ah, 0
mov bx, ax
shl bx, 2
mov ax, [si][bx]
mov [di + 24], ax
add bx, 2
mov ax, [si][bx]
mov [di + 26], ax
pop bx
pop si
ret
WriteCommand ENDP
WriteReg PROC ;------------------------------------------
; args DL - reg nr or Shifted MOD REG R/M, AX - position to write
push bx
push dx
push si
mov bl, IsRegSEGMENT
cmp bl, 1
je writeSegment
mov bh, 0
mov bl, dl
shl bx, 1
mov si, offset allRegs
add di, ax
mov bx, [si][bx]
mov [di], bx ; iraso i eilute
sub di, ax
jmp endWriteReg
writeSegment:
mov dx, safeDX
call WriteSegReg
endWriteReg:
pop si
pop dx
pop bx
ret
WriteReg ENDP ;-------------------------------------------
WriteSegReg PROC ;------------------------------------------
; args DL - ComByte, AX - position to write
push bx
push dx
push si
mov bh, 0
mov bl, dl
and bl, 00011000b
shr bx, 2
mov si, offset segRegs
add di, ax
mov bx, [si][bx]
mov [di], bx ; iraso i eilute
sub di, ax
mov IsRegSEGMENT, 0
pop si
pop dx
pop bx
ret
WriteSegReg ENDP ;-------------------------------------------
WriteRegMemory PROC ;------------------------------------------
; args: DH - ComByte, DL - MOD REG R/M, AX - position to write
; return: AX - place to write next
push bx
push dx
push si
push di
push ax
mov dx, safeDX
mov bx, dx
and bl, 11000111b
cmp bl, 00000110b ; Tiesioginis adresas, MOD = 00, r/m = 110
je jmpCallDirectAddress
mov bh, 0
mov bl, dl
and bl, 00000111b
shl bx, 3
mov si, offset regMemory
add di, ax
mov ax, [si][bx]
mov [di], ax
mov ax, [si][bx + 2]
mov [di + 2], ax
mov ax, [si][bx + 4]
mov [di + 4], ax
mov ax, [si][bx + 6]
mov [di + 6], ax
and dl, 00000111b
cmp dl, 4
pop ax
jge moreThan4
;less than 5
add ax, 7
jmp skipToEnd01
moreThan4:
add ax, 4
jmp skipToEnd01
jmpCallDirectAddress:
pop ax
call WriteDirectAddress
add ax, 8
skipToEnd01:
pop di
pop si
pop dx
pop bx
ret
WriteRegMemory ENDP ;-------------------------------------------
WritePoslinkis PROC
push bx
push cx
push dx
mov bx, ax
mov ch, 0
mov cl, IsPoslinkis
cmp cl, 0
je endPoslinkis
;Yra poslinkis
mov [di][bx], '+ '
mov [di][bx + 2], '0 '
add bx, 4
cmp cl, 1
jne DviejuBaituPoslinkis
;Vieno baito poslinkis
call ReadOneMoreByte
mov [di + bx], ax
mov byte ptr [di][bx + 2], 'h'
mov ax, bx
add ax, 3
jmp endPoslinkis
DviejuBaituPoslinkis:
;Dvieju baitu poslinkis
call ReadOneMoreByte
mov [di][bx + 2], ax
call ReadOneMoreByte
mov [di][bx], ax
mov byte ptr [di][bx + 4], 'h'
mov ax, bx
add ax, 5
jmp endPoslinkis
endPoslinkis:
pop dx
pop cx
pop bx
mov IsPoslinkis, 0
ret
WritePoslinkis ENDP
WriteDirectAddress PROC
;args: ax - place where to write
push bx
push cx
push dx
mov bx, ax
mov [di][bx], '0['
mov [di][bx + 6], ']h'
call ReadOneMoreByte
mov [di][bx + 4], ax
call ReadOneMoreByte
mov [di][bx + 2], ax
mov ax, bx
pop dx
pop cx
pop bx
ret
WriteDirectAddress ENDP
WriteFreeOperand PROC
; args: IsPoslinkis - num of bytes, AX - place to write
;return: AX - symbols written
push bx
push cx
push dx
mov bx, ax
mov ch, 0