【发布时间】:2016-04-22 11:48:27
【问题描述】:
我在此汇编代码中找不到错误:
extern accept1,str1,concate,str2,substring
section .data
msg db "1.Concate 2 strings",10,"2.Find substring",10,"3.Exit",10,"Enter choice: "
msglen equ $-msg
section .bss
cnt resd 1
choice resb 1
%macro read 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro
%macro print 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro
section .text
global _start
_start:
begin:
print msg,msglen
read choice,1
cmp byte[choice],31h
jne next
call accept1
call concate
next:
cmp byte[choice],32h
jne next
call accept1
call substring
exit:
cmp byte[choice],33h
jne begin
mov eax,1
mov ebx,0
int 80h
这是代码的第二部分:
global accept1,concate,str1,str2,substring
section .data
msg1 db "Enter the 1st string: "
msg1len equ $-msg1
msg2 db "Enter the 2nd string: "
msg2len equ $-msg2
nl db " ",10
nllen equ $-nl
section .bss
str1 resb 15
str2 resb 15
strlen1 resb 15
strlen2 resb 15
count resb 1
temp resb 100
%macro read 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro
%macro print 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro
section .text
accept1:
print msg1,msg1len
read str1,15
dec al
mov [strlen1],al
print msg2,msg2len
read str2,15
dec al
mov [strlen2],al
ret
concate:
cld
mov esi,str2
mov edi,str1
add edi,[strlen1]
mov ecx,[strlen2]
rep movsb
mov eax,[strlen1]
add eax,[strlen2]
mov [temp],eax
print str1,15
print nl,nllen
ret
substring:
CLD
mov byte[count],00
mov esi,str2
mov edi,str1
mov ebp,edi
mov eax,[strlen1]
sub eax,[strlen2]
inc eax
up:
mov ecx,[strlen2]
repe cmpsb
jnz next
inc byte[count]
next:
inc ebp
mov edi,ebp
mov esi,str2
dec eax
jnz up
add byte[count],30h
print count,1
print nl,nllen
ret
【问题讨论】:
-
调试器.......................
-
可惜我不知道怎么用
-
这是学习的好时机。谷歌是你的朋友。大量在线信息可帮助您使用调试器。
-
我明天有考试
-
你还是应该学会使用调试器。此外,学习通读您的代码。只需几秒钟的检查就可以发现:
next: cmp byte[choice],32h,然后是jne next。因此,如果byte [choice]不等于32h,则您处于无限循环中。