Can I add al register to eax register? Trying to create an assembly code in c++ to turn string number into int number (operand size conflict) [duplicate]

  assembly, c++, x86

basically the title, task is that we need to turn a string number into an int number through assembly, I think I found a code that might be working, but there is one error I can’t seem to be able to solve, it’s an error "operand size conflict" in a line that’s:

add eax, temp_char

#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {

    int iLettersCount;
    char* argv1 = argv[1];

    if (argc < 2) {
        printf("Nepateiktas parametrasn");
        return(0);
    }


    __asm {
        atoi :
        mov eax, 0
        mov ecx, argv1

            convert:
            mov al, byte ptr [ecx]
            mov temp_char, al
            cmp temp_char, '0'
            je done

            cmp temp_char, 48
            jl error

            cmp temp_char, 57
            jg error

            sub temp_char, 48
            imul eax, 10
            add eax, temp_char

            inc rdi
            jmp convert

            error :
            mov eax, -1

            done :
            ret 


};


    return(0);
}

Thank you for any suggestions and answers!

Source: Windows Questions C++

LEAVE A COMMENT