2014-01-18 52 views
-1

我是新來的nasm。 我有關於nasm的基本知識 我的程序基本上將兩個數組作爲輸入並使用冒泡排序對它們進行排序,然後合併它們以獲得一個新數組(排序),但在接受輸入時,程序不能正常工作期待它的工作。 我似乎無法找到該錯誤。 我所有的功能正在fine.There可問題「合併」的標籤 .I'm無法檢查NASM計劃 - 合併兩個陣列

請幫

section .data 

msg1: db "Enter the size of first array ",10 
len1: equ $-msg1 

msg2: db "Enter the size of second array ",10 
len2: equ $-msg2 

msg3: db "Enter the element ",10 
len3: equ $-msg3 

msg4: db "MERGED ARRAY IS ",10 
len4: equ $-msg4 

comma: db "," 
nline:db 10 

section .bss 

arr1: resb 100 
arr2: resb 100 
array: resb 200 
d1: resb 1 
d0: resb 1 
temp: resb 1 
num: resb 1 
size1: resb 1 
size2: resb 1 
size: resb 1 
i: resb 1 
j: resb 1 
s: resb 1 
r: resb 1 
read: resb 1 
section .text 
global _start: 


     ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
read_digit: 
mov eax, 3 
mov ebx, 0 
mov ecx, d1 
mov edx, 1 
int 80h 

mov eax, 3 
mov ebx, 0 
mov ecx, d0 
mov edx, 1 
int 80h 

mov eax, 3 
mov ebx, 0 
mov ecx, temp 
mov edx, 1 
int 80h 

    sub byte[d1], 30h 
    sub byte[d0], 30h 

    mov al, byte[d1] 
    mov dl, 10 
    mul dl 
    add al, byte[d0] 
    mov byte[read],al 
ret 
    ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 


    ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
read_array: 

    push rbx 

    ;Printing the message to enter the numbers 
    mov eax, 4 
mov ebx, 1 
    mov ecx, msg3 
mov edx, len3 
int 80h 

    ;Reading the number 
    mov eax, 3 
    mov ebx, 0 
    mov ecx, d1 
    mov edx, 1 
    int 80h 

mov eax, 3 
mov ebx, 0 
mov ecx, d0 
mov edx, 1 
int 80h 

mov eax, 3 
mov ebx, 0 
mov ecx, temp 
mov edx, 1 
int 80h 


sub byte[d1], 30h 
sub byte[d0], 30h 
mov al, byte[d1] 
mov dl, 10 
mul dl 
add al, byte[d0] 

;al now contains the number 
pop rbx 

mov byte[ebx], al 

add ebx, 1 

dec byte[r] 
cmp byte[r], 0 
jg read_array 
jmp end 

end: 
ret 
    ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 


     ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    sort: 
    mov byte[i], 0 

    i_loop: 
mov byte[j], 0 
j_loop: 
    mov ebx, ecx;needs ebx so given it in ecx 
    movzx eax, byte[j] 
    add ebx, eax 
    mov eax, ebx 
    add eax, 1 
    mov dl, byte[ebx] 
    mov dh, byte[eax] 
    cmp dh, dl 
    jl swap 
    jmp no_swap 

    swap: 
    mov byte[ebx], dh 
    mov byte[eax], dl 

no_swap: 
    inc byte[j] 
    mov al, byte[s] 
    sub al, byte[i] 
    sub al, 1 
    cmp byte[j], al 
    jl j_loop 

    inc byte[i] 
    mov al, byte[s] 
cmp byte[i], al 
    jl i_loop 
jmp over 

over: 
ret 
    ;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

_start: 


mov eax, 4 
mov ebx, 1 
mov ecx, msg1 
mov edx, len1 
int 80h 

