关于装配 CF(Carry) 和 OF(Overflow) 标志 [英] about assembly CF(Carry) and OF(Overflow) flag

查看:18
本文介绍了关于装配 CF(Carry) 和 OF(Overflow) 标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,CF 表示无符号进位,OF 表示有符号溢出.那么汇编程序如何区分无符号和有符号数据,因为它只是一个位序列?(通过额外的内存存储类型信息,或者通过位置信息或其他?)这两个标志可以互换使用吗?

It's known that CF indicates unsigned carry out and OF indicates signed overflow. So how does an assembly program differentiate between unsigned and signed data since it's only a sequence of bits? (Through additional memory storage for type information, or through positional information or else?) And could these two flags be used interchangeably?

推荐答案

区别在于用于操作数据的指令,而不是数据本身.现代计算机(自 1970 年左右)使用称为二进制补码的整数数据表示,其中加法和减法对有符号数和无符号数的工作方式完全相同.

The distinction is in what instructions are used to manipulate the data, not the data itself. Modern computers (since circa 1970) use a representation of integer data called two's-complement in which addition and subtraction work exactly the same on both signed and unsigned numbers.

  • 表示的不同在于对最高有效位(也称为符号位)的解释.对于无符号数,当该数处于完全正数范围的上半部分时,设置最高有效位.对于有符号数字,当数字位于整个范围的下半部分和负半部分时,设置最高有效位.

  • The difference in representation is the interpretation given to the most significant bit (also called the sign bit). For unsigned numbers the most significant bit is set when the number is in the upper half of the wholly positive range. For signed numbers the most significant bit is set when the number is in the lower and negative half of the whole range.

不同的指令可能对同一位使用不同的解释.例如,大多数大型机器都有有符号和无符号乘法指令.具有设置小于"指令的机器可能同时具有有符号和无符号风格.

Different instructions may use different interpretations of the same bit. For example most big machines have both signed and unsigned multiply instructions. Machines with a 'set less than' instruction may have both signed and unsigned flavors.

OF(溢出标志)表明进位是否翻转了结果中最高有效位的符号,使其与参数的最高有效位不同.如果将数字解释为无符号数,则溢出标志无关紧要,但如果将它们解释为有符号数,则 OF 表示,例如,两个大的正数相加,结果为负数.

The OF (overflow flag) tells whether a carry flipped the sign of the most significant bit in the result so that it is different from the most significant bits of the arguments. If numbers are interpreted as unsigned, the overflow flag is irrelevant, but if they are interpreted as signed, OF means, e.g., two large positive numbers were added and the result was negative.

CF(进位标志)表明某个位是否完全从字中取出(例如进入第 33 位或第 65 位).如果数字被解释为无符号,进位标志意味着加法溢出,结果太大而无法放入机器字.溢出标志无关紧要.

The CF (carry flag) tells whether a bit was carried out of the word entirely (e.g. into bit 33 or bit 65). If numbers are interpreted as unsigned, carry flag means that addition overflowed, and the result is too large to fit in a machine word. The overflow flag is irrelevant.

你的问题的答案是汇编代码有几种区分有符号数据和无符号数据的方法:

The answer to your question is that assembly code has several ways of distinguishing signed from unsigned data:

  • 它可以选择 CF 或 OF 进行有符号或无符号比较.
  • 它可以选择有符号或无符号乘除指令.
  • 它可以选择有符号或无符号右移(有符号复制高位;无符号移位为零).

这篇关于关于装配 CF(Carry) 和 OF(Overflow) 标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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