80x86汇编中最坏的内存访问

时间:2022-04-07 03:13:52

In a 80486 computer, what is the worst case (include the fetch) number of memory accesses of this instruction:

在80486计算机中,该指令的最坏情况(包括获取)内存访问次数是多少:

add dword [x],0x123FA4

It is known that an opcode with no operands is two bytes in length.

众所周知,没有操作数的操作码的长度是两个字节。

1 个解决方案

#1


From memory, the instruction has an opcode byte ("add"), an address mode byte, an offset for x (4 bytes) and the constant (4 bytes) ==> 10 bytes. I assume the 486 fetches 4 bytes at a time from memory with a bus address aligned to 4 byte DWORD boundaries. So 10 bytes arguably takes 3 memory reads (= 10/4 rounded up) no matter where you place them. Howevever, if the opcode byte is place in the last byte of a DWORD, the remaining 9 bytes span 3 more DWORDS to the total number of reads can actually be 4.

从存储器开始,指令具有操作码字节(“add”),地址模式字节,x(4字节)的偏移量和常量(4字节)==> 10字节。我假设486一次从存储器中取出4个字节,总线地址与4字节DWORD边界对齐。所以10个字节可以说需要3个内存读取(= 10/4向上舍入),无论你放在哪里。但是,如果操作码字节位于DWORD的最后一个字节中,则剩余的9个字节跨越3个以上的DWORDS到读取的总数实际上可以是4。

To do the add, the location X must be fetched. Assume X is split across a DWORD boundary -> 2 reads. Adding the constant happens inside the CPU, and the sum is written back across that same DWORD boundary split --> 2 writes.

要执行添加,必须获取位置X.假设X在DWORD边界上分割 - > 2次读取。添加常量发生在CPU内部,并且总和被写回到相同的DWORD边界分割 - > 2次写入。

So, the worst case should be 8 memory operations.

因此,最坏的情况应该是8个内存操作。

#1


From memory, the instruction has an opcode byte ("add"), an address mode byte, an offset for x (4 bytes) and the constant (4 bytes) ==> 10 bytes. I assume the 486 fetches 4 bytes at a time from memory with a bus address aligned to 4 byte DWORD boundaries. So 10 bytes arguably takes 3 memory reads (= 10/4 rounded up) no matter where you place them. Howevever, if the opcode byte is place in the last byte of a DWORD, the remaining 9 bytes span 3 more DWORDS to the total number of reads can actually be 4.

从存储器开始,指令具有操作码字节(“add”),地址模式字节,x(4字节)的偏移量和常量(4字节)==> 10字节。我假设486一次从存储器中取出4个字节,总线地址与4字节DWORD边界对齐。所以10个字节可以说需要3个内存读取(= 10/4向上舍入),无论你放在哪里。但是,如果操作码字节位于DWORD的最后一个字节中,则剩余的9个字节跨越3个以上的DWORDS到读取的总数实际上可以是4。

To do the add, the location X must be fetched. Assume X is split across a DWORD boundary -> 2 reads. Adding the constant happens inside the CPU, and the sum is written back across that same DWORD boundary split --> 2 writes.

要执行添加,必须获取位置X.假设X在DWORD边界上分割 - > 2次读取。添加常量发生在CPU内部,并且总和被写回到相同的DWORD边界分割 - > 2次写入。

So, the worst case should be 8 memory operations.

因此,最坏的情况应该是8个内存操作。