程序集x86寄存器已签名或未签名 [英] Assembly x86 registers signed or unsigned

查看:90
本文介绍了程序集x86寄存器已签名或未签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常简单的问题,但我找不到答案. x86程序集(eax,ebx edx等)中的寄存器是签名的还是未签名的?如果默认情况下对它们进行了签名,那么例如,如果我们将变量声明为unsigned int,计算机如何知道将这些寄存器视为unsigned?谢谢!

I know this is a really simple question, but I couldn't find an answer to this. Are the registers in x86 assembly (eax, ebx edx etc) signed or unsigned? If they're signed by default, how does the computer know to treat the registers as unsigned if for example we will declare a variable as unsigned int? Thanks!

推荐答案

CPU不知道也不在乎.相反,标志寄存器中的位是在某些操作上设置的,程序对这些标志的作用方式取决于源代码告诉它的内容.

The CPU does not know nor does it care. Instead, bits in the Flags register are set on certain operations, and how your program acts on those flags depends on what the source code told it to.

例如,

mov eax, 0FFFFFFFFh
test eax, eax
js isNegative

vs.

mov eax, 0FFFFFFFFh
test eax, eax
jb isNegative

第一个跳转到"IsNegative",因为test在此处设置符号标志.第二个不是,因为test将进位标志重置为0,而jb仅在它为1时才跳转.

The first jumps to 'IsNegative' because test sets the Sign Flag here. The second does not, because test resets the Carry Flag to 0 and jb only jumps if it is 1.

这篇关于程序集x86寄存器已签名或未签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