简体   繁体   English

与内存相关的 ISA 功能有哪些?

[英]What are the memory-related ISA features?

I'm preparing for a Computer Architecture exam, and I can't seem to answer this question:我正在准备计算机体系结构考试,但我似乎无法回答这个问题:

The following code is useful in checking a memory-related ISA feature.以下代码可用于检查与内存相关的 ISA 功能。 What can you determine using this function?使用此 function 可以确定什么?

#define X 0
#define Y 1

int mystery_test(){
        int i = 1;
        char *p = (char *) &i;
        if(p[0] == 1) return X;
        else return Y;
}

I was thinking that it would check that pointers and arrays are basically the same, but that isn't a memory-related feature so I'm pretty sure my answer is wrong.我在想它会检查指针和 arrays 是否基本相同,但这不是与内存相关的功能,所以我很确定我的答案是错误的。

Could someone help, please?有人可以帮忙吗? And also, what are the memory-related ISA features?此外,与内存相关的 ISA 功能是什么?

Thank you!谢谢!

The answer from Retired Ninja is way more than you ever want to know, but the shorter version is that the mystery code is testing the endian-ness of the CPU.来自 Retired Ninja 的答案比你想知道的要多得多,但更简短的版本是神秘代码正在测试 CPU 的字节序。

We all know that memory in modern CPUs is byte oriented, but when it's storing a larger item - say, a 4-byte integer - what order does it lay down the components?我们都知道现代 CPU 中的 memory 是面向字节的,但是当它存储更大的项目时 - 例如,一个 4 字节的 integer - 它放置组件的顺序是什么?

Imagine the integer value 0x11223344, which is four separate bytes (0x11.. 0x44).想象一下 integer 值 0x11223344,即四个单独的字节 (0x11.. 0x44)。 They can't all fit at a single byte memory address, so the CPU has to put them in some kind of order.它们不能全部放在单个字节 memory 地址中,因此 CPU 必须将它们按某种顺序排列。

Little-endian means the low part - the 0x44 - is in the lowest memory address, while big-endian puts the most significant byte first; Little-endian 表示低位 - 0x44 - 位于最低的 memory 地址中,而 big-endian 将最高有效字节放在首位; here we're pretending that it's stored at memory location 0x9000 (chosen at random):这里我们假设它存储在 memory 位置 0x9000(随机选择):

        Little   Big -endian
0x9000: x44     x11
0x9001: x33     x22
0x9002: x22     x33
0x9003: x11     x44

It has to pick something , right?它必须选择一些东西,对吗?

The code you're considering is storing an integer 1 value into a 4 (or 8) byte chunk of memory, so it's going to be in one of these two organizations:您正在考虑的代码是将 integer 1 值存储到 memory 的 4(或 8)字节块中,因此它将位于以下两个组织之一中:

        Little  Big
0x9000: x01     x00   
0x9001: x00     x00
0x9002: x00     x00
0x9003: x00     x01

But by turning an integer pointer into a char pointer, it's looking at only the low byte, and the 0/1 value tells you if this is big-endian or little-endian.但是通过将integer指针转换为char指针,它只查看低字节,0/1 值告诉您这是大端还是小端。

Return is X/0 for little-endian or Y/1 for big-endian.对于 little-endian,返回 X/0,对于 big-endian,返回 Y/1。

Good luck on your exam.祝你考试顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM