汇编程序nasm显示所提供数字的所有除数

时间:2014-03-24 22:36:55

标签: assembly nasm

我必须编写显示所提供数字的所有除数的程序。数字是从键盘读取并存储在bufor但是我的程序运行不正常而且我被困在黑点...运行后我Segmentation fault (core dumped)可能会有更多的expirienced帮助它。欢迎所有建议!提前谢谢。

_start:             ;


;*******reading from keyboard

mov rax, 0 ; kyboard descriptior
mov rdx, 10 ; bytes to read
mov rdi,0 ; keyboard reading
mov rsi, bufor ; 
syscall; function call

;********loop for*************************  
    mov rax, [bufor] ;
    mov rcx, 1
    mov rcx, 2      ; ECX is i=10
for_loop:
    cmp     rcx, [bufor]        
    jae     loop_end    ; go into, when i >= edi

    xor rdx,rdx ; to avoid div errors
    mov rax, [bufor]   ;

    div rcx         ; 

    push rbp ; push function pointer to stack
    mov  rbp, rsp; store stack pointer
    push rcx ; push counter pointer to stack
    cmp  rdx, 0
    je   display

    inc  rcx                ; i++
    jmp  for_loop

loop_end:
        jmp exit


display: 
    mov  rax, 1     ; fun number

    mov rdi, 1      
    mov rsi, rcx    ; 
    mov rdx, 5      ; 
    syscall
        jmp done

done:
    pop rcx ; getcounter 
    pop rbp ;get function pointer
    ret             ; return


;*********exit from program*******
exit:
   mov rax, 60
   syscall




section .data           ; 

section .bss
     bufor       resb 5           ; bufor 5 bytes

0 个答案:

没有答案