call read_digit 
mov al,byte[read] 
mov byte[size1],al 
mov byte[r],al 
mov ebx,arr1 
call read_array 


    mov eax, 4 
    mov ebx, 1 
    mov ecx, msg3 
    mov edx, len3 
    int 80h 

    call read_digit 
    mov al,byte[read] 
    mov byte[size2],al 
    mov byte[r],al 
    mov ebx,arr2 
    call read_array 

    mov al,byte[size1] 
    mov byte[s],al 
    mov ecx,arr1 
    call sort 

    mov al,byte[size2] 
    mov byte[s],al 
    mov ecx,arr2 
    call sort 

    mov al,byte[size1] 
    mov ah,byte[size2] 
    add al,ah 
    sub al,1 
    mov byte[size],al 


    mov byte[i],0 
mov eax,arr1 
mov ebx,arr2 
mov ecx,array 

merge: 
mov dl,byte[eax] 
mov dh,byte[ebx] 

cmp dl,dh 
jna A                 ;if L[a]<=L[b] ;a[i]=L[a] a=a+1 
jmp B 


A: 
    mov byte[ecx],dl 
    add eax,1 
    add ecx,1 
    inc byte[i] 
    mov dl,byte[size] 
    cmp byte[i],dl 
    je done 
    jmp merge 

B: 
    mov byte[ecx],dh 
    add ebx,1 
    add ecx,1 
    inc byte[i] 
    mov dl,byte[size] 
    cmp byte[i],dl 
    je done 
    jmp merge 



done: 

mov eax, 4 
mov ebx, 1 
mov ecx, msg4 
mov edx, len4 
int 80h 

    mov ebx,array 
    mov al,byte[size] 
    mov byte[temp],al 

print: 
push rbx 

    mov al,byte[array] 
mov byte[num],al 

movzx ax,byte[num] 
    mov bl,10 
    div bl 
    mov byte[d1],al 
mov byte[d0],ah 

    add byte[d1],48 
add byte[d0],48 

mov eax, 4 
mov ebx, 1 
mov ecx, d1 
mov edx, 1 
int 80h 

    mov eax, 4 
mov ebx, 1 
mov ecx, d0 
mov edx, 1 
int 80h 

mov eax, 4 
mov ebx, 1 
mov ecx, comma 
    mov edx, 1 
int 80h 

pop rbx 

add ebx,1 
    dec byte[temp] 
cmp byte[temp],0 
jg print 

mov eax,1 
mov ebx,0 
int 80h 

回答

0

只有2種可能的錯誤,你可以在裝配:

  • 旁邊的每個指令的評論描述不正確的算法
  • 說明不這樣做旁邊的註釋爲t下襬描述

要找到您的錯誤,我開始檢查每條指令旁邊的註釋是否描述了正確的算法。它沒有。然後我繼續說,並檢查每條指令是否符合其評論所說的。他們都沒有。你的代碼是100%純錯誤。

例如,這段代碼是100個%錯誤:

mov al, byte[d1] 
    mov dl, 10 
    mul dl 
    add al, byte[d0] 

...這這一段代碼可能是100%正確的:

mov al, byte[d1] ;al = first digit read from standard input 
    mov dl, 10   ;dl = 10 
    mul dl    ;al = ax = first digit * 10 
    add al, byte[d0] ;al = al + second digit from standard input 
         ; = first digit * 10 + second digit 

以同樣的方式,這段代碼是100個%錯誤:

mov eax, 3 
    mov ebx, 0 
    mov ecx, d1 
    mov edx, 1 
    int 80h 

...這這一段代碼可能是100%正確的:

%define SYSAPI_READ 3  ;Linux kernel function number for "READ()" 
%define STDIN   0  ;File descriptor number for standard input 

    mov eax, SYSAPI_READ  ;eax = function number for Linux API 
    mov ebx, STDIN   ;ebx = file descriptor 
    mov ecx, d1    ;ecx = address of destination buffer 
    mov edx, 1    ;edx = number of bytes to read 
    int 80h     ;Call Linux kernel API 

如果你試圖解決所有的「缺乏的意見」的錯誤,這是非常有可能你甚至沒有嘗試找到你的其他問題/秒。