Assembly Loop: How many times does NOP run?

  • Thread starter Thread starter JJBladester
  • Start date Start date
  • Tags Tags
    Assembly Loop
Click For Summary
The discussion focuses on calculating the number of NOP instructions executed in a nested assembly loop designed for a delay. The outer loop runs 4000 times, and the inner loop executes 62000 times, with four NOP instructions in each inner iteration. The correct calculation reveals that the NOP instructions run 248,000 times for each outer loop iteration, totaling 992,000 NOPs across all iterations. The conversation also touches on the importance of measuring the delay accurately to determine processor speed, suggesting that an 8253 timer could be used for more precise timing. The exercise emphasizes understanding the relationship between the loop execution and the processor's performance.
JJBladester
Gold Member
Messages
281
Reaction score
2

Homework Statement



How many NOP instructions are run in the nested loop below?


OUTER DW 4000 ;outer loop count
INNER DW 62000 ;inner loop count

MOV DX,OUTER
WAIT1: MOV CX,INNER
WAIT2:
NOP
NOP
NOP
NOP
LOOP WAIT2
DEC DX
JNZ WAIT1
RET
DELAY ENDP


The Attempt at a Solution



I am creating a delay loop for use with an 8253 timer which is used to create a tone on a PC's internal speaker. The program is written in assembly. I am having a hard time figuring out how many times NOP executes in the code above.

I believe it is inner + outer = (4)(62000) + (4)(4000) = 264,000.

Any insight would be appreciated.
 
Physics news on Phys.org
JJBladester said:

Homework Statement



How many NOP instructions are run in the nested loop below?


OUTER DW 4000 ;outer loop count
INNER DW 62000 ;inner loop count

MOV DX,OUTER
WAIT1: MOV CX,INNER
WAIT2:
NOP
NOP
NOP
NOP
LOOP WAIT2
DEC DX
JNZ WAIT1
RET
DELAY ENDP


The Attempt at a Solution



I am creating a delay loop for use with an 8253 timer which is used to create a tone on a PC's internal speaker. The program is written in assembly. I am having a hard time figuring out how many times NOP executes in the code above.

I believe it is inner + outer = (4)(62000) + (4)(4000) = 264,000.

Any insight would be appreciated.

I think you're way off. For each iteration of the outer loop, the inner loop runs 62,000 times, so the NOP instructions run 62,000 * 4 = 248,000 times.

That's for each iteration of the outer loop, which runs 4000 times. What does that mean for the statements in the inner loop body?
 
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?
 
rcgldr said:
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?

One of the points of the exercise is to determine the speed of the computer's processor by how long it takes the NOP loop to run (how long the tone plays).

You're right, processor independence would normally be desired, but not in this case.
 
JJBladester said:
One of the points of the exercise is to determine the speed of the computer's processor by how long it takes the NOP loop to run (how long the tone plays).
You could run the loop and read the timer before and after the loop. However the timer may wrap around if your loop takes too long. One way to avoid this would be to intercept the timer interrupt and use an interrupt count as the "upper" bits of the counter timer. Depending on how the timer is programmed, it may count down by 1 or count down by 2 (if it's by 2, there's a sequence of port I/O writes and reads to get the upper bit of the counter).
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
Replies
6
Views
2K