2016-04-22 14 views
-1

私はトラブルこのアセンブリコードに誤りを見つけたんだ

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 

これは、コードの2番目の部分ですが:

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 

それはプログラムがありますfarプロシージャを実装するためのものです。実行すると、プログラムは無限ループに入ります。ここでは、出力のスナップショットがあります:入力は「2」よりも何か他のものだった場合out.png

+1

デバッガ................................ –

+0

残念ながら、私はどのように使用するのか分かりませんそれは –

+0

これは学ぶのによい時間です。 Googleはあなたの友人です。デバッガの使用に役立つオンライン情報がたくさんあります。 – lurker

答えて

0
next: 
cmp byte[choice],32h 
jne next 

これは無限ループになります。これになる必要があります。

next: 
cmp byte[choice],32h 
jne exit 

それが直接、「2番目の文字列を入力します」にジャンプ

コードが正しく構成されていません。連結または部分文字列検索の後にjmpにラベルbeginのいずれか、またはプログラムの真の終わりのいずれかが必要です。

begin: 
    print msg,msglen 
    read choice,1 

    cmp byte[choice],31h 
    jne next 
    call accept1 
    call concate 
    jmp OverAndOut 

next: 
    cmp byte[choice],32h 
    jne exit 
    call accept1 
    call substring 
    jmp OverAndOut 

exit: 
    cmp byte[choice],33h 
    jne begin 

OverAndOut: 
    mov eax,1 
    mov ebx,0 
    int 80h 
関連する問題