ZIP indir
0
main
1 dal
git@carbon4code.com:ahmet/libasm.git
Ahmet Kerem Final
4 commit
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