delay with MOV/LOOP

Typical Pentium software delay loops can be written using MOV and LOOP instructions.
For example, the following instruction sequence can be used for a delay loop: MOV CX,countDELAY: LOOP DELAY
The initial loop counter value of “count” can be calculated using the cycles required to execute the following Pentium instructions:MOV reg/imm (1 cycle)LOOP label (5/6 cycles)
Note that the Pentium LOOP instruction requires two different execution times. LOOP requires six cycles when the Pentium branches if the CX is not equal to zero after autodecrementing CX by 1. However, the Pentium goes to the next instruction and does not branch when CX = 0 after autodecrementing CX by 1, and this requires five cycles.
This means that the DELAY loop will require six cycles for (count - 1) times, and the last iteration will take five cycles.
For a 100-MHz Pentium clock, each cycle is 10 ns. For 2 ms, total cycles =2ms/10ns= 200,000. The loop will require six cycles for (count - 1) times when CX + 0, and five cycles will be required when no branch is taken (CX = 0). Thus, total cycles including the MOV = 1 + 6 x (count - 1) + 5 = 200,000. Hence, count = 33,333,0. Therefore, CX must be loaded with 33,33310

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章