[英]Why can I mov into eax, into ax, but not into al, or even maybe into ah?
If I mov, eax 12345
and later mov var, eax
(assuming var is a 32bit int etc..etc..) and output var
later it'll output correctly. 如果我
mov, eax 12345
和更高版本的mov var, eax
(假设var是一个32bit的int等..等。)然后输出var
它将正确输出。
Same with ax
. 与
ax
相同。 mov ax, 65535
-> mov var16, ax
will output correctly. mov ax, 65535
> mov var16, ax
将正确输出。
But if I mov
into al
or even ah
it won't output anything. 但是,如果我
mov
到al
,甚至ah
也不会输出任何东西。
Perhaps moving into ah
not working makes sense. 也许搬进去
ah
不行是有道理的。 But why is that so for both? 但是为什么两者都这样呢?
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;
}
The problem is not (only) with your assembly code, it's the way you print your value: 问题不仅仅与汇编代码有关,而是您打印值的方式:
cout << c1 << endl;
Even though c1 is unsigned char (aka uint8), C++ iostreams treat it the same way they treat an ordinary char. 即使c1是无符号字符(也称为uint8),C ++ iostream对待它们的方式也与对待普通字符相同。 In other words, that code is roughly equivalent to:
换句话说,该代码大致等效于:
printf("%c\n", c1);
Just cast it to unsigned int and it should work fine. 只需将其转换为unsigned int,它就可以正常工作。
BTW, on some platforms (eg Linux PowerPC) the ordinary char is actually unsigned. 顺便说一句,在某些平台(例如Linux PowerPC)上,普通字符实际上是未签名的。
256
equals to 2^8
256
等于2^8
when you use int8
, it uses twos complement approach , so the number is between [-128 , 127]
当您使用
int8
,它使用二进制补码方法,因此数字在[-128 , 127]
I think if you change its type to unsigned integer , it must work 我认为如果将其类型更改为无符号 整数 ,则它必须可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.