Reputation: 203
I've just started programming in Assembly for my computer organization course, and I keep getting an operand size conflict
error whenever I try to compile this asm
block within a C program.
The arrayOfLetters[]
object is a char array, so shouldn't each element be one byte? The code works when I do mov eax, arrayOfLetters[1]
, but I'm not sure why that works, as the eax
register is 4 bytes.
#include <stdio.h>
#define SIZE 3
char findMinLetter( char arrayOfLetters[], int arraySize )
{
char min;
__asm{
push eax
push ebx
push ecx
push edx
mov dl, 0x7f // initialize DL
mov al, arrayOfLetters[1] //Problem occurs here
mov min, dl // read DL
pop edx
pop ecx
pop ebx
pop eax
}
return min;
}
int main()
{
char arrayOfLetters[ SIZE ] = {'a','B','c'};
int i;
printf("\nThe original array of letters is:\n\n");
for(i=0; i<SIZE; i++){
printf("%c ", arrayOfLetters[i]);
}
printf("\n\n");
printf("The smallest (potentially capitalized) letter is: %c\n", findMinLetter( arrayOfLetters, SIZE ));
return 0;
}
Upvotes: 1
Views: 1973
Reputation:
Use mov al, BYTE PTR arrayOfLetters[1]
.
You can compile the code with MSVC using cl input.c /Faoutput.asm
to get an assembly printout - this would show that simply using arrayOfLetters[1]
translates to DWORD PTR
and you need to explicity state you want a BYTE PTR
.
Upvotes: 3