有符号和无符号的区别,负字节是什么意思? [英] The difference between signed and unsigned, what means a negative byte?

查看:62
本文介绍了有符号和无符号的区别,负字节是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解决下面的问题,但我不了解解决方案所需的概念.

让我们考虑以下双字串:B234*A68C*h, *52B4*78C8h, *1AB3*C470h, F9DC*98B6*h.需要:

1) 在屏幕上打印 words' 的排名,这些排名具有每个双字的最小值(考虑它们无符号)

答案是'2112'(粗体字有最小值)

2) 在屏幕上打印这些单词中具有最大值值的字节的总和(考虑它们签名)>

3) 在屏幕上打印严格否定双字的*下位词*

如何区分有符号和无符号?负下位词实际上是什么意思?它是一个不适合区间 [0, 255] 的值吗?

解决方案

word 是 16 位.双字是 32 位,可以被认为是由两个单独的字组成.

在双字中,低位字是低位字(低位内存地址,因为 x86 是小端).高位字是高位字(位于较高内存地址的字).

寄存器不区分 signedunsigned 值.没有两种独立的数据类型,正如您通常在高级语言中所认为的那样.有符号和无符号之间的区别仅在您使用指令对字/双字进行操作时才起作用.指令分为三类:

  • 无符号指令,将寄存器/内存中的值视为无符号值.示例:ja(如果高于则跳转).

  • Signed 指令,将寄存器/内存中的值视为有符号值.示例:jg(大于则跳转).

  • 不可知指令,其行为方式与将值解释为有符号还是无符号无关紧要.示例:add(有符号和无符号加法相同,因为这是二进制补码算法的一个属性).

x86 指令的任何参考页/文档都应指定指令是有符号的还是无符号的.如果没有指定,则指令是不可知的.

希望这有助于澄清一些事情!

I need to solve the problem below, but I don't understand the concepts needed for solution.

Let's consider the following string of doublewords: B234*A68C*h, *52B4*78C8h, *1AB3*C470h, F9DC*98B6*h. It is required to:

1) print on the screen the words' ranks that have the minimum value from each doubleword (considering them unsigned)

The answer is '2112' (the bold words have the minimum value)

2) print on the screen the sum of the bytes that have the maximum value from these words (considering them signed)

3) print on the screen the strictly negative *lower words* of the doublewords

How can I differentiate signed from unsigned? What does actually mean negative lower word? Is it a value that doesn't fit in the interval [0, 255]?

解决方案

A word is 16 bits. A doubleword is 32 bits and can be thought of as made up of two individual words.

In a doubleword, the lower word is the low-order word (the one at the lower memory address, since x86 is little-endian). The upper word is the high-order word (the one at the higher memory address).

Registers don't differentiate between signed or unsigned values. There aren't two separate data types as you would normally think of them in a higher-level language. The difference between signed and unsigned only comes into play when you operate on words/doublewords using instructions. There are three classes of instructions:

  • Unsigned instructions, which treat values in registers/memory as unsigned values. Example: ja (jump if above).

  • Signed instructions, which treat values in registers/memory as signed values. Example: jg (jump if greater than).

  • Agnostic instructions, which behave in such a way that it doesn't matter whether the values are interpreted as signed or unsigned. Example: add (signed and unsigned addition are the same since this is a property of two's-complement arithmetic).

Any reference page/document of x86 instructions should specify whether an instruction is signed or unsigned. If it doesn't specify, the instruction is agnostic.

Hope this helps clarify things a bit!

这篇关于有符号和无符号的区别,负字节是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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