比较两个字符串
1. 题目:比较字符串是否相等
2. 要求:写一程序,比较两个字符串String1和String2所含的字符是否相同;若相同则显示’Match’,否则显示’No Match’。
输入两个字符串之后,将串操作所必须的寄存器等参数设置好,然后使用串操作指令进行从头到尾的比较,两个字符串相等的条件是串长度相等且对应的字符相同。
复制代码
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
2081 ; Example assembly language program -- 2 ; Author: karllen 3 ; Date: revised 05/2014 4 5 .386 6 .MODEL FLAT 7 8 ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD 9 10 INCLUDE io.h ; header file for input/output 11 12 cr EQU 0dh ; carriage return character 13 Lf EQU 0ah ; line feed 14 15 .STACK 4096 ; reserve 4096-byte stack 16 17 .DATA 18 str1 BYTE 80 DUP(?) 19 str2 BYTE 80 DUP(?) 20 value BYTE 11 DUP(?) 21 length1 DWORD ? 22 length2 DWORD ? 23 24 promot1 BYTE "Please Enter String1",cr,Lf,0 25 promot2 BYTE "Please Enter String2",cr,Lf,0 26 crlf BYTE cr,Lf,0 27 28 answerYes BYTE "Match",cr,Lf,0 29 answerNo BYTE "No Match",cr,Lf,0 30 PUBLIC _start ; make entry point public 31 .CODE ; start of main program code 32 _start: 33 output promot1 34 input str1,80 35 lea eax,str1 36 push eax 37 call strlen 38 add esp,4 39 mov length1,eax 40 dtoa value,eax 41 output value 42 output crlf 43 44 output promot2 45 input str2,80 46 lea eax,str2 47 push eax 48 call strlen 49 add esp,4 50 mov length2,eax 51 dtoa value,eax 52 output value 53 output crlf 54 55 mov edx,length2 56 ;;cmp String1 and String2 57 cmp eax,edx ;如果长度不相等 58 jne endCMP ;则结束 59 ;比较 60 lea esi,str1 61 lea edi,str2 62 mov ecx,length2 ;比较的长度 63 repe cmpsb 64 jz found ;比较成功则跳转 65 66 endCMP: 67 output answerNo 68 jmp endMatch 69 found: 70 output answerYes 71 ; 72 endMatch: 73 74 INVOKE ExitProcess, 0 ; exit with return code 0 75 76 strlen PROC NEAR32 77 push ebp 78 mov ebp, esp 79 80 sub eax, eax 81 mov ebx, [ebp+8] 82 whileChar: cmp BYTE PTR [ebx], 0 83 je endWhileChar 84 inc eax 85 inc ebx 86 jmp whileChar 87 endWhileChar: 88 pop ebp 89 ret 90 strlen ENDP 91 END ; end of source code
转载于:https://www.cnblogs.com/Forever-Kenlen-Ja/p/3734430.html
最后
以上就是负责柠檬最近收集整理的关于汇编语言-比较字符串的全部内容,更多相关汇编语言-比较字符串内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复