• Nasm error undefined reference to printf

    From Mohammad Fayad@21:1/5 to All on Sun Dec 19 17:04:09 2021
    Hello this is my code im trying to do a program that checks if a number is divisble by 2 and 8 and im getting an error undefined printf
    This is the code:

    global _start

    extern _printf

    SECTION .data
    message1: db "Enter a number: ", 0
    number1: db "%d", 0
    integer1: times 10 db 0 ; 32-bits integer = 10 bytes
    msg db 'Divisible by 2 and 8', 0xa,0xd
    len equ $ - msg
    SYS_EXIT equ 1
    STDOUT EQU 1
    SYS_WRITE EQU 4
    SECTION .bss
    val2 resb 2

    SECTION .text

    _start:

    push message1
    call _printf
    pop rbx
    mov eax, 3
    mov ebx, 1
    mov ebx, val2
    mov edx, 2
    int 0x80
    push val2
    mov al, [val2]

    l1:
    .divisble_by_2:
    mov ax, [number1]
    xor dx, dx
    mov bx, 2
    div bx
    cmp dx, 0
    jnz .not_divisible

    .divisble_by_8:
    mov ax, [number1]
    xor dx, dx
    mov bx, 8
    div bx
    cmp dx, 0
    jnz .not_divisible

    .print_number:
    mov edx, [number1]
    add edx, 48
    mov [number1], edx

    mov eax, 4
    mov ebx, 1
    mov ecx, [number1]
    mov edx, len
    int 0x80
    mov eax, .divisble_by_2
    int 0x80

    .not_divisible:
    xor eax, eax
    mov edx, [eax+len]
    mov al, 1
    mov esi, .divisble_by_2
    mov edi, eax
    mov eax, 1
    int 0x80
    jmp _start

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mohammad Fayad@21:1/5 to All on Sun Dec 19 17:08:48 2021
    Hello im trying to write a program that checks if a number is divisble by 2 and 8 and prints numbers in loop and im getting error undefined reference to printf
    This is the code:
    global _start

    extern _printf

    SECTION .data
    message1: db "Enter a number: ", 0
    number1: db "%d", 0
    integer1: times 10 db 0 ; 32-bits integer = 10 bytes
    msg db 'Divisible by 2 and 8', 0xa,0xd
    len equ $ - msg
    SYS_EXIT equ 1
    STDOUT EQU 1
    SYS_WRITE EQU 4
    SECTION .bss
    val2 resb 2

    SECTION .text

    _start:

    push message1
    call _printf
    pop rbx
    mov eax, 3
    mov ebx, 1
    mov ebx, val2
    mov edx, 2
    int 0x80
    push val2
    mov al, [val2]

    l1:
    .divisble_by_2:
    mov ax, [number1]
    xor dx, dx
    mov bx, 2
    div bx
    cmp dx, 0
    jnz .not_divisible

    .divisble_by_8:
    mov ax, [number1]
    xor dx, dx
    mov bx, 8
    div bx
    cmp dx, 0
    jnz .not_divisible

    .print_number:
    mov edx, [number1]
    add edx, 48
    mov [number1], edx

    mov eax, 4
    mov ebx, 1
    mov ecx, [number1]
    mov edx, len
    int 0x80
    mov eax, .divisble_by_2
    int 0x80

    .not_divisible:
    xor eax, eax
    mov edx, [eax+len]
    mov al, 1
    mov esi, .divisble_by_2
    mov edi, eax
    mov eax, 1
    int 0x80
    jmp _start

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Frank Kotler@21:1/5 to Mohammad Fayad on Mon Dec 20 00:20:55 2021
    On 12/19/2021 08:04 PM, Mohammad Fayad wrote:
    Hello this is my code im trying to do a program that checks if a number is divisble by 2 and 8 and im getting an error undefined printf

    Hi Mohammad,

    This is the code:

    global _start

    extern _printf

    No underscore in GNU C?

    Best.
    Frank

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang kern@21:1/5 to Mohammad Fayad on Mon Dec 20 10:29:11 2021
    On 20/12/2021 02:04, Mohammad Fayad wrote:
    Hello this is my code im trying to do a program that checks if a number is divisble by 2 and 8 and im getting an error undefined printf
    This is the code:

    cant help with the error but:
    dividable by two:
    test[variable],01
    jnz not_by_2
    dividable by eight:
    test[variable],07
    jnz by_2_but_not_by8
    by2and8:
    ...

    or much easier:
    test[variable],15
    ;dividable by 2 and 8 if four least significant bits are zero
    jnz failed
    by2and8:
    ...
    __
    wolfgang

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From wolfgang kern@21:1/5 to wolfgang kern on Mon Dec 20 10:55:42 2021
    On 20/12/2021 10:29, wolfgang kern wrote:
    On 20/12/2021 02:04, Mohammad Fayad wrote:
    Hello this is my code im trying to do a program that checks if a
    number is divisble by 2 and 8 and im getting an error undefined printf
    This is the code:

    cant help with the error but:
    dividable by two:
      test[variable],01
      jnz not_by_2
    dividable by eight:
      test[variable],07
      jnz by_2_but_not_by8
    by2and8:
    ...

    or much easier:
     test[variable],15
     ;dividable by 2 and 8 if four least significant bits are zero
     jnz failed
    by2and8:
    ...

    oops :):)
    if a number is dividable by 8 then it's dividable by 2 as well

    __
    wolfgang

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)