0

I was trying to access element by element of my array of chars (initialized with calloc) in order to then convert each element to its hexadecimal representation, but when the lenght of the string goes above 1, it kind of takes all of the elements instead of only the first one when doing mov ecx,[eax] which should only go for the first element

This is my code:

//Initialize array
char* myArray = (char*)calloc(8,sizeof(char));
printf("Type the array: ");
scanf("%s",myArray);
__asm {
    mov eax,myArray
    mov ecx,[eax]
    push ecx
    push format
    call printf
   }
    

When the array is 'A' I get 65 which is the ascii representation (that's what I expect)

But when the array is 'AB' I get 16961 instead of 65

I don't quite understand why this is happening or if I missing something.

Pd. I Know I have to make a loop to iterate over all of the characters, but this is the part that is giving me problems, so I skipped the loop.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Leo
  • 11
  • 2

0 Answers0