2016-04-22 12 views
-1

Ich habe Probleme in diesem Assembler-Code zu finden, Fehler:Problem hat, in meinem Assembly Language-Programm zu finden, Fehler

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 

Dies ist der zweite Teil des Codes:

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 

Es ist ein Programm für die Umsetzung weites Verfahren. Wenn es ausgeführt wird, geht das Programm in eine Endlosschleife. Hier Momentaufnahme der Ausgabe: out.png

+1

Debugger ................................ –

+0

Leider kann ich nicht verwenden es –

+0

Dies wäre eine gute Zeit zu lernen. Google ist dein Freund hier. Viele Online-Informationen zur Verwendung des Debuggers. – lurker

Antwort

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

Dies wird eine Endlosschleife, wenn die Eingabe etwas anderes war als „2“. Dies muss werden:

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

springt er direkt auf "zweite Zeichenfolge eingeben:"

Ihr Code ist nicht richtig strukturiert. Nach dem Verketten oder dem Unterstringsuchen müssen Sie entweder jmp entweder mit dem Label anfangen oder sonst zum wahren Ende des Programms.

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 
Verwandte Themen