Ahmet Kerem Final
libasm ft_calloc.s
ft_calloc.s 463 B
global ft_calloc
extern malloc
extern __errno_location
ENOMEM equ 12
section .text
ft_calloc:
push rbx
mov rax, rdi
mul rsi
jc .fail
mov rbx, rax
mov rdi, rax
call malloc wrt ..plt
test rax, rax
jz .end
xor rcx, rcx
.loop:
cmp rcx, rbx
jae .end
mov BYTE[rax + rcx], 0
inc rcx
jmp .loop
.fail:
call __errno_location wrt ..plt
mov DWORD [rax], ENOMEM
xor eax, eax
.end:
pop rbx
ret