Поменять местами первое и последнее слова
24.12.2010, 13:27. Показов 2533. Ответов 0
Задача: поменять местами первое и последнее слова + записать результат в файл + надо пробелы лишние удалить (не реализовал, но и не главное)
Что-то у меня не правильно работает...не пойму что:
Assembler | 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
| .model small
.stack 100h
.386
.data
buf db 100
len db ?
stri db 100 dup ('$')
rstr db 100 dup ('$')
percar db 10,13,'$'
msgi db 'enter string: $'
msgv db 'entered string: $'
msgr db 'result string: $'
probel db ' '
lenbw dw ?
lenew dw ?
wordfromb dw ?
wordfrome dw ?
lenstrmid dw ?
strmid dw ?
filename db 'file.txt',0
handle dw ?
lenc dw ?
.code
begin: mov ax,@data
mov ds,ax
mov es,ax
xor ax,ax
; vyvodit msgi
mov ah,09h
lea dx,msgi
int 21h
; vvod stroki
mov ah,0ah
lea dx,buf
int 21h
; perevod karetki
mov ah,09h
lea dx,percar
int 21h
; vyvod msgv
mov ah,09h
lea dx,msgv
int 21h
; vyvod vvedenoy stroki
mov ah,09h
lea dx,stri
int 21h
; schitaem dlinu pervogo slova
lea di,stri
mov al,len
cbw
mov lenc,ax
mov cx,lenc
xor bx,bx
cld
mov al,probel
repne scasb
mov bx,lenc
sub bx,cx
sub bx,1
mov lenbw,bx
xor bx,bx
; schitaem dlinu poslednego slova
lea di,stri
add di,lenc
dec di
mov cx,lenc
xor bx,bx
std
mov al,probel
repne scasb
mov bx,lenc
sub bx,cx
sub bx,1
mov lenew,bx
xor bx,bx
; zapisyvaem pervoe slovo v "wordfromb"
lea di,wordfromb
lea si,stri
mov cx,lenbw
cld
met3: movsb
loop met3
; zapisyvaem poslednee slovo v "wordfrome"
lea di,wordfrome
lea si,stri
add si,lenc
sub si,lenew
sub si,1
mov cx,lenew
cld
met4: movsb
loop met4
; schitaem "lenstrmid"
lea si,stri
add si,lenc
sub si,lenew
sub si,lenbw
mov lenstrmid,si
; zapisyvaem vse chto ostalos mejdu "wordfromb" i "wordfrome" v "strmid"
lea si,stri
lea di,strmid
mov cx,lenstrmid
cld
met5: movsb
loop met5
;zapisyvaem "wordfromb","wordfrome" i "strmid" v "rstr"
lea di,rstr
mov cx,lenbw
met6: movsb
loop met6
lea si,strmid
mov cx,lenstrmid
met7: movsb
loop met7
lea si,wordfrome
mov cx,lenew
met8: movsb
loop met8
; zapisyvaem "rstr" v file
mov ah, 3ch
mov dx, offset filename
xor cx, cx
int 21h ; sozdaem file
mov handle,ax
mov ah,40h
mov bx,handle
mov cx,lenc
mov dx,offset rstr
int 21h ; zapisyvaem "rstr" v file
mov ah,3eh
mov bx,handle
int 21h ; zakryvaem file
mov ax,4c00h
int 21h
end begin ; the end |
|
Добавлено через 3 часа 30 минут
написал сам уже (удаление лишних пробелов пока не сделал)
вот...возможно пригодится:
Assembler | 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
| .model small
.stack 100h
.386
.data
buf db 100
len db ?
stri db 100 dup ('$')
rstr db 100 dup ('$')
percar db 10,13,'$'
msgi db 'enter string: $'
msgv db 'entered string: $'
msgr db 'result string: $'
probel db ' '
lenbw dw ?
lenew dw ?
wordfromb db 100 dup ('$')
wordfrome db 100 dup ('$')
lenstrmid dw ?
strmid db 100 dup ('$')
filename db 'file.txt',0
handle dw ?
lenc dw ?
.code
begin: mov ax,@data
mov ds,ax
mov es,ax
xor ax,ax
; vyvodit msgi
mov ah,09h
lea dx,msgi
int 21h
; vvod stroki
mov ah,0ah
lea dx,buf
int 21h
; perevod karetki
mov ah,09h
lea dx,percar
int 21h
; vyvod msgv
mov ah,09h
lea dx,msgv
int 21h
; vyvod vvedenoy stroki
mov ah,09h
lea dx,stri
int 21h
; schitaem dlinu pervogo slova
lea di,stri
mov al,len
cbw
mov lenc,ax
mov cx,lenc
xor bx,bx
cld
mov al,probel
repne scasb
mov bx,lenc
sub bx,cx
sub bx,1
mov lenbw,bx
xor bx,bx
; schitaem dlinu poslednego slova
lea di,stri
add di,lenc
dec di
mov cx,lenc
xor bx,bx
std
mov al,probel
repne scasb
mov bx,lenc
sub bx,cx
sub bx,1
mov lenew,bx
xor bx,bx
; zapisyvaem pervoe slovo v "wordfromb"
lea di,wordfromb
lea si,stri
mov cx,lenbw
cld
met3: lodsb
stosb
loop met3
; zapisyvaem poslednee slovo v "wordfrome"
lea di,wordfrome
lea si,stri
add si,lenc
sub si,lenew
mov cx,lenew
cld
met4: lodsb
stosb
loop met4
; schitaem "lenstrmid"
mov ax,lenc
sub ax,lenew
sub ax,lenbw
mov lenstrmid,ax
; zapisyvaem vse chto ostalos mejdu "wordfromb" i "wordfrome" v "strmid"
lea si,stri
add si,lenbw
lea di,strmid
mov cx,lenstrmid
cld
met5: lodsb
stosb
loop met5
;zapisyvaem "wordfrome","wordfromb" i "strmid" v "rstr"
lea si,wordfrome
lea di,rstr
mov cx,lenew
met6: lodsb
stosb
loop met6
lea si,strmid
mov cx,lenstrmid
met7: lodsb
stosb
loop met7
lea si,wordfromb
mov cx,lenbw
met8: lodsb
stosb
loop met8
; zapisyvaem "rstr" v file
mov ah, 3ch
mov dx, offset filename
xor cx, cx
int 21h ; sozdaem file
mov handle,ax
mov ah,40h
mov bx,handle
mov cx,lenc
mov dx,offset rstr
int 21h ; zapisyvaem "rstr" v file
mov ah,3eh
mov bx,handle
int 21h ; zakryvaem file
mov ax,4c00h
int 21h
end begin ; the end |
|
не обращайте внимания на некоторые неиспользуемые переменные в DATA - это я в процессе решил от них отказаться и не удалил из кода.
|