1

How many memory accesses are required in the worst case for the following instructions:

add edx, (to_printf-next_i) ; where to_printf and next_i are labels defined in .text
inc dword [myarray + ebx*4] ; where myarray is a label defined in .data 

Is my answer true?

  1. 0 , since we do not access memory here
  2. fetch: 4 bytes for the address : myarray + ebx*4 -> 2 memory accesses in the worst case
     write: 4 bytes because of "dword" -> 2 memory accesses in the worst case
     read? 
1
  • You want to count the accesses required to fetch the instructions? :) Commented Jun 25, 2012 at 8:27

1 Answer 1

3

inc does 3 things: reads the operand, adds 1 to it, writes the operand back. If the operand is in memory, you normally have 1 read access and 1 write access.

If the operand crosses a cache line boundary, then every access turns into 2 accesses.

But this can be much worse when page translation and virtual memory are enabled and the memory this instruction references is on the disk. TLB misses, other cache misses and all the page table and I/O activity that the OS needs to do to let the instruction execute may incur many more memory accesses. It's nearly impossible to tell how many are needed for this kind of worst case.

Sign up to request clarification or add additional context in comments.

4 Comments

thank you! before i read your answer, my answer to 1 is true?
Unless we also count accesses caused by instruction fetches, the first answer is correct.
thank how do i know ount accesses caused by instruction fetches(in question 1 and 2 and in general?)
It should be the same kind of thing as with data accesses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.