0

Hello so i have a assignment that requires me to make an ASM mix C function. So what i understand is that i have to sub my char either '0' or 48 to get the decimal part. The issue i have is that it always return the address of rdi instead of the value even when i only do mov rax, rdi ; ret. Can someone please help me understand ? Also if you have insight on how to make the atoi function work...

global myitoa

myitoa:
    mov rax, 0
    mov rsi, rdi
    sub rsi, 48
    mov rax, rsi
    ret


#include <stdio.h>

long long myitoa(char *s);

int main() {

    printf("myitoa(\"5\")=%lli\n", myitoa("5")); // 5

the main issue is that i always get the adress back instead of the value

1111 B
  • 1
  • You're returning `p - '0'` instead of `*p - '0'` because your asm doesn't dereference the pointer. It's not going to magically do that if you don't use square brackets. – Peter Cordes Dec 02 '22 at 09:04

0 Answers0