gpt4 book ai didi

c - x86 汇编中的操作数大小冲突

转载 作者:太空宇宙 更新时间:2023-11-04 02:14:07 25 4
gpt4 key购买 nike

我刚开始在我的计算机组织类(class)中使用 Assembly 进行编程,每当我尝试在C程序。

arrayOfLetters[] 对象是一个字符数组,那么每个元素不应该是一个字节吗?当我执行 mov eax, arrayOfLetters[1] 时,代码可以正常工作,但我不确定为什么会这样,因为 eax 寄存器是 4 个字节。

#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

关于c - x86 汇编中的操作数大小冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10070213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com