无法在linux上的汇编程序中编译代码

时间:2017-01-26 08:50:22

标签: gcc assembly nasm

当我使用命令时:

  

gcc Zad4.o -m32 -o Zad4.out

我不认为这是代码的问题,因为我已编译文件(.o)。我在汇编程序中使用的库可能存在问题吗?

我明白了:

usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

汇编程序中有代码:

section .text

    global main
    global isPrime

    extern printf


isPrime:

    push ebp
    mov ebp,esp

    mov eax, [ebp + 8]

    ; if( eax == 1) return false
    cmp eax,1
    je .falseEnd
    ; if( eax == 2) return true
    cmp eax,2
    je .trueEnd

    ; dzielnie eax div 2
    push eax
    mov bx,2
    mov dx,0
    div bx
    mov bx,ax ; bx = eax div 2
    mov cx,3 ; cx - licznik petli 
    pop eax

    .loop:
    cmp cx,bx
    jg .trueEnd
    ; if ( eax % cx == 0 ) return false
    push eax
    mov dx,0
    div cx
    cmp dx,0
    je .falseEnd
    pop eax

    inc cx
    jmp .loop

    .trueEnd:
    mov eax,1
    leave
    ret

    .falseEnd:
    mov eax,0
    leave
    ret


main:
    mov ecx,0

    .loop:
    inc ecx
    cmp ecx, 1000
    jge .end
    push ecx
    call isPrime
    pop ecx
    cmp eax,1
    jne .loop
    push ecx
    push printINT
    call printf
    add esp,4
    pop ecx
    jmp .loop

    .end:
    push printEndLine
    call printf
    add esp, 4
    ret

section .data

    printINT: db'%4d ',0

    printEndLine: db 10,0

0 个答案:

没有答案