Mohammad Fayad
2021-12-20 01:04:09 UTC
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
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