Worst case memory access in 80×86 assembly

assembly

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

add dword [x],0x123FA4

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

Best Answer

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.

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.

So, the worst case should be 8 memory operations.