问题描述
我刚刚开始为我的计算机组织课程在汇编中编程,每当我尝试在一个C程序.
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.
arrayOfLetters[]
对象是一个字符数组,所以每个元素不应该是一个字节吗?当我执行 mov eax, arrayOfLetters[1]
时,代码有效,但我不确定为什么会这样,因为 eax
寄存器是 4 个字节.
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;
}
推荐答案
使用 mov al, BYTE PTR arrayOfLetters[1]
.
您可以使用 cl input.c/Faoutput.asm
使用 MSVC 编译代码以获得汇编打印输出 - 这将表明只需使用 arrayOfLetters[1]
到 DWORD PTR
并且你需要明确说明你想要一个 BYTE PTR
.
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
.
这篇关于x86 程序集中的操作数大小冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!