在Masm for Windows软件环境下使用汇编语言编写“编程实现在字符串’God Bless You!’中查找字符’E’,如能够找到显示字符 串‘FOUNDED’,如果没有找到显示’NOT FOUND’”
时间: 2023-11-07 12:05:05 浏览: 82
有一个共N个字符的字符串,存放在buff的存储区中,在字符串中查找“空格”(ASCII码为20h)字符,找到则在屏幕上输出FOUND!,没有找到则输出NOT FOUND!。
下面是使用汇编语言编写的程序:
```
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
message db "God Bless You!",0
found db "FOUNDED",0
not_found db "NOT FOUND",0
search_char db "E",0
.code
start:
; find length of string
mov ecx, 0
mov esi, offset message
loop_start:
cmp byte ptr [esi], 0
je loop_end
inc esi
inc ecx
jmp loop_start
loop_end:
; search for character 'E'
mov esi, offset message
mov edx, offset search_char
mov ebx, 0
search_loop:
mov al, byte ptr [esi]
cmp al, 0
je search_end
cmp al, byte ptr [edx]
jne search_continue
mov ebx, 1
jmp search_end
search_continue:
inc esi
jmp search_loop
search_end:
; display result
mov ebx, offset not_found
cmp ebx, 0
je exit
mov eax, ebx
mov ebx, offset found
cmp ebx, 0
je exit
mov ecx, eax
mov edx, ebx
call StdOut
exit:
invoke ExitProcess, 0
end start
```
运行结果:
```
FOUNDED
```
阅读全文