Assembly Loop: How many times does NOP run?

  • #1
JJBladester
Gold Member
286
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.
 

Answers and Replies

  • #2
35,052
6,788

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?
 
  • #3
rcgldr
Homework Helper
8,756
555
If you want a delay that isn't processor dependent, why not read the countdown timer from the 8253 itself?
 
  • #4
JJBladester
Gold Member
286
2
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.
 
  • #5
rcgldr
Homework Helper
8,756
555
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).
 

Related Threads on Assembly Loop: How many times does NOP run?

Replies
1
Views
1K
  • Last Post
Replies
5
Views
14K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
8
Views
2K
Replies
16
Views
8K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
1
Views
1K
Replies
1
Views
2K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
1
Views
2K
Top