Starting to learn assembly x86-64 and I’m writing a program that get an array of integers and does some calculations on it, the purpose isn’t relevant to the question, but the calculations include multiplications and divisions, the size and sign of the integers are not known, and the program should handle any case.
I Wonder what is the correct way to do it, should I extend the integers to the x64 size registers or should I work the EDX::EAX extenstions?
My first try is
movl (%r8), %edi #r8 holds the memory address of the array movl 4(%r8), %r10d # assume those are valid elements in the array, the check is done above movl 8(%r8), %eax imul %edi, %eax imul %r10d, %r10d cdq idiv %r10d
but from my understanding, with this instructions if the multiplication cause overflow, eax become 0 and the carry flag turned on, so dividing by r10d can cause SIGFPE due to division by 0.
What is the better approach to that? I tend to work with the x64 bit size registers so it will be easier to handle all the cases but I may be wrong.