GYLNBSF
GYLNBSF
关注数: 54
粉丝数: 34
发帖数: 3,358
关注贴吧数: 32
求大佬帮忙看道题 use C++ Using timing code , design a program that times the how long it takes to write a byte to 2048 memory locations with a variable 'skip'. The skip number should be placed in a loop and should be iterated from 0 to 20000. At each iteration, use printf to write out the number of clock cycles it takes to complete that iteration For example, a 0 skip would write to the 0 memory location 2048 times. A skip of 1 would write to memory location 0, memory location 1.... all the way to memory location 2047. Skip 2 would write to 0,2,4,6, and etc. You would get results for When complete, put your results in excel (time on the Y axis and skip on the X) and see if you can locate where each cache is exceeded. The timing program : #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { char format[] = "Time: %d"; int val; char cache[1000000]; __asm { mov ecx, 2048; lea edi, cache; RDTSC; //Start Time EDX:EAX mov[edi], al; add edi, 16; mov ebx, eax; mov ecx, edx; RDTSC; //End Time sub eax, ebx; sbb edx, ecx; push eax; lea esi, format; push esi; call printf; pop esi; pop esi; nop; } return 0; }
1
下一页