I'm trying to re-write the function strcmp
in assembly.
I wrote this code:
global _ft_strcmp
section .text
_ft_strcmp:
mov rax, 0
mov rdx, -1
_loop:
inc rdx
mov dh, BYTE[rsi + rdx]
mov al, BYTE[rdi + rdx]
cmp dh, al
je _loop
jmp _exit
_exit:
sub dh, al
mov rax, dh
ret
main.c:
#include <stdio.h>
#include <string.h>
int ft_strcmp(char *s1, char *s2);
int main()
{
printf("|-%d-||-%d-|\n",ft_strcmp("mehdi", "Mehdi"), strcmp("mehdi", "Mehdi"));
return (0);
}
when I compile the file ft_strcmp.s I get this error:
test nasm -f macho64 ft_strcmp.s
ft_strcmp.s:18: error: invalid combination of opcode and operands
EDIT: I'm using Intel x86_64 syntax :)