Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly NASM-hamming距离_Assembly_Nasm_Hamming Code - Fatal编程技术网

Assembly NASM-hamming距离

Assembly NASM-hamming距离,assembly,nasm,hamming-code,Assembly,Nasm,Hamming Code,我编写了这个汇编代码来确定用户输入的两个字符串之间的汉明距离。我对汇编一点也不熟悉,这是我除了编写helloWorld之外的第一次尝试 除了打印两个字符串之间的距离外,我认为代码应该是正确的 extern printf extern sscanf extern fscanf section .data ; instatiating constants ( variables ) msg1: db "Enter string to be compared less than 256 char

我编写了这个汇编代码来确定用户输入的两个字符串之间的汉明距离。我对汇编一点也不熟悉,这是我除了编写helloWorld之外的第一次尝试

除了打印两个字符串之间的距离外,我认为代码应该是正确的

extern printf
extern sscanf
extern fscanf

section .data ; instatiating constants ( variables ) 

msg1: db "Enter string to be compared less than 256 characters:",10 ; db allocates 
                                                                ;space in memory
len1: equ $-msg1 

msg2 db "Enter another string to be compared:",10 ;
len2: equ $-msg2

count:  dd 0               ;for the hamming code loop
    ; another string for "hamming distance"
    ; maybe make an error message


section .bss ; reserve space for data
;;  the bss section typically includes all uninitialized variables, as
;;  well as uninitialized variables declared STATIC

input1:     resb 256    ; 256 is max length of buffer
input2:     resb 256    ; "                        "
length1:    resb 4      ; reserve length of first string
length2:    resb 4      ; reserve lenght of second string


section .text ; 

global main

main:


; access to the contents of a memory location
; requires square brackets around the address

;; any access to the address of a variable doesn't require brackets

            ; mov is
;; http://www.freebsd.org/doc/en/books/developers-handbook/x86-system-ca        lls.html

;; Prompt user for input
mov     eax, 4      ; moves sys_call write to eax
mov     ebx, 1      ;moves std_out to ebx
mov     ecx, msg1
mov     edx, len1
int 0x80        ; could do 080h , calls kernel to write
;;
;;
;; Get user input
mov     eax, 3          ;Moves sys_call read to eax
mov     ebx, 0      ;Moves sys_call std_in to ebx
mov     ecx, input1     ; address of buffer
mov     edx, 255
int 0x80        ;length of buffer
;;
;;
;; Error checking
sub     eax,1       ;remove carriage return
mov     [length1], eax  ;save length of string

;; Prompt user for input
mov     eax, 4      ; moves sys_call write to eax
mov     ebx, 1      ;moves std_out to ebx
mov     ecx, msg2
mov     edx, len2
int     0x80        ; could do 080h , calls kernel to write
;;
;;
;; Get user input
mov     eax, 3          ;Moves sys_call read to eax
mov     ebx, 0      ;Moves sys_call std_in to ebx
mov     ecx, input2     ; address of buffer
mov     edx, 255
int     0x80        ;length of buffer
;;
;;
;; Error checking
sub     eax,1       ;remove carriage return
mov     [length2], eax  ;save length of string

loop:
mov     esi, input1               ; point to start of string1 
mov     edi, input2               ; point to start of string2

mov     eax,[length1]       ; compare string sizes 
mov     ebx,[length2]       ; and loop based on smallest 
cmp     eax,ebx         ; string size
jg      str2_Sml        ; string2 is smaller jump     

                ; string1 is smaller...
mov     ecx, eax            ; initialize count
jmp     L1_test         ; start the loop

str2_Sml:
mov     ecx, ebx            ; initialize count
jmp     L1_test         ; start the loop

L1_test:     
cmp     ecx,31          ; if there are more then 31 chars
jb      L1_top  
mov     ecx,31          ; fail safe


L1_top:

mov     al, [esi]               ; get a character from str1
mov     bl, [edi]               ; get a character from str2
inc     esi                     ; update str1 ptr
inc     edi         ; update str2 ptr

xor     al, bl          ; find the different bits   
mov     ah, 8           ; setup innerloop counter
L2_top:
dec     ah      ; decrement bit counter
jz      L1_cont     ; get new char to ham every
                ; 8 bits

shr     al,1        ; rotate string1 
jc      Bit_on      ; bit is on
jmp     L2_top      ; bit is off so re-loop         

Bit_on:
                ; we have a different bit
inc     dword [count]   ; inc ham count
jmp     L2_top      ; cont loop

L1_cont:
dec     ecx                     ; update char count
jnz     L1_top                  ; loop to top if more chars

;trying to print
我想这就是我的错误所在:

mov     eax, 4      ; moves sys_call write to eax
mov     ebx, 1  ;moves std_out to ebx
mov     ecx,ecx
mov     edx, 255
int 0x80            ; calls kernel




exit:   
mov     eax, 1      ;exit
mov     ebx, 0      ;
int 0x80        ;kernel command

什么错误?它不能建造吗?你是否运行它并得到一个错误,或错误的答案?在你说你有问题的区域,你有mov ecx,ecx。这不仅不起任何作用,而且ecx包含一个字符计数,此时可能为0。它不应该是要为即将到来的int 0x80打印的字符串的地址吗?我假设您需要将计算出的汉明距离转换为ASCII字符串,并将该字符串的地址放入ecx中。