-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab2.asm
128 lines (112 loc) · 2.17 KB
/
Lab2.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
.model small
.stack 100h
.data
size equ 200
stringTwo db size dup ('$')
substring db ' number$'
len dw 7
strlen dw 0
nstr db 0DH,0AH,24H
nums db '0123456789$'
.code
macro scanf str
lea dx, str
mov offset str, size
mov ah, 0Ah
int 21h
endm
macro print str
mov dx, offset str[2]
mov ah,9
int 21h
endm
macro NextString
mov dx, offset nstr
mov ah,9
int 21h
endm
macro Leave
mov ax, 4C00h
int 21h
endm
start:
mov ax, @data
mov ds, ax
scanf stringTwo
mov cx, 10
mov di, offset nums
l1:
mov si, offset stringTwo
push cx
mov cx, size
mov bl, [di]
l2:
cmp [si], bl
je L_Found
jmp L_Cont
L_Found:
push cx
push di
mov di, si
add si, len
push si
jmp Func
L_Cont:
inc si
cmp [si], '$'
je LeaveFirstLoop
loop l2
LeaveFirstLoop:
inc di
pop cx
loop l1
NextString
print stringTwo
Leave
Func:
;cycle to get strlen
mov si, offset stringTwo
mov cx, 200
len1:
cmp [si], '$'
je len1_Break
inc si
inc strlen
loop len1
len1_Break:
;cycle
mov si, offset stringTwo
add si, strlen
sub strlen, di ; how much symbols to push
add strlen, 2
mov cx, strlen
move1:
push cx
mov cx, len
move2:
mov al, [si]
inc si
mov ah, [si]
mov [si], al
loop move2
sub si, len
dec si
pop cx
loop move1
mov si, offset stringTwo
add si, di
mov cx, len
mov di, si
dec di
mov si, offset substring
f:
mov al, [si]
mov [di], al
inc si
inc di
loop f
pop si
pop di
pop cx
jmp L_Cont
end start