为什么我可以进入EAX,斧头,但不能进入Al,甚至进入AH

Why can I mov into eax, into ax, but not into al, or even maybe into ah?

本文关键字:AH Al 但不能 EAX 为什么 斧头 我可以      更新时间:2023-10-16

如果i mov, eax 12345及以后的 mov var, eax(假设var为32bit int etc.eTC ..),然后输出 var稍后它将正确输出。

ax相同。mov ax, 65535-> mov var16, ax将正确输出。

但是,如果我将mov转到al甚至ah中,则不会输出任何内容。

也许进入ah不起作用是有道理的。但是为什么这两个呢?

typedef int int32;
typedef unsigned char int8;
typedef short int16;
int _tmain(int argc, _TCHAR* argv[])
{
    int8  c1 = 0;
    int8  c2 = 0;
    __asm
    {
        mov al, 255
        mov c1, al
    }
    cout << c1 << endl; //outputs nothing, same if I used ah
    //whereas
    int32 n = 0;
    __asm 
    {
        mov eax, 10000
        mov n, eax
    }
    cout << n << endl; // works fine, well, you get the picture
    return 0;
}

这个问题不是(仅)与您的汇编代码,这是您打印价值的方式:

cout << c1 << endl;

即使C1是未签名的char(又名UINT8),C iostreams也像对待普通char一样对待它。换句话说,该代码大致等于:

printf("%cn", c1);

将其施放给未签名的int,它应该可以正常工作。

btw,在某些平台上(例如Linux PowerPC),普通char实际上是未签名的。

256等于 2^8

当您使用int8时,它使用TWOS补体方法,因此数字在[-128 , 127]

之间

我认为,如果您将其类型更改为 unsigned Integer ,它必须工作