负数被存储为2的内存补,请问CPU知道这是否是正面或负面的? [英] Negative numbers are stored as 2's complement in memory, how does the CPU know if it's negative or positive?

查看:193
本文介绍了负数被存储为2的内存补,请问CPU知道这是否是正面或负面的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-1可以重新$ P $ 4位二进制psented作为(补)1111

-1 can be represented in 4 bit binary as (2's complement) 1111

15也被重新psented 1111 $ P $。

15 is also represented as 1111.

那么,如何CPU 15 -1和区分时,它从内存中获取价值?

So, how does CPU differentiate between 15 and -1 when it gets values from memory?

推荐答案

该CPU不关心字节是否持有-1或15当它移动从一个地方到另一个地方。有作为签署的移动这样的东西。(为相同尺寸的位置 - 存在用于更大或更小的目的地有符号移动)

The CPU doesn't care whether a byte holds -1 or 15 when it moves it from one place to another. There's no such thing as a "signed move" (to a location of the same size - there is a signed move for larger or smaller destinations).

CPU只在乎当它在字节算术重新presentation。该CPU是否知道做根据了选购code,你(或代表你的编译器)选择符号或无符号运算。

The CPU only cares about the representation when it does arithmetic on the byte. The CPU knows whether to do signed or unsigned arithmetic according to the op-code that you (or the compiler on your behalf) chose.

这篇关于负数被存储为2的内存补,请问CPU知道这是否是正面或负面的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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